stanzapath.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. """
  3. sleekxmpp.xmlstream.matcher.stanzapath
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. Part of SleekXMPP: The Sleek XMPP Library
  6. :copyright: (c) 2011 Nathanael C. Fritz
  7. :license: MIT, see LICENSE for more details
  8. """
  9. from sleekxmpp.xmlstream.matcher.base import MatcherBase
  10. from sleekxmpp.xmlstream.stanzabase import fix_ns
  11. class StanzaPath(MatcherBase):
  12. """
  13. The StanzaPath matcher selects stanzas that match a given "stanza path",
  14. which is similar to a normal XPath except that it uses the interfaces and
  15. plugins of the stanza instead of the actual, underlying XML.
  16. :param criteria: Object to compare some aspect of a stanza against.
  17. """
  18. def __init__(self, criteria):
  19. self._criteria = fix_ns(criteria, split=True,
  20. propagate_ns=False,
  21. default_ns='jabber:client')
  22. self._raw_criteria = criteria
  23. def match(self, stanza):
  24. """
  25. Compare a stanza against a "stanza path". A stanza path is similar to
  26. an XPath expression, but uses the stanza's interfaces and plugins
  27. instead of the underlying XML. See the documentation for the stanza
  28. :meth:`~sleekxmpp.xmlstream.stanzabase.ElementBase.match()` method
  29. for more information.
  30. :param stanza: The :class:`~sleekxmpp.xmlstream.stanzabase.ElementBase`
  31. stanza to compare against.
  32. """
  33. return stanza.match(self._criteria) or stanza.match(self._raw_criteria)