[Checkins] SVN: z3c.pt/trunk/ Make sure builtins such as 'path' and 'exists' can be redefined.
Malthe Borch
mborch at gmail.com
Thu Aug 11 04:34:07 EDT 2011
Log message for revision 122531:
Make sure builtins such as 'path' and 'exists' can be redefined.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/setup.py
U z3c.pt/trunk/src/z3c/pt/expressions.py
U z3c.pt/trunk/src/z3c/pt/tests/path.pt
U z3c.pt/trunk/src/z3c/pt/tests/test_templates.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2011-08-10 16:44:08 UTC (rev 122530)
+++ z3c.pt/trunk/CHANGES.txt 2011-08-11 08:34:07 UTC (rev 122531)
@@ -3,6 +3,8 @@
In next release ...
+- Make sure the builtin names 'path' and 'exists' can be redefined.
+
- Guard ``sys.modules`` (mapped to the builtin variable "modules")
against import-time side effects using ``ProxyFactory``.
Modified: z3c.pt/trunk/setup.py
===================================================================
--- z3c.pt/trunk/setup.py 2011-08-10 16:44:08 UTC (rev 122530)
+++ z3c.pt/trunk/setup.py 2011-08-11 08:34:07 UTC (rev 122531)
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys
-version = '2.1'
+version = '2.1.1dev'
install_requires = [
'setuptools',
@@ -10,7 +10,7 @@
'zope.i18n >= 3.5',
'zope.traversing',
'zope.contentprovider',
- 'Chameleon >= 2.2',
+ 'Chameleon >= 2.3.1',
]
setup(name='z3c.pt',
Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py 2011-08-10 16:44:08 UTC (rev 122530)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py 2011-08-11 08:34:07 UTC (rev 122531)
@@ -22,6 +22,7 @@
from chameleon.astutil import load
from chameleon.astutil import Symbol
from chameleon.astutil import Static
+from chameleon.astutil import Builtin
from chameleon.astutil import NameLookupRewriteVisitor
from chameleon.exc import ExpressionError
@@ -217,10 +218,14 @@
class PythonExpr(BasePythonExpr):
- builtins = {
- 'path': template("tales(econtext, rcontext, 'path')", mode="eval"),
- 'exists': template("tales(econtext, rcontext, 'exists')", mode="eval"),
- }
+ builtins = dict(
+ (name, template(
+ "tales(econtext, rcontext, name)",
+ tales=Builtin("tales"),
+ name=ast.Str(s=name),
+ mode="eval"))
+ for name in ('path', 'exists')
+ )
def __init__(self, expression):
self.expression = expression
@@ -229,7 +234,15 @@
return self.translate(self.expression, target)
def rewrite(self, node):
- return self.builtins.get(node.id, node)
+ builtin = self.builtins.get(node.id)
+ if builtin is not None:
+ return template(
+ "get(name) if get(name) is not None else builtin",
+ get=Builtin("get"),
+ name=ast.Str(s=node.id),
+ builtin=builtin,
+ mode="eval"
+ )
@property
def transform(self):
Modified: z3c.pt/trunk/src/z3c/pt/tests/path.pt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/path.pt 2011-08-10 16:44:08 UTC (rev 122530)
+++ z3c.pt/trunk/src/z3c/pt/tests/path.pt 2011-08-11 08:34:07 UTC (rev 122531)
@@ -3,3 +3,7 @@
tal:condition="support">
WYSWIWYG supported.
</div>
+
+<div tal:define="path string:some path">
+ <span tal:content="path" />
+</div>
\ No newline at end of file
Modified: z3c.pt/trunk/src/z3c/pt/tests/test_templates.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_templates.py 2011-08-10 16:44:08 UTC (rev 122530)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_templates.py 2011-08-11 08:34:07 UTC (rev 122531)
@@ -41,8 +41,8 @@
result = template(editor="dummy")
self.failUnless("supported" in result)
+ self.failUnless("some path" in result)
-
def test_suite():
import sys
return unittest.findTestCases(sys.modules[__name__])
More information about the checkins
mailing list