cubicweb/server/repository.py
changeset 12021 cc8135ecfbb8
parent 12016 88ed82a25f8a
child 12025 ba79f4a4f5d8
equal deleted inserted replaced
12020:304477158337 12021:cc8135ecfbb8
    46                       UnknownEid, AuthenticationError, ExecutionError,
    46                       UnknownEid, AuthenticationError, ExecutionError,
    47                       BadConnectionId,
    47                       BadConnectionId,
    48                       UniqueTogetherError, onevent, ViolatedConstraint)
    48                       UniqueTogetherError, onevent, ViolatedConstraint)
    49 from cubicweb import set_log_methods
    49 from cubicweb import set_log_methods
    50 from cubicweb import cwvreg, schema, server
    50 from cubicweb import cwvreg, schema, server
    51 from cubicweb.server import ShuttingDown, utils, hook, querier, sources
    51 from cubicweb.server import utils, hook, querier, sources
    52 from cubicweb.server.session import Session, InternalManager
    52 from cubicweb.server.session import Session, InternalManager
    53 
    53 
    54 
    54 
    55 NO_CACHE_RELATIONS = set([
    55 NO_CACHE_RELATIONS = set([
    56     ('owned_by', 'object'),
    56     ('owned_by', 'object'),
   698 
   698 
   699     @deprecated('[3.23] use .new_session instead (and get a plain session object)')
   699     @deprecated('[3.23] use .new_session instead (and get a plain session object)')
   700     def connect(self, login, **kwargs):
   700     def connect(self, login, **kwargs):
   701         return self.new_session(login, **kwargs).sessionid
   701         return self.new_session(login, **kwargs).sessionid
   702 
   702 
   703     @deprecated('[3.23] use session.close() directly')
       
   704     def close(self, sessionid):
       
   705         self._get_session(sessionid).close()
       
   706 
       
   707     # session handling ########################################################
   703     # session handling ########################################################
   708 
   704 
   709     def close_sessions(self):
   705     def close_sessions(self):
   710         """close every opened sessions"""
   706         """close every opened sessions"""
   711         for session in list(self._sessions.values()):
   707         for session in list(self._sessions.values()):
   735         """
   731         """
   736         with Session(InternalManager(), self).new_cnx() as cnx:
   732         with Session(InternalManager(), self).new_cnx() as cnx:
   737             cnx.user._cw = cnx  # XXX remove when "vreg = user._cw.vreg" hack in entity.py is gone
   733             cnx.user._cw = cnx  # XXX remove when "vreg = user._cw.vreg" hack in entity.py is gone
   738             with cnx.security_enabled(read=False, write=False):
   734             with cnx.security_enabled(read=False, write=False):
   739                 yield cnx
   735                 yield cnx
   740 
       
   741     def _get_session(self, sessionid, txid=None, checkshuttingdown=True):
       
   742         """return the session associated with the given session identifier"""
       
   743         if checkshuttingdown and self.shutting_down:
       
   744             raise ShuttingDown('Repository is shutting down')
       
   745         try:
       
   746             session = self._sessions[sessionid]
       
   747         except KeyError:
       
   748             raise BadConnectionId('No such session %s' % sessionid)
       
   749         return session
       
   750 
   736 
   751     # data sources handling ###################################################
   737     # data sources handling ###################################################
   752     # * correspondance between eid and type
   738     # * correspondance between eid and type
   753     # * correspondance between eid and local id (i.e. specific to a given source)
   739     # * correspondance between eid and local id (i.e. specific to a given source)
   754 
   740