equal
deleted
inserted
replaced
|
1 from AccessControl import getSecurityManager |
|
2 |
|
3 from cubicweb.dbapi import connect, Connection, Cursor |
|
4 from cubicweb.common.utils import ResultSet, ResultSetIterator, ResultSetRow, Entity |
|
5 |
|
6 Connection.__allow_access_to_unprotected_subobjects__ = 1 |
|
7 Cursor.__allow_access_to_unprotected_subobjects__ = 1 |
|
8 ResultSet.__allow_access_to_unprotected_subobjects__ = 1 |
|
9 ResultSetIterator.__allow_access_to_unprotected_subobjects__ = 1 |
|
10 ResultSetRow.__allow_access_to_unprotected_subobjects__ = 1 |
|
11 Entity.__allow_access_to_unprotected_subobjects__ = 1 |
|
12 |
|
13 CNX_CACHE = {} |
|
14 |
|
15 def get_connection(context, user=None, password=None, |
|
16 host=None, database=None, group='cubicweb'): |
|
17 """get a connection on an cubicweb server""" |
|
18 request = context.REQUEST |
|
19 zope_user = getSecurityManager().getUser() |
|
20 if user is None: |
|
21 user = zope_user.getId() |
|
22 key = (user, host, database) |
|
23 try: |
|
24 return CNX_CACHE[key] |
|
25 except KeyError: |
|
26 if password is None: |
|
27 password = zope_user._getPassword() |
|
28 cnx = connect(user, password, host, database, group) |
|
29 CNX_CACHE[key] = cnx |
|
30 return cnx |
|
31 |