[Erp5-report] r30469 - in /erp5/trunk/products: ERP5/Document/ ERP5Type/patches/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Nov 10 14:30:32 CET 2009


Author: leonardo
Date: Tue Nov 10 14:30:30 2009
New Revision: 30469

URL: http://svn.erp5.org?rev=30469&view=rev
Log:
Fix XML import of Unicode objects on business templates on Zope 2.12

Zope 2.12 uses the python2.6 built-in expat which, when combined with our custom
export of unicode objects was causing UnicodeDecodeErrors.

In the future, we need to push all these xml import fixes upstream.


Modified:
    erp5/trunk/products/ERP5/Document/BusinessTemplate.py
    erp5/trunk/products/ERP5Type/patches/ppml.py

Modified: erp5/trunk/products/ERP5/Document/BusinessTemplate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/BusinessTemplate.py?rev=30469&r1=30468&r2=30469&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/BusinessTemplate.py [utf8] Tue Nov 10 14:30:30 2009
@@ -61,13 +61,13 @@
 from copy import deepcopy
 from zExceptions import BadRequest
 import OFS.XMLExportImport
+from Products.ERP5Type.patches.ppml import importXML
 customImporters={
-    XMLExportImport.magic: XMLExportImport.importXML,
+    XMLExportImport.magic: importXML,
     }
 
 from zLOG import LOG, WARNING, PROBLEM
 from warnings import warn
-from OFS.ObjectManager import customImporters
 from gzip import GzipFile
 from xml.dom.minidom import parse
 from xml.sax.saxutils import escape
@@ -699,6 +699,8 @@
       else:
         obj = connection.importFile(file_obj, customImporters=customImporters)
     else:
+      # FIXME: Why not use the importXML function directly? Are there any BT5s
+      # with actual .zexp files on the wild?
       obj = connection.importFile(file_obj, customImporters=customImporters)
     self.removeProperties(obj)
     self._objects[file_name[:-4]] = obj

Modified: erp5/trunk/products/ERP5Type/patches/ppml.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/ppml.py?rev=30469&r1=30468&r2=30469&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/ppml.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/patches/ppml.py [utf8] Tue Nov 10 14:30:30 2009
@@ -771,8 +771,41 @@
         'persistent': save_persis,
         }
 
+# FIXME: Leo: Do we still need to replace ppml.xmlPickler now that we're
+# using our own xmlPickler in our own importXML function below? Do we support
+# any other use of xmlPickler except for Business Template export/import?
 ppml.xmlPickler = xmlPickler
 
 class Tuple(Sequence): pass
 
 ppml.Tuple = Tuple
+
+# not a patch, but imported and used directly by
+# Products.ERP5.Document.BusinessTemplate. It is a copy of
+# from OFS.XMLExportImport.importXML from Zope 2.12
+def importXML(jar, file, clue=''):
+    from OFS.XMLExportImport import save_record, save_zopedata, start_zopedata
+    from tempfile import TemporaryFile
+    import xml.parsers.expat
+    if type(file) is str:
+        file=open(file, 'rb')
+    outfile=TemporaryFile()
+    data=file.read()
+    F=xmlPickler()
+    F.end_handlers['record'] = save_record
+    F.end_handlers['ZopeData'] = save_zopedata
+    F.start_handlers['ZopeData'] = start_zopedata
+    F.binary=1
+    F.file=outfile
+    # Our BTs XML files don't declare encoding but have accented chars in them
+    # So we have to declare an encoding but not use unicode, so the unpickler
+    # can deal with the utf-8 strings directly
+    p=xml.parsers.expat.ParserCreate('utf-8')
+    p.returns_unicode = False
+
+    p.CharacterDataHandler=F.handle_data
+    p.StartElementHandler=F.unknown_starttag
+    p.EndElementHandler=F.unknown_endtag
+    r=p.Parse(data)
+    outfile.seek(0)
+    return jar.importFile(outfile,clue)




More information about the Erp5-report mailing list