[ZPT] CVS: Zope/lib/python/TAL - DummyEngine.py:1.29.18.1 TALDefs.py:1.25.18.1 TALInterpreter.py:1.66.2.1
Shane Hathaway
shane@cvs.zope.org
Fri, 1 Mar 2002 17:26:43 -0500
Update of /cvs-repository/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv13270
Modified Files:
Tag: shane-better-tracebacks-branch
DummyEngine.py TALDefs.py TALInterpreter.py
Log Message:
Made it so TALESErrors do not carry other exceptions and replaced the
getTALESError() method with createErrorInfo(), used when processing "on-error"
directives.
=== Zope/lib/python/TAL/DummyEngine.py 1.29 => 1.29.18.1 ===
import driver
-from TALDefs import NAME_RE, TALError, TALESError
+from TALDefs import NAME_RE, TALESError, ErrorInfo
Default = []
@@ -97,8 +97,7 @@
try:
return eval(expr, self.globals, self.locals)
except:
- raise TALESError("evaluation error in %s" % `expr`,
- info=sys.exc_info())
+ raise TALESError("evaluation error in %s" % `expr`)
raise TALESError("unrecognized expression: " + `expression`)
def evaluateValue(self, expr):
@@ -161,8 +160,8 @@
seq = self.evaluateSequence(expr)
return Iterator(name, seq, self)
- def getTALESError(self):
- return TALESError
+ def createErrorInfo(self, err, position):
+ return ErrorInfo(err, position)
def getDefault(self):
return Default
=== Zope/lib/python/TAL/TALDefs.py 1.25 => 1.25.18.1 ===
class TALESError(TALError):
+ pass
- # This exception can carry around another exception + traceback
- def takeTraceback(self):
- t = self.info[2]
- self.info = self.info[:2] + (None,)
- return t
+class ErrorInfo:
+
+ def __init__(self, err, position=(None, None)):
+ if isinstance(err, Exception):
+ self.type = err.__class__
+ self.value = err
+ else:
+ self.type = err
+ self.value = None
+ self.lineno = position[0]
+ self.offset = position[1]
+
- def __init__(self, msg, position=(None, None), info=(None, None, None)):
- t, v, tb = info
- if t:
- if issubclass(t, Exception) and t.__module__ == "exceptions":
- err = t.__name__
- else:
- err = str(t)
- v = v is not None and str(v)
- if v:
- err = "%s: %s" % (err, v)
- msg = "%s: %s" % (msg, err)
- TALError.__init__(self, msg, position)
- self.info = info
import re
_attr_re = re.compile(r"\s*([^\s]+)\s+([^\s].*)\Z", re.S)
=== Zope/lib/python/TAL/TALInterpreter.py 1.66 => 1.66.2.1 ===
self.macros = macros
self.engine = engine
- self.TALESError = engine.getTALESError()
self.Default = engine.getDefault()
self.stream = stream or sys.stdout
self._stream_write = self.stream.write
@@ -553,16 +552,15 @@
self._stream_write = stream.write
try:
self.interpret(block)
- except self.TALESError, err:
+ except Exception, exc:
self.restoreState(state)
engine = self.engine
engine.beginScope()
- err.lineno, err.offset = self.position
- engine.setLocal('error', err)
+ error = engine.createErrorInfo(exc, self.position)
+ engine.setLocal('error', error)
try:
self.interpret(handler)
finally:
- err.takeTraceback()
engine.endScope()
else:
self.restoreOutputState(state)