109 defaultnsgroup=config['pyro-ns-group'], |
109 defaultnsgroup=config['pyro-ns-group'], |
110 nshost=config['pyro-ns-host']) |
110 nshost=config['pyro-ns-host']) |
111 except Exception, ex: |
111 except Exception, ex: |
112 raise ConnectionError(str(ex)) |
112 raise ConnectionError(str(ex)) |
113 |
113 |
114 def repo_connect(repo, login, password, cnxprops=None): |
114 def repo_connect(repo, login, **kwargs): |
115 """Constructor to create a new connection to the CubicWeb repository. |
115 """Constructor to create a new connection to the CubicWeb repository. |
116 |
116 |
117 Returns a Connection instance. |
117 Returns a Connection instance. |
118 """ |
118 """ |
119 cnxprops = cnxprops or ConnectionProperties('inmemory') |
119 if not 'cnxprops' in kwargs: |
120 cnxid = repo.connect(unicode(login), password, cnxprops=cnxprops) |
120 kwargs['cnxprops'] = ConnectionProperties('inmemory') |
121 cnx = Connection(repo, cnxid, cnxprops) |
121 cnxid = repo.connect(unicode(login), **kwargs) |
122 if cnxprops.cnxtype == 'inmemory': |
122 cnx = Connection(repo, cnxid, kwargs['cnxprops']) |
|
123 if kwargs['cnxprops'].cnxtype == 'inmemory': |
123 cnx.vreg = repo.vreg |
124 cnx.vreg = repo.vreg |
124 return cnx |
125 return cnx |
125 |
126 |
126 def connect(database=None, login=None, password=None, host=None, group=None, |
127 def connect(database=None, login=None, host=None, group=None, |
127 cnxprops=None, setvreg=True, mulcnx=True, initlog=True): |
128 cnxprops=None, setvreg=True, mulcnx=True, initlog=True, **kwargs): |
128 """Constructor for creating a connection to the CubicWeb repository. |
129 """Constructor for creating a connection to the CubicWeb repository. |
129 Returns a Connection object. |
130 Returns a Connection object. |
130 |
131 |
131 When method is 'pyro', setvreg is True, try to deal with connections to |
132 When method is 'pyro', setvreg is True, try to deal with connections to |
132 differents instances in the same process unless specified otherwise by |
133 differents instances in the same process unless specified otherwise by |
152 print 'aliasing', newetype, 'to', oldetype |
153 print 'aliasing', newetype, 'to', oldetype |
153 schema._entities[newetype] = schema._entities[oldetype] |
154 schema._entities[newetype] = schema._entities[oldetype] |
154 vreg.set_schema(schema) |
155 vreg.set_schema(schema) |
155 else: |
156 else: |
156 vreg = None |
157 vreg = None |
157 cnx = repo_connect(repo, login, password, cnxprops) |
158 cnx = repo_connect(repo, login, cnxprops=cnxprops, **kwargs) |
158 cnx.vreg = vreg |
159 cnx.vreg = vreg |
159 return cnx |
160 return cnx |
160 |
161 |
161 def in_memory_cnx(config, login, password): |
162 def in_memory_cnx(config, login, **kwargs): |
162 """usefull method for testing and scripting to get a dbapi.Connection |
163 """usefull method for testing and scripting to get a dbapi.Connection |
163 object connected to an in-memory repository instance |
164 object connected to an in-memory repository instance |
164 """ |
165 """ |
165 if isinstance(config, cwvreg.CubicWebVRegistry): |
166 if isinstance(config, cwvreg.CubicWebVRegistry): |
166 vreg = config |
167 vreg = config |
169 vreg = None |
170 vreg = None |
170 # get local access to the repository |
171 # get local access to the repository |
171 repo = get_repository('inmemory', config=config, vreg=vreg) |
172 repo = get_repository('inmemory', config=config, vreg=vreg) |
172 # connection to the CubicWeb repository |
173 # connection to the CubicWeb repository |
173 cnxprops = ConnectionProperties('inmemory') |
174 cnxprops = ConnectionProperties('inmemory') |
174 cnx = repo_connect(repo, login, password, cnxprops=cnxprops) |
175 cnx = repo_connect(repo, login, cnxprops=cnxprops, **kwargs) |
175 return repo, cnx |
176 return repo, cnx |
176 |
177 |
177 |
178 |
178 class DBAPIRequest(RequestSessionBase): |
179 class DBAPIRequest(RequestSessionBase): |
179 |
180 |