[Zope3-checkins] CVS: Zope3/src/zope/tales - tales.py:1.6

Jim Fulton jim@zope.com
Tue, 20 May 2003 16:29:59 -0400


Update of /cvs-repository/Zope3/src/zope/tales
In directory cvs.zope.org:/tmp/cvs-serv31201/src/zope/tales

Modified Files:
	tales.py 
Log Message:
Moved the iterator code here. Modified iterators to work with Python
iterators and iterables. Added doctest tests.

Changed the strategy used to manage variables. Variables
(context.vars) is now just a dictionary, rather than a special
object.  Likewise for the repeat variables.

Added a context hook so that subclasses can override the way context
variables are set. (Specifically so that Zope contexts can put
security proxies around the context (top-level) variables.

Attempted to make the module usable even if zope.tal can't be
imported.

Renamed a bunch of interfaces to reflect the TAL expression, rather
than TALES.

Moved the SimpleExpr class, which is only used for testing to the test
package. 



=== Zope3/src/zope/tales/tales.py 1.5 => 1.6 === (433/533 lines abridged)
--- Zope3/src/zope/tales/tales.py:1.5	Thu May  1 15:35:50 2003
+++ Zope3/src/zope/tales/tales.py	Tue May 20 16:29:59 2003
@@ -13,7 +13,7 @@
 ##############################################################################
 """TALES
 
-An implementation of a generic TALES engine
+An implementation of a TAL expression engine
 """
 __metaclass__ = type # All classes are new style when run with Python 2.2+
 
@@ -24,10 +24,18 @@
 
 from zope.proxy import proxy_compatible_isinstance as isinstance_ex
 from zope.proxy.context.wrapper import getbaseobject
-from zope.pagetemplate import iterator
-from zope.pagetemplate import safemapping
+from zope.tales.interfaces import ITALESIterator
+from zope.interface import implements
 
-from zope.tal.interfaces import ITALESCompiler, ITALESEngine, ITALESErrorInfo
+try:
+    from zope import tal
+except ImportError:
+    tal = None
+
+if tal:
+    from zope.tal.interfaces import ITALExpressionCompiler, ITALExpressionEngine
+    from zope.tal.interfaces import ITALExpressionErrorInfo
+    from zope.tales.interfaces import ITALESIterator
 
 
 NAME_RE = r"[a-zA-Z][a-zA-Z0-9_]*"
@@ -52,28 +60,383 @@
 
 _marker = object()
 
+class Iterator(object):
+    """TALES Iterator
+    """
+
+    if tal:
+        implements(ITALESIterator)
 
-class Iterator(iterator.Iterator):
     def __init__(self, name, seq, context):
-        iterator.Iterator.__init__(self, seq)
-        self.name = name
-        self._context = context
+        """Construct an iterator

[-=- -=- -=- 433 lines omitted -=- -=- -=-]

 
     def endScope(self):
+        self._vars_stack.pop()
+        self.vars = self._vars_stack[-1]
+
+        
         scope = self._scope_stack.pop()
-        self.local_vars = lv = scope[0]
-        v = self.vars
-        v._pop()
-        v._push(lv)
         # Pop repeat variables, if any
-        i = len(scope) - 1
+        i = len(scope) 
         while i:
+            i = i - 1
             name, value = scope[i]
             if value is None:
                 del self.repeat_vars[name]
             else:
                 self.repeat_vars[name] = value
-            i = i - 1
 
     def setLocal(self, name, value):
-        self.local_vars[name] = value
+        self.vars[name] = value
 
     def setGlobal(self, name, value):
-        self.global_vars[name] = value
+        for vars in self._vars_stack:
+            vars[name] = value
 
     def setRepeat(self, name, expr):
         expr = self.evaluate(expr)
@@ -327,15 +697,3 @@
             from cgi import escape
             return '<b>Names:</b><pre>%s</pre>' % (escape(s))
         return None
-
-
-
-class SimpleExpr:
-    '''Simple example of an expression type handler'''
-    def __init__(self, name, expr, engine):
-        self._name = name
-        self._expr = expr
-    def __call__(self, econtext):
-        return self._name, self._expr
-    def __repr__(self):
-        return '<SimpleExpr %s %s>' % (self._name, `self._expr`)