author | Alexandre Fayolle <alexandre.fayolle@logilab.fr> |
Sun, 11 Apr 2010 11:59:45 +0000 | |
branch | stable |
changeset 5211 | 8fac9cd3c510 |
parent 4212 | ab6573088b4a |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
3 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2172
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
7 |
""" |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
8 |
from AccessControl import getSecurityManager |
0 | 9 |
|
10 |
from cubicweb.dbapi import connect, Connection, Cursor |
|
11 |
from cubicweb.common.utils import ResultSet, ResultSetIterator, ResultSetRow, Entity |
|
12 |
||
13 |
Connection.__allow_access_to_unprotected_subobjects__ = 1 |
|
14 |
Cursor.__allow_access_to_unprotected_subobjects__ = 1 |
|
15 |
ResultSet.__allow_access_to_unprotected_subobjects__ = 1 |
|
16 |
ResultSetIterator.__allow_access_to_unprotected_subobjects__ = 1 |
|
17 |
ResultSetRow.__allow_access_to_unprotected_subobjects__ = 1 |
|
18 |
Entity.__allow_access_to_unprotected_subobjects__ = 1 |
|
19 |
||
20 |
CNX_CACHE = {} |
|
21 |
||
22 |
def get_connection(context, user=None, password=None, |
|
23 |
host=None, database=None, group='cubicweb'): |
|
24 |
"""get a connection on an cubicweb server""" |
|
25 |
request = context.REQUEST |
|
26 |
zope_user = getSecurityManager().getUser() |
|
27 |
if user is None: |
|
28 |
user = zope_user.getId() |
|
29 |
key = (user, host, database) |
|
30 |
try: |
|
31 |
return CNX_CACHE[key] |
|
32 |
except KeyError: |
|
33 |
if password is None: |
|
34 |
password = zope_user._getPassword() |
|
35 |
cnx = connect(user, password, host, database, group) |
|
36 |
CNX_CACHE[key] = cnx |
|
37 |
return cnx |
|
38 |