[ZPT] CVS: Products/PageTemplates - CHANGES.txt:1.17 Expressions.py:1.19 TALES.py:1.20 ZopePageTemplate.py:1.16

Evan Simpson evan@zope.com
Mon, 13 Aug 2001 13:45:53 -0400


Update of /cvs-repository/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv15494

Modified Files:
	CHANGES.txt Expressions.py TALES.py ZopePageTemplate.py 
Log Message:
Fix up exception handling


=== Products/PageTemplates/CHANGES.txt 1.16 => 1.17 ===
 
         - History comparison tried to expand macros
+
+        - Iterator exceptions weren't converted
+
+        - 'Unauthorized' exception couldn't be handled by on-error


=== Products/PageTemplates/Expressions.py 1.18 => 1.19 ===
         _engine = Engine()
         installHandlers(_engine)
+        _engine._nocatch = (TALESError, 'Redirect')
     return _engine
 
 def installHandlers(engine):


=== Products/PageTemplates/TALES.py 1.19 => 1.20 ===
 
     def next(self):
-        if ZTUtils.Iterator.next(self):
-            self._context.setLocal(self.name, self.seq[self.index])
-            return 1
+        try:
+            if ZTUtils.Iterator.next(self):
+                self._context.setLocal(self.name, self.seq[self.index])
+                return 1
+        except TALESError:
+            raise
+        except:
+            raise TALESError, ('repeat/%s' % self.name,
+                               sys.exc_info()), sys.exc_info()[2]
         return 0
 
 
@@ -224,9 +230,12 @@
     '''
 
     _context_class = SafeMapping
+    _nocatch = TALESError
 
     def __init__(self, engine, contexts):
         self._engine = engine
+        if hasattr(engine, '_nocatch'):
+            self._nocatch = engine._nocatch
         self.contexts = contexts
         contexts['nothing'] = None
         contexts['default'] = Default
@@ -284,15 +293,13 @@
             expression = self._engine.compile(expression)
         try:
             v = expression(self)
-        except TALESError:
+            if isinstance(v, Exception):
+                raise v
+        except self._nocatch:
             raise
         except:
-            if sys.exc_info()[0] in ('Redirect', 'Unauthorized'):
-                raise
             raise TALESError, (`expression`, sys.exc_info()), sys.exc_info()[2]
         else:
-            if isinstance(v, Exception):
-                raise v
             return v
 
     evaluateValue = evaluate


=== Products/PageTemplates/ZopePageTemplate.py 1.15 => 1.16 ===
 from OFS.PropertyManager import PropertyManager
 from PageTemplate import PageTemplate
+from TALES import TALESError
 
 try:
     from webdav.Lockable import ResourceLockedError
@@ -262,7 +263,12 @@
         # Execute the template in a new security context.
         security.addContext(self)
         try:
-            result = self.pt_render(extra_context=bound_names)
+            try:
+                result = self.pt_render(extra_context=bound_names)
+            except TALESError, err:
+                if err.type == 'Unauthorized':
+                    raise err.type, err.value
+                raise
             if keyset is not None:
                 # Store the result in the cache.
                 self.ZCacheable_set(result, keywords=keyset)