Changeset 222:e1dafcc79586 for wokkel


Ignore:
Timestamp:
Oct 4, 2016, 9:39:09 AM (4 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Parents:
220:c8a97efc6fa6 (diff), 221:cd2b3dff1f2f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
hg-git-rename-source:
git
Message:

Merge branch 'master' into item-get-by-ids

Location:
wokkel
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wokkel/pubsub.py

    r220 r222  
    1111"""
    1212
    13 from zope.interface import implements
     13from __future__ import division, absolute_import
     14
     15from zope.interface import implementer
    1416
    1517from twisted.internet import defer
    1618from twisted.python import log
     19from twisted.python.compat import StringType, iteritems, unicode
    1720from twisted.words.protocols.jabber import jid, error
    1821from twisted.words.xish import domish
     
    104107
    105108    @ivar nodeIdentifier: The identifier of the node subscribed to.  The root
    106         node is denoted by C{None}.
    107     @type nodeIdentifier: C{unicode}
     109        node is denoted by L{None}.
     110    @type nodeIdentifier: L{unicode}
    108111
    109112    @ivar subscriber: The subscribing entity.
     
    112115    @ivar state: The subscription state. One of C{'subscribed'}, C{'pending'},
    113116                 C{'unconfigured'}.
    114     @type state: C{unicode}
     117    @type state: L{unicode}
    115118
    116119    @ivar options: Optional list of subscription options.
    117     @type options: C{dict}
     120    @type options: L{dict}
    118121
    119122    @ivar subscriptionIdentifier: Optional subscription identifier.
    120     @type subscriptionIdentifier: C{unicode}
     123    @type subscriptionIdentifier: L{unicode}
    121124    """
    122125
     
    169172        """
    170173        @param id: optional item identifier
    171         @type id: C{unicode}
     174        @type id: L{unicode}
    172175        @param payload: optional item payload. Either as a domish element, or
    173176                        as serialized XML.
    174         @type payload: object providing L{domish.IElement} or C{unicode}.
     177        @type payload: object providing L{domish.IElement} or L{unicode}.
    175178        """
    176179
     
    179182            self['id'] = id
    180183        if payload is not None:
    181             if isinstance(payload, basestring):
     184            if isinstance(payload, StringType):
    182185                self.addRawXml(payload)
    183186            else:
     
    192195    The set of instance variables used depends on the type of request. If
    193196    a variable is not applicable or not passed in the request, its value is
    194     C{None}.
     197    L{None}.
    195198
    196199    @ivar verb: The type of publish-subscribe request. See C{_requestVerbMap}.
    197     @type verb: C{str}.
     200    @type verb: L{str}.
    198201
    199202    @ivar affiliations: Affiliations to be modified.
    200     @type affiliations: C{set}
     203    @type affiliations: L{set}
    201204
    202205    @ivar items: The items to be published, as L{domish.Element}s.
    203     @type items: C{list}
     206    @type items: L{list}
    204207
    205208    @ivar itemIdentifiers: Identifiers of the items to be retrieved or
    206209                           retracted.
    207     @type itemIdentifiers: C{set}
     210    @type itemIdentifiers: L{set}
    208211
    209212    @ivar maxItems: Maximum number of items to retrieve.
    210     @type maxItems: C{int}.
     213    @type maxItems: L{int}.
    211214
    212215    @ivar nodeIdentifier: Identifier of the node the request is about.
    213     @type nodeIdentifier: C{unicode}
     216    @type nodeIdentifier: L{unicode}
    214217
    215218    @ivar nodeType: The type of node that should be created, or for which the
    216219                    configuration is retrieved. C{'leaf'} or C{'collection'}.
    217     @type nodeType: C{str}
     220    @type nodeType: L{str}
    218221
    219222    @ivar options: Configurations options for nodes, subscriptions and publish
     
    225228
    226229    @ivar subscriptionIdentifier: Identifier for a specific subscription.
    227     @type subscriptionIdentifier: C{unicode}
     230    @type subscriptionIdentifier: L{unicode}
    228231
    229232    @ivar subscriptions: Subscriptions to be modified, as a set of
    230233        L{Subscription}.
    231     @type subscriptions: C{set}
     234    @type subscriptions: L{set}
    232235
    233236    @ivar affiliations: Affiliations to be modified, as a dictionary of entity
    234237        (L{JID<twisted.words.protocols.jabber.jid.JID>} to affiliation
    235         (C{unicode}).
    236     @type affiliations: C{dict}
     238        (L{unicode}).
     239    @type affiliations: L{dict}
    237240    """
    238241
     
    275278
    276279    # Map request verb to request iq type and subelement name
    277     _verbRequestMap = dict(((v, k) for k, v in _requestVerbMap.iteritems()))
     280    _verbRequestMap = dict(((v, k) for k, v in iteritems(_requestVerbMap)))
    278281
    279282    # Map request verb to parameter handler names
     
    646649    @type recipient: L{wokkel.pubsub.ItemsEvent}
    647650    @param nodeIdentifier: Identifier of the node the event pertains to.
    648     @type nodeIdentifier: C{unicode}
     651    @type nodeIdentifier: L{unicode}
    649652    @param headers: SHIM headers, see L{wokkel.shim.extractHeaders}.
    650     @type headers: C{dict}
     653    @type headers: L{dict}
    651654    """
    652655
     
    664667
    665668    @param items: List of received items as domish elements.
    666     @type items: C{list} of L{domish.Element}
     669    @type items: L{list} of L{domish.Element}
    667670    """
    668671
     
    689692
    690693
     694@implementer(IPubSubClient)
    691695class PubSubClient(XMPPHandler):
    692696    """
    693697    Publish subscribe client protocol.
    694698    """
    695 
    696     implements(IPubSubClient)
    697699
    698700    def connectionInitialized(self):
     
    771773        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    772774        @param nodeIdentifier: Optional suggestion for the id of the node.
    773         @type nodeIdentifier: C{unicode}
     775        @type nodeIdentifier: L{unicode}
    774776        @param options: Optional node configuration options.
    775         @type options: C{dict}
     777        @type options: L{dict}
    776778        """
    777779        request = PubSubRequest('create')
     
    806808        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    807809        @param nodeIdentifier: The identifier of the node.
    808         @type nodeIdentifier: C{unicode}
     810        @type nodeIdentifier: L{unicode}
    809811        """
    810812        request = PubSubRequest('delete')
     
    824826
    825827        @param nodeIdentifier: The identifier of the node.
    826         @type nodeIdentifier: C{unicode}
     828        @type nodeIdentifier: L{unicode}
    827829
    828830        @param subscriber: The entity to subscribe to the node. This entity
     
    831833
    832834        @param options: Subscription options.
    833         @type options: C{dict}
     835        @type options: L{dict}
    834836
    835837        @return: Deferred that fires with L{Subscription} or errbacks with
     
    876878
    877879        @param nodeIdentifier: The identifier of the node.
    878         @type nodeIdentifier: C{unicode}
     880        @type nodeIdentifier: L{unicode}
    879881
    880882        @param subscriber: The entity to unsubscribe from the node.
     
    882884
    883885        @param subscriptionIdentifier: Optional subscription identifier.
    884         @type subscriptionIdentifier: C{unicode}
     886        @type subscriptionIdentifier: L{unicode}
    885887        """
    886888        request = PubSubRequest('unsubscribe')
     
    900902        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    901903        @param nodeIdentifier: The identifier of the node.
    902         @type nodeIdentifier: C{unicode}
     904        @type nodeIdentifier: L{unicode}
    903905        @param items: Optional list of L{Item}s to publish.
    904         @type items: C{list}
     906        @type items: L{list}
    905907        """
    906908        request = PubSubRequest('publish')
     
    921923
    922924        @param nodeIdentifier: The identifier of the node.
    923         @type nodeIdentifier: C{unicode}
     925        @type nodeIdentifier: L{unicode}
    924926
    925927        @param maxItems: Optional limit on the number of retrieved items.
    926         @type maxItems: C{int}
     928        @type maxItems: L{int}
    927929
    928930        @param itemIdentifiers: Identifiers of the items to be retrieved.
     
    932934            case the node has been subscribed to multiple times, this narrows
    933935            the results to the specific subscription.
    934         @type subscriptionIdentifier: C{unicode}
     936        @type subscriptionIdentifier: L{unicode}
    935937        """
    936938        request = PubSubRequest('items')
     
    964966
    965967        @param nodeIdentifier: The identifier of the node.
    966         @type nodeIdentifier: C{unicode}
     968        @type nodeIdentifier: L{unicode}
    967969
    968970        @param subscriber: The entity subscribed to the node.
     
    970972
    971973        @param subscriptionIdentifier: Optional subscription identifier.
    972         @type subscriptionIdentifier: C{unicode}
     974        @type subscriptionIdentifier: L{unicode}
    973975
    974976        @rtype: L{data_form.Form}
     
    10011003
    10021004        @param nodeIdentifier: The identifier of the node.
    1003         @type nodeIdentifier: C{unicode}
     1005        @type nodeIdentifier: L{unicode}
    10041006
    10051007        @param subscriber: The entity subscribed to the node.
     
    10071009
    10081010        @param options: Subscription options.
    1009         @type options: C{dict}.
     1011        @type options: L{dict}.
    10101012
    10111013        @param subscriptionIdentifier: Optional subscription identifier.
    1012         @type subscriptionIdentifier: C{unicode}
     1014        @type subscriptionIdentifier: L{unicode}
    10131015        """
    10141016        request = PubSubRequest('optionsSet')
     
    10291031
    10301032
     1033@implementer(IPubSubService, disco.IDisco)
    10311034class PubSubService(XMPPHandler, IQHandlerMixin):
    10321035    """
     
    10531056                         keys C{'category'}, C{'type'} and C{'name'}.
    10541057    @ivar pubSubFeatures: List of supported publish-subscribe features for
    1055                           service discovery, as C{str}.
    1056     @type pubSubFeatures: C{list} or C{None}
    1057     """
    1058 
    1059     implements(IPubSubService, disco.IDisco)
     1058                          service discovery, as L{str}.
     1059    @type pubSubFeatures: L{list} or L{None}
     1060    """
    10601061
    10611062    iqHandlers = {
     
    13561357            affiliations['node'] = request.nodeIdentifier
    13571358
    1358         for entity, affiliation in result.iteritems():
     1359        for entity, affiliation in iteritems(result):
    13591360            item = affiliations.addElement('affiliation')
    13601361            item['jid'] = entity.full()
     
    14551456
    14561457
     1458@implementer(IPubSubResource)
    14571459class PubSubResource(object):
    1458 
    1459     implements(IPubSubResource)
    14601460
    14611461    features = []
  • wokkel/pubsub.py

    r212 r222  
    914914
    915915
    916     def items(self, service, nodeIdentifier, maxItems=None,
     916    def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None,
    917917              subscriptionIdentifier=None, sender=None):
    918918        """
     
    927927        @param maxItems: Optional limit on the number of retrieved items.
    928928        @type maxItems: L{int}
     929
     930        @param itemIdentifiers: Identifiers of the items to be retrieved.
     931        @type itemIdentifiers: C{set}
    929932
    930933        @param subscriptionIdentifier: Optional subscription identifier. In
     
    940943        request.subscriptionIdentifier = subscriptionIdentifier
    941944        request.sender = sender
     945        request.itemIdentifiers = itemIdentifiers
    942946
    943947        def cb(iq):
  • wokkel/test/test_pubsub.py

    r220 r222  
    55Tests for L{wokkel.pubsub}
    66"""
     7
     8from __future__ import division, absolute_import
    79
    810from zope.interface import verify
     
    113115        element = subscription.toElement()
    114116        self.assertEqual('1234', element.getAttribute('subid'))
     117
     118
     119
     120class ItemTests(unittest.TestCase):
     121    """
     122    Tests for L{pubsub.Item}.
     123    """
     124
     125    def test_payloadRaw(self):
     126        """
     127        Adding a payload as a string assumes serialized XML.
     128        """
     129        payload = "<test xmlns='foo'/>"
     130        item = pubsub.Item(payload=payload)
     131        self.assertEqual(payload, item.children[0])
     132
     133
     134    def test_payloadElement(self):
     135        """
     136        Adding a payload as an domish Element, just adds that element as child.
     137        """
     138        payload = domish.Element(('foo', 'test'))
     139        item = pubsub.Item(payload=payload)
     140        self.assertIs(payload, item.children[0])
    115141
    116142
     
    29542980        def configureSet(request):
    29552981            self.assertEquals(['pubsub#deliver_payloads'],
    2956                               request.options.keys())
     2982                              list(request.options.keys()))
    29572983
    29582984        self.resource.getConfigurationOptions = getConfigurationOptions
  • wokkel/test/test_pubsub.py

    r212 r222  
    828828
    829829
     830    def test_itemsWithItemIdentifiers(self):
     831        """
     832        Test sending items request with item identifiers.
     833        """
     834        def cb(items):
     835            self.assertEquals(2, len(items))
     836            self.assertEquals([item1, item2], items)
     837
     838        d = self.protocol.items(JID('pubsub.example.org'), 'test',
     839                                itemIdentifiers=['item1', 'item2'])
     840        d.addCallback(cb)
     841
     842        iq = self.stub.output[-1]
     843        self.assertEquals('pubsub.example.org', iq.getAttribute('to'))
     844        self.assertEquals('get', iq.getAttribute('type'))
     845        self.assertEquals('pubsub', iq.pubsub.name)
     846        self.assertEquals(NS_PUBSUB, iq.pubsub.uri)
     847        children = list(domish.generateElementsQNamed(iq.pubsub.children,
     848                                                      'items', NS_PUBSUB))
     849        self.assertEquals(1, len(children))
     850        child = children[0]
     851        self.assertEquals('test', child['node'])
     852        itemIdentifiers = [item.getAttribute('id') for item in
     853                           domish.generateElementsQNamed(child.children, 'item',
     854                                                         NS_PUBSUB)]
     855        self.assertEquals(['item1', 'item2'], itemIdentifiers)
     856
     857        response = toResponse(iq, 'result')
     858        items = response.addElement((NS_PUBSUB, 'pubsub')).addElement('items')
     859        items['node'] = 'test'
     860        item1 = items.addElement('item')
     861        item1['id'] = 'item1'
     862        item2 = items.addElement('item')
     863        item2['id'] = 'item2'
     864
     865        self.stub.send(response)
     866
     867        return d
     868
     869
    830870    def test_itemsWithSubscriptionIdentifier(self):
    831871        """
Note: See TracChangeset for help on using the changeset viewer.