source: ralphm-patches/blah.patch @ 45:51ac2274f989

Last change on this file since 45:51ac2274f989 was 45:51ac2274f989, checked in by Ralph Meijer <ralphm@…>, 9 years ago

Work on using a real Item class and managing affiliations support.

File size: 4.1 KB
  • wokkel/generic.py

    # HG changeset patch
    # Parent a0345fbc24e0350063691188c77dc64fbba743e8
    diff -r a0345fbc24e0 -r a10c0972bda4 wokkel/generic.py
    a b  
    3939    @return: The DOM structure, or C{None} on empty or incomplete input.
    4040    @rtype: L{domish.Element}
    4141    """
    42     roots = []
    4342    results = []
    4443    elementStream = domish.elementStream()
    45     elementStream.DocumentStartEvent = roots.append
    46     elementStream.ElementEvent = lambda elem: roots[0].addChild(elem)
    47     elementStream.DocumentEndEvent = lambda: results.append(roots[0])
    48     elementStream.parse(string)
     44    elementStream.DocumentStartEvent = lambda _: None
     45    elementStream.ElementEvent = lambda elem: results.append(elem)
     46    elementStream.DocumentEndEvent = lambda: None
     47    elementStream.parse('<dummy>%s</dummy>' % string)
    4948    return results and results[0] or None
    5049
    5150
  • wokkel/pubsub.py

    diff -r a0345fbc24e0 -r a10c0972bda4 wokkel/pubsub.py
    a b  
    159159    """
    160160    Publish subscribe item.
    161161
    162     @ivar itemIdentifier: optional item identifier
     162    @ivar itemIdentifier: Optional item identifier.
    163163    @type itemIdentifier: L{unicode}
    164     @ivar payload: optional item payload. Either as a domish element, or as
     164    @ivar payload: Optional item payload. Either as a L{domish.Element}, or as
    165165        serialized XML.
    166     @type payload: object providing L{domish.IElement} or L{unicode}.
     166    @type payload: Object providing L{domish.IElement} or L{unicode}.
     167    @ivar timestamp: Optional timestamp when the item was published as 8601
     168    string. Timestamps that include a time component must have a time zone
     169    indicated.
     170    @type timestamp: C{unicode}
     171    @ivar publisher: Optional entity that published this item.
     172    @type publisher: L{JID}
    167173    """
    168174
    169     def __init__(self, itemIdentifier=None, payload=None):
     175    def __init__(self, itemIdentifier=None, payload=None,
     176                       timestamp=None, publisher=None):
    170177        self.itemIdentifier = itemIdentifier
    171178        self.payload = payload
     179        self.timestamp = timestamp
     180        self.publisher = publisher
    172181
    173182
    174183    def toElement(self, namespace=NS_PUBSUB):
     
    191200
    192201        if self.payload is not None:
    193202            if isinstance(self.payload, basestring):
    194                 self.addRawXml(self.payload)
     203                element.addRawXml(self.payload)
    195204            else:
    196                 self.addChild(self.payload)
     205                element.addChild(self.payload)
    197206
    198207        return element
    199208
     
    13291338            message = self._createNotification('items', service,
    13301339                                               nodeIdentifier, subscriber,
    13311340                                               subscriptions)
    1332             message.event.items.children = items
     1341            for item in items:
     1342                message.event.items.addChild(item.toElement())
    13331343            self.send(message)
    13341344
    13351345
  • wokkel/test/test_pubsub.py

    diff -r a0345fbc24e0 -r a10c0972bda4 wokkel/test/test_pubsub.py
    a b  
    115115
    116116
    117117
     118class ItemTest(unittest.TestCase):
     119
     120    def test_toElement(self):
     121        item = pubsub.Item(itemIdentifier='test')
     122        element = item.toElement()
     123        self.assertEquals('test', element.getAttribute('id'))
     124
     125
     126    def test_toElementPayload(self):
     127        payload = domish.Element(('testns', 'test'))
     128        item = pubsub.Item(itemIdentifier='test', payload=payload)
     129        element = item.toElement()
     130        self.assertNotIdentical(None, element.test)
     131        self.assertEquals('testns', element.test.uri)
     132
     133
     134    def test_toElementPayloadRawXML(self):
     135        payload = u"<test xmlns='testns'/>"
     136        item = pubsub.Item(itemIdentifier='test', payload=payload)
     137        element = item.toElement()
     138        self.assertEquals(1, len(element.children))
     139        self.assertEquals(payload, element.children[0])
     140
     141
    118142class PubSubClientTest(unittest.TestCase):
    119143    timeout = 2
    120144
Note: See TracBrowser for help on using the repository browser.