Ignore:
Timestamp:
Jul 7, 2008, 4:39:05 PM (13 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@57
Message:

Implement SHIM support.

Author: ralphm.
Fixes #14.

This changes the signature of PubSubClient's itemsReceived and friends, to
have an object to represent the event, for easier addition of new information
from the event's message stanza, like these SHIM headers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r25 r27  
    1717from twisted.words.xish import domish
    1818
    19 from wokkel import disco, data_form
     19from wokkel import disco, data_form, shim
    2020from wokkel.subprotocols import IQHandlerMixin, XMPPHandler
    2121from wokkel.iwokkel import IPubSubClient, IPubSubService
     
    190190
    191191
     192class PubSubEvent(object):
     193    """
     194    A publish subscribe event.
     195
     196    @param sender: The entity from which the notification was received.
     197    @type sender: L{jid.JID}
     198    @param recipient: The entity to which the notification was sent.
     199    @type recipient: L{wokkel.pubsub.ItemsEvent}
     200    @param nodeIdentifier: Identifier of the node the event pertains to.
     201    @type nodeIdentifier: C{unicode}
     202    @param headers: SHIM headers, see L{wokkel.shim.extractHeaders}.
     203    @type headers: L{dict}
     204    """
     205
     206    def __init__(self, sender, recipient, nodeIdentifier, headers):
     207        self.sender = sender
     208        self.recipient = recipient
     209        self.nodeIdentifier = nodeIdentifier
     210        self.headers = headers
     211
     212
     213
     214class ItemsEvent(PubSubEvent):
     215    """
     216    A publish-subscribe event that signifies new, updated and retracted items.
     217
     218    @param items: List of received items as domish elements.
     219    @type items: C{list} of L{domish.Element}
     220    """
     221
     222    def __init__(self, sender, recipient, nodeIdentifier, items, headers):
     223        PubSubEvent.__init__(self, sender, recipient, nodeIdentifier, headers)
     224        self.items = items
     225
     226
     227
     228class DeleteEvent(PubSubEvent):
     229    """
     230    A publish-subscribe event that signifies the deletion of a node.
     231    """
     232
     233
     234
     235class PurgeEvent(PubSubEvent):
     236    """
     237    A publish-subscribe event that signifies the purging of a node.
     238    """
     239
     240
     241
    192242class PubSubClient(XMPPHandler):
    193243    """
     
    204254    def _onEvent(self, message):
    205255        try:
    206             service = jid.JID(message["from"])
     256            sender = jid.JID(message["from"])
    207257            recipient = jid.JID(message["to"])
    208258        except KeyError:
     
    220270
    221271        if eventHandler:
    222             eventHandler(service, recipient, actionElement)
     272            headers = shim.extractHeaders(message)
     273            eventHandler(sender, recipient, actionElement, headers)
    223274            message.handled = True
    224275
    225     def _onEvent_items(self, service, recipient, action):
     276    def _onEvent_items(self, sender, recipient, action, headers):
    226277        nodeIdentifier = action["node"]
    227278
     
    229280                         if element.name in ('item', 'retract')]
    230281
    231         self.itemsReceived(recipient, service, nodeIdentifier, items)
    232 
    233     def _onEvent_delete(self, service, recipient, action):
     282        event = ItemsEvent(sender, recipient, nodeIdentifier, items, headers)
     283        self.itemsReceived(event)
     284
     285    def _onEvent_delete(self, sender, recipient, action, headers):
    234286        nodeIdentifier = action["node"]
    235         self.deleteReceived(recipient, service, nodeIdentifier)
    236 
    237     def _onEvent_purge(self, service, recipient, action):
     287        event = DeleteEvent(sender, recipient, nodeIdentifier, headers)
     288        self.deleteReceived(event)
     289
     290    def _onEvent_purge(self, sender, recipient, action, headers):
    238291        nodeIdentifier = action["node"]
    239         self.purgeReceived(recipient, service, nodeIdentifier)
    240 
    241     def itemsReceived(self, recipient, service, nodeIdentifier, items):
     292        event = PurgeEvent(sender, recipient, nodeIdentifier, headers)
     293        self.purgeReceived(event)
     294
     295    def itemsReceived(self, event):
    242296        pass
    243297
    244     def deleteReceived(self, recipient, service, nodeIdentifier):
     298    def deleteReceived(self, event):
    245299        pass
    246300
    247     def purgeReceived(self, recipient, service, nodeIdentifier):
     301    def purgeReceived(self, event):
    248302        pass
    249303
Note: See TracChangeset for help on using the changeset viewer.