[Checkins] SVN: five.pt/trunk/ Refactor; use new ``parse`` interface for the Python expression implementation.

Malthe Borch mborch at gmail.com
Thu Jul 7 10:30:57 EDT 2011


Log message for revision 122130:
  Refactor; use new ``parse`` interface for the Python expression implementation.

Changed:
  U   five.pt/trunk/CHANGES.txt
  U   five.pt/trunk/setup.py
  U   five.pt/trunk/src/five/pt/expressions.py

-=-
Modified: five.pt/trunk/CHANGES.txt
===================================================================
--- five.pt/trunk/CHANGES.txt	2011-07-07 09:10:20 UTC (rev 122129)
+++ five.pt/trunk/CHANGES.txt	2011-07-07 14:30:56 UTC (rev 122130)
@@ -1,6 +1,13 @@
 Changelog
 =========
 
+In next release ...
+
+- Refactor custom Python expression implementation to use the
+  ``parse`` method. This builds directly on the base implementation
+  and its behavior.
+  [malthe]
+
 2.0-rc2 (2011-05-24)
 ~~~~~~~~~~~~~~~~~~~~
 

Modified: five.pt/trunk/setup.py
===================================================================
--- five.pt/trunk/setup.py	2011-07-07 09:10:20 UTC (rev 122129)
+++ five.pt/trunk/setup.py	2011-07-07 14:30:56 UTC (rev 122130)
@@ -26,7 +26,7 @@
       install_requires=[
           'setuptools',
           'z3c.pt>=2.0-rc1',
-          'Chameleon>=2.0-rc9',
+          'Chameleon>=2.0-rc13',
           'sourcecodegen',
       ],
       entry_points="""

Modified: five.pt/trunk/src/five/pt/expressions.py
===================================================================
--- five.pt/trunk/src/five/pt/expressions.py	2011-07-07 09:10:20 UTC (rev 122129)
+++ five.pt/trunk/src/five/pt/expressions.py	2011-07-07 14:30:56 UTC (rev 122130)
@@ -1,4 +1,3 @@
-from ast import Assign
 from ast import NodeTransformer
 from compiler import parse as ast24_parse
 
@@ -25,11 +24,8 @@
 
 from chameleon.astutil import Symbol
 from chameleon.astutil import Static
-from chameleon.astutil import parse
 from chameleon.codegen import template
-from chameleon.tales import TalesExpr
 from chameleon.utils import decode_htmlentities
-from chameleon.exc import ExpressionError
 from sourcecodegen import generate_code
 
 from z3c.pt import expressions
@@ -172,26 +168,15 @@
         return node
 
 
-class PythonExpr(TalesExpr):
+class PythonExpr(expressions.PythonExpr):
     rm = RestrictionMutator()
     rt = RestrictionTransform()
 
-    def __init__(self, expression):
-        self.expression = expression
-
-    def __call__(self, target, engine):
-        string = self.expression.strip().replace('\n', ' ')
+    def parse(self, string):
         decoded = decode_htmlentities(string)
-
         node = ast24_parse(decoded, 'eval').node
         MutatingWalker.walk(node, self.rm)
         string = generate_code(node)
-
-        try:
-            value = parse(string, 'eval').body
-        except SyntaxError as exc:
-            raise ExpressionError(exc.msg, decoded)
-
+        value = super(PythonExpr, self).parse(string)
         self.rt.visit(value)
-
-        return [Assign([target], value)]
+        return value



More information about the checkins mailing list