Changeset 723

Show
Ignore:
Timestamp:
07/21/08 01:07:30 (4 months ago)
Author:
sylvain
Message:

Added node item retrieval API

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • oss/headstock/headstock/api/discovery.py

    r697 r723  
    154154                            item = Item(jid, i.get_attribute_value('action'), 
    155155                                        i.get_attribute_value('name'), 
    156                                         i.get_attribute_value('node')
     156                                        disco.node_name
    157157                            disco.items.append(item) 
    158158            elif c.xml_ns == XMPP_CLIENT_NS and c.xml_name == 'error': 
     
    193193                    if not isinstance(p, E): 
    194194                        continue 
    195                     if p.xml_ns == XMPP_PUBSUB_NS and p.xml_name == 'subscriptions':    
     195                    if p.xml_ns == XMPP_PUBSUB_NS and p.xml_name == 'subscriptions': 
    196196                        for s in p.xml_children:                     
    197197                            if not isinstance(s, E): 
  • oss/headstock/headstock/api/pubsub.py

    r698 r723  
    272272                                if q.xml_name == 'item': 
    273273                                    node.item = Item(q.get_attribute_value('id'))                                     
     274            elif i.xml_ns == XMPP_CLIENT_NS and i.xml_name == 'error': 
     275                node.error = Error.from_element(i) 
     276 
     277        return node 
     278         
     279    @staticmethod 
     280    def to_request_item(e): 
     281        iq = Entity.to_element(e) 
     282        pubsub = E(u'pubsub', namespace=XMPP_PUBSUB_NS, parent=iq) 
     283        attrs = {u'node': e.node_name} 
     284        items = E(u'items', attributes=attrs, namespace=XMPP_PUBSUB_NS, parent=pubsub) 
     285        attrs = {u'id': e.item.id} 
     286        item = E(u'item', attributes=attrs, namespace=XMPP_PUBSUB_NS, parent=items) 
     287 
     288        return iq 
     289 
     290    @staticmethod 
     291    def from_request_item(e): 
     292        node = Node(JID.parse(e.get_attribute_value('from')), 
     293                    JID.parse(e.get_attribute_value('to')), 
     294                    type=e.get_attribute_value('type'), 
     295                    stanza_id=e.get_attribute_value('id')) 
     296 
     297        for i in e.xml_children: 
     298            if i.xml_ns in [XMPP_PUBSUB_NS]: 
     299                for p in i.xml_children: 
     300                    if p.xml_ns in [XMPP_PUBSUB_NS]: 
     301                        if p.xml_name == 'items': 
     302                            node.node_name = p.get_attribute_value('node') 
     303                            for q in p.xml_children: 
     304                                if q.xml_name == 'item': 
     305                                    payload = None 
     306                                    if q.xml_children: payload = q.xml_children 
     307                                    node.item = Item(q.get_attribute_value('id'), 
     308                                                     payload=payload)                                     
    274309            elif i.xml_ns == XMPP_CLIENT_NS and i.xml_name == 'error': 
    275310                node.error = Error.from_element(i)