Clone a node and give it the new owner document. Called by Node.cloneNode and Document.importNode
(node, deep, newOwnerDocument)
| 1898 | |
| 1899 | |
| 1900 | def _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) |
no test coverage detected
searching dependent graphs…