Commit 7e13514d authored by Evan Simpson's avatar Evan Simpson

Fix up exception handling

parent cd7d2a45
......@@ -17,3 +17,7 @@ Page Template changes
- Expressions with embedded newlines were broken
- History comparison tried to expand macros
- Iterator exceptions weren't converted
- 'Unauthorized' exception couldn't be handled by on-error
......@@ -89,7 +89,7 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, string literals, and paths.
"""
__version__='$Revision: 1.18 $'[11:-2]
__version__='$Revision: 1.19 $'[11:-2]
import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
......@@ -103,6 +103,7 @@ def getEngine():
if _engine is None:
_engine = Engine()
installHandlers(_engine)
_engine._nocatch = (TALESError, 'Redirect')
return _engine
def installHandlers(engine):
......
......@@ -87,7 +87,7 @@
An implementation of a generic TALES engine
"""
__version__='$Revision: 1.19 $'[11:-2]
__version__='$Revision: 1.20 $'[11:-2]
import re, sys, ZTUtils
from MultiMapping import MultiMapping
......@@ -158,9 +158,15 @@ class Iterator(ZTUtils.Iterator):
self._context = context
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 @@ class Context:
'''
_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 @@ class Context:
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
......
......@@ -87,7 +87,7 @@
Zope object encapsulating a Page Template.
"""
__version__='$Revision: 1.15 $'[11:-2]
__version__='$Revision: 1.16 $'[11:-2]
import os, AccessControl, Acquisition, sys
from Globals import DTMLFile, MessageDialog, package_home
......@@ -103,6 +103,7 @@ from OFS.Cache import Cacheable
from OFS.Traversable import Traversable
from OFS.PropertyManager import PropertyManager
from PageTemplate import PageTemplate
from TALES import TALESError
try:
from webdav.Lockable import ResourceLockedError
......@@ -262,7 +263,12 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
# 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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment