Hi,

GenericSetup is cursed with Zope2's strings-are-str attitude; thus e.g. a type with a non-ASCII description is unexportable.

Since CPS's current encoding is iso8859-15, the dirty bug attached exports iso8859-15 xml files: the DOM tree is (hopefully) built in Unicode, then encoded in Latin 9.

Best regards,

yves
Index: GenericSetup/utils.py
===================================================================
--- GenericSetup/utils.py	(revision 45483)
+++ GenericSetup/utils.py	(working copy)
@@ -339,6 +339,11 @@
     """minidom element with 'pretty' XML output.
     """
 
+    def setAttribute(self, attname, value):
+        if isinstance(value, str):
+            value = value.decode('iso8859-15')
+        return Element.setAttribute(self, attname, value)
+
     def writexml(self, writer, indent="", addindent="", newl=""):
         # indent = current indentation
         # addindent = indentation to add to higher levels
@@ -400,6 +405,11 @@
         e = _Element(qualifiedName, namespaceURI, prefix)
         e.ownerDocument = self
         return e
+    
+    def createTextNode(self, data):
+        if isinstance(data, str):
+            data = data.decode('iso8859-15')
+        return Document.createTextNode(self, data)
 
     def writexml(self, writer, indent="", addindent="", newl="",
                  encoding = None):
@@ -496,7 +506,7 @@
         """Export the object as a file body.
         """
         self._doc.appendChild(self._exportNode())
-        return self._doc.toprettyxml(' ')
+        return self._doc.toprettyxml(' ', encoding='iso8859-15')
 
     def _importBody(self, body):
         """Import the object from the file body.
@@ -623,8 +633,10 @@
             else:
                 if prop_map.get('type') == 'boolean':
                     prop = str(bool(prop))
+                elif isinstance(prop, str):
+                    prop = prop.decode('iso8859-15')
                 elif not isinstance(prop, basestring):
-                    prop = str(prop)
+                    prop = unicode(prop)
                 child = self._doc.createTextNode(prop)
                 node.appendChild(child)
 
_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel

Reply via email to