Example #1
0
    def testPublish(self):
        "Testing iq/pubsub/publish stanzas"
        iq = self.Iq()
        iq['pubsub']['publish']['node'] = 'thingers'
        payload = ET.fromstring("""
          <thinger xmlns="http://andyet.net/protocol/thinger" x="1" y='2'>
             <child1 />
             <child2 normandy='cheese' foo='bar' />
           </thinger>""")
        payload2 = ET.fromstring("""
          <thinger2 xmlns="http://andyet.net/protocol/thinger2" x="12" y='22'>
            <child12 />
            <child22 normandy='cheese2' foo='bar2' />
           </thinger2>""")
        item = pubsub.Item()
        item['id'] = 'asdf'
        item['payload'] = payload
        item2 = pubsub.Item()
        item2['id'] = 'asdf2'
        item2['payload'] = payload2
        iq['pubsub']['publish'].append(item)
        iq['pubsub']['publish'].append(item2)

        self.check(
            iq, """
          <iq id="0">
            <pubsub xmlns="http://jabber.org/protocol/pubsub">
              <publish node="thingers">
                <item id="asdf">
                  <thinger xmlns="http://andyet.net/protocol/thinger" y="2" x="1">
                    <child1 />
                    <child2 foo="bar" normandy="cheese" />
                  </thinger>
                </item>
                <item id="asdf2">
                  <thinger2 xmlns="http://andyet.net/protocol/thinger2" y="22" x="12">
                    <child12 />
                    <child22 foo="bar2" normandy="cheese2" />
                  </thinger2>
                </item>
              </publish>
            </pubsub>
          </iq>""")
Example #2
0
 def handlePublish(self, stanza):
     """iq/{http://jabber.org/protocol/pubsub}pubsub/{http://jabber.org/protocol/pubsub}publish"""
     node = self.nodes.get(stanza['pubsub']['publish']['node'])
     ids = []
     if node is None:
         stanza.reply()
         stanza['error']['condition'] = 'item-not-found'
         stanza.send()
         return
     for item in stanza['pubsub']['publish']:
         item_id = self.publish(stanza['pubsub']['publish']['node'],
                                item['payload'], item['id'],
                                stanza['from'].bare)
         ids.append(item_id)
     stanza.reply()
     #stanza['pubsub'].clear()
     for id in ids:
         item = Pubsub.Item()
         item['id'] = id
         stanza['pubsub']['publish'].append(item)
     stanza.send()
Example #3
0
 def handleGetItems(self, iq):
     node = self.nodes.get(iq['pubsub']['items']['node'])
     if node is None:
         iq.reply()
         iq['error']['condition'] = 'item-not-found'
         iq.send()
         return
     item_insts = node.getItems(who=iq['from'])
     if len(item_insts) == 0 or item_insts is None:
         iq.reply()
         iq['error']['condition'] = 'item-not-found'
         iq.send()
         return
     iq.reply()
     for item_inst in item_insts:
         item = Pubsub.Item()
         item['payload'] = item_inst.payload
         item['id'] = item_inst.name
         iq['pubsub']['items'].append(item)
     iq['pubsub']['items']['node'] = node.name
     iq['type'] = 'result'
     iq.send()