1.1 --- a/libxml2dom/__init__.py Sat Sep 29 22:34:24 2007 +0000
1.2 +++ b/libxml2dom/__init__.py Sat Sep 29 22:40:31 2007 +0000
1.3 @@ -31,6 +31,16 @@
1.4 import urllib # for parseURI in HTML mode
1.5 import xml.dom # for getElementById
1.6
1.7 +# Standard namespaces.
1.8 +
1.9 +XML_NAMESPACE = xml.dom.XML_NAMESPACE
1.10 +
1.11 +# Default namespace bindings for XPath.
1.12 +
1.13 +default_ns = {
1.14 + "xml" : XML_NAMESPACE
1.15 + }
1.16 +
1.17 class Implementation(object):
1.18
1.19 "Contains an abstraction over the DOM implementation."
1.20 @@ -478,7 +488,10 @@
1.21 # NOTE: To be finished.
1.22
1.23 def xpath(self, expr, variables=None, namespaces=None):
1.24 - result = Node_xpath(self._node, expr, variables, namespaces)
1.25 + ns = {}
1.26 + ns.update(default_ns)
1.27 + ns.update(namespaces or {})
1.28 + result = Node_xpath(self._node, expr, variables, ns)
1.29 if isinstance(result, str):
1.30 return to_unicode(result)
1.31 elif hasattr(result, "__len__"):
2.1 --- a/libxml2dom/xmpp.py Sat Sep 29 22:34:24 2007 +0000
2.2 +++ b/libxml2dom/xmpp.py Sat Sep 29 22:40:31 2007 +0000
2.3 @@ -54,6 +54,8 @@
2.4 import select
2.5 import base64 # for auth elements
2.6
2.7 +# XMPP-related namespaces.
2.8 +
2.9 XMPP_BIND_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-bind"
2.10 XMPP_CLIENT_NAMESPACE = "jabber:client"
2.11 XEP_0022_EVENT_NAMESPACE = "jabber:x:event"
2.12 @@ -62,6 +64,18 @@
2.13 XMPP_SESSION_NAMESPACE = "urn:ietf:params:xml:ns:xmpp-session"
2.14 XMPP_STREAMS_NAMESPACE = "http://etherx.jabber.org/streams"
2.15
2.16 +# Default namespace bindings for XPath.
2.17 +
2.18 +default_ns = {
2.19 + "bind" : XMPP_BIND_NAMESPACE,
2.20 + "client" : XMPP_CLIENT_NAMESPACE,
2.21 + "event": XEP_0022_EVENT_NAMESPACE,
2.22 + "register" : XMPP_REGISTER_NAMESPACE,
2.23 + "sasl" : XMPP_SASL_NAMESPACE,
2.24 + "session" : XMPP_SESSION_NAMESPACE,
2.25 + "stream" : XMPP_STREAMS_NAMESPACE
2.26 + }
2.27 +
2.28 class XMPPImplementation(libxml2dom.Implementation):
2.29
2.30 "Contains an XMPP-specific implementation."
2.31 @@ -141,25 +155,18 @@
2.32
2.33 class XMPPNode(libxml2dom.Node):
2.34
2.35 - "Convenience modifications to nodes specific to libxml2dom.svg."
2.36 + "Convenience modifications to nodes specific to libxml2dom.xmpp."
2.37
2.38 def xpath(self, expr, variables=None, namespaces=None):
2.39
2.40 """
2.41 Evaluate the given 'expr' using the optional 'variables' and
2.42 - 'namespaces'. If not otherwise specified, the "stream" prefix will be
2.43 - bound to XMPP_STREAMS_NAMESPACE as defined in this module.
2.44 + 'namespaces'. If not otherwise specified, the prefixes given in the
2.45 + module global 'default_ns' will be bound as in that dictionary.
2.46 """
2.47
2.48 - ns = {
2.49 - "bind" : XMPP_BIND_NAMESPACE,
2.50 - "client" : XMPP_CLIENT_NAMESPACE,
2.51 - "event": XEP_0022_EVENT_NAMESPACE,
2.52 - "register" : XMPP_REGISTER_NAMESPACE,
2.53 - "sasl" : XMPP_SASL_NAMESPACE,
2.54 - "session" : XMPP_SESSION_NAMESPACE,
2.55 - "stream" : XMPP_STREAMS_NAMESPACE
2.56 - }
2.57 + ns = {}
2.58 + ns.update(default_ns)
2.59 ns.update(namespaces or {})
2.60 return libxml2dom.Node.xpath(self, expr, variables, ns)
2.61
2.62 @@ -169,6 +176,9 @@
2.63
2.64 pass
2.65
2.66 +class XMPPElement(XMPPNode):
2.67 + pass
2.68 +
2.69 class XMPPAuthElement(XMPPNode):
2.70
2.71 "An XMPP auth element."
2.72 @@ -383,9 +393,6 @@
2.73 class XMPPStreamElement(XMPPNode):
2.74 pass
2.75
2.76 -class XMPPElement(XMPPNode):
2.77 - pass
2.78 -
2.79 # Classes providing XMPP session support.
2.80
2.81 class SessionTerminated(Exception):