[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/apidoc/viewmodule/ The presentation service is gone.

Stephan Richter srichter at cosmos.phy.tufts.edu
Fri Sep 17 12:15:38 EDT 2004


Log message for revision 27570:
  
  The presentation service is gone.
  
  Adjust presentation documentation module to use the adapter service, instead
  the presentation service.
  
  


Changed:
  U   Zope3/trunk/src/zope/app/apidoc/viewmodule/__init__.py
  U   Zope3/trunk/src/zope/app/apidoc/viewmodule/browser.py
  U   Zope3/trunk/src/zope/app/apidoc/viewmodule/configure.zcml
  U   Zope3/trunk/src/zope/app/apidoc/viewmodule/skin_layer.pt
  U   Zope3/trunk/src/zope/app/apidoc/viewmodule/tests.py


-=-
Modified: Zope3/trunk/src/zope/app/apidoc/viewmodule/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/viewmodule/__init__.py	2004-09-17 16:15:36 UTC (rev 27569)
+++ Zope3/trunk/src/zope/app/apidoc/viewmodule/__init__.py	2004-09-17 16:15:38 UTC (rev 27570)
@@ -16,30 +16,24 @@
 $Id$
 """
 __docformat__ = 'restructuredtext'
+from zope.interface import Interface, Attribute
+from zope.interface import implements, classImplements, providedBy
+from zope.publisher.interfaces.browser import ISkin, ILayer, IDefaultSkin
+
 from zope.app import zapi
-from zope.interface import implements, classImplements, Interface, Attribute
-from zope.component.presentation import SkinRegistration
-from zope.component.presentation import DefaultSkinRegistration
-from zope.component.presentation import LayerRegistration
 from zope.app.apidoc.interfaces import IDocumentationModule
-from zope.app.apidoc.utilities import relativizePath
+from zope.app.apidoc.utilities import relativizePath, getPythonPath
 from zope.app.i18n import ZopeMessageIDFactory as _
 from zope.app.location import locate
 
-# TODO: Temporary hack, since registering an adapter for a particular class is
-# broken.
-class ISkinRegistration(Interface): pass
-classImplements(SkinRegistration, ISkinRegistration)
 
-class ILayerRegistration(Interface): pass
-classImplements(LayerRegistration, ILayerRegistration)
-
-
 class ISkinDocumentation(Interface):
     """Provides useful information of skins for documentation."""
 
     name = Attribute("""Name of the skin.""")
 
+    interface = Attribute("""The interface that represents the skin.""")
+
     layers = Attribute("A list of ILayerDocumentation objects that represent "
                        "the layers of this skin.")
 
@@ -53,6 +47,8 @@
 
     name = Attribute("""Name of the layer.""")
 
+    interface = Attribute("""The interface that represents the layer.""")
+
     doc = Attribute("A string that describes the skin and/or its origin.")
 
 
@@ -92,26 +88,19 @@
     def getSkins(self):
         """Get the names of all available skins.
 
-        Examples::
+        Example::
 
           >>> module = ViewModule()
           >>> skins = [skin.name for skin in module.getSkins()]
           >>> skins.sort()
           >>> skins
-          ['skinA', 'skinB', 'skinC']
-
-          >>> pres = zapi.getGlobalService('Presentation')
-          >>> pres.defineSkin('skinD', ['layer3'])
-          >>> skins = [skin.name for skin in module.getSkins()]
-          >>> skins.sort()
-          >>> skins
-          ['skinA', 'skinB', 'skinC', 'skinD']
+          [u'skinA', u'skinB', u'skinC']
         """ 
-        # Only the global presentation service defines skins 
-        service = zapi.getGlobalService('Presentation')
-        skins = [ISkinDocumentation(reg)
-                 for reg in service.registrations()
-                 if isinstance(reg, SkinRegistration)]
+        # Only the global presentation service defines skins
+        utils = zapi.getService(zapi.servicenames.Utilities)
+        skins = [SkinDocumentation(reg)
+                 for reg in utils.registrations()
+                 if reg.name != '' and reg.provided is ISkin]
         skins.sort(lambda x, y: cmp(x.name, y.name))
         # Make sure skins have a location
         [locate(skin, self, skin.name) for skin in skins]
@@ -129,27 +118,28 @@
 
       >>> from zope.app.apidoc.tests import pprint
 
-      >>> pres = zapi.getGlobalService('Presentation')
-      >>> reg = pres._registrations[('skin', 'skinA')]
+      >>> utils = zapi.getGlobalService(zapi.servicenames.Utilities)
+      >>> reg = utils._registrations[(ISkin, 'skinA')]
       >>> doc = SkinDocumentation(reg)
       >>> doc.name
-      'skinA'
+      u'skinA'
       >>> doc.default
       True
       >>> pprint(doc.layers)
-      [LayerDocumentation('default')]
+      []
+      >>> doc.interface
+      'zope.app.apidoc.viewmodule.tests.SkinA'
 
-      >>> reg = pres._registrations[('skin', 'skinC')]
+      >>> reg = utils._registrations[(ISkin, 'skinC')]
       >>> doc = SkinDocumentation(reg)
       >>> doc.name
-      'skinC'
+      u'skinC'
       >>> doc.default
       False
       >>> pprint(doc.layers)
-      [LayerDocumentation('layer4'),
-       LayerDocumentation('layer2'),
-       LayerDocumentation('layer1'),
-       LayerDocumentation('default')]
+      [LayerDocumentation(u'layer3'), LayerDocumentation(u'layer2')]
+      >>> doc.interface
+      'zope.app.apidoc.viewmodule.tests.SkinC'
     """
     implements(ISkinDocumentation)
 
@@ -158,15 +148,17 @@
         self.context = context
 
     # See ISkinDocumentation
-    name = property(lambda self: self.context.skin)
+    name = property(lambda self: self.context.name)
 
+    # See ISkinDocumentation
+    interface = property(lambda self: getPythonPath(self.context.component))
+
     def isDefault(self):
         """Return whether this skin is the default skin."""
-        service = zapi.getService('Presentation')
-        for registration in service.registrations():
-            if isinstance(registration, DefaultSkinRegistration) and \
-                   registration.skin == self.context.skin:
-                return True
+        adapters = zapi.getService(zapi.servicenames.Adapters)
+        skin = adapters.lookup((self.context.component,), IDefaultSkin, '')
+        if skin is self.context.component:
+            return True
         return False
 
     # See ISkinDocumentation
@@ -177,18 +169,12 @@
 
         Each element of the list is a LayerDocumentation component.
         """
-        service = zapi.getService('Presentation')
-        layers = [ILayerDocumentation(reg)
-                  for reg in service.registrations()
-                  if (isinstance(reg, LayerRegistration) and
-                      reg.layer in self.context.layers)]
-
+        utils = zapi.getService(zapi.servicenames.Utilities)
+        layers = [LayerDocumentation(reg)
+                  for reg in utils.registrations()
+                  if reg.name != '' and reg.provided is ILayer and \
+                     self.context.component.isOrExtends(reg.component)]
         
-        if 'default' in self.context.layers:
-            default = LayerRegistration('default',
-                                        'This is a predefined layer.')
-            layers.append(ILayerDocumentation(default))
-
         # Make sure skins have a location
         [locate(layer, self, layer.name) for layer in layers]
         return layers
@@ -216,7 +202,7 @@
         """Representation of the object in a doctest-friendly format."""
         return '%s(%r, %r)' % (
             self.__class__.__name__,
-            self.name, self.context.layers)        
+            self.name, [l.name for l in self.getLayers()])
 
 
 class LayerDocumentation(object):
@@ -230,19 +216,18 @@
 
       >>> from zope.app.apidoc.tests import pprint
 
-      >>> LayerRegistration = type('LayerRegistration', (object,),
-      ...                          {'layer': u'help', 'doc': u'documentation'})
-
       >>> ParserInfo = type('ParserInfo', (object,),
       ...                   {'file': u'Zope3/src/zope/app/configure.zcml',
       ...                    'line': 5})
 
-      >>> reg = LayerRegistration()
+      >>> utils = zapi.getGlobalService(zapi.servicenames.Utilities)
+      >>> reg = utils._registrations[(ILayer, 'layer1')]
+
       >>> layerdoc = LayerDocumentation(reg)
       >>> layerdoc.name
-      u'help'
+      u'layer1'
       >>> layerdoc.doc
-      u'documentation'
+      u'layer 1 doc'
 
       >>> reg.doc = ParserInfo()
       >>> layerdoc.doc
@@ -256,8 +241,11 @@
         self.context = context
 
     # See ILayerDocumentation
-    name = property(lambda self: self.context.layer)
+    name = property(lambda self: self.context.name)
 
+    # See ILayerDocumentation
+    interface = property(lambda self: getPythonPath(self.context.component))
+
     def getDoc(self):
         """Generate documentation."""
         if isinstance(self.context.doc, (str, unicode)):

Modified: Zope3/trunk/src/zope/app/apidoc/viewmodule/browser.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/viewmodule/browser.py	2004-09-17 16:15:36 UTC (rev 27569)
+++ Zope3/trunk/src/zope/app/apidoc/viewmodule/browser.py	2004-09-17 16:15:38 UTC (rev 27570)
@@ -18,7 +18,14 @@
 from types import ClassType
 
 from zope.interface import Interface
+from zope.component.adapter import AdapterRegistration
+from zope.publisher.interfaces.browser import ILayer
 
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.xmlrpc import IXMLRPCRequest
+from zope.publisher.interfaces.http import IHTTPRequest
+from zope.publisher.interfaces.ftp import IFTPRequest
+
 from zope.app import zapi
 from zope.app.publisher.browser.icon import IconViewFactory
 from zope.app.apidoc.utilities import getPythonPath, getPermissionIds
@@ -65,8 +72,10 @@
         Example::
 
           >>> menu = Menu()
-          >>> menu.getInterfaceIds()
-          [u'IBrowserRequest', u'IFoo']
+          >>> u'IFoo' in menu.getInterfaceIds()
+          True
+          >>> u'IBrowserRequest' in menu.getInterfaceIds()
+          True
         """
         ids = searchInterfaceIds(self)
         ids.sort()
@@ -87,9 +96,9 @@
          >>> view.context = ViewModule()
          >>> skins = view.getSkins(False)
          >>> pprint(skins)
-         [SkinDocumentation('skinA', ['default']),
-          SkinDocumentation('skinB', ['layer5', 'layer4', 'default']),
-          SkinDocumentation('skinC', ['layer4', 'layer2', 'layer1', 'default'])]
+         [SkinDocumentation(u'skinA', []),
+          SkinDocumentation(u'skinB', [u'layer1', u'layer2']),
+          SkinDocumentation(u'skinC', [u'layer3', u'layer2'])]
         """
         skins = self.context.getSkins()
         if columns:
@@ -193,6 +202,32 @@
     return info
 
 
+def _getPresentationType(iface):
+    """Get the presentation type from a layer interface.
+
+    Examples::
+
+      >>> class ILayer1(IBrowserRequest): pass
+      >>> _getPresentationType(ILayer1)
+      <InterfaceClass zope.publisher.interfaces.browser.IBrowserRequest>
+
+      >>> class ILayer2(IHTTPRequest): pass
+      >>> _getPresentationType(ILayer2)
+      <InterfaceClass zope.publisher.interfaces.http.IHTTPRequest>
+
+      >>> class ILayer3(Interface): pass
+      >>> _getPresentationType(ILayer3)
+      <InterfaceClass zope.app.apidoc.viewmodule.browser.ILayer3>
+    """
+    # Note that the order of the requests matters here, since we want to
+    # inspect the most specific one first. For example, IBrowserRequest is also
+    # an IHTTPRequest. 
+    for type in [IBrowserRequest, IXMLRPCRequest, IHTTPRequest, IFTPRequest]:
+        if iface.isOrExtends(type):
+            return type
+    return iface
+    
+
 class ViewsDetails(object):
     """View for Views"""
 
@@ -206,19 +241,20 @@
 
         self.show_all = request.has_key('all')
 
-        from zope.component.presentation import PresentationRegistration
-        from zope.proxy import removeAllProxies
-        service = zapi.getService('Presentation')
+        service = zapi.getService(zapi.servicenames.Adapters)
         # This is okay here, since we only read from the service. Once
         # registration objects have sensible security declarations, we can
         # remove that call. 
+        from zope.proxy import removeAllProxies
         service = removeAllProxies(service)
         self.regs = [reg
                      for reg in service.registrations()
-                     if (isinstance(reg, PresentationRegistration) and
+                     if (isinstance(reg, AdapterRegistration) and
+                         reg.required[-1] is not None and
                          # TODO: Handle multiple required ifaces at some point.
-                         self.iface.isOrExtends(reg.required[0]) and 
-                         self.type is reg.required[-1])]
+                         self.iface.isOrExtends(reg.required[0]
+                                                or Interface) and
+                         reg.required[-1].isOrExtends(self.type))]
 
 
     def getViewsByLayers(self):
@@ -235,7 +271,7 @@
           >>> view = ViewsDetails(None, TestRequest(form=form))
           >>> layer = view.getViewsByLayers()[0]
           >>> layer['name']
-          'default'
+          u'layer1'
           >>> view = layer['views'][0]
           >>> pprint(view)
           [('factory',
@@ -259,8 +295,9 @@
                 entry = {'name' : reg.name or '<i>no name</i>',
                          # TODO: Deal with tuple
                          'required' : getPythonPath(reg.required[0]),
-                         'type' : getPythonPath(reg.required[-1]),
-                         'factory' : _getFactoryData(reg.factory),
+                         'type' : getPythonPath(
+                                      _getPresentationType(reg.required[-1])),
+                         'factory' : _getFactoryData(reg.value),
                          'provided' : getPythonPath(reg.provided)
                          }
 
@@ -274,9 +311,18 @@
 
                 # Educated choice of the attribute name
                 entry.update(getPermissionIds('publishTraverse',
-                                              klass=reg.factory))
+                                              klass=reg.value))
 
-                layer = entries.setdefault(reg.layer, [])
+                # Determine the layer
+                layer = reg.required[-1]
+                name = [name for name, util in zapi.getUtilitiesFor(ILayer)
+                        if util is layer]
+                if name:
+                    name = name[0]
+                else:
+                    name = '<no layer>'
+                    
+                layer = entries.setdefault(name, [])
                 layer.append(entry)
 
         for entry in entries.values():

Modified: Zope3/trunk/src/zope/app/apidoc/viewmodule/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/viewmodule/configure.zcml	2004-09-17 16:15:36 UTC (rev 27569)
+++ Zope3/trunk/src/zope/app/apidoc/viewmodule/configure.zcml	2004-09-17 16:15:38 UTC (rev 27570)
@@ -17,25 +17,11 @@
     <allow attributes="getLayers isDefault getDoc"/>
   </class>
 
-  <adapter
-      for=".ISkinRegistration"
-      provides=".ISkinDocumentation"
-      factory=".SkinDocumentation"
-      permission="zope.app.apidoc.UseAPIDoc"
-      trusted="True" />
-
   <class class=".LayerDocumentation">
     <allow interface=".ILayerDocumentation" />
     <allow attributes="getDoc"/>
   </class>
 
-  <adapter
-      for=".ILayerRegistration"
-      provides=".ILayerDocumentation"
-      factory=".LayerDocumentation"
-      permission="zope.app.apidoc.UseAPIDoc"
-      trusted="True" />
-
   <browser:page
       for=".ViewModule"
       permission="zope.app.apidoc.UseAPIDoc"

Modified: Zope3/trunk/src/zope/app/apidoc/viewmodule/skin_layer.pt
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/viewmodule/skin_layer.pt	2004-09-17 16:15:36 UTC (rev 27569)
+++ Zope3/trunk/src/zope/app/apidoc/viewmodule/skin_layer.pt	2004-09-17 16:15:38 UTC (rev 27570)
@@ -28,9 +28,15 @@
             <i style="font-weight: normal"
                tal:condition="skin/default" i18n:translate="">(default)</i>
           </h3>
-          <div class="small">
+          <span class="small">
+                  <a href=""
+                     tal:attributes="href 
+                      string:../Interface/${skin/interface}/apiindex.html"
+                     tal:content="skin/interface">Interface</a>
+          </span>      
+          <span class="small">
             <i tal:content="skin/doc">Skin Doc</i>
-          </div>      
+          </span>
 
           <div class="indent">
             <ul>
@@ -38,6 +44,12 @@
                 <b tal:content="layer/name">default</b>
                 <br />
                 <span class="small">
+                  <a href=""
+                     tal:attributes="href 
+                      string:../Interface/${layer/interface}/apiindex.html"
+                     tal:content="layer/interface">Interface</a>
+                </span>      
+                <span class="small">
                   <i tal:content="layer/doc">Layer Doc</i>
                 </span>
               </li>

Modified: Zope3/trunk/src/zope/app/apidoc/viewmodule/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/viewmodule/tests.py	2004-09-17 16:15:36 UTC (rev 27569)
+++ Zope3/trunk/src/zope/app/apidoc/viewmodule/tests.py	2004-09-17 16:15:38 UTC (rev 27570)
@@ -16,44 +16,52 @@
 $Id$
 """
 import unittest
-from zope.interface import Interface
+
+from zope.interface import Interface, directlyProvides
 from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.publisher.interfaces.browser import ISkin, ILayer, IDefaultSkin
 from zope.testing.doctestunit import DocTestSuite
+
 from zope.app import zapi
 from zope.app.tests import placelesssetup, ztapi
 from zope.app.component.interface import provideInterface
 
-from zope.app.apidoc.viewmodule import ISkinRegistration
-from zope.app.apidoc.viewmodule import ISkinDocumentation, SkinDocumentation
-from zope.app.apidoc.viewmodule import ILayerRegistration
-from zope.app.apidoc.viewmodule import ILayerDocumentation, LayerDocumentation
-
 class IFoo(Interface):
     pass
 
 class FooView(object):
     pass
 
+class Layer1(IBrowserRequest): pass
+class Layer2(IBrowserRequest): pass
+class Layer3(IBrowserRequest): pass
+
+class SkinA(IBrowserRequest): pass
+class SkinB(Layer1, Layer2): pass
+class SkinC(Layer2, Layer3): pass
+
 def setUp(test):
     placelesssetup.setUp()
 
-    ztapi.provideAdapter(ISkinRegistration, ISkinDocumentation,
-                         SkinDocumentation)
-    ztapi.provideAdapter(ILayerRegistration, ILayerDocumentation,
-                         LayerDocumentation)
+    provideInterface(u'zope.app.layers.layer1', Layer1)
+    provideInterface(u'layer1', Layer1, ILayer, u'layer 1 doc')
+    provideInterface(u'zope.app.layers.layer2', Layer2)
+    provideInterface(u'layer2', Layer2, ILayer, u'layer 2 doc')
+    provideInterface(u'zope.app.layers.layer3', Layer3)
+    provideInterface(u'layer3', Layer3, ILayer, u'layer 3 doc')
 
-    pres = zapi.getGlobalService('Presentation')
-    for index in range(1, 6):
-        pres.defineLayer('layer'+str(index))
-    pres.defineSkin('skinA', ['default'], 'doc skin A')
-    pres.defineSkin('skinB', ['layer5', 'layer4', 'default'], 'doc skin B')
-    pres.defineSkin('skinC', ['layer4', 'layer2', 'layer1', 'default'],
-                    'doc skin C')
-    pres.setDefaultSkin('skinA', 'default is A')
+    provideInterface(u'zope.app.skins.skinA', SkinA)
+    provideInterface(u'skinA', SkinA, ISkin, u'skin 1 doc')
+    provideInterface(u'zope.app.skins.skinB', SkinB)
+    provideInterface(u'skinB', SkinB, ISkin, u'skin 2 doc')
+    provideInterface(u'zope.app.skins.skinC', SkinC)
+    provideInterface(u'skinC', SkinC, ISkin, u'skin 3 doc')
 
+    ztapi.provideAdapter((IBrowserRequest,), IDefaultSkin, SkinA, '')
+
     provideInterface('IFoo', IFoo)
     provideInterface('IBrowserRequest', IBrowserRequest)
-    ztapi.browserView(IFoo, 'index.html', FooView, layer='default')
+    ztapi.browserView(IFoo, 'index.html', FooView, layer=Layer1)
 
 
 def test_suite():



More information about the Zope3-Checkins mailing list