summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-08-26 18:18:00 -0400
committerLance Stout <lancestout@gmail.com>2010-08-26 18:18:00 -0400
commit00d7952001ce82e4c89699970dee38f29f4c7419 (patch)
tree21439d1f7d59954d42cf43617972f196855dd82d /sleekxmpp
parent56766508b3550f6dbf9ea89516c6423842011494 (diff)
downloadslixmpp-00d7952001ce82e4c89699970dee38f29f4c7419.tar.gz
slixmpp-00d7952001ce82e4c89699970dee38f29f4c7419.tar.bz2
slixmpp-00d7952001ce82e4c89699970dee38f29f4c7419.tar.xz
slixmpp-00d7952001ce82e4c89699970dee38f29f4c7419.zip
Fixed ElementBase._fix_ns and related methods to respect namespaces which contain forward slashes.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py39
1 files changed, 25 insertions, 14 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index 854aceba..8814df78 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -507,7 +507,7 @@ class ElementBase(object):
keep -- Indicates if the element should be kept if its text is
removed. Defaults to False.
"""
- name = self._fix_ns(name)
+ path = self._fix_ns(name, split=True)
element = self.xml.find(name)
if not text and not keep:
@@ -520,7 +520,7 @@ class ElementBase(object):
# of generating new elements.
last_xml = self.xml
walked = []
- for ename in name.split('/'):
+ for ename in path:
walked.append(ename)
element = self.xml.find("/".join(walked))
if element is None:
@@ -545,8 +545,7 @@ class ElementBase(object):
all -- If True, remove all empty elements in the path to the
deleted element. Defaults to False.
"""
- name = self._fix_ns(name)
- path = name.split("/")
+ path = self._fix_ns(name, split=True)
original_target = path[-1]
for level, _ in enumerate(path):
@@ -755,21 +754,33 @@ class ElementBase(object):
"""
return self
- def _fix_ns(self, xpath):
+ def _fix_ns(self, xpath, split=False):
"""
Apply the stanza's namespace to elements in an XPath expression.
Arguments:
xpath -- The XPath expression to fix with namespaces.
- """
-
- def fix_ns(name):
- """Apply namespace to an element if needed."""
- if "}" in name:
- return name
- return "{%s}%s" % (self.namespace, name)
-
- return "/".join(map(fix_ns, xpath.split("/")))
+ split -- Indicates if the fixed XPath should be left as a
+ list of element names with namespaces. Defaults to
+ False, which returns a flat string path.
+ """
+ fixed = []
+ ns_blocks = xpath.split('{')
+ for ns_block in ns_blocks:
+ if '}' in ns_block:
+ namespace = ns_block.split('}')[0]
+ elements = ns_block.split('}')[1].split('/')
+ else:
+ namespace = self.namespace
+ elements = ns_block.split('/')
+
+ for element in elements:
+ if element:
+ fixed.append('{%s}%s' % (namespace,
+ element))
+ if split:
+ return fixed
+ return '/'.join(fixed)
def __eq__(self, other):
"""