2000-09-24 02:21:58 -03:00
|
|
|
"""\
|
2000-12-14 14:16:11 -04:00
|
|
|
minidom.py -- a lightweight DOM implementation.
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-02-05 15:17:50 -04:00
|
|
|
parse("foo.xml")
|
2000-07-21 19:05:49 -03:00
|
|
|
|
2001-02-05 15:17:50 -04:00
|
|
|
parseString("<foo><bar/></foo>")
|
2000-07-21 19:05:49 -03:00
|
|
|
|
2000-06-29 16:39:57 -03:00
|
|
|
Todo:
|
|
|
|
=====
|
|
|
|
* convenience methods for getting elements and text.
|
|
|
|
* more testing
|
|
|
|
* bring some of the writer and linearizer code into conformance with this
|
|
|
|
interface
|
|
|
|
* SAX 2 namespaces
|
|
|
|
"""
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
import string
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
_string = string
|
|
|
|
del string
|
|
|
|
|
2001-11-30 18:21:58 -04:00
|
|
|
from xml.dom import HierarchyRequestErr, EMPTY_NAMESPACE
|
2000-12-30 23:50:23 -04:00
|
|
|
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
# localize the types, and allow support for Unicode values if available:
|
2000-09-24 02:21:58 -03:00
|
|
|
import types
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
_TupleType = types.TupleType
|
|
|
|
try:
|
|
|
|
_StringTypes = (types.StringType, types.UnicodeType)
|
|
|
|
except AttributeError:
|
|
|
|
_StringTypes = (types.StringType,)
|
|
|
|
del types
|
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
import xml.dom
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-09-28 01:33:06 -03:00
|
|
|
|
|
|
|
if list is type([]):
|
|
|
|
class NodeList(list):
|
|
|
|
def item(self, index):
|
|
|
|
if 0 <= index < len(self):
|
|
|
|
return self[index]
|
|
|
|
|
2001-09-28 17:25:45 -03:00
|
|
|
length = property(lambda self: len(self),
|
|
|
|
doc="The number of nodes in the NodeList.")
|
2001-09-28 01:33:06 -03:00
|
|
|
|
|
|
|
else:
|
|
|
|
def NodeList():
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2001-09-28 17:25:45 -03:00
|
|
|
class Node(xml.dom.Node):
|
2000-09-24 02:21:58 -03:00
|
|
|
allnodes = {}
|
|
|
|
_debug = 0
|
|
|
|
_makeParentNodes = 1
|
|
|
|
debug = None
|
2000-12-30 23:50:23 -04:00
|
|
|
childNodeTypes = ()
|
2001-03-13 06:50:13 -04:00
|
|
|
namespaceURI = None # this is non-null only for elements and attributes
|
2001-09-28 17:25:45 -03:00
|
|
|
parentNode = None
|
|
|
|
ownerDocument = None
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __init__(self):
|
2001-09-28 01:33:06 -03:00
|
|
|
self.childNodes = NodeList()
|
2000-10-23 15:09:50 -03:00
|
|
|
if Node._debug:
|
2000-09-24 02:21:58 -03:00
|
|
|
index = repr(id(self)) + repr(self.__class__)
|
|
|
|
Node.allnodes[index] = repr(self.__dict__)
|
|
|
|
if Node.debug is None:
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
Node.debug = _get_StringIO()
|
2001-02-05 15:17:50 -04:00
|
|
|
#open("debug4.out", "w")
|
2000-09-24 02:21:58 -03:00
|
|
|
Node.debug.write("create %s\n" % index)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __nonzero__(self):
|
|
|
|
return 1
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def toxml(self):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
writer = _get_StringIO()
|
2000-09-24 02:21:58 -03:00
|
|
|
self.writexml(writer)
|
2000-06-29 16:39:57 -03:00
|
|
|
return writer.getvalue()
|
|
|
|
|
2001-02-05 20:14:08 -04:00
|
|
|
def toprettyxml(self, indent="\t", newl="\n"):
|
2001-03-31 12:30:40 -04:00
|
|
|
# indent = the indentation string to prepend, per level
|
|
|
|
# newl = the newline string to append
|
|
|
|
writer = _get_StringIO()
|
|
|
|
self.writexml(writer, "", indent, newl)
|
|
|
|
return writer.getvalue()
|
2001-02-05 20:14:08 -04:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def hasChildNodes(self):
|
|
|
|
if self.childNodes:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _get_firstChild(self):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if self.childNodes:
|
|
|
|
return self.childNodes[0]
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _get_lastChild(self):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if self.childNodes:
|
|
|
|
return self.childNodes[-1]
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2001-09-29 01:58:32 -03:00
|
|
|
try:
|
|
|
|
property
|
|
|
|
except NameError:
|
|
|
|
def __getattr__(self, key):
|
|
|
|
if key[0:2] == "__":
|
|
|
|
raise AttributeError, key
|
|
|
|
# getattr should never call getattr!
|
|
|
|
if self.__dict__.has_key("inGetAttr"):
|
|
|
|
del self.inGetAttr
|
|
|
|
raise AttributeError, key
|
|
|
|
|
|
|
|
prefix, attrname = key[:5], key[5:]
|
|
|
|
if prefix == "_get_":
|
|
|
|
self.inGetAttr = 1
|
|
|
|
if hasattr(self, attrname):
|
|
|
|
del self.inGetAttr
|
|
|
|
return (lambda self=self, attrname=attrname:
|
|
|
|
getattr(self, attrname))
|
|
|
|
else:
|
|
|
|
del self.inGetAttr
|
|
|
|
raise AttributeError, key
|
|
|
|
else:
|
|
|
|
self.inGetAttr = 1
|
|
|
|
try:
|
|
|
|
func = getattr(self, "_get_" + key)
|
|
|
|
except AttributeError:
|
|
|
|
raise AttributeError, key
|
|
|
|
del self.inGetAttr
|
|
|
|
return func()
|
|
|
|
else:
|
|
|
|
firstChild = property(_get_firstChild,
|
|
|
|
doc="First child node, or None.")
|
|
|
|
lastChild = property(_get_lastChild,
|
|
|
|
doc="Last child node, or None.")
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def insertBefore(self, newChild, refChild):
|
2001-03-13 06:50:13 -04:00
|
|
|
if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE:
|
2001-12-06 00:32:18 -04:00
|
|
|
for c in tuple(newChild.childNodes):
|
2001-03-13 06:50:13 -04:00
|
|
|
self.insertBefore(c, refChild)
|
|
|
|
### The DOM does not clearly specify what to return in this case
|
|
|
|
return newChild
|
2000-12-30 23:50:23 -04:00
|
|
|
if newChild.nodeType not in self.childNodeTypes:
|
|
|
|
raise HierarchyRequestErr, \
|
2001-02-05 15:17:50 -04:00
|
|
|
"%s cannot be child of %s" % (repr(newChild), repr(self))
|
2000-12-20 10:47:24 -04:00
|
|
|
if newChild.parentNode is not None:
|
|
|
|
newChild.parentNode.removeChild(newChild)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if refChild is None:
|
|
|
|
self.appendChild(newChild)
|
|
|
|
else:
|
|
|
|
index = self.childNodes.index(refChild)
|
|
|
|
self.childNodes.insert(index, newChild)
|
|
|
|
newChild.nextSibling = refChild
|
|
|
|
refChild.previousSibling = newChild
|
|
|
|
if index:
|
|
|
|
node = self.childNodes[index-1]
|
|
|
|
node.nextSibling = newChild
|
|
|
|
newChild.previousSibling = node
|
|
|
|
else:
|
|
|
|
newChild.previousSibling = None
|
|
|
|
if self._makeParentNodes:
|
|
|
|
newChild.parentNode = self
|
|
|
|
return newChild
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def appendChild(self, node):
|
2001-03-13 06:50:13 -04:00
|
|
|
if node.nodeType == self.DOCUMENT_FRAGMENT_NODE:
|
2001-12-06 00:32:18 -04:00
|
|
|
for c in tuple(node.childNodes):
|
2001-03-13 06:50:13 -04:00
|
|
|
self.appendChild(c)
|
|
|
|
### The DOM does not clearly specify what to return in this case
|
|
|
|
return node
|
2000-12-30 23:50:23 -04:00
|
|
|
if node.nodeType not in self.childNodeTypes:
|
|
|
|
raise HierarchyRequestErr, \
|
2001-02-05 15:17:50 -04:00
|
|
|
"%s cannot be child of %s" % (repr(node), repr(self))
|
2000-12-20 10:47:24 -04:00
|
|
|
if node.parentNode is not None:
|
|
|
|
node.parentNode.removeChild(node)
|
2000-10-09 17:04:16 -03:00
|
|
|
if self.childNodes:
|
|
|
|
last = self.lastChild
|
|
|
|
node.previousSibling = last
|
|
|
|
last.nextSibling = node
|
|
|
|
else:
|
|
|
|
node.previousSibling = None
|
|
|
|
node.nextSibling = None
|
2000-09-24 02:21:58 -03:00
|
|
|
self.childNodes.append(node)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if self._makeParentNodes:
|
|
|
|
node.parentNode = self
|
2000-07-01 01:58:47 -03:00
|
|
|
return node
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def replaceChild(self, newChild, oldChild):
|
2001-03-13 06:50:13 -04:00
|
|
|
if newChild.nodeType == self.DOCUMENT_FRAGMENT_NODE:
|
|
|
|
refChild = oldChild.nextSibling
|
|
|
|
self.removeChild(oldChild)
|
|
|
|
return self.insertBefore(newChild, refChild)
|
2000-12-30 23:50:23 -04:00
|
|
|
if newChild.nodeType not in self.childNodeTypes:
|
|
|
|
raise HierarchyRequestErr, \
|
2001-02-05 15:17:50 -04:00
|
|
|
"%s cannot be child of %s" % (repr(newChild), repr(self))
|
2000-12-20 10:47:24 -04:00
|
|
|
if newChild.parentNode is not None:
|
|
|
|
newChild.parentNode.removeChild(newChild)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if newChild is oldChild:
|
|
|
|
return
|
2000-09-24 02:21:58 -03:00
|
|
|
index = self.childNodes.index(oldChild)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
self.childNodes[index] = newChild
|
|
|
|
if self._makeParentNodes:
|
|
|
|
newChild.parentNode = self
|
|
|
|
oldChild.parentNode = None
|
|
|
|
newChild.nextSibling = oldChild.nextSibling
|
|
|
|
newChild.previousSibling = oldChild.previousSibling
|
2000-12-28 14:40:56 -04:00
|
|
|
oldChild.nextSibling = None
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
oldChild.previousSibling = None
|
2000-12-28 14:40:56 -04:00
|
|
|
if newChild.previousSibling:
|
|
|
|
newChild.previousSibling.nextSibling = newChild
|
|
|
|
if newChild.nextSibling:
|
|
|
|
newChild.nextSibling.previousSibling = newChild
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
return oldChild
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def removeChild(self, oldChild):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
self.childNodes.remove(oldChild)
|
2000-12-20 10:47:24 -04:00
|
|
|
if oldChild.nextSibling is not None:
|
|
|
|
oldChild.nextSibling.previousSibling = oldChild.previousSibling
|
|
|
|
if oldChild.previousSibling is not None:
|
2001-01-27 04:47:37 -04:00
|
|
|
oldChild.previousSibling.nextSibling = oldChild.nextSibling
|
2000-12-20 10:47:24 -04:00
|
|
|
oldChild.nextSibling = oldChild.previousSibling = None
|
2001-01-27 04:47:37 -04:00
|
|
|
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if self._makeParentNodes:
|
|
|
|
oldChild.parentNode = None
|
|
|
|
return oldChild
|
|
|
|
|
|
|
|
def normalize(self):
|
2000-12-14 14:16:11 -04:00
|
|
|
L = []
|
|
|
|
for child in self.childNodes:
|
|
|
|
if child.nodeType == Node.TEXT_NODE:
|
|
|
|
data = child.data
|
|
|
|
if data and L and L[-1].nodeType == child.nodeType:
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
# collapse text node
|
|
|
|
node = L[-1]
|
|
|
|
node.data = node.nodeValue = node.data + child.data
|
|
|
|
node.nextSibling = child.nextSibling
|
|
|
|
child.unlink()
|
2000-12-14 14:16:11 -04:00
|
|
|
elif data:
|
|
|
|
if L:
|
|
|
|
L[-1].nextSibling = child
|
|
|
|
child.previousSibling = L[-1]
|
|
|
|
else:
|
|
|
|
child.previousSibling = None
|
|
|
|
L.append(child)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
else:
|
2000-12-14 14:16:11 -04:00
|
|
|
# empty text node; discard
|
|
|
|
child.unlink()
|
|
|
|
else:
|
|
|
|
if L:
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
L[-1].nextSibling = child
|
|
|
|
child.previousSibling = L[-1]
|
2000-12-14 14:16:11 -04:00
|
|
|
else:
|
|
|
|
child.previousSibling = None
|
|
|
|
L.append(child)
|
|
|
|
if child.nodeType == Node.ELEMENT_NODE:
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
child.normalize()
|
2000-12-14 14:16:11 -04:00
|
|
|
self.childNodes[:] = L
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def cloneNode(self, deep):
|
2000-07-01 01:58:47 -03:00
|
|
|
import new
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
clone = new.instance(self.__class__, self.__dict__.copy())
|
|
|
|
if self._makeParentNodes:
|
|
|
|
clone.parentNode = None
|
2001-09-28 01:33:06 -03:00
|
|
|
clone.childNodes = NodeList()
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if deep:
|
|
|
|
for child in self.childNodes:
|
|
|
|
clone.appendChild(child.cloneNode(1))
|
2000-07-01 01:58:47 -03:00
|
|
|
return clone
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-02-02 15:40:19 -04:00
|
|
|
# DOM Level 3 (Working Draft 2001-Jan-26)
|
|
|
|
|
|
|
|
def isSameNode(self, other):
|
|
|
|
return self is other
|
|
|
|
|
|
|
|
# minidom-specific API:
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def unlink(self):
|
2001-03-13 06:50:13 -04:00
|
|
|
self.parentNode = self.ownerDocument = None
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
for child in self.childNodes:
|
|
|
|
child.unlink()
|
2000-09-24 02:21:58 -03:00
|
|
|
self.childNodes = None
|
2000-10-13 17:11:42 -03:00
|
|
|
self.previousSibling = None
|
|
|
|
self.nextSibling = None
|
2000-07-01 01:58:47 -03:00
|
|
|
if Node._debug:
|
2000-09-24 02:21:58 -03:00
|
|
|
index = repr(id(self)) + repr(self.__class__)
|
|
|
|
self.debug.write("Deleting: %s\n" % index)
|
2000-07-01 01:58:47 -03:00
|
|
|
del Node.allnodes[index]
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _write_data(writer, data):
|
2000-06-29 16:39:57 -03:00
|
|
|
"Writes datachars to writer."
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
replace = _string.replace
|
|
|
|
data = replace(data, "&", "&")
|
|
|
|
data = replace(data, "<", "<")
|
|
|
|
data = replace(data, "\"", """)
|
|
|
|
data = replace(data, ">", ">")
|
2000-06-29 16:39:57 -03:00
|
|
|
writer.write(data)
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _getElementsByTagNameHelper(parent, name, rc):
|
2000-06-29 16:39:57 -03:00
|
|
|
for node in parent.childNodes:
|
2000-09-24 02:21:58 -03:00
|
|
|
if node.nodeType == Node.ELEMENT_NODE and \
|
|
|
|
(name == "*" or node.tagName == name):
|
|
|
|
rc.append(node)
|
|
|
|
_getElementsByTagNameHelper(node, name, rc)
|
2000-06-29 16:39:57 -03:00
|
|
|
return rc
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _getElementsByTagNameNSHelper(parent, nsURI, localName, rc):
|
2000-06-29 16:39:57 -03:00
|
|
|
for node in parent.childNodes:
|
2000-09-24 02:21:58 -03:00
|
|
|
if node.nodeType == Node.ELEMENT_NODE:
|
2001-06-03 11:06:42 -03:00
|
|
|
if ((localName == "*" or node.localName == localName) and
|
2000-09-24 02:21:58 -03:00
|
|
|
(nsURI == "*" or node.namespaceURI == nsURI)):
|
|
|
|
rc.append(node)
|
2000-12-14 14:16:11 -04:00
|
|
|
_getElementsByTagNameNSHelper(node, nsURI, localName, rc)
|
|
|
|
return rc
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
class DocumentFragment(Node):
|
|
|
|
nodeType = Node.DOCUMENT_FRAGMENT_NODE
|
|
|
|
nodeName = "#document-fragment"
|
|
|
|
nodeValue = None
|
|
|
|
attributes = None
|
|
|
|
parentNode = None
|
|
|
|
childNodeTypes = (Node.ELEMENT_NODE,
|
|
|
|
Node.TEXT_NODE,
|
|
|
|
Node.CDATA_SECTION_NODE,
|
|
|
|
Node.ENTITY_REFERENCE_NODE,
|
|
|
|
Node.PROCESSING_INSTRUCTION_NODE,
|
|
|
|
Node.COMMENT_NODE,
|
|
|
|
Node.NOTATION_NODE)
|
|
|
|
|
|
|
|
|
2000-06-29 16:39:57 -03:00
|
|
|
class Attr(Node):
|
2000-09-24 02:21:58 -03:00
|
|
|
nodeType = Node.ATTRIBUTE_NODE
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
attributes = None
|
|
|
|
ownerElement = None
|
2000-12-30 23:50:23 -04:00
|
|
|
childNodeTypes = (Node.TEXT_NODE, Node.ENTITY_REFERENCE_NODE)
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2001-11-30 18:21:58 -04:00
|
|
|
def __init__(self, qName, namespaceURI=EMPTY_NAMESPACE, localName=None, prefix=None):
|
2000-06-29 16:39:57 -03:00
|
|
|
# skip setattr for performance
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
d = self.__dict__
|
|
|
|
d["localName"] = localName or qName
|
|
|
|
d["nodeName"] = d["name"] = qName
|
|
|
|
d["namespaceURI"] = namespaceURI
|
|
|
|
d["prefix"] = prefix
|
2000-09-24 02:21:58 -03:00
|
|
|
Node.__init__(self)
|
2000-07-01 01:58:47 -03:00
|
|
|
# nodeValue and value are set elsewhere
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __setattr__(self, name, value):
|
2000-12-14 14:16:11 -04:00
|
|
|
d = self.__dict__
|
2000-09-24 02:21:58 -03:00
|
|
|
if name in ("value", "nodeValue"):
|
2000-12-14 14:16:11 -04:00
|
|
|
d["value"] = d["nodeValue"] = value
|
|
|
|
elif name in ("name", "nodeName"):
|
|
|
|
d["name"] = d["nodeName"] = value
|
2000-06-29 16:39:57 -03:00
|
|
|
else:
|
2000-12-14 14:16:11 -04:00
|
|
|
d[name] = value
|
2000-06-29 16:39:57 -03:00
|
|
|
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
def cloneNode(self, deep):
|
|
|
|
clone = Node.cloneNode(self, deep)
|
|
|
|
if clone.__dict__.has_key("ownerElement"):
|
|
|
|
del clone.ownerElement
|
|
|
|
return clone
|
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
|
|
|
|
class NamedNodeMap:
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
"""The attribute list is a transient interface to the underlying
|
|
|
|
dictionaries. Mutations here will change the underlying element's
|
2000-12-14 14:16:11 -04:00
|
|
|
dictionary.
|
|
|
|
|
|
|
|
Ordering is imposed artificially and does not reflect the order of
|
|
|
|
attributes as found in an input document.
|
|
|
|
"""
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
|
2001-12-06 14:27:48 -04:00
|
|
|
def __init__(self, attrs, attrsNS, ownerElement):
|
2000-09-24 02:21:58 -03:00
|
|
|
self._attrs = attrs
|
|
|
|
self._attrsNS = attrsNS
|
2001-12-06 14:27:48 -04:00
|
|
|
self._ownerElement = ownerElement
|
2000-12-14 14:16:11 -04:00
|
|
|
|
2001-09-29 01:58:32 -03:00
|
|
|
try:
|
|
|
|
property
|
|
|
|
except NameError:
|
|
|
|
def __getattr__(self, name):
|
|
|
|
if name == "length":
|
|
|
|
return len(self._attrs)
|
|
|
|
raise AttributeError, name
|
|
|
|
else:
|
|
|
|
length = property(lambda self: len(self._attrs),
|
|
|
|
doc="Number of nodes in the NamedNodeMap.")
|
2000-09-24 02:21:58 -03:00
|
|
|
|
|
|
|
def item(self, index):
|
2000-06-29 16:39:57 -03:00
|
|
|
try:
|
2000-12-14 14:16:11 -04:00
|
|
|
return self[self._attrs.keys()[index]]
|
2000-06-29 16:39:57 -03:00
|
|
|
except IndexError:
|
|
|
|
return None
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def items(self):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
L = []
|
|
|
|
for node in self._attrs.values():
|
2001-01-27 04:38:34 -04:00
|
|
|
L.append((node.nodeName, node.value))
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
return L
|
2000-09-24 02:21:58 -03:00
|
|
|
|
|
|
|
def itemsNS(self):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
L = []
|
|
|
|
for node in self._attrs.values():
|
2001-11-30 18:21:58 -04:00
|
|
|
L.append(((node.namespaceURI, node.localName), node.value))
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
return L
|
2000-10-23 15:09:50 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def keys(self):
|
2000-07-01 01:58:47 -03:00
|
|
|
return self._attrs.keys()
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def keysNS(self):
|
2000-07-01 01:58:47 -03:00
|
|
|
return self._attrsNS.keys()
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def values(self):
|
2000-07-01 01:58:47 -03:00
|
|
|
return self._attrs.values()
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-01-27 04:38:34 -04:00
|
|
|
def get(self, name, value = None):
|
|
|
|
return self._attrs.get(name, value)
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __len__(self):
|
2000-06-29 16:39:57 -03:00
|
|
|
return self.length
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __cmp__(self, other):
|
|
|
|
if self._attrs is getattr(other, "_attrs", None):
|
2000-06-29 16:39:57 -03:00
|
|
|
return 0
|
2000-10-23 15:09:50 -03:00
|
|
|
else:
|
2000-09-24 02:21:58 -03:00
|
|
|
return cmp(id(self), id(other))
|
2000-06-29 16:39:57 -03:00
|
|
|
|
|
|
|
#FIXME: is it appropriate to return .value?
|
2000-09-24 02:21:58 -03:00
|
|
|
def __getitem__(self, attname_or_tuple):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if type(attname_or_tuple) is _TupleType:
|
2000-07-01 01:58:47 -03:00
|
|
|
return self._attrsNS[attname_or_tuple]
|
2000-06-29 16:39:57 -03:00
|
|
|
else:
|
2000-07-01 01:58:47 -03:00
|
|
|
return self._attrs[attname_or_tuple]
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-07-01 16:21:47 -03:00
|
|
|
# same as set
|
2000-09-24 02:21:58 -03:00
|
|
|
def __setitem__(self, attname, value):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if type(value) in _StringTypes:
|
2000-09-24 02:21:58 -03:00
|
|
|
node = Attr(attname)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
node.value = value
|
2001-12-06 14:27:48 -04:00
|
|
|
node.ownerDocument = self._ownerElement.ownerDocument
|
2000-07-01 16:21:47 -03:00
|
|
|
else:
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if not isinstance(value, Attr):
|
|
|
|
raise TypeError, "value must be a string or Attr object"
|
2000-09-24 02:21:58 -03:00
|
|
|
node = value
|
2000-12-14 14:16:11 -04:00
|
|
|
self.setNamedItem(node)
|
|
|
|
|
|
|
|
def setNamedItem(self, node):
|
2001-02-20 21:30:26 -04:00
|
|
|
if not isinstance(node, Attr):
|
|
|
|
raise HierarchyRequestErr, \
|
|
|
|
"%s cannot be child of %s" % (repr(node), repr(self))
|
2000-12-14 14:16:11 -04:00
|
|
|
old = self._attrs.get(node.name)
|
2000-07-01 16:21:47 -03:00
|
|
|
if old:
|
|
|
|
old.unlink()
|
2000-09-24 02:21:58 -03:00
|
|
|
self._attrs[node.name] = node
|
|
|
|
self._attrsNS[(node.namespaceURI, node.localName)] = node
|
2001-12-06 14:27:48 -04:00
|
|
|
node.ownerElement = self._ownerElement
|
2000-12-14 14:16:11 -04:00
|
|
|
return old
|
|
|
|
|
|
|
|
def setNamedItemNS(self, node):
|
|
|
|
return self.setNamedItem(node)
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __delitem__(self, attname_or_tuple):
|
|
|
|
node = self[attname_or_tuple]
|
2000-07-01 01:58:47 -03:00
|
|
|
node.unlink()
|
|
|
|
del self._attrs[node.name]
|
|
|
|
del self._attrsNS[(node.namespaceURI, node.localName)]
|
2000-12-14 14:16:11 -04:00
|
|
|
self.length = len(self._attrs)
|
|
|
|
|
|
|
|
AttributeList = NamedNodeMap
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
|
2000-10-07 09:10:28 -03:00
|
|
|
class Element(Node):
|
2000-09-24 02:21:58 -03:00
|
|
|
nodeType = Node.ELEMENT_NODE
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
nextSibling = None
|
|
|
|
previousSibling = None
|
2000-12-30 23:50:23 -04:00
|
|
|
childNodeTypes = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
|
|
|
|
Node.COMMENT_NODE, Node.TEXT_NODE,
|
|
|
|
Node.CDATA_SECTION_NODE, Node.ENTITY_REFERENCE_NODE)
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2001-11-30 18:21:58 -04:00
|
|
|
def __init__(self, tagName, namespaceURI=EMPTY_NAMESPACE, prefix=None,
|
2000-09-24 02:21:58 -03:00
|
|
|
localName=None):
|
|
|
|
Node.__init__(self)
|
2000-06-29 16:39:57 -03:00
|
|
|
self.tagName = self.nodeName = tagName
|
2000-09-24 02:21:58 -03:00
|
|
|
self.localName = localName or tagName
|
|
|
|
self.prefix = prefix
|
|
|
|
self.namespaceURI = namespaceURI
|
|
|
|
self.nodeValue = None
|
2000-06-29 16:39:57 -03:00
|
|
|
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
self._attrs = {} # attributes are double-indexed:
|
|
|
|
self._attrsNS = {} # tagName -> Attribute
|
|
|
|
# URI,localName -> Attribute
|
|
|
|
# in the future: consider lazy generation
|
|
|
|
# of attribute objects this is too tricky
|
|
|
|
# for now because of headaches with
|
|
|
|
# namespaces.
|
|
|
|
|
|
|
|
def cloneNode(self, deep):
|
|
|
|
clone = Node.cloneNode(self, deep)
|
|
|
|
clone._attrs = {}
|
|
|
|
clone._attrsNS = {}
|
|
|
|
for attr in self._attrs.values():
|
|
|
|
node = attr.cloneNode(1)
|
|
|
|
clone._attrs[node.name] = node
|
|
|
|
clone._attrsNS[(node.namespaceURI, node.localName)] = node
|
|
|
|
node.ownerElement = clone
|
|
|
|
return clone
|
|
|
|
|
|
|
|
def unlink(self):
|
|
|
|
for attr in self._attrs.values():
|
|
|
|
attr.unlink()
|
|
|
|
self._attrs = None
|
|
|
|
self._attrsNS = None
|
|
|
|
Node.unlink(self)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getAttribute(self, attname):
|
2001-02-05 15:17:50 -04:00
|
|
|
try:
|
|
|
|
return self._attrs[attname].value
|
|
|
|
except KeyError:
|
|
|
|
return ""
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getAttributeNS(self, namespaceURI, localName):
|
2001-02-05 15:17:50 -04:00
|
|
|
try:
|
|
|
|
return self._attrsNS[(namespaceURI, localName)].value
|
|
|
|
except KeyError:
|
|
|
|
return ""
|
2000-09-24 02:21:58 -03:00
|
|
|
|
|
|
|
def setAttribute(self, attname, value):
|
|
|
|
attr = Attr(attname)
|
2000-06-29 16:39:57 -03:00
|
|
|
# for performance
|
2001-12-06 14:27:48 -04:00
|
|
|
d = attr.__dict__
|
|
|
|
d["value"] = d["nodeValue"] = value
|
|
|
|
d["ownerDocument"] = self.ownerDocument
|
2000-09-24 02:21:58 -03:00
|
|
|
self.setAttributeNode(attr)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def setAttributeNS(self, namespaceURI, qualifiedName, value):
|
|
|
|
prefix, localname = _nssplit(qualifiedName)
|
2000-06-29 16:39:57 -03:00
|
|
|
# for performance
|
2000-09-24 02:21:58 -03:00
|
|
|
attr = Attr(qualifiedName, namespaceURI, localname, prefix)
|
2001-12-06 14:27:48 -04:00
|
|
|
d = attr.__dict__
|
|
|
|
d["value"] = d["nodeValue"] = value
|
|
|
|
d["ownerDocument"] = self.ownerDocument
|
2000-09-24 02:21:58 -03:00
|
|
|
self.setAttributeNode(attr)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getAttributeNode(self, attrname):
|
|
|
|
return self._attrs.get(attrname)
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getAttributeNodeNS(self, namespaceURI, localName):
|
2001-02-05 15:17:50 -04:00
|
|
|
return self._attrsNS.get((namespaceURI, localName))
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def setAttributeNode(self, attr):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
if attr.ownerElement not in (None, self):
|
2001-01-27 04:38:34 -04:00
|
|
|
raise xml.dom.InuseAttributeErr("attribute node already owned")
|
2000-09-24 02:21:58 -03:00
|
|
|
old = self._attrs.get(attr.name, None)
|
2000-07-01 01:58:47 -03:00
|
|
|
if old:
|
|
|
|
old.unlink()
|
2000-09-24 02:21:58 -03:00
|
|
|
self._attrs[attr.name] = attr
|
|
|
|
self._attrsNS[(attr.namespaceURI, attr.localName)] = attr
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
|
|
|
|
# This creates a circular reference, but Element.unlink()
|
|
|
|
# breaks the cycle since the references to the attribute
|
|
|
|
# dictionaries are tossed.
|
|
|
|
attr.ownerElement = self
|
|
|
|
|
|
|
|
if old is not attr:
|
|
|
|
# It might have already been part of this node, in which case
|
|
|
|
# it doesn't represent a change, and should not be returned.
|
|
|
|
return old
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
setAttributeNodeNS = setAttributeNode
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def removeAttribute(self, name):
|
2000-07-01 01:58:47 -03:00
|
|
|
attr = self._attrs[name]
|
2000-09-24 02:21:58 -03:00
|
|
|
self.removeAttributeNode(attr)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def removeAttributeNS(self, namespaceURI, localName):
|
2000-07-01 01:58:47 -03:00
|
|
|
attr = self._attrsNS[(namespaceURI, localName)]
|
2000-09-24 02:21:58 -03:00
|
|
|
self.removeAttributeNode(attr)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def removeAttributeNode(self, node):
|
2000-07-01 01:58:47 -03:00
|
|
|
node.unlink()
|
|
|
|
del self._attrs[node.name]
|
|
|
|
del self._attrsNS[(node.namespaceURI, node.localName)]
|
2000-10-23 15:09:50 -03:00
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
removeAttributeNodeNS = removeAttributeNode
|
|
|
|
|
2000-12-28 14:40:56 -04:00
|
|
|
def hasAttribute(self, name):
|
|
|
|
return self._attrs.has_key(name)
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2000-12-28 14:40:56 -04:00
|
|
|
def hasAttributeNS(self, namespaceURI, localName):
|
2001-01-27 04:47:37 -04:00
|
|
|
return self._attrsNS.has_key((namespaceURI, localName))
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getElementsByTagName(self, name):
|
|
|
|
return _getElementsByTagNameHelper(self, name, [])
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getElementsByTagNameNS(self, namespaceURI, localName):
|
2001-07-04 03:25:53 -03:00
|
|
|
return _getElementsByTagNameNSHelper(self, namespaceURI, localName, [])
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __repr__(self):
|
|
|
|
return "<DOM Element: %s at %s>" % (self.tagName, id(self))
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-02-05 20:14:08 -04:00
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
|
|
|
# indent = current indentation
|
|
|
|
# addindent = indentation to add to higher levels
|
|
|
|
# newl = newline string
|
|
|
|
writer.write(indent+"<" + self.tagName)
|
2000-10-23 15:09:50 -03:00
|
|
|
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
attrs = self._get_attributes()
|
|
|
|
a_names = attrs.keys()
|
2000-06-29 16:39:57 -03:00
|
|
|
a_names.sort()
|
|
|
|
|
|
|
|
for a_name in a_names:
|
2000-09-24 02:21:58 -03:00
|
|
|
writer.write(" %s=\"" % a_name)
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
_write_data(writer, attrs[a_name].value)
|
2000-06-29 16:39:57 -03:00
|
|
|
writer.write("\"")
|
|
|
|
if self.childNodes:
|
2001-02-05 20:14:08 -04:00
|
|
|
writer.write(">%s"%(newl))
|
2000-06-29 16:39:57 -03:00
|
|
|
for node in self.childNodes:
|
2001-02-05 20:14:08 -04:00
|
|
|
node.writexml(writer,indent+addindent,addindent,newl)
|
|
|
|
writer.write("%s</%s>%s" % (indent,self.tagName,newl))
|
2000-06-29 16:39:57 -03:00
|
|
|
else:
|
2001-02-05 20:14:08 -04:00
|
|
|
writer.write("/>%s"%(newl))
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _get_attributes(self):
|
2001-12-06 14:27:48 -04:00
|
|
|
return NamedNodeMap(self._attrs, self._attrsNS, self)
|
2000-09-24 02:21:58 -03:00
|
|
|
|
2001-09-29 01:58:32 -03:00
|
|
|
try:
|
|
|
|
property
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
attributes = property(_get_attributes,
|
|
|
|
doc="NamedNodeMap of attributes on the element.")
|
|
|
|
|
2001-02-05 15:17:50 -04:00
|
|
|
def hasAttributes(self):
|
|
|
|
if self._attrs or self._attrsNS:
|
|
|
|
return 1
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
class Comment(Node):
|
|
|
|
nodeType = Node.COMMENT_NODE
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
nodeName = "#comment"
|
|
|
|
attributes = None
|
2000-12-30 23:50:23 -04:00
|
|
|
childNodeTypes = ()
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __init__(self, data):
|
|
|
|
Node.__init__(self)
|
|
|
|
self.data = self.nodeValue = data
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-02-05 20:14:08 -04:00
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
|
|
|
writer.write("%s<!--%s-->%s" % (indent,self.data,newl))
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
class ProcessingInstruction(Node):
|
|
|
|
nodeType = Node.PROCESSING_INSTRUCTION_NODE
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
attributes = None
|
2000-12-30 23:50:23 -04:00
|
|
|
childNodeTypes = ()
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def __init__(self, target, data):
|
|
|
|
Node.__init__(self)
|
2000-06-29 16:39:57 -03:00
|
|
|
self.target = self.nodeName = target
|
|
|
|
self.data = self.nodeValue = data
|
2000-09-24 02:21:58 -03:00
|
|
|
|
2001-02-05 20:14:08 -04:00
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
|
|
|
writer.write("%s<?%s %s?>%s" % (indent,self.target, self.data, newl))
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-04-04 11:09:46 -03:00
|
|
|
class CharacterData(Node):
|
2000-09-24 02:21:58 -03:00
|
|
|
def __init__(self, data):
|
2001-01-08 00:04:34 -04:00
|
|
|
if type(data) not in _StringTypes:
|
|
|
|
raise TypeError, "node contents must be a string"
|
2000-09-24 02:21:58 -03:00
|
|
|
Node.__init__(self)
|
2000-06-29 16:39:57 -03:00
|
|
|
self.data = self.nodeValue = data
|
2001-04-04 12:15:18 -03:00
|
|
|
self.length = len(data)
|
2001-04-04 11:09:46 -03:00
|
|
|
|
2000-06-29 16:39:57 -03:00
|
|
|
def __repr__(self):
|
2000-09-24 02:21:58 -03:00
|
|
|
if len(self.data) > 10:
|
|
|
|
dotdotdot = "..."
|
2000-06-29 16:39:57 -03:00
|
|
|
else:
|
2000-09-24 02:21:58 -03:00
|
|
|
dotdotdot = ""
|
2001-04-04 11:09:46 -03:00
|
|
|
return "<DOM %s node \"%s%s\">" % (
|
|
|
|
self.__class__.__name__, self.data[0:10], dotdotdot)
|
|
|
|
|
|
|
|
def substringData(self, offset, count):
|
|
|
|
if offset < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be negative")
|
|
|
|
if offset >= len(self.data):
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be beyond end of data")
|
|
|
|
if count < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("count cannot be negative")
|
|
|
|
return self.data[offset:offset+count]
|
|
|
|
|
|
|
|
def appendData(self, arg):
|
|
|
|
self.data = self.data + arg
|
|
|
|
self.nodeValue = self.data
|
2001-04-04 12:15:18 -03:00
|
|
|
self.length = len(self.data)
|
2001-04-04 11:09:46 -03:00
|
|
|
|
|
|
|
def insertData(self, offset, arg):
|
|
|
|
if offset < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be negative")
|
|
|
|
if offset >= len(self.data):
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be beyond end of data")
|
|
|
|
if arg:
|
|
|
|
self.data = "%s%s%s" % (
|
|
|
|
self.data[:offset], arg, self.data[offset:])
|
|
|
|
self.nodeValue = self.data
|
2001-04-04 12:15:18 -03:00
|
|
|
self.length = len(self.data)
|
2001-04-04 11:09:46 -03:00
|
|
|
|
|
|
|
def deleteData(self, offset, count):
|
|
|
|
if offset < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be negative")
|
|
|
|
if offset >= len(self.data):
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be beyond end of data")
|
|
|
|
if count < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("count cannot be negative")
|
|
|
|
if count:
|
|
|
|
self.data = self.data[:offset] + self.data[offset+count:]
|
|
|
|
self.nodeValue = self.data
|
2001-04-04 12:15:18 -03:00
|
|
|
self.length = len(self.data)
|
2001-04-04 11:09:46 -03:00
|
|
|
|
|
|
|
def replaceData(self, offset, count, arg):
|
|
|
|
if offset < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be negative")
|
|
|
|
if offset >= len(self.data):
|
|
|
|
raise xml.dom.IndexSizeErr("offset cannot be beyond end of data")
|
|
|
|
if count < 0:
|
|
|
|
raise xml.dom.IndexSizeErr("count cannot be negative")
|
|
|
|
if count:
|
|
|
|
self.data = "%s%s%s" % (
|
|
|
|
self.data[:offset], arg, self.data[offset+count:])
|
|
|
|
self.nodeValue = self.data
|
2001-04-04 12:15:18 -03:00
|
|
|
self.length = len(self.data)
|
2001-04-04 11:09:46 -03:00
|
|
|
|
|
|
|
class Text(CharacterData):
|
|
|
|
nodeType = Node.TEXT_NODE
|
|
|
|
nodeName = "#text"
|
|
|
|
attributes = None
|
|
|
|
childNodeTypes = ()
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
def splitText(self, offset):
|
|
|
|
if offset < 0 or offset > len(self.data):
|
2001-01-27 04:38:34 -04:00
|
|
|
raise xml.dom.IndexSizeErr("illegal offset value")
|
2000-12-14 14:16:11 -04:00
|
|
|
newText = Text(self.data[offset:])
|
|
|
|
next = self.nextSibling
|
|
|
|
if self.parentNode and self in self.parentNode.childNodes:
|
|
|
|
if next is None:
|
|
|
|
self.parentNode.appendChild(newText)
|
|
|
|
else:
|
|
|
|
self.parentNode.insertBefore(newText, next)
|
|
|
|
self.data = self.data[:offset]
|
2001-04-04 12:15:18 -03:00
|
|
|
self.nodeValue = self.data
|
|
|
|
self.length = len(self.data)
|
2000-12-14 14:16:11 -04:00
|
|
|
return newText
|
|
|
|
|
2001-02-05 20:14:08 -04:00
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
|
|
|
_write_data(writer, "%s%s%s"%(indent, self.data, newl))
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-04-04 11:09:46 -03:00
|
|
|
|
|
|
|
class CDATASection(Text):
|
|
|
|
nodeType = Node.CDATA_SECTION_NODE
|
|
|
|
nodeName = "#cdata-section"
|
|
|
|
|
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
2001-09-19 10:28:25 -03:00
|
|
|
writer.write("<![CDATA[%s]]>" % self.data)
|
2001-04-04 11:09:46 -03:00
|
|
|
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _nssplit(qualifiedName):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
fields = _string.split(qualifiedName, ':', 1)
|
2000-07-01 01:58:47 -03:00
|
|
|
if len(fields) == 2:
|
|
|
|
return fields
|
|
|
|
elif len(fields) == 1:
|
2001-11-30 18:21:58 -04:00
|
|
|
return (None, fields[0])
|
2000-09-24 02:21:58 -03:00
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
|
|
|
|
class DocumentType(Node):
|
|
|
|
nodeType = Node.DOCUMENT_TYPE_NODE
|
|
|
|
nodeValue = None
|
|
|
|
attributes = None
|
|
|
|
name = None
|
|
|
|
publicId = None
|
|
|
|
systemId = None
|
2001-04-05 11:41:30 -03:00
|
|
|
internalSubset = None
|
2000-12-14 14:16:11 -04:00
|
|
|
entities = None
|
|
|
|
notations = None
|
|
|
|
|
|
|
|
def __init__(self, qualifiedName):
|
|
|
|
Node.__init__(self)
|
|
|
|
if qualifiedName:
|
|
|
|
prefix, localname = _nssplit(qualifiedName)
|
|
|
|
self.name = localname
|
|
|
|
|
|
|
|
|
|
|
|
class DOMImplementation:
|
|
|
|
def hasFeature(self, feature, version):
|
|
|
|
if version not in ("1.0", "2.0"):
|
|
|
|
return 0
|
|
|
|
feature = _string.lower(feature)
|
|
|
|
return feature == "core"
|
|
|
|
|
|
|
|
def createDocument(self, namespaceURI, qualifiedName, doctype):
|
|
|
|
if doctype and doctype.parentNode is not None:
|
2001-02-05 15:17:50 -04:00
|
|
|
raise xml.dom.WrongDocumentErr(
|
|
|
|
"doctype object owned by another DOM tree")
|
2001-03-13 06:50:13 -04:00
|
|
|
doc = self._createDocument()
|
2000-12-14 14:16:11 -04:00
|
|
|
if doctype is None:
|
|
|
|
doctype = self.createDocumentType(qualifiedName, None, None)
|
2001-02-05 21:16:06 -04:00
|
|
|
if not qualifiedName:
|
|
|
|
# The spec is unclear what to raise here; SyntaxErr
|
|
|
|
# would be the other obvious candidate. Since Xerces raises
|
|
|
|
# InvalidCharacterErr, and since SyntaxErr is not listed
|
|
|
|
# for createDocument, that seems to be the better choice.
|
|
|
|
# XXX: need to check for illegal characters here and in
|
|
|
|
# createElement.
|
|
|
|
raise xml.dom.InvalidCharacterErr("Element with no name")
|
|
|
|
prefix, localname = _nssplit(qualifiedName)
|
|
|
|
if prefix == "xml" \
|
|
|
|
and namespaceURI != "http://www.w3.org/XML/1998/namespace":
|
|
|
|
raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
|
|
|
|
if prefix and not namespaceURI:
|
|
|
|
raise xml.dom.NamespaceErr(
|
|
|
|
"illegal use of prefix without namespaces")
|
|
|
|
element = doc.createElementNS(namespaceURI, qualifiedName)
|
|
|
|
doc.appendChild(element)
|
2001-03-13 06:50:13 -04:00
|
|
|
doctype.parentNode = doctype.ownerDocument = doc
|
2000-12-14 14:16:11 -04:00
|
|
|
doc.doctype = doctype
|
|
|
|
doc.implementation = self
|
|
|
|
return doc
|
|
|
|
|
|
|
|
def createDocumentType(self, qualifiedName, publicId, systemId):
|
|
|
|
doctype = DocumentType(qualifiedName)
|
|
|
|
doctype.publicId = publicId
|
|
|
|
doctype.systemId = systemId
|
|
|
|
return doctype
|
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
# internal
|
|
|
|
def _createDocument(self):
|
|
|
|
return Document()
|
2000-12-14 14:16:11 -04:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
class Document(Node):
|
|
|
|
nodeType = Node.DOCUMENT_NODE
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
nodeName = "#document"
|
|
|
|
nodeValue = None
|
|
|
|
attributes = None
|
2000-12-14 14:16:11 -04:00
|
|
|
doctype = None
|
|
|
|
parentNode = None
|
2001-03-13 06:50:13 -04:00
|
|
|
previousSibling = nextSibling = None
|
2000-12-14 14:16:11 -04:00
|
|
|
|
|
|
|
implementation = DOMImplementation()
|
2000-12-30 23:50:23 -04:00
|
|
|
childNodeTypes = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
|
|
|
|
Node.COMMENT_NODE, Node.DOCUMENT_TYPE_NODE)
|
2000-09-24 02:21:58 -03:00
|
|
|
|
|
|
|
def appendChild(self, node):
|
2000-12-30 23:50:23 -04:00
|
|
|
if node.nodeType not in self.childNodeTypes:
|
|
|
|
raise HierarchyRequestErr, \
|
2001-02-05 15:17:50 -04:00
|
|
|
"%s cannot be child of %s" % (repr(node), repr(self))
|
2000-12-20 10:47:24 -04:00
|
|
|
if node.parentNode is not None:
|
|
|
|
node.parentNode.removeChild(node)
|
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
if node.nodeType == Node.ELEMENT_NODE \
|
|
|
|
and self._get_documentElement():
|
2001-02-05 15:17:50 -04:00
|
|
|
raise xml.dom.HierarchyRequestErr(
|
|
|
|
"two document elements disallowed")
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
return Node.appendChild(self, node)
|
2000-07-01 01:58:47 -03:00
|
|
|
|
2000-12-20 10:47:24 -04:00
|
|
|
def removeChild(self, oldChild):
|
|
|
|
self.childNodes.remove(oldChild)
|
|
|
|
oldChild.nextSibling = oldChild.previousSibling = None
|
|
|
|
oldChild.parentNode = None
|
|
|
|
if self.documentElement is oldChild:
|
|
|
|
self.documentElement = None
|
2001-01-27 04:47:37 -04:00
|
|
|
|
2000-12-20 10:47:24 -04:00
|
|
|
return oldChild
|
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
def _get_documentElement(self):
|
|
|
|
for node in self.childNodes:
|
|
|
|
if node.nodeType == Node.ELEMENT_NODE:
|
|
|
|
return node
|
|
|
|
|
2001-09-29 01:58:32 -03:00
|
|
|
try:
|
|
|
|
property
|
|
|
|
except NameError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
documentElement = property(_get_documentElement,
|
|
|
|
doc="Top-level element of this document.")
|
|
|
|
|
2000-12-14 14:16:11 -04:00
|
|
|
def unlink(self):
|
|
|
|
if self.doctype is not None:
|
|
|
|
self.doctype.unlink()
|
|
|
|
self.doctype = None
|
|
|
|
Node.unlink(self)
|
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
def createDocumentFragment(self):
|
|
|
|
d = DocumentFragment()
|
|
|
|
d.ownerDoc = self
|
|
|
|
return d
|
|
|
|
|
|
|
|
def createElement(self, tagName):
|
|
|
|
e = Element(tagName)
|
|
|
|
e.ownerDocument = self
|
|
|
|
return e
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
def createTextNode(self, data):
|
|
|
|
t = Text(data)
|
|
|
|
t.ownerDocument = self
|
|
|
|
return t
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-04-04 11:09:46 -03:00
|
|
|
def createCDATASection(self, data):
|
|
|
|
c = CDATASection(data)
|
|
|
|
c.ownerDocument = self
|
|
|
|
return c
|
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
def createComment(self, data):
|
|
|
|
c = Comment(data)
|
|
|
|
c.ownerDocument = self
|
|
|
|
return c
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
def createProcessingInstruction(self, target, data):
|
|
|
|
p = ProcessingInstruction(target, data)
|
|
|
|
p.ownerDocument = self
|
|
|
|
return p
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-03-13 06:50:13 -04:00
|
|
|
def createAttribute(self, qName):
|
|
|
|
a = Attr(qName)
|
|
|
|
a.ownerDocument = self
|
2001-03-31 12:30:40 -04:00
|
|
|
a.value = ""
|
2001-03-13 06:50:13 -04:00
|
|
|
return a
|
2000-06-29 16:39:57 -03:00
|
|
|
|
|
|
|
def createElementNS(self, namespaceURI, qualifiedName):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
prefix, localName = _nssplit(qualifiedName)
|
2001-03-13 06:50:13 -04:00
|
|
|
e = Element(qualifiedName, namespaceURI, prefix, localName)
|
|
|
|
e.ownerDocument = self
|
|
|
|
return e
|
2000-06-29 16:39:57 -03:00
|
|
|
|
|
|
|
def createAttributeNS(self, namespaceURI, qualifiedName):
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
prefix, localName = _nssplit(qualifiedName)
|
2001-03-13 06:50:13 -04:00
|
|
|
a = Attr(qualifiedName, namespaceURI, localName, prefix)
|
|
|
|
a.ownerDocument = self
|
2001-03-31 12:30:40 -04:00
|
|
|
a.value = ""
|
2001-03-13 06:50:13 -04:00
|
|
|
return a
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def getElementsByTagName(self, name):
|
2001-07-04 03:25:53 -03:00
|
|
|
return _getElementsByTagNameHelper(self, name, [])
|
|
|
|
|
|
|
|
def getElementsByTagNameNS(self, namespaceURI, localName):
|
|
|
|
return _getElementsByTagNameNSHelper(self, namespaceURI, localName, [])
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2001-02-05 20:14:08 -04:00
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
2001-02-05 15:17:50 -04:00
|
|
|
writer.write('<?xml version="1.0" ?>\n')
|
2000-06-29 16:39:57 -03:00
|
|
|
for node in self.childNodes:
|
2001-02-05 20:14:08 -04:00
|
|
|
node.writexml(writer, indent, addindent, newl)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
def _get_StringIO():
|
2000-12-14 14:16:11 -04:00
|
|
|
# we can't use cStringIO since it doesn't support Unicode strings
|
|
|
|
from StringIO import StringIO
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
return StringIO()
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def _doparse(func, args, kwargs):
|
|
|
|
events = apply(func, args, kwargs)
|
|
|
|
toktype, rootNode = events.getEvent()
|
|
|
|
events.expandNode(rootNode)
|
2001-02-05 21:16:06 -04:00
|
|
|
events.clear()
|
2000-06-29 16:39:57 -03:00
|
|
|
return rootNode
|
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def parse(*args, **kwargs):
|
2000-12-14 14:16:11 -04:00
|
|
|
"""Parse a file into a DOM by filename or file object."""
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
from xml.dom import pulldom
|
2000-09-24 02:21:58 -03:00
|
|
|
return _doparse(pulldom.parse, args, kwargs)
|
2000-06-29 16:39:57 -03:00
|
|
|
|
2000-09-24 02:21:58 -03:00
|
|
|
def parseString(*args, **kwargs):
|
2000-12-14 14:16:11 -04:00
|
|
|
"""Parse a file into a DOM from a string."""
|
Reduce the visibility of imported modules for cleaner "from ... import *"
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
2000-11-21 18:02:22 -04:00
|
|
|
from xml.dom import pulldom
|
2000-09-24 02:21:58 -03:00
|
|
|
return _doparse(pulldom.parseString, args, kwargs)
|
2001-02-22 10:05:50 -04:00
|
|
|
|
|
|
|
def getDOMImplementation():
|
|
|
|
return Document.implementation
|