dbapi.py
changeset 7876 df15d194a134
parent 7815 2a164a9cf81c
child 7894 ad0eeb0f7a8d
equal deleted inserted replaced
7875:65e460690139 7876:df15d194a134
   221     additionel credential might be required"""
   221     additionel credential might be required"""
   222     cnxprops = ConnectionProperties('inmemory')
   222     cnxprops = ConnectionProperties('inmemory')
   223     return repo_connect(repo, login, cnxprops=cnxprops, **kwargs)
   223     return repo_connect(repo, login, cnxprops=cnxprops, **kwargs)
   224 
   224 
   225 def in_memory_repo_cnx(config, login, **kwargs):
   225 def in_memory_repo_cnx(config, login, **kwargs):
   226     """usefull method for testing and scripting to get a dbapi.Connection
   226     """useful method for testing and scripting to get a dbapi.Connection
   227     object connected to an in-memory repository instance
   227     object connected to an in-memory repository instance
   228     """
   228     """
   229     # connection to the CubicWeb repository
   229     # connection to the CubicWeb repository
   230     repo = in_memory_repo(config)
   230     repo = in_memory_repo(config)
   231     return repo, in_memory_cnx(repo, login, **kwargs)
   231     return repo, in_memory_cnx(repo, login, **kwargs)
       
   232 
       
   233 
       
   234 def anonymous_session(vreg):
       
   235     """return a new anonymous session
       
   236 
       
   237     raises an AuthenticationError if anonymous usage is not allowed
       
   238     """
       
   239     anoninfo = vreg.config.anonymous_user()
       
   240     if anoninfo is None: # no anonymous user
       
   241         raise AuthenticationError('anonymous access is not authorized')
       
   242     anon_login, anon_password = anoninfo
       
   243     cnxprops = ConnectionProperties(vreg.config.repo_method)
       
   244     # use vreg's repository cache
       
   245     repo = vreg.config.repository(vreg)
       
   246     anon_cnx = repo_connect(repo, anon_login,
       
   247                             cnxprops=cnxprops, password=anon_password)
       
   248     anon_cnx.vreg = vreg
       
   249     return DBAPISession(anon_cnx, anon_login)
       
   250 
   232 
   251 
   233 class _NeedAuthAccessMock(object):
   252 class _NeedAuthAccessMock(object):
   234     def __getattribute__(self, attr):
   253     def __getattribute__(self, attr):
   235         raise AuthenticationError()
   254         raise AuthenticationError()
   236     def __nonzero__(self):
   255     def __nonzero__(self):