[Zope3-checkins] SVN: Zope3/trunk/src/zope/configuration/ Added the ability to crudely control action execution by providing an

Jim Fulton jim at zope.com
Fri Jun 4 09:19:45 EDT 2004


Log message for revision 25249:
Added the ability to crudely control action execution by providing an
order argument.



-=-
Modified: Zope3/trunk/src/zope/configuration/config.py
===================================================================
--- Zope3/trunk/src/zope/configuration/config.py	2004-06-04 13:14:51 UTC (rev 25248)
+++ Zope3/trunk/src/zope/configuration/config.py	2004-06-04 13:19:44 UTC (rev 25249)
@@ -325,7 +325,7 @@
 
 
 
-    def action(self, discriminator, callable=None, args=(), kw={}):
+    def action(self, discriminator, callable=None, args=(), kw={}, order=0):
         """Add an action with the given discriminator, callable and arguments
 
         For testing purposes, the callable and arguments may be omitted.
@@ -363,10 +363,18 @@
         >>> c.actions[-1]
         (None, None, (), {}, ('foo.zcml',), '?')
 
+        Finally, we can add an order argument to crudely control the order
+        of execution:
+        
+        >>> c.action(None, order=99999)
+        >>> c.actions[-1]
+        (None, None, (), {}, ('foo.zcml',), '?', 99999)
+
         """
         action = (discriminator, callable, args, kw,
                   getattr(self, 'includepath', ()),
                   getattr(self, 'info', ''),
+                  order,
                   )
 
         # remove trailing false items
@@ -569,7 +577,7 @@
 
         """
         for action in resolveConflicts(self.actions):
-            (discriminator, callable, args, kw, includepath, info
+            (discriminator, callable, args, kw, includepath, info, order
              ) = expand_action(*action)
             if callable is None:
                 continue
@@ -1342,9 +1350,9 @@
 # Conflict resolution
 
 def expand_action(discriminator, callable=None, args=(), kw={},
-                   includepath=(), info=''):
+                   includepath=(), info='', order=0):
     return (discriminator, callable, args, kw,
-            includepath, info)
+            includepath, info, order)
 
 def resolveConflicts(actions):
     """Resolve conflicting actions
@@ -1366,15 +1374,15 @@
     ...    (1, f, (1,), {}, (), 'first'),
     ...    (1, f, (2,), {}, ('x',), 'second'),
     ...    (1, f, (3,), {}, ('y',), 'third'),
-    ...    (4, f, (4,), {}, ('y',)),
+    ...    (4, f, (4,), {}, ('y',), 'should be last', 99999),
     ...    (3, f, (3,), {}, ('y',)),
     ...    (None, f, (5,), {}, ('y',)),
     ... ]))
     [(None, f),
      (1, f, (1,), {}, (), 'first'),
-     (4, f, (4,), {}, ('y',)),
      (3, f, (3,), {}, ('y',)),
-     (None, f, (5,), {}, ('y',))]
+     (None, f, (5,), {}, ('y',)),
+     (4, f, (4,), {}, ('y',), 'should be last')]
 
     >>> try:
     ...     v = resolveConflicts([
@@ -1399,21 +1407,23 @@
     unique = {}
     output = []
     for i in range(len(actions)):
-        (discriminator, callable, args, kw, includepath, info
+        (discriminator, callable, args, kw, includepath, info, order
          ) = expand_action(*(actions[i]))
+
+        order = order or i
         if discriminator is None:
             # The discriminator is None, so this directive can
             # never conflict. We can add it directly to the
             # configuration actions.
             output.append(
-                (i, discriminator, callable, args, kw, includepath, info)
+                (order, discriminator, callable, args, kw, includepath, info)
                 )
             continue
 
 
         a = unique.setdefault(discriminator, [])
         a.append(
-            (includepath, i, callable, args, kw, info)
+            (includepath, order, callable, args, kw, info)
             )
 
     # Check for conflicts

Modified: Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py
===================================================================
--- Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py	2004-06-04 13:14:51 UTC (rev 25248)
+++ Zope3/trunk/src/zope/configuration/tests/test_xmlconfig.py	2004-06-04 13:19:44 UTC (rev 25249)
@@ -326,8 +326,9 @@
        'info': clean_info_path(`info`),
        'includepath': [clean_path(p) for p in includepath],
        }
-      for (discriminator, callable, args, kw, includepath, info)
-      in actions]
+      for (discriminator, callable, args, kw, includepath, info, order)
+      in [config.expand_action(*action) for action in actions]
+      ]
 
 def clean_text_w_paths(error):
     r = []

Modified: Zope3/trunk/src/zope/configuration/xmlconfig.py
===================================================================
--- Zope3/trunk/src/zope/configuration/xmlconfig.py	2004-06-04 13:14:51 UTC (rev 25248)
+++ Zope3/trunk/src/zope/configuration/xmlconfig.py	2004-06-04 13:19:44 UTC (rev 25249)
@@ -393,10 +393,10 @@
     # and munge the includepath:
     newactions = []
     for action in config.resolveConflicts(_context.actions[nactions:]):
-        (discriminator, callable, args, kw, oldincludepath, info
+        (discriminator, callable, args, kw, oldincludepath, info, order
          ) = config.expand_action(*action)
         newactions.append(
-            (discriminator, callable, args, kw, includepath, info)
+            (discriminator, callable, args, kw, includepath, info, order)
             )
 
     # and replace the new actions with the munched new actions:




More information about the Zope3-Checkins mailing list