181 |
181 |
182 Hooks controls: |
182 Hooks controls: |
183 |
183 |
184 :attr:`hooks_mode`, may be either `HOOKS_ALLOW_ALL` or `HOOKS_DENY_ALL`. |
184 :attr:`hooks_mode`, may be either `HOOKS_ALLOW_ALL` or `HOOKS_DENY_ALL`. |
185 |
185 |
186 :attr:`enabled_hook_categories`, when :attr:`hooks_mode` is |
186 :attr:`enabled_hook_cats`, when :attr:`hooks_mode` is |
187 `HOOKS_DENY_ALL`, this set contains hooks categories that are enabled. |
187 `HOOKS_DENY_ALL`, this set contains hooks categories that are enabled. |
188 |
188 |
189 :attr:`disabled_hook_categories`, when :attr:`hooks_mode` is |
189 :attr:`disabled_hook_cats`, when :attr:`hooks_mode` is |
190 `HOOKS_ALLOW_ALL`, this set contains hooks categories that are disabled. |
190 `HOOKS_ALLOW_ALL`, this set contains hooks categories that are disabled. |
191 |
191 |
192 Security level Management: |
192 Security level Management: |
193 |
193 |
194 :attr:`read_security` and :attr:`write_security`, boolean flags telling if |
194 :attr:`read_security` and :attr:`write_security`, boolean flags telling if |
296 """add an operation to be executed at the end of the transaction""" |
296 """add an operation to be executed at the end of the transaction""" |
297 if index is None: |
297 if index is None: |
298 self.pending_operations.append(operation) |
298 self.pending_operations.append(operation) |
299 else: |
299 else: |
300 self.pending_operations.insert(index, operation) |
300 self.pending_operations.insert(index, operation) |
|
301 |
|
302 # Hooks control ########################################################### |
|
303 |
|
304 def disable_hook_categories(self, *categories): |
|
305 """disable the given hook categories: |
|
306 |
|
307 - on HOOKS_DENY_ALL mode, ensure those categories are not enabled |
|
308 - on HOOKS_ALLOW_ALL mode, ensure those categories are disabled |
|
309 """ |
|
310 changes = set() |
|
311 self.pruned_hooks_cache.clear() |
|
312 if self.hooks_mode is HOOKS_DENY_ALL: |
|
313 enabledcats = self.enabled_hook_cats |
|
314 for category in categories: |
|
315 if category in enabledcats: |
|
316 enabledcats.remove(category) |
|
317 changes.add(category) |
|
318 else: |
|
319 disabledcats = self.disabled_hook_cats |
|
320 for category in categories: |
|
321 if category not in disabledcats: |
|
322 disabledcats.add(category) |
|
323 changes.add(category) |
|
324 return tuple(changes) |
|
325 |
|
326 def enable_hook_categories(self, *categories): |
|
327 """enable the given hook categories: |
|
328 |
|
329 - on HOOKS_DENY_ALL mode, ensure those categories are enabled |
|
330 - on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled |
|
331 """ |
|
332 changes = set() |
|
333 self.pruned_hooks_cache.clear() |
|
334 if self.hooks_mode is HOOKS_DENY_ALL: |
|
335 enabledcats = self.enabled_hook_cats |
|
336 for category in categories: |
|
337 if category not in enabledcats: |
|
338 enabledcats.add(category) |
|
339 changes.add(category) |
|
340 else: |
|
341 disabledcats = self.disabled_hook_cats |
|
342 for category in categories: |
|
343 if category in disabledcats: |
|
344 disabledcats.remove(category) |
|
345 changes.add(category) |
|
346 return tuple(changes) |
|
347 |
|
348 def is_hook_category_activated(self, category): |
|
349 """return a boolean telling if the given category is currently activated |
|
350 or not |
|
351 """ |
|
352 if self.hooks_mode is HOOKS_DENY_ALL: |
|
353 return category in self.enabled_hook_cats |
|
354 return category not in self.disabled_hook_cats |
|
355 |
|
356 def is_hook_activated(self, hook): |
|
357 """return a boolean telling if the given hook class is currently |
|
358 activated or not |
|
359 """ |
|
360 return self.is_hook_category_activated(hook.category) |
301 |
361 |
302 |
362 |
303 def tx_attr(attr_name, writable=False): |
363 def tx_attr(attr_name, writable=False): |
304 """return a property to forward attribute access to transaction. |
364 """return a property to forward attribute access to transaction. |
305 |
365 |
815 finally: |
875 finally: |
816 self.set_hooks_mode(oldmode) |
876 self.set_hooks_mode(oldmode) |
817 |
877 |
818 disabled_hook_categories = tx_attr('disabled_hook_cats') |
878 disabled_hook_categories = tx_attr('disabled_hook_cats') |
819 enabled_hook_categories = tx_attr('enabled_hook_cats') |
879 enabled_hook_categories = tx_attr('enabled_hook_cats') |
820 |
880 disable_hook_categories = tx_meth('disable_hook_categories') |
821 def disable_hook_categories(self, *categories): |
881 enable_hook_categories = tx_meth('enable_hook_categories') |
822 """disable the given hook categories: |
882 is_hook_category_activated = tx_meth('is_hook_category_activated') |
823 |
883 is_hook_activated = tx_meth('is_hook_activated') |
824 - on HOOKS_DENY_ALL mode, ensure those categories are not enabled |
|
825 - on HOOKS_ALLOW_ALL mode, ensure those categories are disabled |
|
826 """ |
|
827 changes = set() |
|
828 self.pruned_hooks_cache.clear() |
|
829 if self.hooks_mode is HOOKS_DENY_ALL: |
|
830 enabledcats = self.enabled_hook_categories |
|
831 for category in categories: |
|
832 if category in enabledcats: |
|
833 enabledcats.remove(category) |
|
834 changes.add(category) |
|
835 else: |
|
836 disabledcats = self.disabled_hook_categories |
|
837 for category in categories: |
|
838 if category not in disabledcats: |
|
839 disabledcats.add(category) |
|
840 changes.add(category) |
|
841 return tuple(changes) |
|
842 |
|
843 def enable_hook_categories(self, *categories): |
|
844 """enable the given hook categories: |
|
845 |
|
846 - on HOOKS_DENY_ALL mode, ensure those categories are enabled |
|
847 - on HOOKS_ALLOW_ALL mode, ensure those categories are not disabled |
|
848 """ |
|
849 changes = set() |
|
850 self.pruned_hooks_cache.clear() |
|
851 if self.hooks_mode is HOOKS_DENY_ALL: |
|
852 enabledcats = self.enabled_hook_categories |
|
853 for category in categories: |
|
854 if category not in enabledcats: |
|
855 enabledcats.add(category) |
|
856 changes.add(category) |
|
857 else: |
|
858 disabledcats = self.disabled_hook_categories |
|
859 for category in categories: |
|
860 if category in disabledcats: |
|
861 disabledcats.remove(category) |
|
862 changes.add(category) |
|
863 return tuple(changes) |
|
864 |
|
865 def is_hook_category_activated(self, category): |
|
866 """return a boolean telling if the given category is currently activated |
|
867 or not |
|
868 """ |
|
869 if self.hooks_mode is HOOKS_DENY_ALL: |
|
870 return category in self.enabled_hook_categories |
|
871 return category not in self.disabled_hook_categories |
|
872 |
|
873 def is_hook_activated(self, hook): |
|
874 """return a boolean telling if the given hook class is currently |
|
875 activated or not |
|
876 """ |
|
877 return self.is_hook_category_activated(hook.category) |
|
878 |
884 |
879 # connection management ################################################### |
885 # connection management ################################################### |
880 |
886 |
881 def keep_cnxset_mode(self, mode): |
887 def keep_cnxset_mode(self, mode): |
882 """set `mode`, e.g. how the session will keep its connections set: |
888 """set `mode`, e.g. how the session will keep its connections set: |