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

Fred L. Drake, Jr. fred at zope.com
Wed Jul 7 16:38:24 EDT 2004


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

(Merged from Zope3 trunk revision 26166 by Marius Gedminas.)



-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/tales/pythonexpr.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/tales/pythonexpr.py	2004-07-07 20:27:20 UTC (rev 26188)
+++ Zope3/branches/ZopeX3-3.0/src/zope/tales/pythonexpr.py	2004-07-07 20:38:24 UTC (rev 26189)
@@ -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/branches/ZopeX3-3.0/src/zope/tales/tests/test_expressions.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/tales/tests/test_expressions.py	2004-07-07 20:27:20 UTC (rev 26188)
+++ Zope3/branches/ZopeX3-3.0/src/zope/tales/tests/test_expressions.py	2004-07-07 20:38:24 UTC (rev 26189)
@@ -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