Ignore:
Timestamp:
Jan 3, 2008, 10:58:54 AM (14 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@34
Message:

Add unsubscribe method to PubSubClient?.

Author: ralphm
Fixes #4.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r7 r10  
    11# -*- test-case-name: wokkel.test.test_pubsub -*-
    22#
    3 # Copyright (c) 2003-2007 Ralph Meijer
     3# Copyright (c) 2003-2008 Ralph Meijer
    44# See LICENSE for details.
    55
     
    7878
    7979
    80 
    8180class SubscriptionPending(Exception):
    8281    """
     
    146145                self.addChild(payload)
    147146
     147
    148148class PubSubRequest(xmlstream.IQ):
    149149    """
     
    168168
    169169    def send(self, to):
    170         destination = unicode(to)
     170        """
     171        Send out request.
     172
     173        Extends L{xmlstream.IQ.send} by requiring the C{to} parameter to be
     174        a L{JID} instance.
     175
     176        @param to: Entity to send the request to.
     177        @type to: L{JID}
     178        """
     179        destination = to.full()
    171180        return xmlstream.IQ.send(self, destination)
     181
    172182
    173183class CreateNode(PubSubRequest):
     
    178188        if node:
    179189            self.command["node"] = node
     190
    180191
    181192class DeleteNode(PubSubRequest):
     
    185196        self.command["node"] = node
    186197
     198
    187199class Subscribe(PubSubRequest):
    188200    verb = 'subscribe'
     
    193205        self.command["jid"] = subscriber.full()
    194206
     207
     208class Unsubscribe(PubSubRequest):
     209    verb = 'unsubscribe'
     210
     211    def __init__(self, xs, node, subscriber):
     212        PubSubRequest.__init__(self, xs)
     213        self.command["node"] = node
     214        self.command["jid"] = subscriber.full()
     215
     216
    195217class Publish(PubSubRequest):
    196218    verb = 'publish'
     
    208230
    209231        return item
     232
    210233
    211234class PubSubClient(XMPPHandler):
     
    270293        return request.send(service).addCallback(cb)
    271294
     295    def unsubscribe(self, service, nodeIdentifier, subscriber):
     296        request = Unsubscribe(self.xmlstream, nodeIdentifier, subscriber)
     297        return request.send(service)
     298
    272299    def publish(self, service, nodeIdentifier, items=[]):
    273300        request = Publish(self.xmlstream, nodeIdentifier)
     
    276303
    277304        return request.send(service)
     305
    278306
    279307class PubSubService(XMPPHandler, IQHandlerMixin):
Note: See TracChangeset for help on using the changeset viewer.