source: ralphm-patches/pubsub_client_sender.patch @ 3:5868b365661f

Last change on this file since 3:5868b365661f was 3:5868b365661f, checked in by Ralph Meijer <ralphm@…>, 13 years ago

Add patch for supplying a sender JID for pubsub client requests.

File size: 4.3 KB
  • wokkel/pubsub.py

    diff -r 52898d5828ee wokkel/pubsub.py
    a b  
    150150                   C{verb}.
    151151    """
    152152
    153     def __init__(self, xs, verb, namespace=NS_PUBSUB, method='set'):
     153    def __init__(self, xs, verb, namespace=NS_PUBSUB, method='set',
     154                       sender=None):
    154155        xmlstream.IQ.__init__(self, xs, method)
     156        if sender:
     157            self['from'] = sender.full()
    155158        self.addElement((namespace, 'pubsub'))
    156159
    157160        self.command = self.pubsub.addElement(verb)
     
    295298        pass
    296299
    297300
    298     def createNode(self, service, nodeIdentifier=None):
     301    def createNode(self, service, nodeIdentifier=None, sender=None):
    299302        """
    300303        Create a publish subscribe node.
    301304
     
    306309        """
    307310
    308311
    309         request = _PubSubRequest(self.xmlstream, 'create')
     312        request = _PubSubRequest(self.xmlstream, 'create', sender=sender)
    310313        if nodeIdentifier:
    311314            request.command['node'] = nodeIdentifier
    312315
     
    321324        return request.send(service).addCallback(cb)
    322325
    323326
    324     def deleteNode(self, service, nodeIdentifier):
     327    def deleteNode(self, service, nodeIdentifier, sender=None):
    325328        """
    326329        Delete a publish subscribe node.
    327330
     
    330333        @param nodeIdentifier: The identifier of the node.
    331334        @type nodeIdentifier: C{unicode}
    332335        """
    333         request = _PubSubRequest(self.xmlstream, 'delete', NS_PUBSUB_OWNER)
     336        request = _PubSubRequest(self.xmlstream, 'delete', NS_PUBSUB_OWNER,
     337                                 sender=None)
    334338        request.command['node'] = nodeIdentifier
    335339        return request.send(service)
    336340
    337341
    338     def subscribe(self, service, nodeIdentifier, subscriber):
     342    def subscribe(self, service, nodeIdentifier, subscriber, sender=None):
    339343        """
    340344        Subscribe to a publish subscribe node.
    341345
     
    347351                           will get notifications of new published items.
    348352        @type subscriber: L{JID}
    349353        """
    350         request = _PubSubRequest(self.xmlstream, 'subscribe')
     354        request = _PubSubRequest(self.xmlstream, 'subscribe', sender=sender)
    351355        if nodeIdentifier:
    352356            request.command['node'] = nodeIdentifier
    353357        request.command['jid'] = subscriber.full()
     
    368372        return request.send(service).addCallback(cb)
    369373
    370374
    371     def unsubscribe(self, service, nodeIdentifier, subscriber):
     375    def unsubscribe(self, service, nodeIdentifier, subscriber, sender=None):
    372376        """
    373377        Unsubscribe from a publish subscribe node.
    374378
     
    379383        @param subscriber: The entity to unsubscribe from the node.
    380384        @type subscriber: L{JID}
    381385        """
    382         request = _PubSubRequest(self.xmlstream, 'unsubscribe')
     386        request = _PubSubRequest(self.xmlstream, 'unsubscribe', sender=sender)
    383387        if nodeIdentifier:
    384388            request.command['node'] = nodeIdentifier
    385389        request.command['jid'] = subscriber.full()
    386390        return request.send(service)
    387391
    388392
    389     def publish(self, service, nodeIdentifier, items=None):
     393    def publish(self, service, nodeIdentifier, items=None, sender=None):
    390394        """
    391395        Publish to a publish subscribe node.
    392396
     
    397401        @param items: Optional list of L{Item}s to publish.
    398402        @type items: C{list}
    399403        """
    400         request = _PubSubRequest(self.xmlstream, 'publish')
     404        request = _PubSubRequest(self.xmlstream, 'publish', sender=sender)
    401405        request.command['node'] = nodeIdentifier
    402406        if items:
    403407            for item in items:
     
    406410        return request.send(service)
    407411
    408412
    409     def items(self, service, nodeIdentifier, maxItems=None):
     413    def items(self, service, nodeIdentifier, maxItems=None, sender=None):
    410414        """
    411415        Retrieve previously published items from a publish subscribe node.
    412416
     
    417421        @param maxItems: Optional limit on the number of retrieved items.
    418422        @type maxItems: C{int}
    419423        """
    420         request = _PubSubRequest(self.xmlstream, 'items', method='get')
     424        request = _PubSubRequest(self.xmlstream, 'items', method='get',
     425                                 sender=sender)
    421426        if nodeIdentifier:
    422427            request.command['node'] = nodeIdentifier
    423428        if maxItems:
Note: See TracBrowser for help on using the repository browser.