server/session.py
changeset 8789 465a87e6a89a
parent 8788 194f1418bc7e
child 8790 c3fc17d79e85
equal deleted inserted replaced
8788:194f1418bc7e 8789:465a87e6a89a
   307         - on HOOKS_DENY_ALL mode, ensure those categories are not enabled
   307         - on HOOKS_DENY_ALL mode, ensure those categories are not enabled
   308         - on HOOKS_ALLOW_ALL mode, ensure those categories are disabled
   308         - on HOOKS_ALLOW_ALL mode, ensure those categories are disabled
   309         """
   309         """
   310         changes = set()
   310         changes = set()
   311         self.pruned_hooks_cache.clear()
   311         self.pruned_hooks_cache.clear()
       
   312         categories = set(categories)
   312         if self.hooks_mode is HOOKS_DENY_ALL:
   313         if self.hooks_mode is HOOKS_DENY_ALL:
   313             enabledcats = self.enabled_hook_cats
   314             enabledcats = self.enabled_hook_cats
   314             for category in categories:
   315             changes = enabledcats & categories
   315                 if category in enabledcats:
   316             enabledcats -= changes # changes is small hence faster
   316                     enabledcats.remove(category)
       
   317                     changes.add(category)
       
   318         else:
   317         else:
   319             disabledcats = self.disabled_hook_cats
   318             disabledcats = self.disabled_hook_cats
   320             for category in categories:
   319             changes = categories - disabledcats
   321                 if category not in disabledcats:
   320             disabledcats |= changes # changes is small hence faster
   322                     disabledcats.add(category)
       
   323                     changes.add(category)
       
   324         return tuple(changes)
   321         return tuple(changes)
   325 
   322 
   326     def enable_hook_categories(self, *categories):
   323     def enable_hook_categories(self, *categories):
   327         """enable the given hook categories:
   324         """enable the given hook categories:
   328 
   325 
   329         - on HOOKS_DENY_ALL mode, ensure those categories are enabled
   326         - on HOOKS_DENY_ALL mode, ensure those categories are enabled
   330         - on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled
   327         - on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled
   331         """
   328         """
   332         changes = set()
   329         changes = set()
   333         self.pruned_hooks_cache.clear()
   330         self.pruned_hooks_cache.clear()
       
   331         categories = set(categories)
   334         if self.hooks_mode is HOOKS_DENY_ALL:
   332         if self.hooks_mode is HOOKS_DENY_ALL:
   335             enabledcats = self.enabled_hook_cats
   333             enabledcats = self.enabled_hook_cats
   336             for category in categories:
   334             changes = categories - enabledcats
   337                 if category not in enabledcats:
   335             enabledcats |= changes # changes is small hence faster
   338                     enabledcats.add(category)
       
   339                     changes.add(category)
       
   340         else:
   336         else:
   341             disabledcats = self.disabled_hook_cats
   337             disabledcats = self.disabled_hook_cats
   342             for category in categories:
   338             changes = disabledcats & categories
   343                 if category in disabledcats:
   339             disabledcats -= changes # changes is small hence faster
   344                     disabledcats.remove(category)
       
   345                     changes.add(category)
       
   346         return tuple(changes)
   340         return tuple(changes)
   347 
   341 
   348     def is_hook_category_activated(self, category):
   342     def is_hook_category_activated(self, category):
   349         """return a boolean telling if the given category is currently activated
   343         """return a boolean telling if the given category is currently activated
   350         or not
   344         or not