[Zope-Checkins] SVN: Zope/trunk/ Ported the lazy expression into zope.tales and require a new version of it.
Hanno Schlichting
hannosch at hannosch.eu
Fri Jan 1 15:14:42 EST 2010
Log message for revision 107519:
Ported the lazy expression into zope.tales and require a new version of it.
Changed:
U Zope/trunk/doc/CHANGES.rst
U Zope/trunk/setup.py
U Zope/trunk/src/Products/PageTemplates/DeferExpr.py
U Zope/trunk/src/Products/PageTemplates/Expressions.py
U Zope/trunk/src/Products/PageTemplates/tests/testExpressions.py
U Zope/trunk/versions.cfg
-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst 2010-01-01 20:12:39 UTC (rev 107518)
+++ Zope/trunk/doc/CHANGES.rst 2010-01-01 20:14:41 UTC (rev 107519)
@@ -11,6 +11,8 @@
Restructuring
+++++++++++++
+- Ported the lazy expression into zope.tales and require a new version of it.
+
- Updated Five documentation to clarify its role in regard to Zope packages.
- Removed the deprecated ``five:containerEvents`` directive, which had been
Modified: Zope/trunk/setup.py
===================================================================
--- Zope/trunk/setup.py 2010-01-01 20:12:39 UTC (rev 107518)
+++ Zope/trunk/setup.py 2010-01-01 20:14:41 UTC (rev 107519)
@@ -130,7 +130,7 @@
'zope.size',
'zope.structuredtext',
'zope.tal',
- 'zope.tales',
+ 'zope.tales >= 3.5.0',
'zope.testbrowser',
'zope.testing',
'zope.traversing',
Modified: Zope/trunk/src/Products/PageTemplates/DeferExpr.py
===================================================================
--- Zope/trunk/src/Products/PageTemplates/DeferExpr.py 2010-01-01 20:12:39 UTC (rev 107518)
+++ Zope/trunk/src/Products/PageTemplates/DeferExpr.py 2010-01-01 20:14:41 UTC (rev 107519)
@@ -10,48 +10,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
-"""Lazy expression handler
-A lazy expressions is implemented similarly to the defer expression
-but has a different result. While a defer expression is evaluated
-every time it is used according to its context a lazy expression is
-evaluted only the first time it is used. Lazy expression are known
-under the name lazy initialization of variables, too. A common use
-case for a lazy expression is a lazy binding of a costly expression.
-While one could call an expression only when it's required it makes
-sense to define it only one time when it could be used multiple times.
-
-Example
-
- <div tal:define="lazyvar lazy:here/suckMyCPU">
- <div tal:condition="foo" tal:content="lazyvar" />
- <div tal:condition="bar" tal:content="lazyvar" />
- <div tal:condition"python: not (foo or bar)">...</div>
- </div>
-"""
+# BBB
from zope.tales.expressions import DeferWrapper, DeferExpr
-_marker = object()
-
-# TODO These should really be integrated into the zope.tales implementation
-
-class LazyWrapper(DeferWrapper):
- """Wrapper for lazy: expression
- """
- def __init__(self, expr, econtext):
- DeferWrapper.__init__(self, expr, econtext)
- self._result = _marker
-
- def __call__(self):
- r = self._result
- if r is _marker:
- self._result = r = self._expr(self._econtext)
- return r
-
-class LazyExpr(DeferExpr):
- """lazy: expression handler for lazy initialization of expressions
- """
- def __call__(self, econtext):
- return LazyWrapper(self._c, econtext)
-
- def __repr__(self):
- return 'lazy:%s' % `self._s`
+from zope.tales.expressions import LazyWrapper, LazyExpr
Modified: Zope/trunk/src/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/trunk/src/Products/PageTemplates/Expressions.py 2010-01-01 20:12:39 UTC (rev 107518)
+++ Zope/trunk/src/Products/PageTemplates/Expressions.py 2010-01-01 20:14:41 UTC (rev 107519)
@@ -26,6 +26,7 @@
from zope.pagetemplate.engine import ZopeEngine as Z3Engine
from zope.proxy import removeAllProxies
from zope.tales.expressions import DeferExpr
+from zope.tales.expressions import LazyExpr
from zope.tales.expressions import NotExpr
from zope.tales.expressions import PathExpr
from zope.tales.expressions import StringExpr
@@ -45,7 +46,6 @@
from zope.contentprovider.tales import TALESProviderExpression
from Products.PageTemplates import ZRPythonExpr
-from Products.PageTemplates.DeferExpr import LazyExpr
from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
SecureModuleImporter = ZRPythonExpr._SecureModuleImporter()
Modified: Zope/trunk/src/Products/PageTemplates/tests/testExpressions.py
===================================================================
--- Zope/trunk/src/Products/PageTemplates/tests/testExpressions.py 2010-01-01 20:12:39 UTC (rev 107518)
+++ Zope/trunk/src/Products/PageTemplates/tests/testExpressions.py 2010-01-01 20:14:41 UTC (rev 107519)
@@ -83,18 +83,6 @@
ec = self._makeContext()
self.failUnless(ec.evaluate('x | nothing') is None)
- def DONT_test_evaluate_with_empty_element(self):
- # empty path elements aren't supported anymore, for the lack
- # of a use case
- ec = self._makeContext()
- self.assertEqual(ec.evaluate('d/'), 'blank')
-
- def DONT_test_evaluate_with_empty_element_and_alternative(self):
- # empty path elements aren't supported anymore, for the lack
- # of a use case
- ec = self._makeContext()
- self.assertEqual(ec.evaluate('d/ | nothing'), 'blank')
-
def test_evaluate_dict_key_as_underscore(self):
ec = self._makeContext()
self.assertEqual(ec.evaluate('d/_'), 'under')
@@ -131,13 +119,13 @@
ec.endScope()
def test_defer_expression_returns_wrapper(self):
- from Products.PageTemplates.DeferExpr import DeferWrapper
+ from zope.tales.expressions import DeferWrapper
ec = self._makeContext()
defer = ec.evaluate('defer: b')
self.failUnless(isinstance(defer, DeferWrapper))
def test_lazy_expression_returns_wrapper(self):
- from Products.PageTemplates.DeferExpr import LazyWrapper
+ from zope.tales.expressions import LazyWrapper
ec = self._makeContext()
lazy = ec.evaluate('lazy: b')
self.failUnless(isinstance(lazy, LazyWrapper))
@@ -269,6 +257,3 @@
unittest.makeSuite(UnicodeEncodingConflictResolverTests),
unittest.makeSuite(ZopeContextTests),
))
-
-if __name__=='__main__':
- main()
Modified: Zope/trunk/versions.cfg
===================================================================
--- Zope/trunk/versions.cfg 2010-01-01 20:12:39 UTC (rev 107518)
+++ Zope/trunk/versions.cfg 2010-01-01 20:14:41 UTC (rev 107519)
@@ -66,7 +66,7 @@
zope.size = 3.4.1
zope.structuredtext = 3.4.0
zope.tal = 3.5.2
-zope.tales = 3.4.0
+zope.tales = 3.5.0
zope.testbrowser = 3.7.0
zope.testing = 3.8.3
zope.traversing = 3.12.0
More information about the Zope-Checkins
mailing list