# HG changeset patch # User Paul Boddie # Date 1390773318 -3600 # Node ID 98f6eeafe0d092c1c0da8edf10afb42d8792e707 # Parent 8e57ff2336bf1cc4dfbfd80870b9fc5d2b88e96d Changed the origin of specific namespace defaults in XPath operations, initialising document-specific default namespaces in the document object instead of acquiring such defaults from the module namespace in the xpath method invocation. diff -r 8e57ff2336bf -r 98f6eeafe0d0 README.txt --- a/README.txt Sun Jan 26 21:53:15 2014 +0100 +++ b/README.txt Sun Jan 26 22:55:18 2014 +0100 @@ -94,6 +94,10 @@ * Changed the parsing of HTML documents retrieved using parseURI to use the libxml2 network retrieval support. * Exposed LSException and XIncludeException through libxml2dom. + * Changed the origin of specific namespace defaults in XPath operations, + initialising document-specific default namespaces in the document object + instead of acquiring such defaults from the module namespace in the xpath + method invocation. New in libxml2dom 0.5 (Changes since libxml2dom 0.4.7) ------------------------------------------------------ diff -r 8e57ff2336bf -r 98f6eeafe0d0 libxml2dom/__init__.py --- a/libxml2dom/__init__.py Sun Jan 26 21:53:15 2014 +0100 +++ b/libxml2dom/__init__.py Sun Jan 26 22:55:18 2014 +0100 @@ -3,7 +3,7 @@ """ DOM wrapper around libxml2, specifically the libxml2mod Python extension module. -Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012, 2013 Paul Boddie +Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2012, 2013, 2014 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -523,8 +523,9 @@ """ ns = {} - ns.update(default_ns) - ns.update(namespaces or {}) + ns.update(self.ownerDocument.namespaces) + if namespaces: + ns.update(namespaces) result = Node_xpath(self._node, expr, variables, ns) if isinstance(result, str): return to_unicode(result) @@ -588,10 +589,17 @@ VAL_FALSE = 6 VAL_UNKNOWN = 7 - def __init__(self, node, impl): + def __init__(self, node, impl, namespaces=None): self._node = node self.implementation = self.impl = impl self.error_handler = libxml2dom.errors.DOMErrorHandler() + self.namespaces = {} + self._update_namespaces([default_ns, namespaces]) + + def _update_namespaces(self, additional_namespaces): + for namespaces in additional_namespaces: + if namespaces: + self.namespaces.update(namespaces) # Standard DOM properties and their implementations. diff -r 8e57ff2336bf -r 98f6eeafe0d0 libxml2dom/soap.py --- a/libxml2dom/soap.py Sun Jan 26 21:53:15 2014 +0100 +++ b/libxml2dom/soap.py Sun Jan 26 22:55:18 2014 +0100 @@ -6,7 +6,7 @@ See: http://www.w3.org/TR/2007/REC-soap12-part0-20070427/ -Copyright (C) 2007, 2008 Paul Boddie +Copyright (C) 2007, 2008, 2014 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -66,19 +66,6 @@ "Convenience modifications to nodes specific to libxml2dom.soap." - def xpath(self, expr, variables=None, namespaces=None): - - """ - Evaluate the given 'expr' using the optional 'variables' and - 'namespaces'. If not otherwise specified, the prefixes given in the - module global 'default_ns' will be bound as in that dictionary. - """ - - ns = {} - ns.update(default_ns) - ns.update(namespaces or {}) - return libxml2dom.Node.xpath(self, expr, variables, ns) - def add_or_replace_element(self, new_element): """ @@ -163,6 +150,16 @@ "A SOAP document fragment." + def __init__(self, node, impl, namespaces=None): + + """ + Initialise the document with the given 'node', implementation 'impl', + and 'namespaces' details. + """ + + libxml2dom._Document.__init__(self, node, impl, None) + self._update_namespaces([default_ns, namespaces]) + def _envelope(self): return (self.xpath("env:Envelope|SOAP-ENV:Envelope") or [None])[0] diff -r 8e57ff2336bf -r 98f6eeafe0d0 libxml2dom/svg.py --- a/libxml2dom/svg.py Sun Jan 26 21:53:15 2014 +0100 +++ b/libxml2dom/svg.py Sun Jan 26 22:55:18 2014 +0100 @@ -5,7 +5,7 @@ See: http://www.w3.org/TR/SVGMobile12/python-binding.html See: http://www.w3.org/TR/SVGMobile12/svgudom.html -Copyright (C) 2007, 2008, 2012 Paul Boddie +Copyright (C) 2007, 2008, 2012, 2014 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -33,6 +33,10 @@ SVG_NAMESPACE = "http://www.w3.org/2000/svg" +default_ns = { + "svg" : SVG_NAMESPACE + } + comma_wsp = re.compile("\s*,\s*|\s+") TYPE_MISMATCH_ERR = 17 @@ -737,20 +741,9 @@ class SVGNode(libxml2dom.Node): - "Convenience modifications to nodes specific to libxml2dom.svg." - - def xpath(self, expr, variables=None, namespaces=None): + "An SVG-specific node." - """ - Evaluate the given 'expr' using the optional 'variables' and - 'namespaces'. If not otherwise specified, the "svg" prefix will be bound - to SVG_NAMESPACE as defined in this module. - """ - - namespaces = namespaces or {} - if not namespaces.has_key("svg"): - namespaces["svg"] = SVG_NAMESPACE - return libxml2dom.Node.xpath(self, expr, variables, namespaces) + pass # NOTE: DocumentEvent is from DOM Level 3 Events. # NOTE: EventSystem is a special libxml2dom.events class. @@ -759,14 +752,15 @@ "An SVG-specific document node." - def __init__(self, node, impl): + def __init__(self, node, impl, namespaces=None): """ Initialise the document with the given 'node', implementation 'impl', and global (SVGGlobal) details. """ - libxml2dom._Document.__init__(self, node, impl) + libxml2dom._Document.__init__(self, node, impl, None) + self._update_namespaces([default_ns, namespaces]) self.global_ = self.impl.get_global(self) # parent class SVGElement(SVGNode, EventTarget, TraitAccess, ElementTraversal): # NOTE: SVGNode instead of Element. diff -r 8e57ff2336bf -r 98f6eeafe0d0 libxml2dom/xmpp.py --- a/libxml2dom/xmpp.py Sun Jan 26 21:53:15 2014 +0100 +++ b/libxml2dom/xmpp.py Sun Jan 26 22:55:18 2014 +0100 @@ -10,7 +10,7 @@ See: http://www.xmpp.org/rfcs/rfc3920.html See: http://www.xmpp.org/rfcs/rfc3921.html -Copyright (C) 2007, 2009 Paul Boddie +Copyright (C) 2007, 2009, 2014 Paul Boddie This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free @@ -159,26 +159,23 @@ class XMPPNode(libxml2dom.Node): - "Convenience modifications to nodes specific to libxml2dom.xmpp." - - def xpath(self, expr, variables=None, namespaces=None): + "An XMPP-specific node." - """ - Evaluate the given 'expr' using the optional 'variables' and - 'namespaces'. If not otherwise specified, the prefixes given in the - module global 'default_ns' will be bound as in that dictionary. - """ - - ns = {} - ns.update(default_ns) - ns.update(namespaces or {}) - return libxml2dom.Node.xpath(self, expr, variables, ns) + pass class XMPPDocument(libxml2dom._Document, XMPPNode): "An XMPP document fragment." - pass + def __init__(self, node, impl, namespaces=None): + + """ + Initialise the document with the given 'node', implementation 'impl', + and 'namespaces' details. + """ + + libxml2dom._Document.__init__(self, node, impl, None) + self._update_namespaces([default_ns, namespaces]) class XMPPElement(XMPPNode): pass