Ignore:
Timestamp:
Oct 4, 2007, 9:47:22 AM (15 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Convert:
svn:b33ecbfc-034c-dc11-8662-000475d9059e/trunk@13
Message:

Support services on a JID.

Author: ralphm
Fixes #2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r2 r6  
    222222    def _onItems(self, message):
    223223        try:
    224             notifier = jid.JID(message["from"])
    225             node = message.event.items["node"]
     224            service = jid.JID(message["from"])
     225            recipient = jid.JID(message["to"])
     226            nodeIdentifier = message.event.items["node"]
    226227        except KeyError:
    227228            return
     
    230231                         if element.name == 'item']
    231232
    232         self.itemsReceived(notifier, node, items)
    233 
    234     def itemsReceived(self, notifier, node, items):
     233        self.itemsReceived(recipient, service, nodeIdentifier, items)
     234
     235    def itemsReceived(self, recipient, service, nodeIdentifier, items):
    235236        pass
    236237
    237     def createNode(self, service, node=None):
    238         request = CreateNode(self.xmlstream, node)
     238    def createNode(self, service, nodeIdentifier=None):
     239        request = CreateNode(self.xmlstream, nodeIdentifier)
    239240
    240241        def cb(iq):
     
    243244            except AttributeError:
    244245                # the suggested node identifier was accepted
    245                 new_node = node
     246                new_node = nodeIdentifier
    246247            return new_node
    247248
    248249        return request.send(service).addCallback(cb)
    249250
    250     def deleteNode(self, service, node):
    251         return DeleteNode(self.xmlstream, node).send(service)
    252 
    253     def subscribe(self, service, node, subscriber):
    254         request = Subscribe(self.xmlstream, node, subscriber)
     251    def deleteNode(self, service, nodeIdentifier):
     252        return DeleteNode(self.xmlstream, nodeIdentifier).send(service)
     253
     254    def subscribe(self, service, nodeIdentifier, subscriber):
     255        request = Subscribe(self.xmlstream, nodeIdentifier, subscriber)
    255256
    256257        def cb(iq):
     
    269270        return request.send(service).addCallback(cb)
    270271
    271     def publish(self, service, node, items=[]):
    272         request = Publish(self.xmlstream, node)
     272    def publish(self, service, nodeIdentifier, items=[]):
     273        request = Publish(self.xmlstream, nodeIdentifier)
    273274        for item in items:
    274275            request.command.addChild(item)
     
    343344        self.xmlstream.addObserver(PUBSUB_OWNER_SET, self.handleRequest)
    344345
    345     def getDiscoInfo(self, target, requestor, nodeIdentifier):
     346    def getDiscoInfo(self, requestor, target, nodeIdentifier):
    346347        info = []
    347348
     
    379380            return d
    380381
    381     def getDiscoItems(self, target, requestor, nodeIdentifier):
     382    def getDiscoItems(self, requestor, target, nodeIdentifier):
    382383        if nodeIdentifier or self.hideNodes:
    383384            return defer.succeed([])
     
    390391    def _onPublish(self, iq):
    391392        requestor = jid.internJID(iq["from"]).userhostJID()
     393        service = jid.internJID(iq["to"])
    392394
    393395        try:
     
    401403                items.append(element)
    402404
    403         return self.publish(requestor, nodeIdentifier, items)
     405        return self.publish(requestor, service, nodeIdentifier, items)
    404406
    405407    def _onSubscribe(self, iq):
    406408        requestor = jid.internJID(iq["from"]).userhostJID()
     409        service = jid.internJID(iq["to"])
    407410
    408411        try:
     
    421424            return response
    422425
    423         d = self.subscribe(requestor, nodeIdentifier, subscriber)
     426        d = self.subscribe(requestor, service, nodeIdentifier, subscriber)
    424427        d.addCallback(toResponse)
    425428        return d
     
    427430    def _onUnsubscribe(self, iq):
    428431        requestor = jid.internJID(iq["from"]).userhostJID()
     432        service = jid.internJID(iq["to"])
    429433
    430434        try:
     
    434438            raise BadRequest
    435439
    436         return self.unsubscribe(requestor, nodeIdentifier, subscriber)
     440        return self.unsubscribe(requestor, service, nodeIdentifier, subscriber)
    437441
    438442    def _onOptionsGet(self, iq):
     
    444448    def _onSubscriptions(self, iq):
    445449        requestor = jid.internJID(iq["from"]).userhostJID()
     450        service = jid.internJID(iq["to"])
    446451
    447452        def toResponse(result):
     
    455460            return response
    456461
    457         d = self.subscriptions(requestor)
     462        d = self.subscriptions(requestor, service)
    458463        d.addCallback(toResponse)
    459464        return d
     
    461466    def _onAffiliations(self, iq):
    462467        requestor = jid.internJID(iq["from"]).userhostJID()
     468        service = jid.internJID(iq["to"])
    463469
    464470        def toResponse(result):
     
    473479            return response
    474480
    475         d = self.affiliations(requestor)
     481        d = self.affiliations(requestor, service)
    476482        d.addCallback(toResponse)
    477483        return d
     
    479485    def _onCreate(self, iq):
    480486        requestor = jid.internJID(iq["from"]).userhostJID()
     487        service = jid.internJID(iq["to"])
    481488        nodeIdentifier = iq.pubsub.create.getAttribute("node")
    482489
     
    490497                return None
    491498
    492         d = self.create(requestor, nodeIdentifier)
     499        d = self.create(requestor, service, nodeIdentifier)
    493500        d.addCallback(toResponse)
    494501        return d
     
    504511    def _onDefault(self, iq):
    505512        requestor = jid.internJID(iq["from"]).userhostJID()
     513        service = jid.internJID(iq["to"])
    506514
    507515        def toResponse(options):
     
    511519            return response
    512520
    513         d = self.getDefaultConfiguration(requestor)
     521        d = self.getDefaultConfiguration(requestor, service)
    514522        d.addCallback(toResponse)
    515523        return d
     
    517525    def _onConfigureGet(self, iq):
    518526        requestor = jid.internJID(iq["from"]).userhostJID()
     527        service = jid.internJID(iq["to"])
    519528        nodeIdentifier = iq.pubsub.configure.getAttribute("node")
    520529
     
    529538            return response
    530539
    531         d = self.getConfiguration(requestor, nodeIdentifier)
     540        d = self.getConfiguration(requestor, service, nodeIdentifier)
    532541        d.addCallback(toResponse)
    533542        return d
     
    535544    def _onConfigureSet(self, iq):
    536545        requestor = jid.internJID(iq["from"]).userhostJID()
     546        service = jid.internJID(iq["to"])
    537547        nodeIdentifier = iq.pubsub.configure["node"]
    538548
     
    566576            if options["FORM_TYPE"] == NS_PUBSUB + "#node_config":
    567577                del options["FORM_TYPE"]
    568                 return self.setConfiguration(requestor, nodeIdentifier,
    569                                              options)
     578                return self.setConfiguration(requestor, service,
     579                                             nodeIdentifier, options)
    570580
    571581        raise BadRequest
     
    573583    def _onItems(self, iq):
    574584        requestor = jid.internJID(iq["from"]).userhostJID()
     585        service = jid.internJID(iq["to"])
    575586
    576587        try:
     
    605616            return response
    606617
    607         d = self.items(requestor, nodeIdentifier, maxItems, itemIdentifiers)
     618        d = self.items(requestor, service, nodeIdentifier, maxItems,
     619                       itemIdentifiers)
    608620        d.addCallback(toResponse)
    609621        return d
     
    611623    def _onRetract(self, iq):
    612624        requestor = jid.internJID(iq["from"]).userhostJID()
     625        service = jid.internJID(iq["to"])
    613626
    614627        try:
     
    625638                    raise BadRequest
    626639
    627         return self.retract(requestor, nodeIdentifier, itemIdentifiers)
     640        return self.retract(requestor, service, nodeIdentifier,
     641                            itemIdentifiers)
    628642
    629643    def _onPurge(self, iq):
    630644        requestor = jid.internJID(iq["from"]).userhostJID()
     645        service = jid.internJID(iq["to"])
    631646
    632647        try:
     
    635650            raise BadRequest
    636651
    637         return self.purge(requestor, nodeIdentifier)
     652        return self.purge(requestor, service, nodeIdentifier)
    638653
    639654    def _onDelete(self, iq):
    640655        requestor = jid.internJID(iq["from"]).userhostJID()
     656        service = jid.internJID(iq["to"])
    641657
    642658        try:
     
    645661            raise BadRequest
    646662
    647         return self.delete(requestor, nodeIdentifier)
     663        return self.delete(requestor, service, nodeIdentifier)
    648664
    649665    def _onAffiliationsGet(self, iq):
     
    661677    # public methods
    662678
    663     def notifyPublish(self, entity, nodeIdentifier, notifications):
     679    def notifyPublish(self, service, nodeIdentifier, notifications):
    664680
    665681        print notifications
    666682        for recipient, items in notifications:
    667683            message = domish.Element((None, "message"))
    668             message["from"] = entity.full()
     684            message["from"] = service.full()
    669685            message["to"] = recipient.full()
    670686            event = message.addElement((NS_PUBSUB_EVENT, "event"))
     
    674690            self.send(message)
    675691
    676     def getNodeInfo(self, requestor, nodeIdentifier):
     692    def getNodeInfo(self, requestor, service, nodeIdentifier):
    677693        return None
    678694
    679     def getNodes(self, requestor):
     695    def getNodes(self, requestor, service):
    680696        return []
    681697
    682     def publish(self, requestor, nodeIdentifier, items):
     698    def publish(self, requestor, service, nodeIdentifier, items):
    683699        raise Unsupported('publish')
    684700
    685     def subscribe(self, requestor, nodeIdentifier, subscriber):
     701    def subscribe(self, requestor, service, nodeIdentifier, subscriber):
    686702        raise Unsupported('subscribe')
    687703
    688     def unsubscribe(self, requestor, nodeIdentifier, subscriber):
     704    def unsubscribe(self, requestor, service, nodeIdentifier, subscriber):
    689705        raise Unsupported('subscribe')
    690706
    691     def subscriptions(self, requestor):
     707    def subscriptions(self, requestor, service):
    692708        raise Unsupported('retrieve-subscriptions')
    693709
    694     def affiliations(self, requestor):
     710    def affiliations(self, requestor, service):
    695711        raise Unsupported('retrieve-affiliations')
    696712
    697     def create(self, requestor, nodeIdentifier):
     713    def create(self, requestor, service, nodeIdentifier):
    698714        raise Unsupported('create-nodes')
    699715
    700     def getDefaultConfiguration(self, requestor):
     716    def getDefaultConfiguration(self, requestor, service):
    701717        raise Unsupported('retrieve-default')
    702718
    703     def getConfiguration(self, requestor, nodeIdentifier):
     719    def getConfiguration(self, requestor, service, nodeIdentifier):
    704720        raise Unsupported('config-node')
    705721
    706     def setConfiguration(self, requestor, nodeIdentifier, options):
     722    def setConfiguration(self, requestor, service, nodeIdentifier, options):
    707723        raise Unsupported('config-node')
    708724
    709     def items(self, requestor, nodeIdentifier, maxItems, itemIdentifiers):
     725    def items(self, requestor, service, nodeIdentifier, maxItems,
     726                    itemIdentifiers):
    710727        raise Unsupported('retrieve-items')
    711728
    712     def retract(self, requestor, nodeIdentifier, itemIdentifiers):
     729    def retract(self, requestor, service, nodeIdentifier, itemIdentifiers):
    713730        raise Unsupported('retract-items')
    714731
    715     def purge(self, requestor, nodeIdentifier):
     732    def purge(self, requestor, service, nodeIdentifier):
    716733        raise Unsupported('purge-nodes')
    717734
    718     def delete(self, requestor, nodeIdentifier):
     735    def delete(self, requestor, service, nodeIdentifier):
    719736        raise Unsupported('delete-nodes')
    720 
Note: See TracChangeset for help on using the changeset viewer.