[XML-SIG] xml.dom.minidom.Document.createTextNode does not accept str subclasses

Fred L. Drake, Jr. fdrake@acm.org
Mon, 13 Jan 2003 12:09:03 -0500

Rodrigo B. de Oliveira writes:
 > The way CharacterData checks for the stringness of the data argument
 > does not allow str subclasses.

What version of PyXML are you using?  For 0.8 and 0.8.1, this problem
should be solved, but you aren't allowed to simply call the
constructor any more; that doesn't enforce all the invariants
directly.  You'll need to call the createTextNode() method of the
document object.

 > I figured that the reason the code is testing for type equality instead
 > of type compatibility (isinstance) is probably compatibility with python
 > versions were isinstance was not available. Is that correct?

The current version of the code provides a suitable isinstance() when
needed; see the xml.dom.minicompat module for the specific code if
you're interested.

 > If so, how about having something like this?
 > class CharacterData(Node):
 >     def __init__(self, data):
 >         if not _isString(data):
 >             raise TypeError, "node contents must be a string"

But, as noted above, there isn't a CharacterData.__init__() any more.


Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation