85 if exctype: |
85 if exctype: |
86 self.session.rollback(free_cnxset=self.free_cnxset) |
86 self.session.rollback(free_cnxset=self.free_cnxset) |
87 else: |
87 else: |
88 self.session.commit(free_cnxset=self.free_cnxset) |
88 self.session.commit(free_cnxset=self.free_cnxset) |
89 |
89 |
90 |
90 @deprecated('[3.17] use <object>.allow/deny_all_hooks_but instead') |
91 class hooks_control(object): |
91 def hooks_control(obj, *args, **kwargs): |
|
92 return obj.hooks_control(*args, **kwargs) |
|
93 |
|
94 class _hooks_control(object): |
92 """context manager to control activated hooks categories. |
95 """context manager to control activated hooks categories. |
93 |
96 |
94 If mode is session.`HOOKS_DENY_ALL`, given hooks categories will |
97 If mode is session.`HOOKS_DENY_ALL`, given hooks categories will |
95 be enabled. |
98 be enabled. |
96 |
99 |
97 If mode is session.`HOOKS_ALLOW_ALL`, given hooks categories will |
100 If mode is session.`HOOKS_ALLOW_ALL`, given hooks categories will |
98 be disabled. |
101 be disabled. |
99 |
102 |
100 .. sourcecode:: python |
103 .. sourcecode:: python |
101 |
104 |
102 with hooks_control(self.session, self.session.HOOKS_ALLOW_ALL, 'integrity'): |
105 with _hooks_control(self.session, self.session.HOOKS_ALLOW_ALL, 'integrity'): |
103 # ... do stuff with all but 'integrity' hooks activated |
106 # ... do stuff with all but 'integrity' hooks activated |
104 |
107 |
105 with hooks_control(self.session, self.session.HOOKS_DENY_ALL, 'integrity'): |
108 with _hooks_control(self.session, self.session.HOOKS_DENY_ALL, 'integrity'): |
106 # ... do stuff with none but 'integrity' hooks activated |
109 # ... do stuff with none but 'integrity' hooks activated |
107 |
110 |
108 This is an internal api, you should rather use |
111 This is an internal api, you should rather use |
109 :meth:`~cubicweb.server.session.Session.deny_all_hooks_but` or |
112 :meth:`~cubicweb.server.session.Session.deny_all_hooks_but` or |
110 :meth:`~cubicweb.server.session.Session.allow_all_hooks_but` session |
113 :meth:`~cubicweb.server.session.Session.allow_all_hooks_but` session |
994 |
997 |
995 # hooks activation control ################################################# |
998 # hooks activation control ################################################# |
996 # all hooks should be activated during normal execution |
999 # all hooks should be activated during normal execution |
997 |
1000 |
998 def allow_all_hooks_but(self, *categories): |
1001 def allow_all_hooks_but(self, *categories): |
999 return hooks_control(self, HOOKS_ALLOW_ALL, *categories) |
1002 return _hooks_control(self, HOOKS_ALLOW_ALL, *categories) |
1000 def deny_all_hooks_but(self, *categories): |
1003 def deny_all_hooks_but(self, *categories): |
1001 return hooks_control(self, HOOKS_DENY_ALL, *categories) |
1004 return _hooks_control(self, HOOKS_DENY_ALL, *categories) |
1002 |
1005 |
1003 hooks_mode = tx_attr('hooks_mode') |
1006 hooks_mode = tx_attr('hooks_mode') |
1004 |
1007 |
1005 disabled_hook_categories = tx_attr('disabled_hook_cats') |
1008 disabled_hook_categories = tx_attr('disabled_hook_cats') |
1006 enabled_hook_categories = tx_attr('enabled_hook_cats') |
1009 enabled_hook_categories = tx_attr('enabled_hook_cats') |