[Checkins] SVN: Zope/branches/easter-sprint_traversal-refactor/lib/python/ Further on the path.... but not yet done.

Lennart Regebro regebro at gmail.com
Thu Apr 27 16:40:05 EDT 2006


Log message for revision 67671:
  Further on the path.... but not yet done.
  

Changed:
  U   Zope/branches/easter-sprint_traversal-refactor/lib/python/OFS/Traversable.py
  U   Zope/branches/easter-sprint_traversal-refactor/lib/python/ZPublisher/BaseRequest.py

-=-
Modified: Zope/branches/easter-sprint_traversal-refactor/lib/python/OFS/Traversable.py
===================================================================
--- Zope/branches/easter-sprint_traversal-refactor/lib/python/OFS/Traversable.py	2006-04-27 20:39:35 UTC (rev 67670)
+++ Zope/branches/easter-sprint_traversal-refactor/lib/python/OFS/Traversable.py	2006-04-27 20:40:05 UTC (rev 67671)
@@ -25,9 +25,14 @@
 from Acquisition import Acquired, aq_inner, aq_parent, aq_base
 from zExceptions import NotFound
 from ZODB.POSException import ConflictError
-from zope.interface import implements
+from zope.interface import implements, Interface
 
 from interfaces import ITraversable
+from zope.app.traversing.interfaces import ITraversable as IZope3Traversable
+from zope.component import queryMultiAdapter
+from zope.app.traversing.interfaces import TraversalError
+from zope.app.traversing.namespace import nsParse
+from zope.app.traversing.namespace import namespaceLookup
 
 _marker = object()
 
@@ -59,6 +64,7 @@
             return self.virtual_url_path()
 
         spp = self.getPhysicalPath()
+            
         try:
             toUrl = self.REQUEST.physicalPathToURL
         except AttributeError:
@@ -133,7 +139,6 @@
         If true, then all of the objects along the path are validated with
         the security machinery. Usually invoked using restrictedTraverse().
         """
-
         if not path:
             return self
 
@@ -188,7 +193,19 @@
                         continue
 
                 bobo_traverse = _getattr(obj, '__bobo_traverse__', _none)
-                if bobo_traverse is not _none:
+                if name and name[:1] in '@+':
+                    # Process URI segment parameters.
+                    ns, nm = nsParse(name)
+                    if ns:
+                        try:
+                            next = namespaceLookup(ns, nm, obj, 
+                                                   self.REQUEST).__of__(obj)
+                            if restricted and not securityManager.validate(
+                                obj, obj, _none, next):
+                                raise Unauthorized, name
+                        except TraversalError:
+                            raise AttributeError(name)
+                elif bobo_traverse is not _none:
                     next = bobo_traverse(REQUEST, name)
                     if restricted:
                         if aq_base(next) is not next:
@@ -216,11 +233,19 @@
                         next = _getattr(obj, name, marker)
                     if next is marker:
                         try:
-                            next=obj[name]
-                        except AttributeError:
-                            # Raise NotFound for easier debugging
-                            # instead of AttributeError: __getitem__
-                            raise NotFound, name
+                            try:
+                                next=obj[name]
+                            except AttributeError:
+                                # Raise NotFound for easier debugging
+                                # instead of AttributeError: __getitem__
+                                raise NotFound, name
+                        except (NotFound, KeyError): 
+                            # Try to look for a view
+                            next = queryMultiAdapter((obj, self.REQUEST), 
+                                                     Interface, name).__of__(obj)
+                            if next is None:
+                                # Didn't find one, reraise the error:
+                                raise
                         if restricted and not securityManager.validate(
                             obj, obj, _none, next):
                             raise Unauthorized, name

Modified: Zope/branches/easter-sprint_traversal-refactor/lib/python/ZPublisher/BaseRequest.py
===================================================================
--- Zope/branches/easter-sprint_traversal-refactor/lib/python/ZPublisher/BaseRequest.py	2006-04-27 20:39:35 UTC (rev 67670)
+++ Zope/branches/easter-sprint_traversal-refactor/lib/python/ZPublisher/BaseRequest.py	2006-04-27 20:40:05 UTC (rev 67671)
@@ -16,9 +16,9 @@
 """
 from urllib import quote
 import xmlrpc
-from zExceptions import Forbidden, Unauthorized
+from zExceptions import Forbidden, Unauthorized, NotFound
 
-from zope.interface import implements, providedBy
+from zope.interface import implements, providedBy, Interface
 from zope.component import queryMultiAdapter
 from zope.component import getSiteManager
 from zope.component.interfaces import ComponentLookupError
@@ -26,7 +26,6 @@
 from zope.app.publication.interfaces import EndRequestEvent
 from zope.app.publisher.browser import queryDefaultViewName
 from zope.publisher.interfaces import IPublishTraverse
-from zope.publisher.interfaces import NotFound
 from zope.component.interfaces import IDefaultViewName
 from zope.publisher.interfaces.browser import IBrowserPublisher
 from zope.publisher.interfaces.browser import IBrowserRequest
@@ -262,8 +261,6 @@
 
 
     def traverseName(self, 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)
@@ -271,15 +268,15 @@
                 try:
                     ob2 = namespaceLookup(ns, nm, ob, self)
                 except TraversalError:
-                    raise NotFound(ob, name)
+                    raise KeyError(ob, name)
 
                 return ob2.__of__(ob)
 
-        if nm == '.':
+        if name == '.':
             return ob
 
         if IPublishTraverse.providedBy(ob):
-            ob2 = ob.publishTraverse(self, nm)
+            ob2 = ob.publishTraverse(self, name)
         else:
             adapter = queryMultiAdapter((ob, self), IPublishTraverse)
             if adapter is None:
@@ -287,7 +284,21 @@
                 ## so we will just use a default adapter.
                 adapter = DefaultPublishTraverse(ob, self)
 
-            ob2 = adapter.publishTraverse(self, nm)
+            try:
+                ob2 = adapter.publishTraverse(self, name)
+            except (AttributeError, KeyError, NotFound):
+                # Find a view even if it doesn't start with @@, but only
+                # If nothing else could be found
+                ob2 = queryMultiAdapter((ob, self), Interface, name)
+                if ob2 is not None:
+                    ob2 = ob2.__of__(ob)
+                    # OFS.Application.__bobo_traverse__ calls
+                    # REQUEST.RESPONSE.notFoundError which sets the HTTP
+                    # status code to 404
+                    self.RESPONSE.setStatus(200)
+                else:
+                    # There was no view, reraise the earlier error:
+                    raise
 
         return ob2
 



More information about the Checkins mailing list