server/hook.py
changeset 8190 2a3c1b787688
parent 8032 bcb87336c7d2
child 8211 543e1579ba0d
--- a/server/hook.py	Thu Feb 02 14:33:30 2012 +0100
+++ b/server/hook.py	Mon Jan 23 13:25:02 2012 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -233,7 +233,7 @@
 or rollback() will restore the hooks.
 
 
-Hooks specific selector
+Hooks specific predicate
 ~~~~~~~~~~~~~~~~~~~~~~~
 .. autoclass:: cubicweb.server.hook.match_rtype
 .. autoclass:: cubicweb.server.hook.match_rtype_sets
@@ -258,13 +258,13 @@
 from logilab.common.decorators import classproperty, cached
 from logilab.common.deprecation import deprecated, class_renamed
 from logilab.common.logging_ext import set_log_methods
+from logilab.common.registry import (Predicate, NotPredicate, OrPredicate,
+                                     classid, objectify_predicate, yes)
 
 from cubicweb import RegistryNotFound
-from cubicweb.vregistry import classid
-from cubicweb.cwvreg import CWRegistry, VRegistry
-from cubicweb.selectors import (objectify_selector, lltrace, ExpectedValueSelector,
-                                is_instance)
-from cubicweb.appobject import AppObject, NotSelector, OrSelector
+from cubicweb.cwvreg import CWRegistry, CWRegistryStore
+from cubicweb.predicates import ExpectedValuePredicate, is_instance
+from cubicweb.appobject import AppObject
 from cubicweb.server.session import security_enabled
 
 ENTITIES_HOOKS = set(('before_add_entity',    'after_add_entity',
@@ -338,14 +338,15 @@
         pruned hooks are the one which:
 
         * are disabled at the session level
-        * have a match_rtype or an is_instance selector which does not
-          match the rtype / etype of the relations / entities for
-          which we are calling the hooks. This works because the
-          repository calls the hooks grouped by rtype or by etype when
-          using the entities or eids_to_from keyword arguments
 
-        Only hooks with a simple selector or an AndSelector of simple
-        selectors are considered for disabling.
+        * have a selector containing a :class:`match_rtype` or an
+          :class:`is_instance` predicate which does not match the rtype / etype
+          of the relations / entities for which we are calling the hooks. This
+          works because the repository calls the hooks grouped by rtype or by
+          etype when using the entities or eids_to_from keyword arguments
+
+        Only hooks with a simple predicate or an AndPredicate of simple
+        predicates are considered for disabling.
 
         """
         if 'entity' in kwargs:
@@ -410,24 +411,22 @@
 
 
 for event in ALL_HOOKS:
-    VRegistry.REGISTRY_FACTORY['%s_hooks' % event] = HooksRegistry
+    CWRegistryStore.REGISTRY_FACTORY['%s_hooks' % event] = HooksRegistry
 
 @deprecated('[3.10] use entity.cw_edited.oldnewvalue(attr)')
 def entity_oldnewvalue(entity, attr):
     return entity.cw_edited.oldnewvalue(attr)
 
 
-# some hook specific selectors #################################################
+# some hook specific predicates #################################################
 
-@objectify_selector
-@lltrace
+@objectify_predicate
 def enabled_category(cls, req, **kwargs):
     if req is None:
         return True # XXX how to deactivate server startup / shutdown event
     return req.is_hook_activated(cls)
 
-@objectify_selector
-@lltrace
+@objectify_predicate
 def from_dbapi_query(cls, req, **kwargs):
     if req.running_dbapi_query:
         return 1
@@ -440,9 +439,9 @@
         return iter(chain(*self.iterators))
 
 
-class match_rtype(ExpectedValueSelector):
+class match_rtype(ExpectedValuePredicate):
     """accept if parameters specified as initializer arguments are specified
-    in named arguments given to the selector
+    in named arguments given to the predicate
 
     :param \*expected: parameters (eg `basestring`) which are expected to be
                        found in named arguments (kwargs)
@@ -453,7 +452,6 @@
         self.toetypes = more.pop('toetypes', None)
         assert not more, "unexpected kwargs in match_rtype: %s" % more
 
-    @lltrace
     def __call__(self, cls, req, *args, **kwargs):
         if kwargs.get('rtype') not in self.expected:
             return 0
@@ -466,10 +464,10 @@
         return 1
 
 
-class match_rtype_sets(ExpectedValueSelector):
+class match_rtype_sets(ExpectedValuePredicate):
     """accept if the relation type is in one of the sets given as initializer
-    argument. The goal of this selector is that it keeps reference to original sets,
-    so modification to thoses sets are considered by the selector. For instance
+    argument. The goal of this predicate is that it keeps reference to original sets,
+    so modification to thoses sets are considered by the predicate. For instance
 
     MYSET = set()
 
@@ -489,7 +487,6 @@
     def __init__(self, *expected):
         self.expected = expected
 
-    @lltrace
     def __call__(self, cls, req, *args, **kwargs):
         for rel_set in self.expected:
             if kwargs.get('rtype') in rel_set:
@@ -535,7 +532,7 @@
     @cached
     def filterable_selectors(cls):
         search = cls.__select__.search_selector
-        if search((NotSelector, OrSelector)):
+        if search((NotPredicate, OrPredicate)):
             return None, None
         enabled_cat = search(enabled_category)
         main_filter = search((is_instance, match_rtype))
@@ -583,7 +580,7 @@
     Notice there are no default behaviour defined when a watched relation is
     deleted, you'll have to handle this by yourself.
 
-    You usually want to use the :class:`match_rtype_sets` selector on concrete
+    You usually want to use the :class:`match_rtype_sets` predicate on concrete
     classes.
     """
     events = ('after_add_relation',)