CVS: Products/ParsedXML - ManageableDOM.py:1.107 PrettyPrinter.py:1.3

Martijn Faassen <[email protected]> Fri, 17 May 2002 11:13:49 -0400
Newsgroups gmane.comp.web.zope.parsed-xml
Message-ID <[email protected]>
Update of /cvs-repository/Products/ParsedXML
In directory cvs.zope.org:/tmp/cvs-serv20993

Modified Files:
	ManageableDOM.py PrettyPrinter.py 
Log Message:
Try to make encoding work better (but not done yet).


=== Products/ParsedXML/ManageableDOM.py 1.106 => 1.107 ===
         """Return the XML representation of this object in a format safe for
         a textarea, with certain entity references quoted."""
-        outStr = str(self) # self.writeStream(encoding='ISO-8859-1').getvalue()
+        # FIXME
+        # perhaps we should output text in the encoding the document
+        # was saved in, but this is too complicated for now, so we just
+        # output UTF-8. Unfortunately this is not very pretty in the browser
+        # unless you set it to display in UTF-8.
+        outStr = self.writeStream(encoding=None).getvalue().encode('UTF-8')
         outStr = string.replace(outStr, '&amp;', '&amp;amp;')        
         outStr = string.replace(outStr, '&lt;', '&amp;lt;')
         outStr = string.replace(outStr, '&gt;', '&amp;gt;')
         outStr = string.replace(outStr, '<', '&lt;')
         outStr = string.replace(outStr, '>', '&gt;') 
-        return outStr #outStr.encode('ISO-8859-1', 'ignore')
+        return outStr
 
     # kinda silly that index_html can be xml, eh?
     # I need to figure out what the convention is for multimode docs.


=== Products/ParsedXML/PrettyPrinter.py 1.2 => 1.3 ===
         if not node.specified:
             return
-        text, delimiter = _translateCdataAttr(node.value)
+        text, delimiter = _translateCdataAttr(node.value,
+                                              encoding=self.encoding)
         f.write(" %s=%s%s%s" % (self.namePrint(node.name),
                                 delimiter, text, delimiter))
         
@@ -287,7 +288,7 @@
     #new_string = utf8_to_code(new_string, encoding) # XXX ugh
     return new_string
 
-def _translateCdataAttr(characters):
+def _translateCdataAttr(characters, encoding='UTF-8'):
     """
     Translate attribute value characters into a legal format;
     return the value and the delimiter used.
@@ -296,11 +297,13 @@
         return '', '"'
     if '"' not in characters or "'" in characters:
         delimiter = '"'
-        new_chars = _translateCdata(characters, allEntRefs = 1)
+        new_chars = _translateCdata(characters, allEntRefs = 1,
+                                    encoding=encoding)
         new_chars = re.sub("&apos;", "'", new_chars)
     else:
         delimiter = "'"
-        new_chars = _translateCdata(characters, allEntRefs = 1)            
+        new_chars = _translateCdata(characters, allEntRefs = 1,
+                                    encoding=encoding)            
         new_chars = re.sub("&quot;", '"', new_chars)
     return new_chars, delimiter