[Checkins] SVN: zope.app.publication/trunk/ Copied traverseName from

Jim Fulton jim at zope.com
Sun Jun 21 09:37:04 EDT 2009


Log message for revision 101189:
  Copied traverseName from
  zope.traversing.publicationtraverse.PublicationTraverser. (That class
  will be modified to use publication object's method.)
  
  Added a test to make sure traverseName uses the proxy method.
  

Changed:
  U   zope.app.publication/trunk/CHANGES.txt
  U   zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py
  U   zope.app.publication/trunk/src/zope/app/publication/zopepublication.py

-=-
Modified: zope.app.publication/trunk/CHANGES.txt
===================================================================
--- zope.app.publication/trunk/CHANGES.txt	2009-06-21 13:37:01 UTC (rev 101188)
+++ zope.app.publication/trunk/CHANGES.txt	2009-06-21 13:37:04 UTC (rev 101189)
@@ -2,6 +2,12 @@
 CHANGES
 =======
 
+3.8.1 (2009-06-21)
+------------------
+
+- Bug fix: The publication traverseName methoid used ProxyFactory
+  rather than the publication proxy method.
+
 3.8.0 (2009-06-20)
 ------------------
 

Modified: zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py	2009-06-21 13:37:01 UTC (rev 101188)
+++ zope.app.publication/trunk/src/zope/app/publication/tests/test_proxycontrol.py	2009-06-21 13:37:04 UTC (rev 101189)
@@ -15,7 +15,9 @@
 import unittest
 import zope.app.publication.browser
 import zope.component
+import zope.interface
 import zope.publisher.interfaces.browser
+import zope.traversing.namespace
 
 class Proxy:
 
@@ -64,9 +66,17 @@
 
 class Publisher:
 
+    zope.interface.implements(
+        zope.publisher.interfaces.browser.IBrowserPublisher)
+
     def __init__(self, context, request):
         self.context = context
 
+    def publishTraverse(self, request, name):
+        result = Sample()
+        result.__name__ = name
+        return result
+
     def browserDefault(self, request):
         return self.context, ['foo']
 
@@ -78,9 +88,10 @@
 
     >>> cleanup.cleanUp()
 
-    >>> zope.component.provideAdapter(
-    ...     Publisher, (Sample, Request),
-    ...     zope.publisher.interfaces.browser.IBrowserPublisher)
+    >>> zope.component.provideAdapter(Publisher, (Sample, Request))
+    >>> zope.component.provideAdapter(Publisher, (Sample, Request), name='foo')
+    >>> zope.component.provideAdapter(zope.traversing.namespace.view,
+    ...                               (Sample, Request), name='view')
 
     >>> pub = Publication(DB())
     >>> request = Request()
@@ -91,6 +102,17 @@
     True
 
     >>> sample = Sample()
+
+    >>> ob = pub.traverseName(request, sample, 'x')
+    Proxy called
+    >>> isinstance(ob, Proxy) and ob.context.__name__ == 'x'
+    True
+
+    >>> ob = pub.traverseName(request, sample, '@@foo')
+    Proxy called
+    >>> isinstance(ob, Proxy) and isinstance(ob.context, Publisher)
+    True
+
     >>> ob, path = pub.getDefaultTraversal(request, sample)
     Proxy called
     >>> isinstance(ob, Proxy) and ob.context == sample and path == ['foo']

Modified: zope.app.publication/trunk/src/zope/app/publication/zopepublication.py
===================================================================
--- zope.app.publication/trunk/src/zope/app/publication/zopepublication.py	2009-06-21 13:37:01 UTC (rev 101188)
+++ zope.app.publication/trunk/src/zope/app/publication/zopepublication.py	2009-06-21 13:37:04 UTC (rev 101189)
@@ -25,17 +25,21 @@
 import transaction
 
 import zope.component
+from zope.component import queryMultiAdapter
 from zope.event import notify
 from zope.security.interfaces import Unauthorized
 from zope.interface import implements, providedBy
 from zope.publisher.publish import mapply
-from zope.publisher.interfaces import Retry, IExceptionSideEffects, IHeld
-from zope.publisher.interfaces import IRequest, IPublication
+from zope.publisher.interfaces import IExceptionSideEffects, IHeld
+from zope.publisher.interfaces import IPublication, IPublishTraverse, IRequest
+from zope.publisher.interfaces import NotFound, Retry
 from zope.security.management import newInteraction, endInteraction
 from zope.security.checker import ProxyFactory
 from zope.security.proxy import removeSecurityProxy
 from zope.traversing.interfaces import IPhysicallyLocatable
 from zope.traversing.interfaces import IEtcNamespace
+from zope.traversing.interfaces import TraversalError
+from zope.traversing.namespace import namespaceLookup, nsParse
 from zope.location import LocationProxy
 from zope.error.interfaces import IErrorReportingUtility
 
@@ -67,7 +71,7 @@
                 "Cleanup without request close")
             self._f()
 
-class ZopePublication(PublicationTraverse):
+class ZopePublication(object):
     """Base Zope publication specification."""
     implements(IPublication)
 
@@ -171,6 +175,36 @@
 
         return self.proxy(app)
 
+    def traverseName(self, request, ob, name):
+        nm = name # the name to look up the object with
+
+        if name and name[:1] in '@+':
+            # Process URI segment parameters.
+            ns, nm = nsParse(name)
+            if ns:
+                try:
+                    ob2 = namespaceLookup(ns, nm, ob, request)
+                except TraversalError:
+                    raise NotFound(ob, name)
+
+                return self.proxy(ob2)
+
+        if nm == '.':
+            return ob
+
+        if IPublishTraverse.providedBy(ob):
+            ob2 = ob.publishTraverse(request, nm)
+        else:
+            # self is marker
+            adapter = queryMultiAdapter((ob, request), IPublishTraverse,
+                                        default=self)
+            if adapter is not self:
+                ob2 = adapter.publishTraverse(request, nm)
+            else:
+                raise NotFound(ob, name, request)
+
+        return self.proxy(ob2)
+
     def callObject(self, request, ob):
         return mapply(ob, request.getPositionalArguments(), request)
 



More information about the Checkins mailing list