server/session.py
changeset 10362 ec8c233ce54b
parent 10361 46d72f33c428
child 10364 8b35a898b334
equal deleted inserted replaced
10361:46d72f33c428 10362:ec8c233ce54b
    74         return obj.allow_all_hooks_but(*categories)
    74         return obj.allow_all_hooks_but(*categories)
    75     elif mode == HOOKS_DENY_ALL:
    75     elif mode == HOOKS_DENY_ALL:
    76         return obj.deny_all_hooks_but(*categories)
    76         return obj.deny_all_hooks_but(*categories)
    77 
    77 
    78 
    78 
    79 class _hooks_control(object): # XXX repoapi: remove me when
    79 class _hooks_control(object):
    80                               # session stop being connection
       
    81     """context manager to control activated hooks categories.
    80     """context manager to control activated hooks categories.
    82 
    81 
    83     If mode is `HOOKS_DENY_ALL`, given hooks categories will
    82     If mode is `HOOKS_DENY_ALL`, given hooks categories will
    84     be enabled.
    83     be enabled.
    85 
    84 
   125                 else:
   124                 else:
   126                     self.cnx.enable_hook_categories(*self.categories)
   125                     self.cnx.enable_hook_categories(*self.categories)
   127         finally:
   126         finally:
   128             self.cnx.hooks_mode = self.oldmode
   127             self.cnx.hooks_mode = self.oldmode
   129 
   128 
   130 class _session_hooks_control(_hooks_control): # XXX repoapi: remove me when
       
   131                                               # session stop being connection
       
   132     """hook control context manager for session
       
   133 
       
   134     Necessary to handle some unholy transaction scope logic."""
       
   135 
       
   136 
       
   137     def __init__(self, session, mode, *categories):
       
   138         self.session = session
       
   139         super_init = super(_session_hooks_control, self).__init__
       
   140         super_init(session._cnx, mode, *categories)
       
   141 
       
   142     def __exit__(self, exctype, exc, traceback):
       
   143         super_exit = super(_session_hooks_control, self).__exit__
       
   144         ret = super_exit(exctype, exc, traceback)
       
   145         if self.cnx.ctx_count == 0:
       
   146             self.session._close_cnx(self.cnx)
       
   147         return ret
       
   148 
   129 
   149 @deprecated('[3.17] use <object>.security_enabled instead')
   130 @deprecated('[3.17] use <object>.security_enabled instead')
   150 def security_enabled(obj, *args, **kwargs):
   131 def security_enabled(obj, *args, **kwargs):
   151     return obj.security_enabled(*args, **kwargs)
   132     return obj.security_enabled(*args, **kwargs)
   152 
   133 
   180         self.cnx.ctx_count -= 1
   161         self.cnx.ctx_count -= 1
   181         if self.oldread is not None:
   162         if self.oldread is not None:
   182             self.cnx.read_security = self.oldread
   163             self.cnx.read_security = self.oldread
   183         if self.oldwrite is not None:
   164         if self.oldwrite is not None:
   184             self.cnx.write_security = self.oldwrite
   165             self.cnx.write_security = self.oldwrite
   185 
       
   186 class _session_security_enabled(_security_enabled):
       
   187     """hook security context manager for session
       
   188 
       
   189     Necessary To handle some unholy transaction scope logic."""
       
   190 
       
   191 
       
   192     def __init__(self, session, read=None, write=None):
       
   193         self.session = session
       
   194         super_init = super(_session_security_enabled, self).__init__
       
   195         super_init(session._cnx, read=read, write=write)
       
   196 
       
   197     def __exit__(self, exctype, exc, traceback):
       
   198         super_exit = super(_session_security_enabled, self).__exit__
       
   199         ret = super_exit(exctype, exc, traceback)
       
   200         if self.cnx.ctx_count == 0:
       
   201             self.session._close_cnx(self.cnx)
       
   202         return ret
       
   203 
   166 
   204 HOOKS_ALLOW_ALL = object()
   167 HOOKS_ALLOW_ALL = object()
   205 HOOKS_DENY_ALL = object()
   168 HOOKS_DENY_ALL = object()
   206 DEFAULT_SECURITY = object() # evaluated to true by design
   169 DEFAULT_SECURITY = object() # evaluated to true by design
   207 
   170