Fred Drake wrote:
On 7/13/05, Dmitry Vasiliev <[EMAIL PROTECTED]> wrote:

Ok. But default 'ascii' encoding seems like a bug for me and I want to change
it to 'utf-8' before the release.

Not using the right encoding for the input would indeed be a bug.  Do
you have a reason to think it's handled incorrectly in XML mode? Expat is allowed to deal with the encoding on it's own; nothing is
done to override the use of the encoding from the XML declaration.

Please file a bug in the collector with a sample input if that's the case.

No. In XML mode input encoding is always handled correctly and we get an unicode PT content. But in HTML mode no encoding/decoding operations is performed on input so we get an str PT content and implicitly default PT input encoding is 'ascii'. I want to apply the attached patch so default PT input encoding explicitly will be 'utf-8'.

Dmitry Vasiliev (dima at
Index: src/zope/pagetemplate/
--- src/zope/pagetemplate/	(revision 33293)
+++ src/zope/pagetemplate/	(working copy)
@@ -22,6 +22,9 @@
 from zope.pagetemplate.pagetemplate import PageTemplate
 def package_home(gdict):
     filename = gdict["__file__"]
     return os.path.dirname(filename)
@@ -31,11 +34,12 @@
     _v_last_read = 0
-    def __init__(self, filename, _prefix=None):
+    def __init__(self, filename, _prefix=None, encoding=DEFAULT_ENCODING):
         path = self.get_path_from_prefix(_prefix)
         self.filename = os.path.join(path, filename)
         if not os.path.isfile(self.filename):
             raise ValueError("No such file", self.filename)
+        self.encoding = encoding
     def get_path_from_prefix(self, _prefix):
         if isinstance(_prefix, str):
@@ -63,12 +67,14 @@
         t = sniff_type(text)
-        if t != "text/xml":
+        if t == "text/xml":
+            text +=
+        else:
             # For HTML, we really want the file read in text mode:
             f = open(self.filename)
-            text = ''
-        text +=
+            text =
+            text = unicode(text, self.encoding)
         self.pt_edit(text, t)
Zope3-dev mailing list

Reply via email to