[MERGE] Merged with addons/trunk.
[odoo/odoo.git] / addons / auth_openid / utils.py
1 #!/usr/bin/env python
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2010-2011 OpenERP s.a. (<http://openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21 from contextlib import contextmanager
22 from openerp.modules.registry import RegistryManager
23
24 KEY_LENGTH = 16
25
26 SREG2AX = {     # from http://www.axschema.org/types/#sreg
27     'nickname': 'http://axschema.org/namePerson/friendly',
28     'email': 'http://axschema.org/contact/email',
29     'fullname': 'http://axschema.org/namePerson',
30     'dob': 'http://axschema.org/birthDate',
31     'gender': 'http://axschema.org/person/gender',
32     'postcode': 'http://axschema.org/contact/postalCode/home',
33     'country': 'http://axschema.org/contact/country/home',
34     'language': 'http://axschema.org/pref/language',
35     'timezone': 'http://axschema.org/pref/timezone',
36 }
37
38
39 @contextmanager
40 def cursor(db):
41     cr = RegistryManager.get(db).db.cursor()
42     try:
43         yield cr
44     finally:
45         cr.close()
46
47
48 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: