server/session.py
changeset 9120 fa513ac7a2a5
parent 9113 af6efc15fc90
child 9121 182c620c960b
equal deleted inserted replaced
9119:cc85def2ac57 9120:fa513ac7a2a5
   162 
   162 
   163     def __exit__(self, exctype, exc, traceback):
   163     def __exit__(self, exctype, exc, traceback):
   164         super_exit = super(_session_hooks_control, self).__exit__
   164         super_exit = super(_session_hooks_control, self).__exit__
   165         ret = super_exit(exctype, exc, traceback)
   165         ret = super_exit(exctype, exc, traceback)
   166         if self.cnx.ctx_count == 0:
   166         if self.cnx.ctx_count == 0:
   167             self.session.close_cnx(self.cnx)
   167             self.session._close_cnx(self.cnx)
   168         return ret
   168         return ret
   169 
   169 
   170 @deprecated('[3.17] use <object>.security_enabled instead')
   170 @deprecated('[3.17] use <object>.security_enabled instead')
   171 def security_enabled(obj, *args, **kwargs):
   171 def security_enabled(obj, *args, **kwargs):
   172     return obj.security_enabled(*args, **kwargs)
   172     return obj.security_enabled(*args, **kwargs)
   217 
   217 
   218     def __exit__(self, exctype, exc, traceback):
   218     def __exit__(self, exctype, exc, traceback):
   219         super_exit = super(_session_security_enabled, self).__exit__
   219         super_exit = super(_session_security_enabled, self).__exit__
   220         ret = super_exit(exctype, exc, traceback)
   220         ret = super_exit(exctype, exc, traceback)
   221         if self.cnx.ctx_count == 0:
   221         if self.cnx.ctx_count == 0:
   222             self.session.close_cnx(self.cnx)
   222             self.session._close_cnx(self.cnx)
   223         return ret
   223         return ret
   224 
   224 
   225 HOOKS_ALLOW_ALL = object()
   225 HOOKS_ALLOW_ALL = object()
   226 HOOKS_DENY_ALL = object()
   226 HOOKS_DENY_ALL = object()
   227 DEFAULT_SECURITY = object() # evaluated to true by design
   227 DEFAULT_SECURITY = object() # evaluated to true by design
  1375 
  1375 
  1376         The returned Connection will *not* be managed by the Session.
  1376         The returned Connection will *not* be managed by the Session.
  1377         """
  1377         """
  1378         return Connection(self)
  1378         return Connection(self)
  1379 
  1379 
  1380     def get_cnx(self, cnxid):
  1380     def _get_cnx(self, cnxid):
  1381         """return the <cnxid> connection attached to this session
  1381         """return the <cnxid> connection attached to this session
  1382 
  1382 
  1383         Connection is created if necessary"""
  1383         Connection is created if necessary"""
  1384         with self._lock: # no connection exist with the same id
  1384         with self._lock: # no connection exist with the same id
  1385             try:
  1385             try:
  1392                 cnx = Connection(self, cnxid=cnxid, session_handled=True)
  1392                 cnx = Connection(self, cnxid=cnxid, session_handled=True)
  1393                 self._cnxs[cnxid] = cnx
  1393                 self._cnxs[cnxid] = cnx
  1394                 cnx.__enter__()
  1394                 cnx.__enter__()
  1395         return cnx
  1395         return cnx
  1396 
  1396 
  1397     def close_cnx(self, cnx):
  1397     def _close_cnx(self, cnx):
  1398         """Close a Connection related to a session"""
  1398         """Close a Connection related to a session"""
  1399         assert cnx._session_handled
  1399         assert cnx._session_handled
  1400         cnx.__exit__()
  1400         cnx.__exit__()
  1401         self._cnxs.pop(cnx.connectionid, None)
  1401         self._cnxs.pop(cnx.connectionid, None)
  1402         try:
  1402         try:
  1409         """set the default connection of the current thread to <cnxid>
  1409         """set the default connection of the current thread to <cnxid>
  1410 
  1410 
  1411         Connection is created if necessary"""
  1411         Connection is created if necessary"""
  1412         if cnxid is None:
  1412         if cnxid is None:
  1413             cnxid = threading.currentThread().getName()
  1413             cnxid = threading.currentThread().getName()
  1414         cnx = self.get_cnx(cnxid)
  1414         cnx = self._get_cnx(cnxid)
  1415         # New style session should not be accesed through the session.
  1415         # New style session should not be accesed through the session.
  1416         assert cnx._session_handled
  1416         assert cnx._session_handled
  1417         self.__threaddata.cnx = cnx
  1417         self.__threaddata.cnx = cnx
  1418 
  1418 
  1419     @property
  1419     @property
  1604             pass
  1604             pass
  1605         else:
  1605         else:
  1606             if free_cnxset:
  1606             if free_cnxset:
  1607                 self.free_cnxset()
  1607                 self.free_cnxset()
  1608                 if cnx.ctx_count == 0:
  1608                 if cnx.ctx_count == 0:
  1609                     self.close_cnx(cnx)
  1609                     self._close_cnx(cnx)
  1610                 else:
  1610                 else:
  1611                     cnx.clear()
  1611                     cnx.clear()
  1612             else:
  1612             else:
  1613                 cnx.clear()
  1613                 cnx.clear()
  1614 
  1614