[ZPT] CVS: Releases/Zope/lib/python/Products/PageTemplates - Expressions.py:1.24 ZopePageTemplate.py:1.26

Evan Simpson evan@zope.com
Tue, 6 Nov 2001 15:13:56 -0500


Update of /cvs-repository/Releases/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv27101/Products/PageTemplates

Modified Files:
	Expressions.py ZopePageTemplate.py 
Log Message:
Make ZPT use Unauthorized, when it's available.


=== Releases/Zope/lib/python/Products/PageTemplates/Expressions.py 1.23 => 1.24 ===
 if sys.modules.has_key('Zope'):
     import AccessControl
-    from AccessControl import getSecurityManager
+    from AccessControl import getSecurityManager, Unauthorized
     if hasattr(AccessControl, 'full_read_guard'):
         from ZRPythonExpr import PythonExpr, _SecureModuleImporter, \
              call_with_ns
@@ -128,6 +128,10 @@
     SecureModuleImporter = _SecureModuleImporter()
 else:
     from PythonExpr import getSecurityManager, PythonExpr
+    try:
+        from zExceptions import Unauthorized
+    except ImportError:
+        Unauthorized = "Unauthorized"
     def call_with_ns(f, ns, arg=1):
         if arg==2:
             return f(None, ns)
@@ -206,7 +210,7 @@
             except Undefined, e:
                 ob = e
             except (AttributeError, KeyError, TypeError, IndexError,
-                    'Unauthorized'), e:
+                    Unauthorized), e:
                 ob = Undefined(self._s, sys.exc_info())
 
         if self._name == 'exists':
@@ -311,7 +315,7 @@
         # If the path starts with an empty string, go to the root first.
         self = self.getPhysicalRoot()
         if not securityManager.validateValue(self):
-            raise 'Unauthorized', name
+            raise Unauthorized, name
         i = 1
 
     plen = len(path)
@@ -331,7 +335,7 @@
             o = get(object, 'aq_parent', M)
             if o is not M:
                 if not validate(object, object, name, o):
-                    raise 'Unauthorized', name
+                    raise Unauthorized, name
                 object=o
                 continue
 
@@ -346,7 +350,7 @@
                 and get(object, name) == o):
                 container = object
             if not validate(object, container, name, o):
-                raise 'Unauthorized', name
+                raise Unauthorized, name
         else:
             o=get(object, name, M)
             if o is not M:
@@ -356,14 +360,14 @@
                         name, validate2, validate)
                 else:
                     if not validate(object, object, name, o):
-                        raise 'Unauthorized', name
+                        raise Unauthorized, name
             else:
                 try:
                     o=object[name]
                 except (AttributeError, TypeError):
                     raise AttributeError, name
                 if not validate(object, object, name, o):
-                    raise 'Unauthorized', name
+                    raise Unauthorized, name
         object = o
 
     return object
@@ -371,5 +375,5 @@
 
 def validate2(orig, inst, name, v, real_validate):
     if not real_validate(orig, inst, name, v):
-        raise 'Unauthorized', name
+        raise Unauthorized, name
     return 1


=== Releases/Zope/lib/python/Products/PageTemplates/ZopePageTemplate.py 1.25 => 1.26 ===
 from Shared.DC.Scripts.Script import Script, BindingsUI
 from Shared.DC.Scripts.Signature import FuncCode
-from AccessControl import getSecurityManager
+from AccessControl import getSecurityManager, Unauthorized
 from OFS.History import Historical, html_diff
 from OFS.Cache import Cacheable
 from OFS.Traversable import Traversable
@@ -274,7 +274,8 @@
             try:
                 result = self.pt_render(extra_context=bound_names)
             except TALESError, err:
-                if err.type == 'Unauthorized':
+                if (err.type == Unauthorized or
+                    isinstance(err.type, Unauthorized)):
                     raise err.type, err.value, err.takeTraceback()
                 err.takeTraceback()
                 raise