[Zope-Checkins] CVS: Zope3/lib/python/Zope/PageTemplate - Expressions.py:1.1.2.12 SimpleViewClass.py:1.1.2.8

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


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

Modified Files:
      Tag: Zope-3x-branch
	Expressions.py SimpleViewClass.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/PageTemplate/Expressions.py 1.1.2.11 => 1.1.2.12 ===
 from PythonExpr import PythonExpr
 
+# XXX should we have this dependency?
+from Zope.Exceptions import NotFoundError, Unauthorized
 
 Undefs = (Undefined, AttributeError, KeyError,
           TypeError, IndexError, Unauthorized)
 
+_marker = object()
+
 def simpleTraverse(object, path_items):
     """Traverses a sequence of names, first trying attributes then items.
     """
+
     for name in path_items:
-        if hasattr(object, name):
-            object = getattr(object, name)
+        next = getattr(object, name, _marker)
+        if next is not _marker:
+            object = next
         elif hasattr(object, '__getitem__'):
             object = object[name]
         else:


=== Zope3/lib/python/Zope/PageTemplate/SimpleViewClass.py 1.1.2.7 => 1.1.2.8 ===
 from Zope.Publisher.Browser.IBrowserPublisher import IBrowserPublisher
 from PageTemplateFile import PageTemplateFile
+from Zope.Security.Checker import defineChecker, NamesChecker
 
 class simple(object):
 
@@ -48,12 +49,11 @@
 def SimpleViewClass(src, offering=None, used_for=None):
     if offering is None:
         offering = sys._getframe(1).f_globals
-    
-    class C(simple):
 
-        if used_for is not None: __used_for__ = used_for
-        
-        index=PageTemplateFile(src, offering)
-        index.__permission__ = 'Zope.Public'
+    class_ = type(src, (simple,), {'index': PageTemplateFile(src, offering)})
+    if used_for is not None:
+        class_.__used_for__ = used_for
+
+    defineChecker(class_, NamesChecker('index'))
 
-    return C
+    return class_