source: ralphm-patches/py3-pubsub.patch @ 83:255aae0cf8c5

Last change on this file since 83:255aae0cf8c5 was 78:361e2111a663, checked in by Ralph Meijer <ralphm@…>, 4 years ago

Start port to Python 3.

File size: 12.2 KB
  • wokkel/pubsub.py

    # HG changeset patch
    # Parent  e3ad7d794f8f7df99807bd069eff857630050acf
    
    diff --git a/wokkel/pubsub.py b/wokkel/pubsub.py
    a b  
    1010U{XEP-0060<http://xmpp.org/extensions/xep-0060.html>}.
    1111"""
    1212
    13 from zope.interface import implements
     13from zope.interface import implementer
    1414
    1515from twisted.internet import defer
    1616from twisted.python import log
     17from twisted.python.compat import iteritems, unicode
    1718from twisted.words.protocols.jabber import jid, error
    1819from twisted.words.xish import domish
    1920
     
    103104    A subscription to a node.
    104105
    105106    @ivar nodeIdentifier: The identifier of the node subscribed to.  The root
    106         node is denoted by C{None}.
    107     @type nodeIdentifier: C{unicode}
     107        node is denoted by L{None}.
     108    @type nodeIdentifier: L{unicode}
    108109
    109110    @ivar subscriber: The subscribing entity.
    110111    @type subscriber: L{jid.JID}
    111112
    112113    @ivar state: The subscription state. One of C{'subscribed'}, C{'pending'},
    113114                 C{'unconfigured'}.
    114     @type state: C{unicode}
     115    @type state: L{unicode}
    115116
    116117    @ivar options: Optional list of subscription options.
    117     @type options: C{dict}
     118    @type options: L{dict}
    118119
    119120    @ivar subscriptionIdentifier: Optional subscription identifier.
    120     @type subscriptionIdentifier: C{unicode}
     121    @type subscriptionIdentifier: L{unicode}
    121122    """
    122123
    123124    def __init__(self, nodeIdentifier, subscriber, state, options=None,
     
    168169    def __init__(self, id=None, payload=None):
    169170        """
    170171        @param id: optional item identifier
    171         @type id: C{unicode}
     172        @type id: L{unicode}
    172173        @param payload: optional item payload. Either as a domish element, or
    173174                        as serialized XML.
    174         @type payload: object providing L{domish.IElement} or C{unicode}.
     175        @type payload: object providing L{domish.IElement} or L{unicode}.
    175176        """
    176177
    177178        domish.Element.__init__(self, (None, 'item'))
     
    191192
    192193    The set of instance variables used depends on the type of request. If
    193194    a variable is not applicable or not passed in the request, its value is
    194     C{None}.
     195    L{None}.
    195196
    196197    @ivar verb: The type of publish-subscribe request. See C{_requestVerbMap}.
    197     @type verb: C{str}.
     198    @type verb: L{str}.
    198199
    199200    @ivar affiliations: Affiliations to be modified.
    200     @type affiliations: C{set}
     201    @type affiliations: L{set}
    201202
    202203    @ivar items: The items to be published, as L{domish.Element}s.
    203     @type items: C{list}
     204    @type items: L{list}
    204205
    205206    @ivar itemIdentifiers: Identifiers of the items to be retrieved or
    206207                           retracted.
    207     @type itemIdentifiers: C{set}
     208    @type itemIdentifiers: L{set}
    208209
    209210    @ivar maxItems: Maximum number of items to retrieve.
    210     @type maxItems: C{int}.
     211    @type maxItems: L{int}.
    211212
    212213    @ivar nodeIdentifier: Identifier of the node the request is about.
    213     @type nodeIdentifier: C{unicode}
     214    @type nodeIdentifier: L{unicode}
    214215
    215216    @ivar nodeType: The type of node that should be created, or for which the
    216217                    configuration is retrieved. C{'leaf'} or C{'collection'}.
    217     @type nodeType: C{str}
     218    @type nodeType: L{str}
    218219
    219220    @ivar options: Configurations options for nodes, subscriptions and publish
    220221                   requests.
     
    224225    @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>}
    225226
    226227    @ivar subscriptionIdentifier: Identifier for a specific subscription.
    227     @type subscriptionIdentifier: C{unicode}
     228    @type subscriptionIdentifier: L{unicode}
    228229
    229230    @ivar subscriptions: Subscriptions to be modified, as a set of
    230231        L{Subscription}.
    231     @type subscriptions: C{set}
     232    @type subscriptions: L{set}
    232233
    233234    @ivar affiliations: Affiliations to be modified, as a dictionary of entity
    234235        (L{JID<twisted.words.protocols.jabber.jid.JID>} to affiliation
    235         (C{unicode}).
    236     @type affiliations: C{dict}
     236        (L{unicode}).
     237    @type affiliations: L{dict}
    237238    """
    238239
    239240    verb = None
     
    274275    }
    275276
    276277    # Map request verb to request iq type and subelement name
    277     _verbRequestMap = dict(((v, k) for k, v in _requestVerbMap.iteritems()))
     278    _verbRequestMap = dict(((v, k) for k, v in iteritems(_requestVerbMap)))
    278279
    279280    # Map request verb to parameter handler names
    280281    _parameters = {
     
    645646    @param recipient: The entity to which the notification was sent.
    646647    @type recipient: L{wokkel.pubsub.ItemsEvent}
    647648    @param nodeIdentifier: Identifier of the node the event pertains to.
    648     @type nodeIdentifier: C{unicode}
     649    @type nodeIdentifier: L{unicode}
    649650    @param headers: SHIM headers, see L{wokkel.shim.extractHeaders}.
    650     @type headers: C{dict}
     651    @type headers: L{dict}
    651652    """
    652653
    653654    def __init__(self, sender, recipient, nodeIdentifier, headers):
     
    663664    A publish-subscribe event that signifies new, updated and retracted items.
    664665
    665666    @param items: List of received items as domish elements.
    666     @type items: C{list} of L{domish.Element}
     667    @type items: L{list} of L{domish.Element}
    667668    """
    668669
    669670    def __init__(self, sender, recipient, nodeIdentifier, items, headers):
     
    688689
    689690
    690691
     692@implementer(IPubSubClient)
    691693class PubSubClient(XMPPHandler):
    692694    """
    693695    Publish subscribe client protocol.
    694696    """
    695697
    696     implements(IPubSubClient)
    697 
    698698    def connectionInitialized(self):
    699699        self.xmlstream.addObserver('/message/event[@xmlns="%s"]' %
    700700                                   NS_PUBSUB_EVENT, self._onEvent)
     
    770770        @param service: The publish subscribe service to create the node at.
    771771        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    772772        @param nodeIdentifier: Optional suggestion for the id of the node.
    773         @type nodeIdentifier: C{unicode}
     773        @type nodeIdentifier: L{unicode}
    774774        @param options: Optional node configuration options.
    775         @type options: C{dict}
     775        @type options: L{dict}
    776776        """
    777777        request = PubSubRequest('create')
    778778        request.recipient = service
     
    805805        @param service: The publish subscribe service to delete the node from.
    806806        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    807807        @param nodeIdentifier: The identifier of the node.
    808         @type nodeIdentifier: C{unicode}
     808        @type nodeIdentifier: L{unicode}
    809809        """
    810810        request = PubSubRequest('delete')
    811811        request.recipient = service
     
    823823        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    824824
    825825        @param nodeIdentifier: The identifier of the node.
    826         @type nodeIdentifier: C{unicode}
     826        @type nodeIdentifier: L{unicode}
    827827
    828828        @param subscriber: The entity to subscribe to the node. This entity
    829829            will get notifications of new published items.
    830830        @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>}
    831831
    832832        @param options: Subscription options.
    833         @type options: C{dict}
     833        @type options: L{dict}
    834834
    835835        @return: Deferred that fires with L{Subscription} or errbacks with
    836836            L{SubscriptionPending} or L{SubscriptionUnconfigured}.
     
    875875        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    876876
    877877        @param nodeIdentifier: The identifier of the node.
    878         @type nodeIdentifier: C{unicode}
     878        @type nodeIdentifier: L{unicode}
    879879
    880880        @param subscriber: The entity to unsubscribe from the node.
    881881        @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>}
    882882
    883883        @param subscriptionIdentifier: Optional subscription identifier.
    884         @type subscriptionIdentifier: C{unicode}
     884        @type subscriptionIdentifier: L{unicode}
    885885        """
    886886        request = PubSubRequest('unsubscribe')
    887887        request.recipient = service
     
    899899        @param service: The publish subscribe service that keeps the node.
    900900        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    901901        @param nodeIdentifier: The identifier of the node.
    902         @type nodeIdentifier: C{unicode}
     902        @type nodeIdentifier: L{unicode}
    903903        @param items: Optional list of L{Item}s to publish.
    904         @type items: C{list}
     904        @type items: L{list}
    905905        """
    906906        request = PubSubRequest('publish')
    907907        request.recipient = service
     
    920920        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    921921
    922922        @param nodeIdentifier: The identifier of the node.
    923         @type nodeIdentifier: C{unicode}
     923        @type nodeIdentifier: L{unicode}
    924924
    925925        @param maxItems: Optional limit on the number of retrieved items.
    926         @type maxItems: C{int}
     926        @type maxItems: L{int}
    927927
    928928        @param subscriptionIdentifier: Optional subscription identifier. In
    929929            case the node has been subscribed to multiple times, this narrows
    930930            the results to the specific subscription.
    931         @type subscriptionIdentifier: C{unicode}
     931        @type subscriptionIdentifier: L{unicode}
    932932        """
    933933        request = PubSubRequest('items')
    934934        request.recipient = service
     
    959959        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    960960
    961961        @param nodeIdentifier: The identifier of the node.
    962         @type nodeIdentifier: C{unicode}
     962        @type nodeIdentifier: L{unicode}
    963963
    964964        @param subscriber: The entity subscribed to the node.
    965965        @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>}
    966966
    967967        @param subscriptionIdentifier: Optional subscription identifier.
    968         @type subscriptionIdentifier: C{unicode}
     968        @type subscriptionIdentifier: L{unicode}
    969969
    970970        @rtype: L{data_form.Form}
    971971        """
     
    996996        @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
    997997
    998998        @param nodeIdentifier: The identifier of the node.
    999         @type nodeIdentifier: C{unicode}
     999        @type nodeIdentifier: L{unicode}
    10001000
    10011001        @param subscriber: The entity subscribed to the node.
    10021002        @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>}
    10031003
    10041004        @param options: Subscription options.
    1005         @type options: C{dict}.
     1005        @type options: L{dict}.
    10061006
    10071007        @param subscriptionIdentifier: Optional subscription identifier.
    1008         @type subscriptionIdentifier: C{unicode}
     1008        @type subscriptionIdentifier: L{unicode}
    10091009        """
    10101010        request = PubSubRequest('optionsSet')
    10111011        request.recipient = service
     
    10241024
    10251025
    10261026
     1027@implementer(IPubSubService, disco.IDisco)
    10271028class PubSubService(XMPPHandler, IQHandlerMixin):
    10281029    """
    10291030    Protocol implementation for a XMPP Publish Subscribe Service.
     
    10481049    @ivar discoIdentity: Service discovery identity as a dictionary with
    10491050                         keys C{'category'}, C{'type'} and C{'name'}.
    10501051    @ivar pubSubFeatures: List of supported publish-subscribe features for
    1051                           service discovery, as C{str}.
    1052     @type pubSubFeatures: C{list} or C{None}
     1052                          service discovery, as L{str}.
     1053    @type pubSubFeatures: L{list} or L{None}
    10531054    """
    10541055
    1055     implements(IPubSubService, disco.IDisco)
    1056 
    10571056    iqHandlers = {
    10581057            '/*': '_onPubSubRequest',
    10591058            }
     
    13511350        if request.nodeIdentifier:
    13521351            affiliations['node'] = request.nodeIdentifier
    13531352
    1354         for entity, affiliation in result.iteritems():
     1353        for entity, affiliation in iteritems(result):
    13551354            item = affiliations.addElement('affiliation')
    13561355            item['jid'] = entity.full()
    13571356            item['affiliation'] = affiliation
     
    14501449
    14511450
    14521451
     1452@implementer(IPubSubResource)
    14531453class PubSubResource(object):
    14541454
    1455     implements(IPubSubResource)
    1456 
    14571455    features = []
    14581456    discoIdentity = disco.DiscoIdentity('pubsub',
    14591457                                        'service',
  • wokkel/test/test_pubsub.py

    diff --git a/wokkel/test/test_pubsub.py b/wokkel/test/test_pubsub.py
    a b  
    29132913
    29142914        def configureSet(request):
    29152915            self.assertEquals(['pubsub#deliver_payloads'],
    2916                               request.options.keys())
     2916                              list(request.options.keys()))
    29172917
    29182918        self.resource.getConfigurationOptions = getConfigurationOptions
    29192919        self.resource.configureSet = configureSet
Note: See TracBrowser for help on using the repository browser.