1.1 --- a/libxml2dom/macrolib/macrolib.py Fri Mar 02 22:55:33 2007 +0000
1.2 +++ b/libxml2dom/macrolib/macrolib.py Fri Mar 02 22:56:00 2007 +0000
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 DOM macros for virtual libxml2mod node methods and properties.
1.6
1.7 -Copyright (C) 2003, 2004, 2005, 2006 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2003, 2004, 2005, 2006, 2007 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This library is free software; you can redistribute it and/or
1.11 modify it under the terms of the GNU Lesser General Public
1.12 @@ -49,6 +49,10 @@
1.13 else:
1.14 return s
1.15
1.16 +def check_document(node, tmp):
1.17 + if Node_ownerDocument(node) is not Node_ownerDocument(tmp):
1.18 + raise xml.dom.DOMException(xml.dom.WRONG_DOCUMENT_ERR)
1.19 +
1.20 def get_ns(ns):
1.21 out_ns = to_unicode(libxml2mod.xmlNodeGetContent(ns))
1.22 # Detect "" and produce None as the empty namespace.
1.23 @@ -404,12 +408,15 @@
1.24 return libxml2mod.xmlNewComment(value)
1.25
1.26 def Node_insertBefore(node, tmp, oldNode):
1.27 + check_document(node, tmp)
1.28 return libxml2mod.xmlAddPrevSibling(oldNode, tmp)
1.29
1.30 def Node_replaceChild(node, tmp, oldNode):
1.31 + check_document(node, tmp)
1.32 return libxml2mod.xmlReplaceNode(oldNode, tmp)
1.33
1.34 def Node_appendChild(node, tmp):
1.35 + check_document(node, tmp)
1.36 return libxml2mod.xmlAddChild(node, tmp)
1.37
1.38 def Node_removeChild(node, child):
1.39 @@ -435,7 +442,7 @@
1.40 elif Node_nodeType(other) == xml.dom.Node.COMMENT_NODE:
1.41 return Node_createComment(node, Node_data(other))
1.42
1.43 - raise ValueError, "Node type '%s' (%d) not supported." % (other, Node_nodeType(other))
1.44 + raise xml.dom.DOMException(xml.dom.NOT_SUPPORTED_ERR, "Node type '%s' (%d) not supported." % (other, Node_nodeType(other)))
1.45
1.46 def Node_importNode_DOM(node, other, deep):
1.47 if other.nodeType == xml.dom.Node.ELEMENT_NODE:
1.48 @@ -457,7 +464,7 @@
1.49 elif other.nodeType == xml.dom.Node.COMMENT_NODE:
1.50 return Node_createComment(node, other.data)
1.51
1.52 - raise ValueError, "Node type '%s' (%d) not supported." % (_reverseNodeTypes[other.nodeType], other.nodeType)
1.53 + raise xml.dom.DOMException(xml.dom.NOT_SUPPORTED_ERR, "Node type '%s' (%d) not supported." % (_reverseNodeTypes[other.nodeType], other.nodeType))
1.54
1.55 def Node_xpath(node, expr, variables=None, namespaces=None):
1.56 expr = from_unicode(expr)