[Zope-Checkins] SVN: Zope/branches/Zope-2_8-branch/ Fix for #940:
open pagetemplate files in universal line-endings mode to
avoid python compilation problems
Martijn Pieters
mj at zopatista.com
Sat Mar 11 10:24:12 EST 2006
Log message for revision 65910:
Fix for #940: open pagetemplate files in universal line-endings mode to avoid python compilation problems
Changed:
U Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
U Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/PageTemplateFile.py
U Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/test_ptfile.py
-=-
Modified: Zope/branches/Zope-2_8-branch/doc/CHANGES.txt
===================================================================
--- Zope/branches/Zope-2_8-branch/doc/CHANGES.txt 2006-03-11 15:22:37 UTC (rev 65909)
+++ Zope/branches/Zope-2_8-branch/doc/CHANGES.txt 2006-03-11 15:24:12 UTC (rev 65910)
@@ -28,6 +28,11 @@
- OFS.Image: 'Image.update_data' did not refresh the Etag.
+ - Collector #940: PageTemplateFile: Open files with universal
+ line-endings support to avoid line-endings problems within python
+ expressions.
+
+
Zope 2.8.6 (2006/02/25)
Bugs Fixed
Modified: Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/PageTemplateFile.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/PageTemplateFile.py 2006-03-11 15:22:37 UTC (rev 65909)
+++ Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/PageTemplateFile.py 2006-03-11 15:24:12 UTC (rev 65910)
@@ -139,7 +139,7 @@
if t != "text/xml":
# For HTML, we really want the file read in text mode:
f.close()
- f = open(self.filename)
+ f = open(self.filename, 'U')
text = ''
text += f.read()
f.close()
Modified: Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/test_ptfile.py
===================================================================
--- Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/test_ptfile.py 2006-03-11 15:22:37 UTC (rev 65909)
+++ Zope/branches/Zope-2_8-branch/lib/python/Products/PageTemplates/tests/test_ptfile.py 2006-03-11 15:24:12 UTC (rev 65910)
@@ -3,7 +3,11 @@
import os, os.path
import tempfile
import unittest
+import Zope2
+import transaction
+from Testing.makerequest import makerequest
+
from Products.PageTemplates.PageTemplateFile import PageTemplateFile
@@ -144,10 +148,49 @@
desired_path, pt_path,
)
)
+
+class LineEndingsTestCase(unittest.TestCase):
+ TEMPFILENAME = tempfile.mktemp(".zpt")
+ TAL = ('''<html tal:replace="python: ' '.join(('foo',''',
+ ''' 'bar',''',
+ ''' 'spam',''',
+ ''' 'eggs'))"></html>''')
+ OUTPUT = 'foo bar spam eggs\n'
+
+ def setUp(self):
+ transaction.begin()
+ self.root = makerequest(Zope2.app())
+
+ def tearDown(self):
+ if os.path.exists(self.TEMPFILENAME):
+ os.unlink(self.TEMPFILENAME)
+ transaction.abort()
+ self.root._p_jar.close()
+
+ def runPTWithLineEndings(self, lineendings='\n'):
+ text = lineendings.join(self.TAL)
+ f = open(self.TEMPFILENAME, "wb")
+ f.write(text)
+ f.close()
+ pt = PageTemplateFile(self.TEMPFILENAME).__of__(self.root)
+ return pt()
+
+ def test_unix(self):
+ self.assertEqual(self.runPTWithLineEndings(), self.OUTPUT)
+
+ def test_dos(self):
+ self.assertEqual(self.runPTWithLineEndings('\r\n'), self.OUTPUT)
+
+ def test_mac(self):
+ self.assertEqual(self.runPTWithLineEndings('\r'), self.OUTPUT)
+
def test_suite():
- return unittest.makeSuite(TypeSniffingTestCase)
+ return unittest.TestSuite((
+ unittest.makeSuite(TypeSniffingTestCase),
+ unittest.makeSuite(LineEndingsTestCase),
+ ))
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
More information about the Zope-Checkins
mailing list