[Checkins] SVN: five.pt/trunk/ - Moved evaluate_path and evaluate_exists over to ``z3c.pt``, adding

Sidnei da Silva sidnei at enfoldsystems.com
Mon Jan 19 20:40:47 EST 2009


Log message for revision 94870:
  - Moved evaluate_path and evaluate_exists over to ``z3c.pt``, adding
    support for global ``path()`` and ``exists()`` functions for use in
    ``python:`` expressions to it (LP #317967). [sidnei]
  
  

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/buildout.cfg
  U   five.pt/trunk/src/five/pt/pagetemplate.py

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2009-01-19 23:32:19 UTC (rev 94869)
+++ five.pt/trunk/CHANGES.txt	2009-01-20 01:40:47 UTC (rev 94870)
@@ -1,6 +1,12 @@
 Changelog
 =========
 
+In next version
+
+- Moved evaluate_path and evaluate_exists over to ``z3c.pt``, adding
+  support for global ``path()`` and ``exists()`` functions for use in
+  ``python:`` expressions to it (LP #317967). [sidnei]
+
 five.pt 0.3 (released 12/17/2008)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 

Modified: five.pt/trunk/buildout.cfg
===================================================================
--- five.pt/trunk/buildout.cfg	2009-01-19 23:32:19 UTC (rev 94869)
+++ five.pt/trunk/buildout.cfg	2009-01-20 01:40:47 UTC (rev 94870)
@@ -8,6 +8,8 @@
 
 parts =
     lxml
+    deps
+    z3c.pt-develop
     test
 
 eggs =
@@ -20,14 +22,25 @@
 zope.testing = 3.7.1
 zope.i18n = 3.6.0
 lxml = 2.1.3
+setuptools = 0.6c9
 
 [lxml]
 recipe = z3c.recipe.staticlxml
 egg = lxml>=2.1.3
 
+[deps]
+recipe = infrae.subversion
+urls = 
+   svn+ssh://svn.zope.org/repos/main/z3c.pt/trunk z3c.pt 
+
+[z3c.pt-develop]
+recipe = zc.recipe.egg:develop
+setup = ${buildout:directory}/parts/deps/z3c.pt/setup.py
+
 [test]
 recipe = zc.recipe.testrunner<1.1dev
 eggs = ${buildout:eggs}
+       z3c.pt
 defaults = ['-m', 'five.pt']
 environment = test-environment
 

Modified: five.pt/trunk/src/five/pt/pagetemplate.py
===================================================================
--- five.pt/trunk/src/five/pt/pagetemplate.py	2009-01-19 23:32:19 UTC (rev 94869)
+++ five.pt/trunk/src/five/pt/pagetemplate.py	2009-01-20 01:40:47 UTC (rev 94870)
@@ -1,7 +1,6 @@
 import os
 import sys
 
-from zope import component
 from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
 
 from Acquisition import aq_get
@@ -13,64 +12,13 @@
 from Products.PageTemplates.Expressions import SecureModuleImporter
 
 from z3c.pt import pagetemplate
-
-from chameleon.core import types
-from chameleon.core import config
-from chameleon.core import clauses
-from chameleon.core import generation
-from chameleon.zpt.interfaces import IExpressionTranslator
-
 from five.pt.expressions import path_translator
 
-_marker = object()
-_expr_cache = {}
-
 def get_physical_root(context):
     method = aq_get(context, 'getPhysicalRoot', None)
     if method is not None:
         return method()
 
-def evaluate_expression(pragma, expr):
-    key = "%s(%s)" % (pragma, expr)
-    cache = getattr(_expr_cache, key, _marker)
-    if cache is not _marker:
-        symbol_mapping, parts, source = cache
-    else:
-        translator = component.getUtility(IExpressionTranslator, name=pragma)
-        parts = translator.tales(expr)
-        stream = generation.CodeIO(symbols=config.SYMBOLS)
-        assign = clauses.Assign(parts, 'result')
-        assign.begin(stream)
-        assign.end(stream)
-        source = stream.getvalue()
-
-        symbol_mapping = parts.symbol_mapping.copy()
-        if isinstance(parts, types.parts):
-            for value in parts:
-                symbol_mapping.update(value.symbol_mapping)    
-
-        _expr_cache[key] = symbol_mapping, parts, source
-
-    # acquire template locals and update with symbol mapping
-    frame = sys._getframe()
-    while frame.f_locals.get('econtext', _marker) is _marker:
-        frame = frame.f_back
-        if frame is None:
-            raise RuntimeError, "Can't locate template frame."
-
-    _locals = frame.f_locals
-    _locals.update(symbol_mapping)    
-
-    # execute code and return evaluation
-    exec source in _locals
-    return _locals['result']
-
-def evaluate_path(expr):
-    return evaluate_expression('path', expr)
-
-def evaluate_exists(expr):
-    return evaluate_expression('exists', expr)
-
 class BaseTemplateFile(pagetemplate.BaseTemplateFile):
     """Zope 2-compatible page template class."""
     
@@ -97,8 +45,8 @@
                 here=context,
                 container=context,
                 nothing=None,
-                path=evaluate_path,
-                exists=evaluate_exists,
+                path=pagetemplate.evaluate_path,
+                exists=pagetemplate.evaluate_exists,
                 root=get_physical_root(context),
                 user=getSecurityManager().getUser(),
                 modules=SecureModuleImporter,
@@ -124,8 +72,8 @@
                 here=context,
                 container=context,
                 nothing=None,
-                path=evaluate_path,
-                exists=evaluate_exists,
+                path=pagetemplate.evaluate_path,
+                exists=pagetemplate.evaluate_exists,
                 root=get_physical_root(context),
                 user=getSecurityManager().getUser(),
                 modules=SecureModuleImporter,



More information about the Checkins mailing list