[XML-SIG] unicode data

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Fri, 3 Nov 2000 10:12:59 +0100


> I see this in the DOM CharacterData.py  where a few places throw 
> exceptions :
> 
> if data != None and type(data) != type(''):
>      raise DOMException(SYNTAX_ERR)

That, of course, is a bug in 4DOM. Can you please try the patch below?
I'll include that also in PyXML 0.6.2 (although I do hope there will
be an update from 4Thought, yet).

Regards,
Martin

Index: CharacterData.py
===================================================================
RCS file: /cvsroot/pyxml/xml/xml/dom/CharacterData.py,v
retrieving revision 1.4
diff -u -r1.4 CharacterData.py
--- CharacterData.py	2000/10/02 17:57:43	1.4
+++ CharacterData.py	2000/11/03 09:07:30
@@ -21,6 +21,12 @@
 INDEX_SIZE_ERR = dom.INDEX_SIZE_ERR
 SYNTAX_ERR = dom.SYNTAX_ERR
 
+import types
+try:
+  _StringTypes = [types.StringType, types.UnicodeType]
+except AttributeError:
+  _StringTypes = [types.StringType]
+
 class CharacterData(Node):
     def __init__(self, ownerDocument, data):
         Node.__init__(self, ownerDocument, '', '', '')
@@ -33,7 +39,7 @@
         return self.__dict__['__nodeValue']
 
     def _set_data(self, data):
-        if data != None and type(data) != type(''):
+        if data != None and type(data) not in _StringTypes:
             raise DOMException(SYNTAX_ERR)
         self.__dict__['__nodeValue'] = data
         self.__dict__['__length'] = len(data)
@@ -49,13 +55,13 @@
         return self.data[int(offset):int(offset+count)]
 
     def appendData(self, arg):
-        if type(arg) != type(''):
+        if type(arg) not in _StringTypes:
             raise DOMException(SYNTAX_ERR)
         self._set_data(self.data + arg)
         return
         
     def insertData(self, offset, arg):
-        if type(arg) != type(''):
+        if type(arg) not in _StringTypes:
             raise DOMException(SYNTAX_ERR)
         if offset < 0 or offset >= self.__dict__['__length']:
             raise DOMException(INDEX_SIZE_ERR)
@@ -72,7 +78,7 @@
         return
 
     def replaceData(self, offset, count, arg):  
-        if type(arg) != type(''):
+        if type(arg) not in _StringTypes:
             raise DOMException(SYNTAX_ERR)
         #Really a delete, then an insert
         self.deleteData(offset, count)