Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
fb972e8d
Commit
fb972e8d
authored
Jan 01, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ported the lazy expression into zope.tales and require a new version of it.
parent
362cb476
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
9 additions
and
63 deletions
+9
-63
doc/CHANGES.rst
doc/CHANGES.rst
+2
-0
setup.py
setup.py
+1
-1
src/Products/PageTemplates/DeferExpr.py
src/Products/PageTemplates/DeferExpr.py
+2
-43
src/Products/PageTemplates/Expressions.py
src/Products/PageTemplates/Expressions.py
+1
-1
src/Products/PageTemplates/tests/testExpressions.py
src/Products/PageTemplates/tests/testExpressions.py
+2
-17
versions.cfg
versions.cfg
+1
-1
No files found.
doc/CHANGES.rst
View file @
fb972e8d
...
...
@@ -11,6 +11,8 @@ Trunk (unreleased)
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
...
...
setup.py
View file @
fb972e8d
...
...
@@ -130,7 +130,7 @@ setup(name='Zope2',
'zope.size'
,
'zope.structuredtext'
,
'zope.tal'
,
'zope.tales'
,
'zope.tales
>= 3.5.0
'
,
'zope.testbrowser'
,
'zope.testing'
,
'zope.traversing'
,
...
...
src/Products/PageTemplates/DeferExpr.py
View file @
fb972e8d
...
...
@@ -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
src/Products/PageTemplates/Expressions.py
View file @
fb972e8d
...
...
@@ -26,6 +26,7 @@ from zope.interface import implements
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 zExceptions import Unauthorized
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
()
...
...
src/Products/PageTemplates/tests/testExpressions.py
View file @
fb972e8d
...
...
@@ -83,18 +83,6 @@ class EngineTestsBase(PlacelessSetup):
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 @@ class EngineTestsBase(PlacelessSetup):
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 @@ def test_suite():
unittest
.
makeSuite
(
UnicodeEncodingConflictResolverTests
),
unittest
.
makeSuite
(
ZopeContextTests
),
))
if
__name__
==
'__main__'
:
main
()
versions.cfg
View file @
fb972e8d
...
...
@@ -66,7 +66,7 @@ zope.site = 3.9.0
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment