server/session.py
changeset 8765 9e9029ba2d4e
parent 8764 c4f022a6c7dd
child 8766 db80ffb2f71c
equal deleted inserted replaced
8764:c4f022a6c7dd 8765:9e9029ba2d4e
   139             self.read, self.write)
   139             self.read, self.write)
   140 
   140 
   141     def __exit__(self, exctype, exc, traceback):
   141     def __exit__(self, exctype, exc, traceback):
   142         self.session.reset_security(self.oldread, self.oldwrite)
   142         self.session.reset_security(self.oldread, self.oldwrite)
   143 
   143 
       
   144 HOOKS_ALLOW_ALL = object()
       
   145 HOOKS_DENY_ALL = object()
   144 
   146 
   145 class Transaction(object):
   147 class Transaction(object):
   146     """Repository Transaction
   148     """Repository Transaction
   147 
   149 
   148     Holds all transaction related data
   150     Holds all transaction related data
   677         return getattr(self._threaddata, 'dbapi_query', True)
   679         return getattr(self._threaddata, 'dbapi_query', True)
   678 
   680 
   679     # hooks activation control #################################################
   681     # hooks activation control #################################################
   680     # all hooks should be activated during normal execution
   682     # all hooks should be activated during normal execution
   681 
   683 
   682     HOOKS_ALLOW_ALL = object()
       
   683     HOOKS_DENY_ALL = object()
       
   684 
       
   685     def allow_all_hooks_but(self, *categories):
   684     def allow_all_hooks_but(self, *categories):
   686         return hooks_control(self, self.HOOKS_ALLOW_ALL, *categories)
   685         return hooks_control(self, HOOKS_ALLOW_ALL, *categories)
   687     def deny_all_hooks_but(self, *categories):
   686     def deny_all_hooks_but(self, *categories):
   688         return hooks_control(self, self.HOOKS_DENY_ALL, *categories)
   687         return hooks_control(self, HOOKS_DENY_ALL, *categories)
   689 
   688 
   690     @property
   689     @property
   691     def hooks_mode(self):
   690     def hooks_mode(self):
   692         return getattr(self._threaddata, 'hooks_mode', self.HOOKS_ALLOW_ALL)
   691         return getattr(self._threaddata, 'hooks_mode', self.HOOKS_ALLOW_ALL)
   693 
   692 
   694     def set_hooks_mode(self, mode):
   693     def set_hooks_mode(self, mode):
   695         assert mode is self.HOOKS_ALLOW_ALL or mode is self.HOOKS_DENY_ALL
       
   696         oldmode = getattr(self._threaddata, 'hooks_mode', self.HOOKS_ALLOW_ALL)
   694         oldmode = getattr(self._threaddata, 'hooks_mode', self.HOOKS_ALLOW_ALL)
       
   695         assert mode is HOOKS_ALLOW_ALL or mode is HOOKS_DENY_ALL
   697         self._threaddata.hooks_mode = mode
   696         self._threaddata.hooks_mode = mode
   698         return oldmode
   697         return oldmode
   699 
   698 
   700     def init_hooks_mode_categories(self, mode, categories):
   699     def init_hooks_mode_categories(self, mode, categories):
   701         oldmode = self.set_hooks_mode(mode)
   700         oldmode = self.set_hooks_mode(mode)
   743         - on HOOKS_DENY_ALL mode, ensure those categories are not enabled
   742         - on HOOKS_DENY_ALL mode, ensure those categories are not enabled
   744         - on HOOKS_ALLOW_ALL mode, ensure those categories are disabled
   743         - on HOOKS_ALLOW_ALL mode, ensure those categories are disabled
   745         """
   744         """
   746         changes = set()
   745         changes = set()
   747         self.pruned_hooks_cache.clear()
   746         self.pruned_hooks_cache.clear()
   748         if self.hooks_mode is self.HOOKS_DENY_ALL:
   747         if self.hooks_mode is HOOKS_DENY_ALL:
   749             enabledcats = self.enabled_hook_categories
   748             enabledcats = self.enabled_hook_categories
   750             for category in categories:
   749             for category in categories:
   751                 if category in enabledcats:
   750                 if category in enabledcats:
   752                     enabledcats.remove(category)
   751                     enabledcats.remove(category)
   753                     changes.add(category)
   752                     changes.add(category)
   765         - on HOOKS_DENY_ALL mode, ensure those categories are enabled
   764         - on HOOKS_DENY_ALL mode, ensure those categories are enabled
   766         - on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled
   765         - on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled
   767         """
   766         """
   768         changes = set()
   767         changes = set()
   769         self.pruned_hooks_cache.clear()
   768         self.pruned_hooks_cache.clear()
   770         if self.hooks_mode is self.HOOKS_DENY_ALL:
   769         if self.hooks_mode is HOOKS_DENY_ALL:
   771             enabledcats = self.enabled_hook_categories
   770             enabledcats = self.enabled_hook_categories
   772             for category in categories:
   771             for category in categories:
   773                 if category not in enabledcats:
   772                 if category not in enabledcats:
   774                     enabledcats.add(category)
   773                     enabledcats.add(category)
   775                     changes.add(category)
   774                     changes.add(category)
   783 
   782 
   784     def is_hook_category_activated(self, category):
   783     def is_hook_category_activated(self, category):
   785         """return a boolean telling if the given category is currently activated
   784         """return a boolean telling if the given category is currently activated
   786         or not
   785         or not
   787         """
   786         """
   788         if self.hooks_mode is self.HOOKS_DENY_ALL:
   787         if self.hooks_mode is HOOKS_DENY_ALL:
   789             return category in self.enabled_hook_categories
   788             return category in self.enabled_hook_categories
   790         return category not in self.disabled_hook_categories
   789         return category not in self.disabled_hook_categories
   791 
   790 
   792     def is_hook_activated(self, hook):
   791     def is_hook_activated(self, hook):
   793         """return a boolean telling if the given hook class is currently
   792         """return a boolean telling if the given hook class is currently
  1263 
  1262 
  1264     # these are overridden by set_log_methods below
  1263     # these are overridden by set_log_methods below
  1265     # only defining here to prevent pylint from complaining
  1264     # only defining here to prevent pylint from complaining
  1266     info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
  1265     info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
  1267 
  1266 
       
  1267 Session.HOOKS_ALLOW_ALL = HOOKS_ALLOW_ALL
       
  1268 Session.HOOKS_DENY_ALL = HOOKS_DENY_ALL
       
  1269 
       
  1270 
  1268 
  1271 
  1269 class InternalSession(Session):
  1272 class InternalSession(Session):
  1270     """special session created internaly by the repository"""
  1273     """special session created internaly by the repository"""
  1271     is_internal_session = True
  1274     is_internal_session = True
  1272     running_dbapi_query = False
  1275     running_dbapi_query = False