[Zope3-checkins] SVN: Zope3/trunk/src/zope/tales/ Make Windows-style newlines work in TALES python: expressions.

Marius Gedminas marius at pov.lt
Wed Jul 7 13:03:59 EDT 2004


Log message for revision 26166:
Make Windows-style newlines work in TALES python: expressions.




-=-
Modified: Zope3/trunk/src/zope/tales/pythonexpr.py
===================================================================
--- Zope3/trunk/src/zope/tales/pythonexpr.py	2004-07-07 16:53:13 UTC (rev 26165)
+++ Zope3/trunk/src/zope/tales/pythonexpr.py	2004-07-07 17:03:59 UTC (rev 26166)
@@ -18,7 +18,7 @@
 
 class PythonExpr:
     def __init__(self, name, expr, engine):
-        text = expr.replace('\n', ' ').strip()
+        text = ' '.join(expr.splitlines()).strip()
         self.text = text
         # The next line can legally raise SyntaxError.
         self._code = code = compile(text, '<string>', 'eval')

Modified: Zope3/trunk/src/zope/tales/tests/test_expressions.py
===================================================================
--- Zope3/trunk/src/zope/tales/tests/test_expressions.py	2004-07-07 16:53:13 UTC (rev 26165)
+++ Zope3/trunk/src/zope/tales/tests/test_expressions.py	2004-07-07 17:03:59 UTC (rev 26166)
@@ -126,6 +126,12 @@
         context=self.context
         self.assertEqual(expr(context), 4)
 
+    def testPythonDosNewline(self):
+        expr = self.engine.compile('python: 2 \r\n+\r\n 2\r\n')
+        context=self.context
+        self.assertEqual(expr(context), 4)
+
+
 class FunctionTests(ExpressionTestBase):
 
     def setUp(self):



More information about the Zope3-Checkins mailing list