Commit fd6f0a3f 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 9d6fe0d8
......@@ -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
......@@ -146,8 +150,47 @@ class TypeSniffingTestCase(unittest.TestCase):
)
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