Ignore:
Timestamp:
Jun 10, 2008, 8:12:33 PM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@52
Message:

Clarify use of IQHandlerMixin, fix some doc strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/subprotocols.py

    r8 r22  
    235235    response of C{internal-server-error} to be sent.
    236236
     237    A typical way to use this mixin, is to set up L{xpath} observers on the
     238    C{xmlstream} to call handleRequest, for example in an overridden
     239    L{XMPPHandler.connectionMade}. It is likely a good idea to only listen for
     240    incoming iq get and/org iq set requests, and not for any iq, to prevent
     241    hijacking incoming responses to outgoing iq requests. An example:
     242
     243        >>> QUERY_ROSTER = "/query[@xmlns='jabber:iq:roster']"
     244        >>> class MyHandler(XMPPHandler, IQHandlerMixin):
     245        ...    iqHandlers = {"/iq[@type='get']" + QUERY_ROSTER: 'onRosterGet',
     246        ...                  "/iq[@type='set']" + QUERY_ROSTER: 'onRosterSet'}
     247        ...    def connectionMade(self):
     248        ...        self.xmlstream.addObserver(
     249        ...          "/iq[@type='get' or @type='set']" + QUERY_ROSTER,
     250        ...          self.handleRequest)
     251        ...    def onRosterGet(self, iq):
     252        ...        pass
     253        ...    def onRosterSet(self, iq):
     254        ...        pass
     255
    237256    @cvar iqHandlers: Mapping from XPath queries (as a string) to the method
    238257                      name that will handle requests that match the query.
Note: See TracChangeset for help on using the changeset viewer.