[Zope-Checkins]
SVN: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/
Wire in Zope2-compatible,
but much more simple iterator implementation.
Philipp von Weitershausen
philikon at philikon.de
Wed May 10 16:03:22 EDT 2006
Log message for revision 68091:
Wire in Zope2-compatible, but much more simple iterator implementation.
Changed:
U Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py
U Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PathIterator.py
-=-
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py 2006-05-10 18:57:21 UTC (rev 68090)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/Expressions.py 2006-05-10 20:03:21 UTC (rev 68091)
@@ -17,7 +17,7 @@
$Id$
"""
-from zope.tales.tales import ExpressionEngine, Context
+from zope.tales.tales import ExpressionEngine, Context, Iterator
from zope.tales.expressions import PathExpr, StringExpr, NotExpr
from zope.tales.expressions import DeferExpr, SubPathExpr
from zope.tales.expressions import SimpleModuleImporter
@@ -99,10 +99,48 @@
kwcontexts = contexts
return ZopeContext(self, kwcontexts)
+class ZopeIterator(Iterator):
+
+ # these used to be properties in ZTUtils.Iterator.Iterator
+
+ @property
+ def index(self):
+ return super(ZopeIterator, self).index()
+
+ @property
+ def start(self):
+ return super(ZopeIterator, self).start()
+
+ @property
+ def end(self):
+ return super(ZopeIterator, self).end()
+
+ @property
+ def item(self):
+ return super(ZopeIterator, self).item()
+
+ # these aren't in zope.tales.tales.Iterator, but were in
+ # ZTUtils.Iterator.Iterator
+
+ def first(self, name=None):
+ if self.start:
+ return True
+ return not self.same_part(name, self._last, self.item)
+
+ def last(self, name=None):
+ if self.end:
+ return True
+ return not self.same_part(name, self.item, self._next)
+
+ def same_part(self, name, ob1, ob2):
+ if name is None:
+ return ob1 == ob2
+ no = object()
+ return getattr(ob1, name, no) == getattr(ob2, name, no) is not no
+
def createZopeEngine():
e = ZopeEngine()
- #TODO wire in PathIterator.Iterator after fixing it
- # e.iteratorFactory = Iterator
+ e.iteratorFactory = ZopeIterator
for pt in ZopePathExpr._default_type_names:
e.registerType(pt, ZopePathExpr)
e.registerType('string', StringExpr)
Modified: Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PathIterator.py
===================================================================
--- Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PathIterator.py 2006-05-10 18:57:21 UTC (rev 68090)
+++ Zope/branches/ajung-zpt-end-game/lib/python/Products/PageTemplates/PathIterator.py 2006-05-10 20:03:21 UTC (rev 68091)
@@ -12,33 +12,14 @@
##############################################################################
"""Path Iterator
-A TALES Iterator with the ability to use first() and last() on
-subpaths of elements.
+BBB 2005/05/01 -- to be removed after 12 months
$Id$
"""
-import TALES
-from Expressions import restrictedTraverse, Undefs, getSecurityManager
-
-class Iterator(TALES.Iterator):
- def __bobo_traverse__(self, REQUEST, name):
- if name in ('first', 'last'):
- path = REQUEST['TraversalRequestNameStack']
- names = list(path)
- names.reverse()
- path[:] = [tuple(names)]
- return getattr(self, name)
-
- def same_part(self, name, ob1, ob2):
- if name is None:
- return ob1 == ob2
- if isinstance(name, type('')):
- name = name.split('/')
- name = filter(None, name)
- securityManager = getSecurityManager()
- try:
- ob1 = restrictedTraverse(ob1, name, securityManager)
- ob2 = restrictedTraverse(ob2, name, securityManager)
- except Undefs:
- return 0
- return ob1 == ob2
+import zope.deferredimport
+zope.deferredimport.deprecated(
+ "It has been renamed to ZopeIterator and moved to the "
+ "Products.PageTemplates.Expressions module. This reference will be "
+ "gone in Zope 2.12.",
+ PathIterator = "Products.PageTemplates.Expressions:ZopeIterator"
+ )
More information about the Zope-Checkins
mailing list