[Zope-Checkins]
SVN: Zope/branches/ajung-zpt-encoding-fixes/lib/python/Products/PageTemplates/ZopePageTemplate.py
- enabled strict mode by default (always store ZPT content as
unicode)
Andreas Jung
andreas at andreas-jung.com
Sun Dec 17 10:10:11 EST 2006
Log message for revision 71562:
- enabled strict mode by default (always store ZPT content as unicode)
- add pt_render() in order to convert result of PageTemplate.pt_render() - returned as unicode -
to the output_encoding
- __call__() sets the charset property of the conent-type header according to the output encoding
Changed:
U Zope/branches/ajung-zpt-encoding-fixes/lib/python/Products/PageTemplates/ZopePageTemplate.py
-=-
Modified: Zope/branches/ajung-zpt-encoding-fixes/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-encoding-fixes/lib/python/Products/PageTemplates/ZopePageTemplate.py 2006-12-17 15:08:25 UTC (rev 71561)
+++ Zope/branches/ajung-zpt-encoding-fixes/lib/python/Products/PageTemplates/ZopePageTemplate.py 2006-12-17 15:10:10 UTC (rev 71562)
@@ -114,6 +114,7 @@
self.expand = 0
self.strict = strict
self.ZBindings_edit(self._default_bindings)
+ self.output_encoding = encoding
if not text:
text = open(self._default_content_fn).read()
encoding = 'utf-8'
@@ -252,7 +253,7 @@
try:
response = self.REQUEST.RESPONSE
if not response.headers.has_key('content-type'):
- response.setHeader('content-type', self.content_type)
+ response.setHeader('content-type', '%s; charset=%s' % (self.content_type, self.output_encoding))
except AttributeError:
pass
@@ -353,6 +354,12 @@
# acquisition context, so we don't know where it is. :-(
return None
+ def pt_render(self, source=False, extra_context={}):
+ result = PageTemplate.pt_render(self, source, extra_context)
+ assert isinstance(result, unicode)
+ return result.encode(self.output_encoding)
+
+
def wl_isLocked(self):
return 0
@@ -420,7 +427,7 @@
content_type = guess_type(filename, text)
encoding = sniffEncoding(text, encoding)
- zpt = ZopePageTemplate(id, text, content_type, encoding)
+ zpt = ZopePageTemplate(id, text, content_type, encoding, True)
zpt.pt_setTitle(title, encoding)
self._setObject(id, zpt)
zpt = getattr(self, id)
More information about the Zope-Checkins
mailing list