# HG changeset patch # User paulb # Date 1191105631 0 # Node ID 6d2cdee9b6615e11239b6074d888a66ae8df30fe # Parent cd8ccc2f9e32a27e994e6549b63f289db5b76111 [project @ 2007-09-29 22:40:31 by paulb] Exposed XML_NAMESPACE in libxml2dom. Exposed the default namespaces for XPath in both libxml2dom and libxml2dom.xmpp. diff -r cd8ccc2f9e32 -r 6d2cdee9b661 libxml2dom/__init__.py --- a/libxml2dom/__init__.py Sat Sep 29 22:34:24 2007 +0000 +++ b/libxml2dom/__init__.py Sat Sep 29 22:40:31 2007 +0000 @@ -31,6 +31,16 @@ import urllib # for parseURI in HTML mode import xml.dom # for getElementById +# Standard namespaces. + +XML_NAMESPACE = xml.dom.XML_NAMESPACE + +# Default namespace bindings for XPath. + +default_ns = { + "xml" : XML_NAMESPACE + } + class Implementation(object): "Contains an abstraction over the DOM implementation." @@ -478,7 +488,10 @@ # NOTE: To be finished. def xpath(self, expr, variables=None, namespaces=None): - result = Node_xpath(self._node, expr, variables, namespaces) + ns = {} + ns.update(default_ns) + ns.update(namespaces or {}) + result = Node_xpath(self._node, expr, variables, ns) if isinstance(result, str): return to_unicode(result) elif hasattr(result, "__len__"): diff -r cd8ccc2f9e32 -r 6d2cdee9b661 libxml2dom/xmpp.py --- a/libxml2dom/xmpp.py Sat Sep 29 22:34:24 2007 +0000 +++ b/libxml2dom/xmpp.py Sat Sep 29 22:40:31 2007 +0000 @@ -54,6 +54,8 @@ import select import base64 # for auth elements +# XMPP-related namespaces. + XMPP_BIND_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-bind" XMPP_CLIENT_NAMESPACE = "jabber:client" XEP_0022_EVENT_NAMESPACE = "jabber:x:event" @@ -62,6 +64,18 @@ XMPP_SESSION_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-session" XMPP_STREAMS_NAMESPACE = "http://etherx.jabber.org/streams" +# Default namespace bindings for XPath. + +default_ns = { + "bind" : XMPP_BIND_NAMESPACE, + "client" : XMPP_CLIENT_NAMESPACE, + "event": XEP_0022_EVENT_NAMESPACE, + "register" : XMPP_REGISTER_NAMESPACE, + "sasl" : XMPP_SASL_NAMESPACE, + "session" : XMPP_SESSION_NAMESPACE, + "stream" : XMPP_STREAMS_NAMESPACE + } + class XMPPImplementation(libxml2dom.Implementation): "Contains an XMPP-specific implementation." @@ -141,25 +155,18 @@ class XMPPNode(libxml2dom.Node): - "Convenience modifications to nodes specific to libxml2dom.svg." + "Convenience modifications to nodes specific to libxml2dom.xmpp." def xpath(self, expr, variables=None, namespaces=None): """ Evaluate the given 'expr' using the optional 'variables' and - 'namespaces'. If not otherwise specified, the "stream" prefix will be - bound to XMPP_STREAMS_NAMESPACE as defined in this module. + 'namespaces'. If not otherwise specified, the prefixes given in the + module global 'default_ns' will be bound as in that dictionary. """ - ns = { - "bind" : XMPP_BIND_NAMESPACE, - "client" : XMPP_CLIENT_NAMESPACE, - "event": XEP_0022_EVENT_NAMESPACE, - "register" : XMPP_REGISTER_NAMESPACE, - "sasl" : XMPP_SASL_NAMESPACE, - "session" : XMPP_SESSION_NAMESPACE, - "stream" : XMPP_STREAMS_NAMESPACE - } + ns = {} + ns.update(default_ns) ns.update(namespaces or {}) return libxml2dom.Node.xpath(self, expr, variables, ns) @@ -169,6 +176,9 @@ pass +class XMPPElement(XMPPNode): + pass + class XMPPAuthElement(XMPPNode): "An XMPP auth element." @@ -383,9 +393,6 @@ class XMPPStreamElement(XMPPNode): pass -class XMPPElement(XMPPNode): - pass - # Classes providing XMPP session support. class SessionTerminated(Exception):