[Zope-Checkins] SVN: Zope/trunk/lib/python/Products/PageTemplates/__init__.py added monkeypatch to workaround unicode incompatibility

Andreas Jung andreas at andreas-jung.com
Sun Jan 14 04:42:23 EST 2007


Log message for revision 72014:
  added monkeypatch to workaround unicode incompatibility
  in zope.tal.xmlparsers.XMLParser.parseString()
  

Changed:
  U   Zope/trunk/lib/python/Products/PageTemplates/__init__.py

-=-
Modified: Zope/trunk/lib/python/Products/PageTemplates/__init__.py
===================================================================
--- Zope/trunk/lib/python/Products/PageTemplates/__init__.py	2007-01-14 09:14:57 UTC (rev 72013)
+++ Zope/trunk/lib/python/Products/PageTemplates/__init__.py	2007-01-14 09:42:19 UTC (rev 72014)
@@ -31,3 +31,25 @@
     # Import lazily, and defer initialization to the module
     import ZopePageTemplate
     ZopePageTemplate.initialize(context)
+
+
+# HACK!!!
+# We need to monkeypatch the parseString method of the Zope 3 
+# XMLParser since the internal ZPT representation uses unicode
+# however the XMLParser (using Expat) can only deal with standard
+# Python strings. However we won't and can't convert directly
+# to UTF-8 within the ZPT wrapper code. 
+# Unicode support for (this issue) should be directly added
+# to zope.tal.xmlparser however this requires a new Zope 3.3.X
+# release. For now we fix it here.
+
+from zope.tal.xmlparser import XMLParser
+import logging
+
+def parseString(self, s):
+    if isinstance(s, unicode):
+        s = s.encode('utf-8')
+    self.parser.Parse(s, 1)
+
+XMLParser.parseString = parseString
+logging.info('Monkeypatching zope.tal.xmlparser.XMLParser.parseString()')



More information about the Zope-Checkins mailing list