summaryrefslogtreecommitdiff
path: root/sleekxmpp/xmlstream
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-08-30 14:55:30 -0400
committerLance Stout <lancestout@gmail.com>2010-08-30 14:55:30 -0400
commit9c62bce2060e30e41c3710587f6bd9992625b245 (patch)
tree2439d8ba0f0d8ed24db82f7db8cce762195ae17f /sleekxmpp/xmlstream
parentf5ae27da4f542670560a4ecc0373d7001366b496 (diff)
downloadslixmpp-9c62bce2060e30e41c3710587f6bd9992625b245.tar.gz
slixmpp-9c62bce2060e30e41c3710587f6bd9992625b245.tar.bz2
slixmpp-9c62bce2060e30e41c3710587f6bd9992625b245.tar.xz
slixmpp-9c62bce2060e30e41c3710587f6bd9992625b245.zip
Updated ElementBase.match to respect namespaces with slashes.
Required adding option to _fix_ns to not propagate namespaces to child elements.
Diffstat (limited to 'sleekxmpp/xmlstream')
-rw-r--r--sleekxmpp/xmlstream/stanzabase.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py
index d7c7c7b4..8f4874cd 100644
--- a/sleekxmpp/xmlstream/stanzabase.py
+++ b/sleekxmpp/xmlstream/stanzabase.py
@@ -586,7 +586,8 @@ class ElementBase(object):
string or a list of element names with attribute checks.
"""
if isinstance(xpath, str):
- xpath = xpath.split('/')
+ xpath = self._fix_ns(xpath, split=True, propagate_ns=False)
+
# Extract the tag name and attribute checks for the first XPath node.
components = xpath[0].split('@')
@@ -754,15 +755,20 @@ class ElementBase(object):
"""
return self
- def _fix_ns(self, xpath, split=False):
+ def _fix_ns(self, xpath, split=False, propagate_ns=True):
"""
Apply the stanza's namespace to elements in an XPath expression.
Arguments:
- xpath -- The XPath expression to fix with namespaces.
- 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.
+ xpath -- The XPath expression to fix with namespaces.
+ 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.
+ propagate_ns -- Overrides propagating parent element namespaces
+ to child elements. Useful if you wish to simply
+ split an XPath that has non-specified namespaces,
+ and child and parent namespaces are known not to
+ always match. Defaults to True.
"""
fixed = []
# Split the XPath into a series of blocks, where a block
@@ -774,17 +780,23 @@ class ElementBase(object):
# that do not have namespaces.
namespace = ns_block.split('}')[0]
elements = ns_block.split('}')[1].split('/')
- else:
+ elif use_ns:
# Apply the stanza's namespace to the following
# elements since no namespace was provided.
namespace = self.namespace
elements = ns_block.split('/')
+ else:
+ # We don't want to propagate namespaces.
+ elements = ns_block.split('/')
for element in elements:
if element:
# Skip empty entry artifacts from splitting.
- fixed.append('{%s}%s' % (namespace,
- element))
+ if use_ns:
+ tag = '{%s}%s' % (namespace, element)
+ else:
+ tag = element
+ fixed.append(tag)
if split:
return fixed
return '/'.join(fixed)