[Checkins] SVN: z3c.pt/trunk/ Always use ``"nocall:"`` with an exists-expressions.
Malthe Borch
mborch at gmail.com
Thu Mar 24 11:34:29 EDT 2011
Log message for revision 121113:
Always use ``"nocall:"`` with an exists-expressions.
Changed:
U z3c.pt/trunk/CHANGES.txt
U z3c.pt/trunk/src/z3c/pt/expressions.py
A z3c.pt/trunk/src/z3c/pt/tests/exists.pt
A z3c.pt/trunk/src/z3c/pt/tests/nocall.pt
A z3c.pt/trunk/src/z3c/pt/tests/test_templates.py
-=-
Modified: z3c.pt/trunk/CHANGES.txt
===================================================================
--- z3c.pt/trunk/CHANGES.txt 2011-03-24 15:32:42 UTC (rev 121112)
+++ z3c.pt/trunk/CHANGES.txt 2011-03-24 15:34:29 UTC (rev 121113)
@@ -1,6 +1,13 @@
Changelog
=========
+In next release...
+
+- Fixed an issue with ``"exists:"`` expression where a callable would
+ be attempted called. It is meanwhile implied with this expression
+ types that it should use the ``"nocall:"`` pragma.
+
+
2.0-rc1 (2011-02-28)
~~~~~~~~~~~~~~~~~~~~
Modified: z3c.pt/trunk/src/z3c/pt/expressions.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/expressions.py 2011-03-24 15:32:42 UTC (rev 121112)
+++ z3c.pt/trunk/src/z3c/pt/expressions.py 2011-03-24 15:34:29 UTC (rev 121113)
@@ -92,10 +92,6 @@
return base
-class ExistsExpr(BaseExistsExpr):
- exceptions = AttributeError, LookupError, TypeError, KeyError, NameError
-
-
class PathExpr(BasePathExpr):
path_regex = re.compile(
r'^(?:(nocall|not):\s*)*((?:[A-Za-z_][A-Za-z0-9_:]*)' +
@@ -187,6 +183,13 @@
"nocall:%s" % expression, engine)
+class ExistsExpr(BaseExistsExpr):
+ exceptions = AttributeError, LookupError, TypeError, KeyError, NameError
+
+ def __init__(self, expression):
+ super(ExistsExpr, self).__init__("nocall:" + expression)
+
+
class ProviderExpr(object):
provider_regex = re.compile(r'^[A-Za-z][A-Za-z0-9_\.-]*$')
Added: z3c.pt/trunk/src/z3c/pt/tests/exists.pt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/exists.pt (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/tests/exists.pt 2011-03-24 15:34:29 UTC (rev 121113)
@@ -0,0 +1 @@
+<div tal:condition="exists: options/callable">ok</div>
\ No newline at end of file
Added: z3c.pt/trunk/src/z3c/pt/tests/nocall.pt
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/nocall.pt (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/tests/nocall.pt 2011-03-24 15:34:29 UTC (rev 121113)
@@ -0,0 +1 @@
+<div tal:content="structure nocall: options/callable" />
\ No newline at end of file
Added: z3c.pt/trunk/src/z3c/pt/tests/test_templates.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/tests/test_templates.py (rev 0)
+++ z3c.pt/trunk/src/z3c/pt/tests/test_templates.py 2011-03-24 15:34:29 UTC (rev 121113)
@@ -0,0 +1,35 @@
+import unittest
+
+import zope.component.testing
+import zope.configuration.xmlconfig
+
+
+class TestPageTemplateFile(unittest.TestCase):
+ def setUp(self):
+ import z3c.pt
+ zope.component.testing.setUp(self)
+ zope.configuration.xmlconfig.XMLConfig('configure.zcml', z3c.pt)()
+
+ def tearDown(self):
+ zope.component.testing.tearDown(self)
+
+ def test_nocall(self):
+ from z3c.pt.pagetemplate import PageTemplateFile
+ template = PageTemplateFile("nocall.pt")
+ def dont_call():
+ raise RuntimeError()
+ result = template(callable=dont_call)
+ self.failUnless(repr(dont_call) in result)
+
+ def test_exists(self):
+ from z3c.pt.pagetemplate import PageTemplateFile
+ template = PageTemplateFile("exists.pt")
+ def dont_call():
+ raise RuntimeError()
+ result = template(callable=dont_call)
+ self.failUnless('ok' in result)
+
+
+def test_suite():
+ import sys
+ return unittest.findTestCases(sys.modules[__name__])
More information about the checkins
mailing list