Lines Matching +full:node +full:- +full:version
25 # This is used by the ID-cache invalidation checks; the list isn't
27 # DOCUMENT_NODE or DOCUMENT_FRAGMENT_NODE. (The node being checked is
28 # the node being added or removed, not the node being modified.)
30 _nodeTypes_with_children = (xml.dom.Node.ELEMENT_NODE,
31 xml.dom.Node.ENTITY_REFERENCE_NODE)
34 class Node(xml.dom.Node): class
35 namespaceURI = None # this is non-null only for elements and attributes
41 prefix = EMPTY_PREFIX # non-null only for NS elements and attributes
58 if self.nodeType == Node.DOCUMENT_NODE:
80 return self.childNodes[-1]
106 node = self.childNodes[index-1]
107 node.nextSibling = newChild
108 newChild.previousSibling = node
114 def appendChild(self, node): argument
115 if node.nodeType == self.DOCUMENT_FRAGMENT_NODE:
116 for c in tuple(node.childNodes):
119 return node
120 if node.nodeType not in self._child_node_types:
122 "%s cannot be child of %s" % (repr(node), repr(self)))
123 elif node.nodeType in _nodeTypes_with_children:
125 if node.parentNode is not None:
126 node.parentNode.removeChild(node)
127 _append_child(self, node)
128 node.nextSibling = None
129 return node
182 if child.nodeType == Node.TEXT_NODE:
184 # empty text node; discard
186 L[-1].nextSibling = child.nextSibling
190 elif L and L[-1].nodeType == child.nodeType:
191 # collapse text node
192 node = L[-1]
193 node.data = node.data + child.data
194 node.nextSibling = child.nextSibling
196 child.nextSibling.previousSibling = node
202 if child.nodeType == Node.ELEMENT_NODE:
209 def isSupported(self, feature, version): argument
210 return self.ownerDocument.implementation.hasFeature(feature, version)
213 # Overridden in Element and Attr where localName can be Non-Null
216 # Node interfaces from Level 3 (WD 9 April 2002)
261 # minidom-specific API:
272 # A Node is its own context manager, to ensure that an unlink() call occurs.
280 defproperty(Node, "firstChild", doc="First child node, or None.")
281 defproperty(Node, "lastChild", doc="Last child node, or None.")
282 defproperty(Node, "localName", doc="Namespace-local name of this node.")
285 def _append_child(self, node): argument
289 last = childNodes[-1]
290 node.previousSibling = last
291 last.nextSibling = node
292 childNodes.append(node)
293 node.parentNode = self
295 def _in_document(node): argument
296 # return True iff node is part of a document tree
297 while node is not None:
298 if node.nodeType == Node.DOCUMENT_NODE:
300 node = node.parentNode
311 for node in parent.childNodes:
312 if node.nodeType == Node.ELEMENT_NODE and \
313 (name == "*" or node.tagName == name):
314 rc.append(node)
315 _get_elements_by_tagName_helper(node, name, rc)
319 for node in parent.childNodes:
320 if node.nodeType == Node.ELEMENT_NODE:
321 if ((localName == "*" or node.localName == localName) and
322 (nsURI == "*" or node.namespaceURI == nsURI)):
323 rc.append(node)
324 _get_elements_by_tagName_ns_helper(node, nsURI, localName, rc)
327 class DocumentFragment(Node):
328 nodeType = Node.DOCUMENT_FRAGMENT_NODE
329 nodeName = "#document-fragment"
333 _child_node_types = (Node.ELEMENT_NODE,
334 Node.TEXT_NODE,
335 Node.CDATA_SECTION_NODE,
336 Node.ENTITY_REFERENCE_NODE,
337 Node.PROCESSING_INSTRUCTION_NODE,
338 Node.COMMENT_NODE,
339 Node.NOTATION_NODE)
345 class Attr(Node):
348 nodeType = Node.ATTRIBUTE_NODE
353 _child_node_types = (Node.TEXT_NODE, Node.ENTITY_REFERENCE_NODE)
363 # Add the single child node that represents the value of the attr
372 return self.nodeName.split(":", 1)[-1]
430 elem._magic_id_nodes -= 1
431 self.ownerDocument._magic_id_count -= 1
467 defproperty(Attr, "localName", doc="Namespace-local name of this attribute.")
498 for node in self._attrs.values():
499 L.append((node.nodeName, node.value))
504 for node in self._attrs.values():
505 L.append(((node.namespaceURI, node.localName), node.value))
532 return (id(self) > id(other)) - (id(self) < id(other))
559 node = self._attrs[attname]
561 node = Attr(attname)
562 node.ownerDocument = self._ownerElement.ownerDocument
563 self.setNamedItem(node)
564 node.value = value
568 node = value
569 self.setNamedItem(node)
607 def setNamedItem(self, node): argument
608 if not isinstance(node, Attr):
610 "%s cannot be child of %s" % (repr(node), repr(self)))
611 old = self._attrs.get(node.name)
614 self._attrs[node.name] = node
615 self._attrsNS[(node.namespaceURI, node.localName)] = node
616 node.ownerElement = self._ownerElement
617 _clear_id_cache(node.ownerElement)
620 def setNamedItemNS(self, node): argument
621 return self.setNamedItem(node)
624 node = self[attname_or_tuple]
625 _clear_id_cache(node.ownerElement)
626 node.unlink()
662 class Element(Node):
666 nodeType = Node.ELEMENT_NODE
672 _child_node_types = (Node.ELEMENT_NODE,
673 Node.PROCESSING_INSTRUCTION_NODE,
674 Node.COMMENT_NODE,
675 Node.TEXT_NODE,
676 Node.CDATA_SECTION_NODE,
677 Node.ENTITY_REFERENCE_NODE)
689 # attributes are double-indexed:
690 # tagName -> Attribute
691 # URI,localName -> Attribute
708 return self.tagName.split(":", 1)[-1]
719 Node.unlink(self)
786 raise xml.dom.InuseAttributeErr("attribute node already owned")
797 # It might have already been part of this node, in which case
823 def removeAttributeNode(self, node): argument
824 if node is None:
827 self._attrs[node.name]
831 node.unlink()
832 # Restore this since the node is still useful and otherwise
834 node.ownerDocument = self.ownerDocument
835 return node
870 """Write an XML element to a file-like object
890 Node.TEXT_NODE, Node.CDATA_SECTION_NODE)):
894 for node in self.childNodes:
895 node.writexml(writer, indent+addindent, addindent, newl)
935 doc="Namespace-local name of this element.")
950 """Mixin that makes childless-ness easy to implement and avoids
951 the complexity of the Node methods that deal with children.
966 def appendChild(self, node): argument
990 class ProcessingInstruction(Childless, Node):
991 nodeType = Node.PROCESSING_INSTRUCTION_NODE
1016 class CharacterData(Childless, Node):
1023 Node.__init__(self)
1042 return '<DOM %s node "%r%s">' % (
1093 nodeType = Node.TEXT_NODE
1121 if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
1128 if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
1141 if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
1151 if n.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
1176 doc="True iff this text node contains only whitespace"
1179 doc="The text of all logically-adjacent text nodes.")
1182 def _get_containing_element(node): argument
1183 c = node.parentNode
1185 if c.nodeType == Node.ELEMENT_NODE:
1190 def _get_containing_entref(node): argument
1191 c = node.parentNode
1193 if c.nodeType == Node.ENTITY_REFERENCE_NODE:
1200 nodeType = Node.COMMENT_NODE
1208 if "--" in self.data:
1209 raise ValueError("'--' is not allowed in a comment node")
1210 writer.write("%s<!--%s-->%s" % (indent, self.data, newl))
1216 nodeType = Node.CDATA_SECTION_NODE
1217 nodeName = "#cdata-section"
1250 node = self.getNamedItemNS(*name_or_tuple)
1252 node = self.getNamedItem(name_or_tuple)
1253 if node is None:
1255 return node
1267 "NamedNodeMap instance is read-only")
1271 "NamedNodeMap instance is read-only")
1273 def setNamedItem(self, node): argument
1275 "NamedNodeMap instance is read-only")
1277 def setNamedItemNS(self, node): argument
1279 "NamedNodeMap instance is read-only")
1292 """Mix-in class that supports the publicId and systemId attributes."""
1306 class DocumentType(Identified, Childless, Node):
1307 nodeType = Node.DOCUMENT_TYPE_NODE
1344 entity.version = e.version
1366 class Entity(Identified, Node):
1368 nodeType = Node.ENTITY_NODE
1373 version = None variable in Entity
1388 return self.version
1392 "cannot append children to an entity node")
1396 "cannot insert children below an entity node")
1400 "cannot remove children from an entity node")
1404 "cannot replace children of an entity node")
1406 class Notation(Identified, Childless, Node):
1407 nodeType = Node.NOTATION_NODE
1422 ("ls-load", "3.0"),
1423 ("ls-load", None),
1426 def hasFeature(self, feature, version): argument
1427 if version == "":
1428 version = None
1429 return (feature.lower(), version) in self._features
1495 """Object that represents content-model information for an element.
1523 """Returns true iff the named attribute is a DTD-style ID."""
1527 """Returns true iff the identified attribute is a DTD-style ID."""
1536 def _clear_id_cache(node): argument
1537 if node.nodeType == Node.DOCUMENT_NODE:
1538 node._id_cache.clear()
1539 node._id_search_stack = None
1540 elif _in_document(node):
1541 node.ownerDocument._id_cache.clear()
1542 node.ownerDocument._id_search_stack= None
1544 class Document(Node, DocumentLS):
1547 _child_node_types = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
1548 Node.COMMENT_NODE, Node.DOCUMENT_TYPE_NODE)
1551 nodeType = Node.DOCUMENT_NODE
1564 version = None variable in Document
1574 # mapping of (namespaceURI, localName) -> ElementInfo
1575 # and tagName -> ElementInfo
1609 return self.version
1611 def appendChild(self, node): argument
1612 if node.nodeType not in self._child_node_types:
1614 "%s cannot be child of %s" % (repr(node), repr(self)))
1615 if node.parentNode is not None:
1618 # end up re-ordered to the end.
1619 node.parentNode.removeChild(node)
1621 if node.nodeType == Node.ELEMENT_NODE \
1625 return Node.appendChild(self, node)
1640 for node in self.childNodes:
1641 if node.nodeType == Node.ELEMENT_NODE:
1642 return node
1648 Node.unlink(self)
1656 clone.version = self.version
1661 if childclone.nodeType == Node.DOCUMENT_NODE:
1663 elif childclone.nodeType == Node.DOCUMENT_TYPE_NODE:
1683 raise TypeError("node contents must be a string")
1691 raise TypeError("node contents must be a string")
1726 # A couple of implementation-specific helpers to create node types
1752 # no matching node.
1757 node = stack.pop()
1759 stack.extend([child for child in node.childNodes
1761 # check this node
1762 info = self._get_elem_info(node)
1767 for attr in node.attributes.values():
1770 self._id_cache[attr.value] = node
1772 result = node
1773 elif not node._magic_id_nodes:
1776 self._id_cache[attr.value] = node
1778 result = node
1779 elif not node._magic_id_nodes:
1782 self._id_cache[attr.value] = node
1784 result = node
1785 elif node._magic_id_nodes == 1:
1787 elif node._magic_id_nodes:
1788 for attr in node.attributes.values():
1790 self._id_cache[attr.value] = node
1792 result = node
1804 def isSupported(self, feature, version): argument
1805 return self.implementation.hasFeature(feature, version)
1807 def importNode(self, node, deep): argument
1808 if node.nodeType == Node.DOCUMENT_NODE:
1810 elif node.nodeType == Node.DOCUMENT_TYPE_NODE:
1812 return _clone_node(node, deep, self)
1823 writer.write(f'<?xml version="1.0" {" ".join(declarations)}?>{newl}')
1825 for node in self.childNodes:
1826 node.writexml(writer, indent, addindent, newl)
1835 if n.nodeType not in (Node.ELEMENT_NODE, Node.ATTRIBUTE_NODE):
1848 and n.nodeType == Node.ATTRIBUTE_NODE):
1856 if n.nodeType == Node.ATTRIBUTE_NODE:
1867 if n.nodeType == Node.ELEMENT_NODE:
1870 # attribute node
1878 # we're re-using the existing node. The draft spec has been
1880 # new node is created."
1884 doc="Top-level element of this document.")
1887 def _clone_node(node, deep, newOwnerDocument): argument
1889 Clone a node and give it the new owner document.
1890 Called by Node.cloneNode and Document.importNode
1892 if node.ownerDocument.isSameNode(newOwnerDocument):
1896 if node.nodeType == Node.ELEMENT_NODE:
1897 clone = newOwnerDocument.createElementNS(node.namespaceURI,
1898 node.nodeName)
1899 for attr in node.attributes.values():
1905 for child in node.childNodes:
1909 elif node.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
1912 for child in node.childNodes:
1916 elif node.nodeType == Node.TEXT_NODE:
1917 clone = newOwnerDocument.createTextNode(node.data)
1918 elif node.nodeType == Node.CDATA_SECTION_NODE:
1919 clone = newOwnerDocument.createCDATASection(node.data)
1920 elif node.nodeType == Node.PROCESSING_INSTRUCTION_NODE:
1921 clone = newOwnerDocument.createProcessingInstruction(node.target,
1922 node.data)
1923 elif node.nodeType == Node.COMMENT_NODE:
1924 clone = newOwnerDocument.createComment(node.data)
1925 elif node.nodeType == Node.ATTRIBUTE_NODE:
1926 clone = newOwnerDocument.createAttributeNS(node.namespaceURI,
1927 node.nodeName)
1929 clone.value = node.value
1930 elif node.nodeType == Node.DOCUMENT_TYPE_NODE:
1931 assert node.ownerDocument is not newOwnerDocument
1934 node.name, node.publicId, node.systemId)
1939 for n in node.notations._seq:
1945 for e in node.entities._seq:
1950 entity.version = e.version
1959 raise xml.dom.NotSupportedErr("Cannot clone node %s" % repr(node))
1964 if hasattr(node, '_call_user_data_handler'):
1965 node._call_user_data_handler(operation, node, clone)