Commit 0710e777 authored by Martijn Pieters's avatar Martijn Pieters

Fix for #940: open pagetemplate files in universal line-endings mode to avoid...

Fix for #940: open pagetemplate files in universal line-endings mode to avoid python compilation problems
parent a5e591cc
......@@ -28,6 +28,11 @@ Zope Changes
- 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
......
......@@ -139,7 +139,7 @@ class PageTemplateFile(Item_w__name__, Script, PageTemplate, Traversable):
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()
......
......@@ -3,6 +3,10 @@
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 @@ class TypeSniffingTestCase(unittest.TestCase):
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")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment