[Zope-Checkins] CVS: Releases/Zope/lib/python/TAL - DummyEngine.py:1.37.6.1 ITALES.py:1.4.6.1 TALGenerator.py:1.65.2.1 TALInterpreter.py:1.78.6.1

Evan Simpson evan at 4-am.com
Fri Aug 29 15:16:09 EDT 2003


Update of /cvs-repository/Releases/Zope/lib/python/TAL
In directory cvs.zope.org:/tmp/cvs-serv25364/lib/python/TAL

Modified Files:
      Tag: evan-pathprefix-branch
	DummyEngine.py ITALES.py TALGenerator.py TALInterpreter.py 
Log Message:
Added the ability to define prefixes using tal:define="prefix name expr".
Expression types for the prefix namespace are *not* the same as normal
TALES expression types.  There are only two: 'builtin' and 'ext'.
'builtin' allows the built-in prefix types to be renamed, and 'ext'
(for 'external' and/or 'extension') allows access to additional
prefix types defined by trusted code.  An example of this is
"ext:PageTemplates.NumericConversions", defined in "ExtSample.py".

The convention I'm trying to establish is that 'ext' prefix types
use names of the form "<Product>.<Descriptive Name>".

In order to accomodate this new facility, I had to defer the compilation
step for prefixed path segments until they are evaluated.  The compiled
segment is cached, and reused if the mapping from local prefix name to
prefix type doesn't change (which it usually won't).



=== Releases/Zope/lib/python/TAL/DummyEngine.py 1.37 => 1.37.6.1 ===
--- Releases/Zope/lib/python/TAL/DummyEngine.py:1.37	Mon Apr  7 13:38:27 2003
+++ Releases/Zope/lib/python/TAL/DummyEngine.py	Fri Aug 29 14:15:38 2003
@@ -95,6 +95,9 @@
     def setGlobal(self, name, value):
         self.globals[name] = value
 
+    def setPrefix(self, name, expr):
+        pass
+
     def evaluate(self, expression):
         assert (expression.startswith("$") and expression.endswith("$"),
             expression)


=== Releases/Zope/lib/python/TAL/ITALES.py 1.4 => 1.4.6.1 ===
--- Releases/Zope/lib/python/TAL/ITALES.py:1.4	Mon Apr  7 14:45:45 2003
+++ Releases/Zope/lib/python/TAL/ITALES.py	Fri Aug 29 14:15:38 2003
@@ -131,6 +131,12 @@
         The variable will be named 'name' and have the value 'value'.
         """
 
+    def setPrefix(name, expr):
+        """Set a prefix mapping.
+
+        The prefix will be named 'name' and have the value of 'expr'.
+        """
+
     def setRepeat(name, compiled_expression):
         """
         """


=== Releases/Zope/lib/python/TAL/TALGenerator.py 1.65 => 1.65.2.1 ===
--- Releases/Zope/lib/python/TAL/TALGenerator.py:1.65	Fri Jul 25 14:54:36 2003
+++ Releases/Zope/lib/python/TAL/TALGenerator.py	Fri Aug 29 14:15:38 2003
@@ -266,11 +266,16 @@
     def emitDefines(self, defines):
         for part in TALDefs.splitParts(defines):
             m = re.match(
-                r"(?s)\s*(?:(global|local)\s+)?(%s)\s+(.*)\Z" % NAME_RE, part)
+                r"(?s)\s*(?:(global|local|prefix)\s+)?(%s)\s+(.*)\Z" %
+                NAME_RE, part)
             if not m:
                 raise TALError("invalid define syntax: " + `part`,
                                self.position)
             scope, name, expr = m.group(1, 2, 3)
+            if scope == "prefix":
+                self.emit("setPrefix", name, expr)
+                continue
+            
             scope = scope or "local"
             cexpr = self.compileExpression(expr)
             if scope == "local":


=== Releases/Zope/lib/python/TAL/TALInterpreter.py 1.78 => 1.78.6.1 ===
--- Releases/Zope/lib/python/TAL/TALInterpreter.py:1.78	Mon Apr  7 13:38:27 2003
+++ Releases/Zope/lib/python/TAL/TALInterpreter.py	Fri Aug 29 14:15:38 2003
@@ -472,6 +472,10 @@
         self.engine.setGlobal(name, self.engine.evaluateValue(expr))
     bytecode_handlers["setGlobal"] = do_setLocal
 
+    def do_setPrefix_tal(self, (name, expr)):
+        self.engine.setPrefix(name, expr)
+    bytecode_handlers["setPrefix"] = do_setLocal
+
     def do_beginI18nContext(self, settings):
         get = settings.get
         self.i18nContext = TranslationContext(self.i18nContext,
@@ -733,6 +737,7 @@
     bytecode_handlers_tal["beginScope"] = do_beginScope_tal
     bytecode_handlers_tal["setLocal"] = do_setLocal_tal
     bytecode_handlers_tal["setGlobal"] = do_setGlobal_tal
+    bytecode_handlers_tal["setPrefix"] = do_setPrefix_tal
     bytecode_handlers_tal["insertStructure"] = do_insertStructure_tal
     bytecode_handlers_tal["insertText"] = do_insertText_tal
     bytecode_handlers_tal["loop"] = do_loop_tal




More information about the Zope-Checkins mailing list