dabo Commit
Revision 2212
Date: 2006-06-12 11:41:40 -0700 (Mon, 12 Jun 2006)
Author: ed

Changed:
U   trunk/dabo/lib/xmltodict.py

Log:
Added support for unicode characters.


Diff:
Modified: trunk/dabo/lib/xmltodict.py
===================================================================
--- trunk/dabo/lib/xmltodict.py 2006-06-09 18:07:48 UTC (rev 2211)
+++ trunk/dabo/lib/xmltodict.py 2006-06-12 18:41:40 UTC (rev 2212)
@@ -160,6 +160,8 @@
        """
        if not isinstance(val, basestring):
                val = str(val)
+       if not isinstance(val, unicode):
+               val = unicode(val, "utf-8")
        if noQuote:
                qt = ''
        else:
@@ -172,6 +174,14 @@
                val = val.replace("&", "&")
                # Escape any internal quotes
                val = val.replace('"', '"').replace("'", "'")
+               # Escape any high-order characters
+               chars = []
+               for pos, char in enumerate(list(val)):
+                       if ord(char) > 127:
+                               chars.append("&#%s;" % ord(char))
+                       else:
+                                       chars.append(char)
+               val = "".join(chars)
        return "%s%s%s" % (qt, val, qt)
 
 
@@ -195,7 +205,6 @@
                        noEscape = key in ("sizerInfo",)
                        val = escQuote(val, noEscape)
                        att += " %s=%s" % (key, val)
-
        ret += "%s<%s%s" % ("\t" * level, dct["name"], att)
 
        if (not dct.has_key("cdata") and not dct.has_key("children") 
@@ -251,7 +260,7 @@
 
        if level == 0:
                if header is None:
-                       header = '<?xml version="1.0" encoding="UTF-8" 
standalone="no"?>%s' \
+                       header = '<?xml version="1.0" encoding="utf-8" 
standalone="no"?>%s' \
                                        % eol 
                ret = header + ret
 




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to