[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Traversing - DefaultTraversable.py:1.1.2.5 ITraverser.py:1.1.2.5 Traverser.py:1.1.2.10 __init__.py:1.1.2.7

Jim Fulton jim@zope.com
Sun, 28 Apr 2002 13:17:12 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Traversing
In directory cvs.zope.org:/tmp/cvs-serv17050/lib/python/Zope/App/Traversing

Modified Files:
      Tag: Zope-3x-branch
	DefaultTraversable.py ITraverser.py Traverser.py __init__.py 
Log Message:
HOTYB: Merged SecurityProxy-branch into main branch.  

All tests pass and folders can be listed and added through the web.
It is likely that most other things don't work and will need to be
fixed. The reason is that many accesses that should have been checked
before are now being checked and additional checks and thinking about
permissions and security settings are needed.

I'm in the process of drafting a paper for the wiki that describes the
changes in more detail.


=== Zope3/lib/python/Zope/App/Traversing/DefaultTraversable.py 1.1.2.4 => 1.1.2.5 ===
     def traverse(self, name, furtherPath):
         subject = self._subject
-        if hasattr(subject, name):
-            return getattr(subject, name)
+        r = getattr(subject, name, self) # self used as marker
+        if r is not self:
+            return r
+        
+        if hasattr(subject, '__getitem__'):
+            # Let exceptions propagate.
+            return self._subject[name]
         else:
-            if hasattr(subject, '__getitem__'):
-                # Let exceptions propagate.
-                return self._subject[name]
-            else:
-                raise NotFoundError, name
+            raise NotFoundError, name
 


=== Zope3/lib/python/Zope/App/Traversing/ITraverser.py 1.1.2.4 => 1.1.2.5 ===
         """
     
-    def unrestrictedTraverse(path, default=_RAISE_KEYERROR):
+    def traverse(path, default=_RAISE_KEYERROR):
         """
         Return an object given a path.
         
@@ -50,15 +50,4 @@
         is relative to the current context.
 
         If the object is not found, return 'default' argument.
-        """
-
-    def restrictedTraverse(path, default=_RAISE_KEYERROR):
-        """
-        Return the object obtained by traversing the given path from the object
-        on which the method was called, performing security checks along the
-        way.
-
-        The path argument is the same as for unrestrictedTraverse.
-                
-        If an object is not found then the 'default' argument will be returned.
         """


=== Zope3/lib/python/Zope/App/Traversing/Traverser.py 1.1.2.9 => 1.1.2.10 ===
 from ITraversable import ITraversable
 from Zope.ContextWrapper.IWrapper import IWrapper
-from Zope.ContextWrapper import getcontext, getdict, Wrapper
+from Zope.Proxy.ContextWrapper import getWrapperContext, getWrapperData
+from Zope.Proxy.ContextWrapper import ContextWrapper
 from Zope.ComponentArchitecture import getAdapter
 from Zope.Exceptions import NotFoundError, Unauthorized
-from Zope.App.Security.SecurityManagement import getSecurityManager
+from Zope.Security.SecurityManagement import getSecurityManager
 
 from types import StringTypes
 
@@ -32,7 +33,7 @@
 def WrapperChain(w):
     while w is not None:
         yield w
-        w = getcontext(w)
+        w = getWrapperContext(w)
 
 _marker = object()
 
@@ -58,13 +59,13 @@
         path = []
         
         for w in WrapperChain(self._wrapper):
-            d = getdict(w)
+            d = getWrapperData(w)
             if d:
                 path.insert(0, d['name'])
 
         return tuple(path)
     
-    def unrestrictedTraverse(self, path, default=_marker, restricted=0):
+    def traverse(self, path, default=_marker):
         if not path:
             return self._wrapper
 
@@ -79,16 +80,11 @@
         path.reverse()
         pop = path.pop
 
-        validate = restricted and getSecurityManager().validate
-
         curr = self._wrapper
         if not path[-1]:
             # Start at the root
             pop()
             curr = self.getPhysicalRoot()
-            if restricted:
-                validate(None, curr)
-
         try:
             while path:
                 name = pop()
@@ -97,9 +93,7 @@
                     continue
 
                 if name == '..':
-                    curr = getcontext(curr) or curr
-                    if restricted:
-                        validate(None, curr)
+                    curr = getWrapperContext(curr) or curr
                     continue
 
                 traversable = getAdapter(curr, ITraversable, None)
@@ -107,9 +101,7 @@
                     raise NotFoundError, 'No traversable adapter found'
 
                 next = traversable.traverse(name, path)
-                curr = Wrapper(next, curr, name=name)
-                if restricted:
-                    validate(name, curr)
+                curr = ContextWrapper(next, curr, name=name)
 
             return curr
 
@@ -117,7 +109,4 @@
             if default == _marker:
                 raise
             return default
-
-    def restrictedTraverse(self, path, default=_marker):
-        return self.unrestrictedTraverse(path, default, restricted=1)
 


=== Zope3/lib/python/Zope/App/Traversing/__init__.py 1.1.2.6 => 1.1.2.7 ===
 Traversing the object tree.
 """
-
-import Zope.ContextWrapper
-def ZopeWrapper(obj, context=None, **data):
-    if obj is None or isinstance(obj,
-        (int, long, float, complex, unicode, str)):
-        return obj
-    return Zope.ContextWrapper.Wrapper(obj, context, **data)