Author: jmorliaguet
Date: Sat Nov  5 10:45:56 2005
New Revision: 29009

Modified:
   z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
   z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/__init__.py
   
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py
Log:

- migrated the filter registry to utilities



Modified: z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py        
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/browser/rendering/engine.py        
Sat Nov  5 10:45:56 2005
@@ -22,7 +22,7 @@
 from zope.app.publisher.browser import BrowserView
 from zope.app.traversing.api import getParent
 from zope.app.zapi import getMultiAdapter, queryMultiAdapter
-from zope.component import adapts, getUtility
+from zope.component import adapts, getUtility, queryUtility
 from zope.interface import implements
 from zope.publisher.interfaces import IRequest
 
@@ -42,7 +42,6 @@
 INFO = logging.INFO
 logger = logging.getLogger()
 
-filter_registry = getUtility(IRegistry, 'filters')
 renderer_registry = getUtility(IRegistry, 'renderers')
 accesskey_registry = getUtility(IRegistry, 'accesskeys')
 
@@ -284,21 +283,25 @@
 
         filters = []
         for filter_name in renderer_registry.get((iface, engine), []):
-            filter_proxy = filter_registry.get(filter_name)
+            filter_proxy = queryUtility(IFilter, filter_name)
             if filter_proxy is None:
                 logger.log(INFO, "Filter '%s' is not registered." % 
filter_name)
                 continue
 
-            # the filter id is a dyadic predicate
-            if IPredicate.providedBy(filter_proxy):
-                if len(filter_proxy) != 2:
+            factory = filter_proxy.factory
+            predicate = filter_proxy.predicate
+            template = filter_proxy.template
+
+            # the filter has a dyadic predicate
+            if predicate is not None:
+                if len(predicate) != 2:
                     logger.log(INFO,
                         "Filter '%s' will not be applied. "
                         "Filter predicates of arity %s are not supported."
-                        % (filter_proxy, len(filter_proxy))
+                        % (filter_proxy, len(predicate))
                         )
                     continue
-                res = relations.search(predicate=filter_proxy, first=display)
+                res = relations.search(predicate=predicate, first=display)
                 if not res:
                     continue
                 adapted = relations[res[0]].second
@@ -317,15 +320,15 @@
                         % (filter_name, repr(adapted)))
                     continue
 
-            # the filter proxy is a page template to apply to the element
+            # the filter proxy uses a page template to apply to the element
             # that is being rendered.
-            elif isinstance(filter_proxy, ViewPageTemplateFile):
+            elif template is not None:
                 filter = ZPTViewFilter(element, request)
-                filter.setTemplate(filter_proxy)
+                filter.setTemplate(template)
 
-            # the filter proxy stands for a factory
-            elif IFilter.implementedBy(filter_proxy):
-                filter = filter_proxy()
+            # the filter proxy uses a factory
+            elif factory is not None:
+                filter = factory()
 
             else:
                 logger.log(INFO, "Filter '%s' is not supported." % 
filter_proxy)

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/__init__.py
==============================================================================
--- z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/__init__.py  
(original)
+++ z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/__init__.py  
Sat Nov  5 10:45:56 2005
@@ -17,10 +17,3 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.component import provideUtility
-
-from cpsskins.configuration import ConfigurationRegistry
-from cpsskins.configuration.interfaces import IRegistry
-
-provideUtility(ConfigurationRegistry(), IRegistry, 'filters')
-

Modified: 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py
==============================================================================
--- 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py 
    (original)
+++ 
z3lab/cpsskins/branches/jmo-perspectives/configuration/filters/metaconfigure.py 
    Sat Nov  5 10:45:56 2005
@@ -21,20 +21,22 @@
 
 from zope.app import pagetemplate
 from zope.app.publisher.browser.resourcemeta import resource
-from zope.component import provideAdapter, getUtility
+from zope.component import provideAdapter, queryUtility, provideUtility
 from zope.configuration.exceptions import ConfigurationError
 
-from cpsskins.configuration.interfaces import IRegistry
+from cpsskins.browser.rendering.filter import Filter
 
-filter_registry = getUtility(IRegistry, 'filters')
+_marker = object()
 
 def filter(_context, name='', for_=None, factory=None, predicate=None,
            template='', stylesheet=None):
 
+    from cpsskins.browser.rendering.interfaces import IFilter
+
     if not name:
         raise ConfigurationError("Must specify the filter name.")
 
-    if name in filter_registry:
+    if queryUtility(IFilter, name, _marker) is not _marker:
         raise ConfigurationError, \
             "A filter with the name '%s' has already been registered." % name
 
@@ -49,32 +51,29 @@
                 "With a predicate, must specify an interface and a factory."
 
         # zope:adapter
-        from cpsskins.browser.rendering.interfaces import IFilter
         _context.action(
             discriminator = ('adapter', factory, for_, name),
             callable = provideAdapter,
             args = (factory, (for_,), IFilter, name))
-        filter_registry.register(name, predicate)
+        provideUtility(Filter(predicate=predicate), IFilter, name)
 
     # factory
     elif factory:
         if template or for_:
             raise ConfigurationError(
                 "With a factory, cannot specify a template or an interface.")
-        filter_registry.register(name, factory)
+        provideUtility(Filter(factory=factory), IFilter, name)
 
     # template
     elif template:
         if for_:
             raise ConfigurationError(
                 "With a template, cannot specify an interface")
-        factory = pagetemplate.ViewPageTemplateFile(template)
-        filter_registry.register(name, factory)
+        template = pagetemplate.ViewPageTemplateFile(template)
+        provideUtility(Filter(template=template), IFilter, name)
 
     # register resources
     if stylesheet:
         stylesheet_name = os.path.split(stylesheet)[1]
-        resource(_context=_context,
-                 name=stylesheet_name,
-                 file=stylesheet)
+        resource(_context=_context, name=stylesheet_name, file=stylesheet)
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to