Known subclasses: wokkel.disco.DiscoHandler, wokkel.pubsub.PubSubService, wokkel.xmppim.RosterClientProtocol

XMPP subprotocol mixin for handle incoming IQ stanzas.

This matches up the iq with XPath queries to call methods on itself, wrapping the call so that exceptions result in proper error responses, or, when succesful will reply with a response with optional payload.

Derivatives of this class must provide an XmlStream instance in its xmlstream attribute.

The optional payload is taken from the result of the handler and is expected to be a child or a list of childs.

If an exception is raised, or the deferred has its errback called, the exception is checked for being a error.StanzaError. If so, an error response is sent. Any other exception will cause a error response of internal-server-error to be sent.

A typical way to use this mixin, is to set up xpath observers on the xmlstream to call handleRequest, for example in an overridden XMPPHandler.connectionMade. It is likely a good idea to only listen for incoming iq get and/org iq set requests, and not for any iq, to prevent hijacking incoming responses to outgoing iq requests. An example:

>>> QUERY_ROSTER = "/query[@xmlns='jabber:iq:roster']"
>>> class MyHandler(XMPPHandler, IQHandlerMixin):
...    iqHandlers = {"/iq[@type='get']" + QUERY_ROSTER: 'onRosterGet',
...                  "/iq[@type='set']" + QUERY_ROSTER: 'onRosterSet'}
...    def connectionMade(self):
...        self.xmlstream.addObserver(
...          "/iq[@type='get' or @type='set']" + QUERY_ROSTER,
...          self.handleRequest)
...    def onRosterGet(self, iq):
...        pass
...    def onRosterSet(self, iq):
...        pass
Class Variable iqHandlers Mapping from XPath queries (as a string) to the method name that will handle requests that match the query. (type: dict)
Method handleRequest Find a handler and wrap the call for sending a response stanza.
iqHandlers =
Mapping from XPath queries (as a string) to the method name that will handle requests that match the query. (type: dict)
def handleRequest(self, iq): (source)

Find a handler and wrap the call for sending a response stanza.

API Documentation for wokkel, generated by pydoctor at 2018-12-06 14:45:46.