diff options
author | Lance Stout <lancestout@gmail.com> | 2010-08-30 17:12:10 -0400 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2010-08-30 17:12:10 -0400 |
commit | 3749c1b88c4774b85fcee1e26e8bce8dbeef23c7 (patch) | |
tree | 8a5e889ce11102ca9466bf2375c69a04914f6b9f | |
parent | 998741b87e7babc6e0af9bcf79f10f4422ba96f1 (diff) | |
download | slixmpp-3749c1b88c4774b85fcee1e26e8bce8dbeef23c7.tar.gz slixmpp-3749c1b88c4774b85fcee1e26e8bce8dbeef23c7.tar.bz2 slixmpp-3749c1b88c4774b85fcee1e26e8bce8dbeef23c7.tar.xz slixmpp-3749c1b88c4774b85fcee1e26e8bce8dbeef23c7.zip |
Fixed ElementBase.match to match using sub_interface elements.
-rw-r--r-- | sleekxmpp/xmlstream/stanzabase.py | 6 | ||||
-rw-r--r-- | tests/test_elementbase.py | 20 |
2 files changed, 25 insertions, 1 deletions
diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 7eb3f978..86b528d1 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -614,6 +614,12 @@ class ElementBase(object): if self[name] != value: return False + # Check sub interfaces. + if len(xpath) > 1: + next_tag = xpath[1] + if next_tag in self.sub_interfaces and self[next_tag]: + return True + # Attempt to continue matching the XPath using the stanza's plugins. if not matched_substanzas and len(xpath) > 1: # Convert {namespace}tag@attribs to just tag diff --git a/tests/test_elementbase.py b/tests/test_elementbase.py index 8898b3fc..dfd37b53 100644 --- a/tests/test_elementbase.py +++ b/tests/test_elementbase.py @@ -454,9 +454,16 @@ class TestElementBase(SleekTest): class TestStanza(ElementBase): name = "foo" namespace = "foo" - interfaces = set(('bar','baz')) + interfaces = set(('bar','baz', 'qux')) + sub_interfaces = set(('qux',)) subitem = (TestSubStanza,) + def setQux(self, value): + self._setSubText('qux', text=value) + + def getQux(self): + return self._getSubText('qux') + class TestStanzaPlugin(ElementBase): name = "plugin" namespace = "http://test/slash/bar" @@ -479,6 +486,17 @@ class TestElementBase(SleekTest): self.failUnless(stanza.match("foo@bar=a@baz=b"), "Stanza did not match its own name with multiple attributes.") + stanza['qux'] = 'c' + self.failUnless(stanza.match("foo/qux"), + "Stanza did not match with subelements.") + + stanza['qux'] = '' + self.failUnless(stanza.match("foo/qux") == False, + "Stanza matched missing subinterface element.") + + self.failUnless(stanza.match("foo/bar") == False, + "Stanza matched nonexistent element.") + stanza['plugin']['attrib'] = 'c' self.failUnless(stanza.match("foo/plugin@attrib=c"), "Stanza did not match with plugin and attribute.") |