author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 26 Aug 2009 19:17:50 +0200 | |
branch | stable |
changeset 3027 | 7fd294cbf6ff |
parent 2172 | cf8f9180e63e |
child 4212 | ab6573088b4a |
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 |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
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 |