dbapi.py
changeset 8673 8ea63a2cc2cc
parent 8670 f02139297beb
child 8682 20bd1cdf86ae
equal deleted inserted replaced
8672:e8afecc3b576 8673:8ea63a2cc2cc
   130         return ZMQRepositoryClient(uri)
   130         return ZMQRepositoryClient(uri)
   131     else:
   131     else:
   132         raise ConnectionError('unknown protocol: `%s`' % method)
   132         raise ConnectionError('unknown protocol: `%s`' % method)
   133 
   133 
   134 
   134 
   135 def repo_connect(repo, login, **kwargs):
   135 def _repo_connect(repo, login, **kwargs):
   136     """Constructor to create a new connection to the given CubicWeb repository.
   136     """Constructor to create a new connection to the given CubicWeb repository.
   137 
   137 
   138     Returns a Connection instance.
   138     Returns a Connection instance.
   139 
   139 
   140     Raises AuthenticationError if authentication failed
   140     Raises AuthenticationError if authentication failed
   231                 print 'aliasing', newetype, 'to', oldetype
   231                 print 'aliasing', newetype, 'to', oldetype
   232                 schema._entities[newetype] = schema._entities[oldetype]
   232                 schema._entities[newetype] = schema._entities[oldetype]
   233         vreg.set_schema(schema)
   233         vreg.set_schema(schema)
   234     else:
   234     else:
   235         vreg = None
   235         vreg = None
   236     cnx = repo_connect(repo, login, cnxprops=cnxprops, **kwargs)
   236     cnx = _repo_connect(repo, login, cnxprops=cnxprops, **kwargs)
   237     cnx.vreg = vreg
   237     cnx.vreg = vreg
   238     return cnx
   238     return cnx
   239 
   239 
   240 def in_memory_repo(config):
   240 def in_memory_repo(config):
   241     """Return and in_memory Repository object from a config (or vreg)"""
   241     """Return and in_memory Repository object from a config (or vreg)"""
   251     """useful method for testing and scripting to get a dbapi.Connection
   251     """useful method for testing and scripting to get a dbapi.Connection
   252     object connected to an in-memory repository instance
   252     object connected to an in-memory repository instance
   253     """
   253     """
   254     # connection to the CubicWeb repository
   254     # connection to the CubicWeb repository
   255     repo = in_memory_repo(config)
   255     repo = in_memory_repo(config)
   256     return repo, repo_connect(repo, login, **kwargs)
   256     return repo, _repo_connect(repo, login, **kwargs)
   257 
   257 
   258 # XXX web only method, move to webconfig?
   258 # XXX web only method, move to webconfig?
   259 def anonymous_session(vreg):
   259 def anonymous_session(vreg):
   260     """return a new anonymous session
   260     """return a new anonymous session
   261 
   261 
   265     if anoninfo is None: # no anonymous user
   265     if anoninfo is None: # no anonymous user
   266         raise AuthenticationError('anonymous access is not authorized')
   266         raise AuthenticationError('anonymous access is not authorized')
   267     anon_login, anon_password = anoninfo
   267     anon_login, anon_password = anoninfo
   268     # use vreg's repository cache
   268     # use vreg's repository cache
   269     repo = vreg.config.repository(vreg)
   269     repo = vreg.config.repository(vreg)
   270     anon_cnx = repo_connect(repo, anon_login, password=anon_password)
   270     anon_cnx = _repo_connect(repo, anon_login, password=anon_password)
   271     anon_cnx.vreg = vreg
   271     anon_cnx.vreg = vreg
   272     return DBAPISession(anon_cnx, anon_login)
   272     return DBAPISession(anon_cnx, anon_login)
   273 
   273 
   274 
   274 
   275 class _NeedAuthAccessMock(object):
   275 class _NeedAuthAccessMock(object):
   875         him).
   875         him).
   876         """
   876         """
   877         return self._repo.undo_transaction(self.sessionid, txuuid,
   877         return self._repo.undo_transaction(self.sessionid, txuuid,
   878                                            **self._txid())
   878                                            **self._txid())
   879 
   879 
   880 in_memory_cnx = deprecated('[3.16] use repo_connect instead)')(repo_connect)
   880 in_memory_cnx = deprecated('[3.16] use _repo_connect instead)')(_repo_connect)