[Zope-Checkins] CVS: Zope/lib/python/Products/PageTemplates - PageTemplateFile.py:1.25
Fred L. Drake, Jr.
fred@zope.com
Fri, 4 Apr 2003 14:37:59 -0500
Update of /cvs-repository/Zope/lib/python/Products/PageTemplates
In directory cvs.zope.org:/tmp/cvs-serv26909
Modified Files:
PageTemplateFile.py
Log Message:
Backport src/zope/pagetemplate/pagetemplatefile.py revision 1.5 from Zope 3:
When loading a PageTemplateFile that's not XML, make sure it ends up
loaded in text mode. This was a problem for Windows.
=== Zope/lib/python/Products/PageTemplates/PageTemplateFile.py 1.24 => 1.25 ===
--- Zope/lib/python/Products/PageTemplates/PageTemplateFile.py:1.24 Fri Mar 21 14:22:00 2003
+++ Zope/lib/python/Products/PageTemplates/PageTemplateFile.py Fri Apr 4 14:37:58 2003
@@ -122,7 +122,13 @@
text = f.read()
finally:
f.close()
- self.pt_edit(text, sniff_type(text))
+ t = sniff_type(text)
+ if t != "text/xml" and "\r" in text:
+ # For HTML, we really want the file read in text mode:
+ f = open(self.filename)
+ text = f.read()
+ f.close()
+ self.pt_edit(text, t)
self._cook()
if self._v_errors:
LOG('PageTemplateFile', ERROR, 'Error in template',
@@ -134,6 +140,10 @@
"""Return expanded document source."""
if RESPONSE is not None:
+ # Since _cook_check() can cause self.content_type to change,
+ # we have to make sure we call it before setting the
+ # Content-Type header.
+ self._cook_check()
RESPONSE.setHeader('Content-Type', 'text/plain')
return self.read()