Stanza Matchers

1.0 Documentation

«  Stanza Handlers   ::   Contents   ::   XML Stream  »

Stanza Matchers

The Basic Matcher

class sleekxmpp.xmlstream.matcher.base.MatcherBase(criteria)[source]

Base class for stanza matchers. Stanza matchers are used to pick stanzas out of the XML stream and pass them to the appropriate stream handlers.

Parameters:criteria – Object to compare some aspect of a stanza against.
match(xml)[source]

Check if a stanza matches the stored criteria.

Meant to be overridden.

ID Matching

class sleekxmpp.xmlstream.matcher.id.MatcherId(criteria)[source]

The ID matcher selects stanzas that have the same stanza ‘id’ interface value as the desired ID.

match(xml)[source]

Compare the given stanza’s 'id' attribute to the stored id value.

Parameters:xml – The ElementBase stanza to compare against.

Stanza Path Matching

class sleekxmpp.xmlstream.matcher.stanzapath.StanzaPath(criteria)[source]

The StanzaPath matcher selects stanzas that match a given “stanza path”, which is similar to a normal XPath except that it uses the interfaces and plugins of the stanza instead of the actual, underlying XML.

Parameters:criteria – Object to compare some aspect of a stanza against.
match(stanza)[source]

Compare a stanza against a “stanza path”. A stanza path is similar to an XPath expression, but uses the stanza’s interfaces and plugins instead of the underlying XML. See the documentation for the stanza match() method for more information.

Parameters:stanza – The ElementBase stanza to compare against.

XPath

class sleekxmpp.xmlstream.matcher.xpath.MatchXPath(criteria)[source]

The XPath matcher selects stanzas whose XML contents matches a given XPath expression.

Warning

Using this matcher may not produce expected behavior when using attribute selectors. For Python 2.6 and 3.1, the ElementTree find() method does not support the use of attribute selectors. If you need to support Python 2.6 or 3.1, it might be more useful to use a StanzaPath matcher.

If the value of IGNORE_NS is set to True, then XPath expressions will be matched without using namespaces.

match(xml)[source]

Compare a stanza’s XML contents to an XPath expression.

If the value of IGNORE_NS is set to True, then XPath expressions will be matched without using namespaces.

Warning

In Python 2.6 and 3.1 the ElementTree find() method does not support attribute selectors in the XPath expression.

Parameters:xml – The ElementBase stanza to compare against.

XMLMask

class sleekxmpp.xmlstream.matcher.xmlmask.MatchXMLMask(criteria)[source]

The XMLMask matcher selects stanzas whose XML matches a given XML pattern, or mask. For example, message stanzas with body elements could be matched using the mask:

<message xmlns="jabber:client"><body /></message>

Use of XMLMask is discouraged, and MatchXPath or StanzaPath should be used instead.

The use of namespaces in the mask comparison is controlled by IGNORE_NS. Setting IGNORE_NS to True will disable namespace based matching for ALL XMLMask matchers.

Parameters:criteria – Either an Element XML object or XML string to use as a mask.
match(xml)[source]

Compare a stanza object or XML object against the stored XML mask.

Overrides MatcherBase.match.

Parameters:xml – The stanza object or XML object to compare against.
setDefaultNS(ns)[source]

Set the default namespace to use during comparisons.

Parameters:ns – The new namespace to use as the default.

«  Stanza Handlers   ::   Contents   ::   XML Stream  »

From &yet