mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Fixed ElementBase.match to respect namespaces.
This commit is contained in:
parent
1eaa9cb28c
commit
a3580dcef9
2 changed files with 15 additions and 4 deletions
|
@ -478,7 +478,8 @@ class ElementBase(object):
|
||||||
tag = components[0]
|
tag = components[0]
|
||||||
attributes = components[1:]
|
attributes = components[1:]
|
||||||
|
|
||||||
if tag not in (self.name, self.plugins, self.plugin_attrib):
|
if tag not in (self.name, "{%s}%s" % (self.namespace, self.name),
|
||||||
|
self.plugins, self.plugin_attrib):
|
||||||
# The requested tag is not in this stanza, so no match.
|
# The requested tag is not in this stanza, so no match.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -499,7 +500,8 @@ class ElementBase(object):
|
||||||
|
|
||||||
# Attempt to continue matching the XPath using the stanza's plugins.
|
# Attempt to continue matching the XPath using the stanza's plugins.
|
||||||
if not matched_substanzas and len(xpath) > 1:
|
if not matched_substanzas and len(xpath) > 1:
|
||||||
next_tag = xpath[1].split('@')[0]
|
# Convert {namespace}tag@attribs to just tag
|
||||||
|
next_tag = xpath[1].split('@')[0].split('}')[-1]
|
||||||
if next_tag in self.plugins:
|
if next_tag in self.plugins:
|
||||||
return self.plugins[next_tag].match(xpath[1:])
|
return self.plugins[next_tag].match(xpath[1:])
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -433,7 +433,7 @@ class TestElementBase(SleekTest):
|
||||||
|
|
||||||
class TestSubStanza(ElementBase):
|
class TestSubStanza(ElementBase):
|
||||||
name = "sub"
|
name = "sub"
|
||||||
namespace = "foo"
|
namespace = "baz"
|
||||||
interfaces = set(('attrib',))
|
interfaces = set(('attrib',))
|
||||||
|
|
||||||
class TestStanza(ElementBase):
|
class TestStanza(ElementBase):
|
||||||
|
@ -444,7 +444,7 @@ class TestElementBase(SleekTest):
|
||||||
|
|
||||||
class TestStanzaPlugin(ElementBase):
|
class TestStanzaPlugin(ElementBase):
|
||||||
name = "plugin"
|
name = "plugin"
|
||||||
namespace = "foo"
|
namespace = "bar"
|
||||||
interfaces = set(('attrib',))
|
interfaces = set(('attrib',))
|
||||||
|
|
||||||
registerStanzaPlugin(TestStanza, TestStanzaPlugin)
|
registerStanzaPlugin(TestStanza, TestStanzaPlugin)
|
||||||
|
@ -453,6 +453,9 @@ class TestElementBase(SleekTest):
|
||||||
self.failUnless(stanza.match("foo"),
|
self.failUnless(stanza.match("foo"),
|
||||||
"Stanza did not match its own tag name.")
|
"Stanza did not match its own tag name.")
|
||||||
|
|
||||||
|
self.failUnless(stanza.match("{foo}foo"),
|
||||||
|
"Stanza did not match its own namespaced name.")
|
||||||
|
|
||||||
stanza['bar'] = 'a'
|
stanza['bar'] = 'a'
|
||||||
self.failUnless(stanza.match("foo@bar=a"),
|
self.failUnless(stanza.match("foo@bar=a"),
|
||||||
"Stanza did not match its own name with attribute value check.")
|
"Stanza did not match its own name with attribute value check.")
|
||||||
|
@ -465,11 +468,17 @@ class TestElementBase(SleekTest):
|
||||||
self.failUnless(stanza.match("foo/plugin@attrib=c"),
|
self.failUnless(stanza.match("foo/plugin@attrib=c"),
|
||||||
"Stanza did not match with plugin and attribute.")
|
"Stanza did not match with plugin and attribute.")
|
||||||
|
|
||||||
|
self.failUnless(stanza.match("foo/{bar}plugin"),
|
||||||
|
"Stanza did not match with namespaced plugin.")
|
||||||
|
|
||||||
substanza = TestSubStanza()
|
substanza = TestSubStanza()
|
||||||
substanza['attrib'] = 'd'
|
substanza['attrib'] = 'd'
|
||||||
stanza.append(substanza)
|
stanza.append(substanza)
|
||||||
self.failUnless(stanza.match("foo/sub@attrib=d"),
|
self.failUnless(stanza.match("foo/sub@attrib=d"),
|
||||||
"Stanza did not match with substanzas and attribute.")
|
"Stanza did not match with substanzas and attribute.")
|
||||||
|
|
||||||
|
self.failUnless(stanza.match("foo/{baz}sub"),
|
||||||
|
"Stanza did not match with namespaced substanza.")
|
||||||
|
|
||||||
|
|
||||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestElementBase)
|
||||||
|
|
Loading…
Reference in a new issue