177 group = 'cubicweb' |
177 group = 'cubicweb' |
178 database = 'pyro://%s/%s.%s' % (host, group, database) |
178 database = 'pyro://%s/%s.%s' % (host, group, database) |
179 puri = urlparse(database) |
179 puri = urlparse(database) |
180 method = puri.scheme.lower() |
180 method = puri.scheme.lower() |
181 if method == 'inmemory': |
181 if method == 'inmemory': |
182 config = cwconfig.instance_configuration(puri.path) |
182 config = cwconfig.instance_configuration(puri.netloc) |
183 else: |
183 else: |
184 config = cwconfig.CubicWebNoAppConfiguration() |
184 config = cwconfig.CubicWebNoAppConfiguration() |
185 repo = get_repository(database, config=config) |
185 repo = get_repository(database, config=config) |
186 if method == 'inmemory': |
186 if method == 'inmemory': |
187 vreg = repo.vreg |
187 vreg = repo.vreg |
224 """return a new anonymous session |
224 """return a new anonymous session |
225 |
225 |
226 raises an AuthenticationError if anonymous usage is not allowed |
226 raises an AuthenticationError if anonymous usage is not allowed |
227 """ |
227 """ |
228 anoninfo = vreg.config.anonymous_user() |
228 anoninfo = vreg.config.anonymous_user() |
229 if anoninfo is None: # no anonymous user |
229 if anoninfo[0] is None: # no anonymous user |
230 raise AuthenticationError('anonymous access is not authorized') |
230 raise AuthenticationError('anonymous access is not authorized') |
231 anon_login, anon_password = anoninfo |
231 anon_login, anon_password = anoninfo |
232 # use vreg's repository cache |
232 # use vreg's repository cache |
233 repo = vreg.config.repository(vreg) |
233 repo = vreg.config.repository(vreg) |
234 anon_cnx = _repo_connect(repo, anon_login, password=anon_password) |
234 anon_cnx = _repo_connect(repo, anon_login, password=anon_password) |
363 |
363 |
364 def source_defs(self): |
364 def source_defs(self): |
365 """return the definition of sources used by the repository.""" |
365 """return the definition of sources used by the repository.""" |
366 return self.cnx.source_defs() |
366 return self.cnx.source_defs() |
367 |
367 |
368 @deprecated('[3.8] use direct access to req.session.data dictionary') |
|
369 def session_data(self): |
|
370 """return a dictionary containing session data""" |
|
371 return self.session.data |
|
372 |
|
373 @deprecated('[3.8] use direct access to req.session.data dictionary') |
|
374 def get_session_data(self, key, default=None, pop=False): |
|
375 if pop: |
|
376 return self.session.data.pop(key, default) |
|
377 return self.session.data.get(key, default) |
|
378 |
|
379 @deprecated('[3.8] use direct access to req.session.data dictionary') |
|
380 def set_session_data(self, key, value): |
|
381 self.session.data[key] = value |
|
382 |
|
383 @deprecated('[3.8] use direct access to req.session.data dictionary') |
|
384 def del_session_data(self, key): |
|
385 self.session.data.pop(key, None) |
|
386 |
|
387 # these are overridden by set_log_methods below |
368 # these are overridden by set_log_methods below |
388 # only defining here to prevent pylint from complaining |
369 # only defining here to prevent pylint from complaining |
389 info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
370 info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None |
390 |
371 |
391 set_log_methods(DBAPIRequest, getLogger('cubicweb.dbapi')) |
372 set_log_methods(DBAPIRequest, getLogger('cubicweb.dbapi')) |
417 pass |
398 pass |
418 |
399 |
419 def _txid(self): |
400 def _txid(self): |
420 return self.connection._txid(self) |
401 return self.connection._txid(self) |
421 |
402 |
422 def execute(self, rql, args=None, eid_key=None, build_descr=True): |
403 def execute(self, rql, args=None, build_descr=True): |
423 """execute a rql query, return resulting rows and their description in |
404 """execute a rql query, return resulting rows and their description in |
424 a :class:`~cubicweb.rset.ResultSet` object |
405 a :class:`~cubicweb.rset.ResultSet` object |
425 |
406 |
426 * `rql` should be an Unicode string or a plain ASCII string, containing |
407 * `rql` should be an Unicode string or a plain ASCII string, containing |
427 the rql query |
408 the rql query |
448 |
429 |
449 use:: |
430 use:: |
450 |
431 |
451 execute('Any X WHERE X eid %(x)s', {'x': 123}) |
432 execute('Any X WHERE X eid %(x)s', {'x': 123}) |
452 """ |
433 """ |
453 if eid_key is not None: |
|
454 warn('[3.8] eid_key is deprecated, you can safely remove this argument', |
|
455 DeprecationWarning, stacklevel=2) |
|
456 # XXX use named argument for build_descr in case repo is < 3.8 |
|
457 rset = self._repo.execute(self._sessid, rql, args, |
434 rset = self._repo.execute(self._sessid, rql, args, |
458 build_descr=build_descr, **self._txid()) |
435 build_descr=build_descr, **self._txid()) |
459 rset.req = self.req |
436 rset.req = self.req |
460 return rset |
437 return rset |
461 |
438 |