diff options
author | Lance Stout <lancestout@gmail.com> | 2010-08-25 14:54:09 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-08-25 14:54:09 -0400 |
commit | a3580dcef9129975170d8757f835e02caffca82c (patch) | |
tree | 4fa2d96a0f54767011a2204ac9041640782b261d | |
parent | 1eaa9cb28c426ad35ab8e398ffa77cd9ed7bae30 (diff) | |
download | slixmpp-a3580dcef9129975170d8757f835e02caffca82c.tar.gz slixmpp-a3580dcef9129975170d8757f835e02caffca82c.tar.bz2 slixmpp-a3580dcef9129975170d8757f835e02caffca82c.tar.xz slixmpp-a3580dcef9129975170d8757f835e02caffca82c.zip |
Fixed ElementBase.match to respect namespaces.
-rw-r--r-- | sleekxmpp/xmlstream/stanzabase.py | 6 | ||||
-rw-r--r-- | tests/test_elementbase.py | 13 |
2 files changed, 15 insertions, 4 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index af74919e..d38eb295 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -478,7 +478,8 @@ class ElementBase(object): tag = components[0] 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. return False @@ -499,7 +500,8 @@ class ElementBase(object): # Attempt to continue matching the XPath using the stanza's plugins. 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: return self.plugins[next_tag].match(xpath[1:]) else: diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index d749f08e..0eddd30b 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -433,7 +433,7 @@ class TestElementBase(SleekTest): class TestSubStanza(ElementBase): name = "sub" - namespace = "foo" + namespace = "baz" interfaces = set(('attrib',)) class TestStanza(ElementBase): @@ -444,7 +444,7 @@ class TestElementBase(SleekTest): class TestStanzaPlugin(ElementBase): name = "plugin" - namespace = "foo" + namespace = "bar" interfaces = set(('attrib',)) registerStanzaPlugin(TestStanza, TestStanzaPlugin) @@ -453,6 +453,9 @@ class TestElementBase(SleekTest): self.failUnless(stanza.match("foo"), "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' self.failUnless(stanza.match("foo@bar=a"), "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"), "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['attrib'] = 'd' stanza.append(substanza) self.failUnless(stanza.match("foo/sub@attrib=d"), "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) |