[ZPT] CVS: Zope3/lib/python/Zope/TAL - DummyEngine.py:1.28.14.3 HTMLTALParser.py:1.30.4.3 TALDefs.py:1.24.10.3 TALGenerator.py:1.52.16.3 TALInterpreter.py:1.63.10.3 TALParser.py:1.16.16.3 XMLParser.py:1.6.12.2 driver.py:1.25.18.3 runtest.py:1.19.14.3 timer.py:1.9.24.2
Shane Hathaway
shane@cvs.zope.org
Wed, 13 Mar 2002 22:19:17 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/TAL
In directory cvs.zope.org:/tmp/cvs-serv1513
Modified Files:
Tag: Zope-3x-branch
DummyEngine.py HTMLTALParser.py TALDefs.py TALGenerator.py
TALInterpreter.py TALParser.py XMLParser.py driver.py
runtest.py timer.py
Log Message:
- Made TALGenerator provide the source file name for errors.
- Made it so TALESErrors don't mask another exception, which is unfortunately
brittle.
- Updated license.
=== Zope3/lib/python/Zope/TAL/DummyEngine.py 1.28.14.2 => 1.28.14.3 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Dummy TALES engine so that I can test out the TAL implementation.
"""
@@ -14,7 +20,7 @@
import driver
-from TALDefs import NAME_RE, TALError, TALESError
+from TALDefs import NAME_RE, TALESError, ErrorInfo
Default = []
@@ -26,6 +32,7 @@
class DummyEngine:
position = None
+ source_file = None
def __init__(self, macros=None):
if macros is None:
@@ -38,6 +45,9 @@
def getCompilerError(self):
return CompilerError
+ def setSourceFile(self, source_file):
+ self.source_file = source_file
+
def setPosition(self, position):
self.position = position
@@ -93,8 +103,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):
@@ -158,8 +167,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
=== Zope3/lib/python/Zope/TAL/HTMLTALParser.py 1.30.4.2 => 1.30.4.3 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Parse HTML and compile to TALInterpreter intermediate code.
"""
=== Zope3/lib/python/Zope/TAL/TALDefs.py 1.24.10.2 => 1.24.10.3 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Common definitions used by TAL and METAL compilation an transformation.
"""
@@ -60,27 +66,22 @@
pass
class TALESError(TALError):
+ pass
+
+
+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]
- # This exception can carry around another exception + traceback
- def takeTraceback(self):
- t = self.info[2]
- self.info = self.info[:2] + (None,)
- return t
-
- 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)
=== Zope3/lib/python/Zope/TAL/TALGenerator.py 1.52.16.2 => 1.52.16.3 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Code generator for TALInterpreter intermediate code.
"""
@@ -18,8 +24,9 @@
inMacroUse = 0
inMacroDef = 0
+ source_file = None
- def __init__(self, expressionCompiler=None, xml=1):
+ def __init__(self, expressionCompiler=None, xml=1, source_file=None):
if not expressionCompiler:
from DummyEngine import DummyEngine
expressionCompiler = DummyEngine()
@@ -34,6 +41,9 @@
self.xml = xml
self.emit("version", TAL_VERSION)
self.emit("mode", xml and "xml" or "html")
+ if source_file is not None:
+ self.source_file = source_file
+ self.emit("setSourceFile", source_file)
def getCode(self):
assert not self.stack
@@ -432,6 +442,8 @@
self.pushProgram()
self.emit("version", TAL_VERSION)
self.emit("mode", self.xml and "xml" or "html")
+ if self.source_file is not None:
+ self.emit("setSourceFile", self.source_file)
todo["defineMacro"] = defineMacro
self.inMacroDef = self.inMacroDef + 1
if useMacro:
=== Zope3/lib/python/Zope/TAL/TALInterpreter.py 1.63.10.2 => 1.63.10.3 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Interpreter for a pre-compiled TAL program.
"""
@@ -80,7 +86,6 @@
self.program = program
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
@@ -152,7 +157,8 @@
self._stream_write("\n")
self.col = 0
- def stream_write(self, s):
+ def stream_write(self, s,
+ len=len):
self._stream_write(s)
i = s.rfind('\n')
if i < 0:
@@ -195,6 +201,10 @@
self.endlen = len(self.endsep)
bytecode_handlers["mode"] = do_mode
+ def do_setSourceFile(self, source_file):
+ self.engine.setSourceFile(source_file)
+ bytecode_handlers["setSourceFile"] = do_setSourceFile
+
def do_setPosition(self, position):
self.position = position
self.engine.setPosition(position)
@@ -547,16 +557,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)
=== Zope3/lib/python/Zope/TAL/TALParser.py 1.16.16.2 => 1.16.16.3 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Parse XML and compile to TALInterpreter intermediate code.
"""
=== Zope3/lib/python/Zope/TAL/XMLParser.py 1.6.12.1 => 1.6.12.2 ===
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Generic expat-based XML parser base class.
"""
=== Zope3/lib/python/Zope/TAL/driver.py 1.25.18.2 => 1.25.18.3 ===
-
+#!/usr/bin/env python
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Driver program to test METAL and TAL implementation.
"""
=== Zope3/lib/python/Zope/TAL/runtest.py 1.19.14.2 => 1.19.14.3 ===
-
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Driver program to run METAL and TAL regression tests.
"""
=== Zope3/lib/python/Zope/TAL/timer.py 1.9.24.1 => 1.9.24.2 ===
-
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
# This software is subject to the provisions of the Zope Public License,
-# Version 1.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE
+#
+##############################################################################
"""
Helper program to time compilation and interpretation
"""