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

Fix up exception handling

parent cd7d2a45
...@@ -17,3 +17,7 @@ Page Template changes ...@@ -17,3 +17,7 @@ Page Template changes
- Expressions with embedded newlines were broken - Expressions with embedded newlines were broken
- History comparison tried to expand macros - 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 ...@@ -89,7 +89,7 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, string literals, and paths. for Python expressions, string literals, and paths.
""" """
__version__='$Revision: 1.18 $'[11:-2] __version__='$Revision: 1.19 $'[11:-2]
import re, sys import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \ from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
...@@ -103,6 +103,7 @@ def getEngine(): ...@@ -103,6 +103,7 @@ def getEngine():
if _engine is None: if _engine is None:
_engine = Engine() _engine = Engine()
installHandlers(_engine) installHandlers(_engine)
_engine._nocatch = (TALESError, 'Redirect')
return _engine return _engine
def installHandlers(engine): def installHandlers(engine):
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
An implementation of a generic TALES engine An implementation of a generic TALES engine
""" """
__version__='$Revision: 1.19 $'[11:-2] __version__='$Revision: 1.20 $'[11:-2]
import re, sys, ZTUtils import re, sys, ZTUtils
from MultiMapping import MultiMapping from MultiMapping import MultiMapping
...@@ -158,9 +158,15 @@ class Iterator(ZTUtils.Iterator): ...@@ -158,9 +158,15 @@ class Iterator(ZTUtils.Iterator):
self._context = context self._context = context
def next(self): def next(self):
if ZTUtils.Iterator.next(self): try:
self._context.setLocal(self.name, self.seq[self.index]) if ZTUtils.Iterator.next(self):
return 1 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 return 0
...@@ -224,9 +230,12 @@ class Context: ...@@ -224,9 +230,12 @@ class Context:
''' '''
_context_class = SafeMapping _context_class = SafeMapping
_nocatch = TALESError
def __init__(self, engine, contexts): def __init__(self, engine, contexts):
self._engine = engine self._engine = engine
if hasattr(engine, '_nocatch'):
self._nocatch = engine._nocatch
self.contexts = contexts self.contexts = contexts
contexts['nothing'] = None contexts['nothing'] = None
contexts['default'] = Default contexts['default'] = Default
...@@ -284,15 +293,13 @@ class Context: ...@@ -284,15 +293,13 @@ class Context:
expression = self._engine.compile(expression) expression = self._engine.compile(expression)
try: try:
v = expression(self) v = expression(self)
except TALESError: if isinstance(v, Exception):
raise v
except self._nocatch:
raise raise
except: except:
if sys.exc_info()[0] in ('Redirect', 'Unauthorized'):
raise
raise TALESError, (`expression`, sys.exc_info()), sys.exc_info()[2] raise TALESError, (`expression`, sys.exc_info()), sys.exc_info()[2]
else: else:
if isinstance(v, Exception):
raise v
return v return v
evaluateValue = evaluate evaluateValue = evaluate
......
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
Zope object encapsulating a Page Template. Zope object encapsulating a Page Template.
""" """
__version__='$Revision: 1.15 $'[11:-2] __version__='$Revision: 1.16 $'[11:-2]
import os, AccessControl, Acquisition, sys import os, AccessControl, Acquisition, sys
from Globals import DTMLFile, MessageDialog, package_home from Globals import DTMLFile, MessageDialog, package_home
...@@ -103,6 +103,7 @@ from OFS.Cache import Cacheable ...@@ -103,6 +103,7 @@ from OFS.Cache import Cacheable
from OFS.Traversable import Traversable from OFS.Traversable import Traversable
from OFS.PropertyManager import PropertyManager from OFS.PropertyManager import PropertyManager
from PageTemplate import PageTemplate from PageTemplate import PageTemplate
from TALES import TALESError
try: try:
from webdav.Lockable import ResourceLockedError from webdav.Lockable import ResourceLockedError
...@@ -262,7 +263,12 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -262,7 +263,12 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
# Execute the template in a new security context. # Execute the template in a new security context.
security.addContext(self) security.addContext(self)
try: 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: if keyset is not None:
# Store the result in the cache. # Store the result in the cache.
self.ZCacheable_set(result, keywords=keyset) 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