MCPcopy Index your code
hub / github.com/python/cpython / _clone_node

Function _clone_node

Lib/xml/dom/minidom.py:1900–1979  ·  view source on GitHub ↗

Clone a node and give it the new owner document. Called by Node.cloneNode and Document.importNode

(node, deep, newOwnerDocument)

Source from the content-addressed store, hash-verified

1898
1899
1900def _clone_node(node, deep, newOwnerDocument):
1901 """
1902 Clone a node and give it the new owner document.
1903 Called by Node.cloneNode and Document.importNode
1904 """
1905 if node.ownerDocument.isSameNode(newOwnerDocument):
1906 operation = xml.dom.UserDataHandler.NODE_CLONED
1907 else:
1908 operation = xml.dom.UserDataHandler.NODE_IMPORTED
1909 if node.nodeType == Node.ELEMENT_NODE:
1910 clone = newOwnerDocument.createElementNS(node.namespaceURI,
1911 node.nodeName)
1912 for attr in node.attributes.values():
1913 clone.setAttributeNS(attr.namespaceURI, attr.nodeName, attr.value)
1914 a = clone.getAttributeNodeNS(attr.namespaceURI, attr.localName)
1915 a.specified = attr.specified
1916
1917 if deep:
1918 for child in node.childNodes:
1919 c = _clone_node(child, deep, newOwnerDocument)
1920 clone.appendChild(c)
1921
1922 elif node.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
1923 clone = newOwnerDocument.createDocumentFragment()
1924 if deep:
1925 for child in node.childNodes:
1926 c = _clone_node(child, deep, newOwnerDocument)
1927 clone.appendChild(c)
1928
1929 elif node.nodeType == Node.TEXT_NODE:
1930 clone = newOwnerDocument.createTextNode(node.data)
1931 elif node.nodeType == Node.CDATA_SECTION_NODE:
1932 clone = newOwnerDocument.createCDATASection(node.data)
1933 elif node.nodeType == Node.PROCESSING_INSTRUCTION_NODE:
1934 clone = newOwnerDocument.createProcessingInstruction(node.target,
1935 node.data)
1936 elif node.nodeType == Node.COMMENT_NODE:
1937 clone = newOwnerDocument.createComment(node.data)
1938 elif node.nodeType == Node.ATTRIBUTE_NODE:
1939 clone = newOwnerDocument.createAttributeNS(node.namespaceURI,
1940 node.nodeName)
1941 clone.specified = True
1942 clone.value = node.value
1943 elif node.nodeType == Node.DOCUMENT_TYPE_NODE:
1944 assert node.ownerDocument is not newOwnerDocument
1945 operation = xml.dom.UserDataHandler.NODE_IMPORTED
1946 clone = newOwnerDocument.implementation.createDocumentType(
1947 node.name, node.publicId, node.systemId)
1948 clone.ownerDocument = newOwnerDocument
1949 if deep:
1950 clone.entities._seq = []
1951 clone.notations._seq = []
1952 for n in node.notations._seq:
1953 notation = Notation(n.nodeName, n.publicId, n.systemId)
1954 notation.ownerDocument = newOwnerDocument
1955 clone.notations._seq.append(notation)
1956 if hasattr(n, '_call_user_data_handler'):
1957 n._call_user_data_handler(operation, n, notation)

Callers 3

cloneNodeMethod · 0.85
cloneNodeMethod · 0.85
importNodeMethod · 0.85

Calls 15

NotationClass · 0.85
EntityClass · 0.85
isSameNodeMethod · 0.80
createElementNSMethod · 0.80
setAttributeNSMethod · 0.80
getAttributeNodeNSMethod · 0.80
createTextNodeMethod · 0.80
createCDATASectionMethod · 0.80
createCommentMethod · 0.80
createAttributeNSMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…