[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Allow name and interface to be specified at the same time in the layer and

Stephan Richter srichter at cosmos.phy.tufts.edu
Sat Sep 18 13:01:31 EDT 2004


Log message for revision 27632:
  Allow name and interface to be specified at the same time in the layer and 
  skin directive, which reestablishes backward-compatibility.
  


Changed:
  U   Zope3/trunk/src/zope/app/debugskin/configure.zcml
  U   Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
  U   Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
  U   Zope3/trunk/src/zope/app/rotterdam/configure.zcml
  U   Zope3/trunk/src/zope/app/zopetop/configure.zcml


-=-
Modified: Zope3/trunk/src/zope/app/debugskin/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/debugskin/configure.zcml	2004-09-18 05:23:27 UTC (rev 27631)
+++ Zope3/trunk/src/zope/app/debugskin/configure.zcml	2004-09-18 17:01:31 UTC (rev 27632)
@@ -5,8 +5,7 @@
   <layer name="debug" />
   <skin 
       name="Debug" 
-      layers="debug 
-              zope.app.rotterdam.rotterdam" />
+      layers="debug rotterdam" />
 
   <page
       for="zope.security.interfaces.IUnauthorized"

Modified: Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py	2004-09-18 05:23:27 UTC (rev 27631)
+++ Zope3/trunk/src/zope/app/publisher/browser/metaconfigure.py	2004-09-18 17:01:31 UTC (rev 27632)
@@ -99,6 +99,20 @@
     >>> hasattr(sys.modules['zope.app.layers'], 'layer1')
     False
 
+    Possibility 4: Use an Interface and a Name
+    ------------------------------------------
+
+    >>> context = Context()
+    >>> layer(context, name='layer1', interface=layer1)
+    >>> context.actions[0]['args'][1] is layer1
+    True
+    >>> hasattr(sys.modules['zope.app.layers'], 'layer1')
+    True
+    >>> import pprint
+    >>> pprint.pprint([action['discriminator'] for action in context.actions])
+    [('interface', 'zope.app.publisher.browser.metaconfigure.layer1'),
+     ('layer', 'layer1')]
+
     Here are some disallowed configurations.
 
     >>> context = Context()
@@ -139,8 +153,18 @@
         setattr(layers, name, interface)
         path = 'zope.app.layers.'+name
     else:
-        path = name = interface.__module__ + '.' + interface.getName()
+        path = interface.__module__ + '.' + interface.getName()
 
+        # If a name was specified, make this layer available under this name.
+        # Note that the layer will be still available under its path, since it
+        # is an adapter, and the `LayerField` can resolve paths as well.
+        if name is None:
+            name = path
+        else:
+            # Make the interface available in the `zope.app.layers` module, so
+            # that other directives can find the interface under the name
+            # before the CA is setup.
+            setattr(layers, name, interface)
 
     # Register the layer interface as an interface
     _context.action(
@@ -196,6 +220,19 @@
     >>> context.actions[0]['args'][1] is skin1
     True
 
+    Possibility 3: Specify an interface and a Name
+    ----------------------------------------------
+
+    >>> context = Context()
+    >>> skin(context, name='skin1', interface=skin1)
+    >>> context.actions[0]['args'][1] is skin1
+    True
+    >>> import pprint
+    >>> pprint.pprint([action['discriminator'] for action in context.actions])
+    [('skin', 'skin1'),
+     ('interface', 'zope.app.publisher.browser.metaconfigure.skin1'),
+     ('skin', 'zope.app.publisher.browser.metaconfigure.skin1')]
+
     Here are some disallowed configurations.
 
     >>> context = Context()
@@ -207,21 +244,12 @@
     Traceback (most recent call last):
     ...
     ConfigurationError: You must specify the 'name' or 'interface' attribute.
-
-    >>> skin(context, name=u'skin1')
-    Traceback (most recent call last):
-    ...
-    ConfigurationError: You must specify the 'name' and 'layers' attribute.
     """
     if name is None and interface is None: 
         raise ConfigurationError(
             "You must specify the 'name' or 'interface' attribute.")
-    if (name is not None and layers is None) or \
-       (name is None and layers is not None): 
-        raise ConfigurationError(
-            "You must specify the 'name' and 'layers' attribute.")
 
-    if name is not None:
+    if name is not None and layers is not None:
         interface = InterfaceClass(name, layers,
                                    __doc__='Skin: %s' %name,
                                    __module__='zope.app.skins')
@@ -231,9 +259,19 @@
         setattr(skins, name, interface)
         path = 'zope.app.skins'+name
     else:
-        path = name = interface.__module__ + '.' + interface.getName()
+        path = interface.__module__ + '.' + interface.getName()
 
-    # Register the layer interface as an interface
+        # Register the skin interface as a skin using the passed name.
+        if name is not None:
+            _context.action(
+                discriminator = ('skin', name),
+                callable = provideInterface,
+                args = (name, interface, ISkin, _context.info)
+                )
+        
+        name = path
+
+    # Register the skin interface as an interface
     _context.action(
         discriminator = ('interface', path),
         callable = provideInterface,
@@ -241,7 +279,7 @@
         kw = {'info': _context.info}
         )
 
-    # Register the layer interface as a layer
+    # Register the skin interface as a skin
     _context.action(
         discriminator = ('skin', name),
         callable = provideInterface,

Modified: Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py	2004-09-18 05:23:27 UTC (rev 27631)
+++ Zope3/trunk/src/zope/app/publisher/browser/metadirectives.py	2004-09-18 17:01:31 UTC (rev 27632)
@@ -483,6 +483,10 @@
     name, then a layer interface will be created for you based on the name and
     the `base` interface.
 
+    If you specify the `name` and the `interface`, then the layer will be
+    registered twice for the name. This way we can be backward compatible. 
+    The layer is still available via its dotted name.
+
     If you do not specify a `base`, then `IBrowserRequest` is used by default.
 
     You cannot specify both, the `interface` and the `base` attribute.
@@ -511,6 +515,9 @@
     If you do not specify an `interface`, then one will be automatically
     created for you based on the name using the layers as base interfaces.
 
+    In case you specify an `interface` and a `name`, the skin will be
+    available via its dotted name of the interface and the name you specified.
+
     You cannot specify both, the `interface` and the `layers` attribute.    
     """
 

Modified: Zope3/trunk/src/zope/app/rotterdam/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/configure.zcml	2004-09-18 05:23:27 UTC (rev 27631)
+++ Zope3/trunk/src/zope/app/rotterdam/configure.zcml	2004-09-18 17:01:31 UTC (rev 27632)
@@ -2,7 +2,13 @@
     xmlns="http://namespaces.zope.org/zope"
     xmlns:browser="http://namespaces.zope.org/browser">
 
+  
+  <browser:layer 
+      name="rotterdam"
+      interface="zope.app.rotterdam.rotterdam" />  
+
   <browser:skin 
+      name="Rotterdam"
       interface="zope.app.rotterdam.Rotterdam" />
   
   <browser:resource 

Modified: Zope3/trunk/src/zope/app/zopetop/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/zopetop/configure.zcml	2004-09-18 05:23:27 UTC (rev 27631)
+++ Zope3/trunk/src/zope/app/zopetop/configure.zcml	2004-09-18 17:01:31 UTC (rev 27632)
@@ -2,7 +2,9 @@
   xmlns:zope="http://namespaces.zope.org/zope"
   xmlns="http://namespaces.zope.org/browser">
 
-  <skin interface="zope.app.zopetop.ZopeTop" />
+  <skin 
+      name="ZopeTop"
+      interface="zope.app.zopetop.ZopeTop" />
 
   <page
       for="*"



More information about the Zope3-Checkins mailing list