[Zope3-checkins] SVN: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationregistry.py some more comments

Andreas Jung andreas at andreas-jung.com
Fri Oct 7 07:33:15 EDT 2005


Log message for revision 38866:
  some more comments
  

Changed:
  U   Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationregistry.py

-=-
Modified: Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationregistry.py
===================================================================
--- Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationregistry.py	2005-10-07 11:31:11 UTC (rev 38865)
+++ Zope3/branches/ajung-target-requestpublication-next-try-branch/src/zope/app/publication/requestpublicationregistry.py	2005-10-07 11:33:15 UTC (rev 38866)
@@ -22,11 +22,20 @@
 from zope.app.publication.interfaces import IRequestPublicationRegistry
 
 class RequestPublicationRegistry(object):
+    """ The registry implements a three stage lookup for registred factories
+        to deal with request.
+        {method --> { mimetype -> [{'priority' : some_int,
+                                   'factory' :  factory,
+                                   'name' : some_name }, ...
+                                  ]
+                    },
+        }
+    """
 
     implements(IRequestPublicationRegistry)
 
     def __init__(self):
-        self._d = {}   # method -> { mimetype -> [factories]}
+        self._d = {}   # method -> { mimetype -> {factories_data}}
 
     def register(self, method, mimetype, name, priority, factory):
         """ registers a factory for method+mimetype """
@@ -41,7 +50,7 @@
                 del l[pos]
                 break
         l.append({'name' : name, 'factory' : factory, 'priority' : priority})
-        l.sort(lambda x,y: cmp(x['priority'], y['priority']))
+        l.sort(lambda x,y: -cmp(x['priority'], y['priority'])) # order by descending priority
 
     def getFactoriesFor(self, method, mimetype):
         try:
@@ -55,5 +64,19 @@
             enviroment. 
         """
 
+        factories = self.getFactoriesFor(method, mimetype)
+        if not factories:
+            factories = self.getFactoriesFor(method, '*')
+            if not factories:
+                factories = self.getFactoriesFor('*', '*')
+                if not factories:
+                    return None
 
+        for d in factories:
+            factory = d['factory']
+            if factory.canHandle(environment):
+                return factory
 
+        return None
+
+PublicationRegistry = RequestPublicationRegistry()



More information about the Zope3-Checkins mailing list