[Zope3-checkins] SVN: Zope3/branches/publication-refactor2/src/zope/publisher/ use adapters in the publish method in order to correctly call

Michael Kerrin michael.kerrin at openapp.biz
Fri Apr 21 05:59:21 EDT 2006


Log message for revision 67201:
  use adapters in the publish method in order to correctly call
  the Zope2's request traverse method.
  

Changed:
  U   Zope3/branches/publication-refactor2/src/zope/publisher/browser.py
  U   Zope3/branches/publication-refactor2/src/zope/publisher/interfaces/__init__.py
  U   Zope3/branches/publication-refactor2/src/zope/publisher/publish.py

-=-
Modified: Zope3/branches/publication-refactor2/src/zope/publisher/browser.py
===================================================================
--- Zope3/branches/publication-refactor2/src/zope/publisher/browser.py	2006-04-21 09:51:55 UTC (rev 67200)
+++ Zope3/branches/publication-refactor2/src/zope/publisher/browser.py	2006-04-21 09:59:20 UTC (rev 67201)
@@ -27,6 +27,7 @@
 from zope.interface import implements, directlyProvides
 from zope.i18n.interfaces import IUserPreferredLanguages
 from zope.i18n.interfaces import IUserPreferredCharsets
+from zope.publisher.interfaces import ITraversingRequest
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.publisher.interfaces.browser import IDefaultBrowserLayer
 from zope.publisher.interfaces.browser import IBrowserApplicationRequest
@@ -197,6 +198,14 @@
         L1.sort()
         return ', '.join(["%s: %s" % (key, repr(value)) for key, value in L1])
 
+class TraversingRequest(object):
+    implements(ITraversingRequest)
+    
+    def __init__(self, request):
+        self.request = request
+        
+    def traverse(self, object):
+        return self.request.traverse(object)
 
 class BrowserRequest(HTTPRequest):
     implements(IBrowserRequest, IBrowserApplicationRequest)

Modified: Zope3/branches/publication-refactor2/src/zope/publisher/interfaces/__init__.py
===================================================================
--- Zope3/branches/publication-refactor2/src/zope/publisher/interfaces/__init__.py	2006-04-21 09:51:55 UTC (rev 67200)
+++ Zope3/branches/publication-refactor2/src/zope/publisher/interfaces/__init__.py	2006-04-21 09:59:20 UTC (rev 67201)
@@ -373,6 +373,15 @@
         """Set the request's publication object
         """
 
+    def processInputs():
+        """Do any input processing that needs to be done before traversing
+
+        This is done after construction to allow the publisher to
+        handle errors that arise.
+        """
+
+class ITraversingRequest(IPublisherRequest):
+
     def traverse(object):
         """Traverse from the given object to the published object
 
@@ -387,14 +396,7 @@
 
         """
 
-    def processInputs():
-        """Do any input processing that needs to be done before traversing
 
-        This is done after construction to allow the publisher to
-        handle errors that arise.
-        """
-
-
 class IDebugFlags(Interface):
     """Features that support debugging."""
 

Modified: Zope3/branches/publication-refactor2/src/zope/publisher/publish.py
===================================================================
--- Zope3/branches/publication-refactor2/src/zope/publisher/publish.py	2006-04-21 09:51:55 UTC (rev 67200)
+++ Zope3/branches/publication-refactor2/src/zope/publisher/publish.py	2006-04-21 09:59:20 UTC (rev 67201)
@@ -18,7 +18,7 @@
 $Id$
 """
 import sys
-from zope.publisher.interfaces import Retry
+import interfaces
 from zope.proxy import removeAllProxies
 
 _marker = []  # Create a new marker object.
@@ -134,24 +134,27 @@
                             object = publication.getApplication(request)
 ## XXX - we should use adapters and interfaces here but Five says
 ## that the Zope2 request object implements IPublisherRequest when
-## the API for the traverse method is different on the Zope2 request.
-##                             if IPublisherRequest.providedBy(request):
-##                                 object = request.traverse(object)
-##                             else:
-##                                 # The Zope2 request traverse method corresponds
-##                                 # to a different API, so adapt the request
-##                                 # object to a IPublisherRequest object and
-##                                 # then call the traverse method.
-##                                 object = IPublisherRequest(
-##                                     request).traverse(object)
+### the API for the traverse method is different on the Zope2 request.
+                             #if IPublisherRequest.providedBy(request):
+                                 #object = request.traverse(object)
+                             #else:
+                                 ## The Zope2 request traverse method corresponds
+                                 ## to a different API, so adapt the request
+                                 ## object to a IPublisherRequest object and
+                                 ## then call the traverse method.
                             try:
-                                from ZPublisher.Publication import \
-                                     Zope3HTTPRequestTraverser
-                                object = Zope3HTTPRequestTraverser(
+                                object = interfaces.ITraversingRequest(
                                     request).traverse(object)
-                            except ImportError:
+                            except TypeError:
                                 object = request.traverse(object)
-                            object = request.traverse(object)
+                            #try:
+                                #from ZPublisher.Publication import \
+                                     #Zope3HTTPRequestTraverser
+                                #object = Zope3HTTPRequestTraverser(
+                                    #request).traverse(object)
+                            #except ImportError:
+                                #object = request.traverse(object)
+                            #object = request.traverse(object)
                             publication.afterTraversal(request, object)
 
                             result = publication.callObject(request, object)
@@ -172,7 +175,7 @@
 
                     break # Successful.
 
-                except Retry, retryException:
+                except interfaces.Retry, retryException:
                     if request.supportsRetry():
                         # Create a copy of the request and use it.
                         newrequest = request.retry()



More information about the Zope3-Checkins mailing list