server/hook.py
changeset 10351 91e63306e277
parent 10006 8391bf718485
child 10589 7c23b7de2b8d
equal deleted inserted replaced
10350:31327bd26931 10351:91e63306e277
   318             else:
   318             else:
   319                 entities = []
   319                 entities = []
   320                 eids_from_to = []
   320                 eids_from_to = []
   321             pruned = self.get_pruned_hooks(cnx, event,
   321             pruned = self.get_pruned_hooks(cnx, event,
   322                                            entities, eids_from_to, kwargs)
   322                                            entities, eids_from_to, kwargs)
       
   323 
   323             # by default, hooks are executed with security turned off
   324             # by default, hooks are executed with security turned off
   324             with cnx.security_enabled(read=False):
   325             with cnx.security_enabled(read=False):
   325                 for _kwargs in _iter_kwargs(entities, eids_from_to, kwargs):
   326                 for _kwargs in _iter_kwargs(entities, eids_from_to, kwargs):
   326                     hooks = sorted(self.filtered_possible_objects(pruned, cnx, **_kwargs),
   327                     hooks = sorted(self.filtered_possible_objects(pruned, cnx, **_kwargs),
   327                                    key=lambda x: x.order)
   328                                    key=lambda x: x.order)
   328                     debug = server.DEBUG & server.DBG_HOOKS
   329                     debug = server.DEBUG & server.DBG_HOOKS
   329                     with cnx.security_enabled(write=False):
   330                     with cnx.security_enabled(write=False):
   330                         for hook in hooks:
   331                         with cnx.running_hooks_ops():
   331                             if debug:
   332                             for hook in hooks:
   332                                 print event, _kwargs, hook
   333                                 if debug:
   333                             hook()
   334                                     print event, _kwargs, hook
       
   335                                 hook()
   334 
   336 
   335     def get_pruned_hooks(self, cnx, event, entities, eids_from_to, kwargs):
   337     def get_pruned_hooks(self, cnx, event, entities, eids_from_to, kwargs):
   336         """return a set of hooks that should not be considered by filtered_possible objects
   338         """return a set of hooks that should not be considered by filtered_possible objects
   337 
   339 
   338         the idea is to make a first pass over all the hooks in the
   340         the idea is to make a first pass over all the hooks in the
   423     if req is None:
   425     if req is None:
   424         return True # XXX how to deactivate server startup / shutdown event
   426         return True # XXX how to deactivate server startup / shutdown event
   425     return req.is_hook_activated(cls)
   427     return req.is_hook_activated(cls)
   426 
   428 
   427 @objectify_predicate
   429 @objectify_predicate
   428 def from_dbapi_query(cls, req, **kwargs):
   430 def issued_from_user_query(cls, req, **kwargs):
   429     if req.running_dbapi_query:
   431     return 0 if req.hooks_in_progress else 1
   430         return 1
   432 
   431     return 0
   433 from_dbapi_query = class_renamed('from_dbapi_query',
       
   434                                  issued_from_user_query,
       
   435                                  message='[3.21] ')
       
   436 
   432 
   437 
   433 class rechain(object):
   438 class rechain(object):
   434     def __init__(self, *iterators):
   439     def __init__(self, *iterators):
   435         self.iterators = iterators
   440         self.iterators = iterators
   436     def __iter__(self):
   441     def __iter__(self):