source:
ralphm-patches/py3-pubsub.patch
Last change on this file was 78:361e2111a663, checked in by Ralph Meijer <ralphm@…>, 6 years ago | |
---|---|
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 10 10 U{XEP-0060<http://xmpp.org/extensions/xep-0060.html>}. 11 11 """ 12 12 13 from zope.interface import implement s13 from zope.interface import implementer 14 14 15 15 from twisted.internet import defer 16 16 from twisted.python import log 17 from twisted.python.compat import iteritems, unicode 17 18 from twisted.words.protocols.jabber import jid, error 18 19 from twisted.words.xish import domish 19 20 … … 103 104 A subscription to a node. 104 105 105 106 @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} 108 109 109 110 @ivar subscriber: The subscribing entity. 110 111 @type subscriber: L{jid.JID} 111 112 112 113 @ivar state: The subscription state. One of C{'subscribed'}, C{'pending'}, 113 114 C{'unconfigured'}. 114 @type state: C{unicode}115 @type state: L{unicode} 115 116 116 117 @ivar options: Optional list of subscription options. 117 @type options: C{dict}118 @type options: L{dict} 118 119 119 120 @ivar subscriptionIdentifier: Optional subscription identifier. 120 @type subscriptionIdentifier: C{unicode}121 @type subscriptionIdentifier: L{unicode} 121 122 """ 122 123 123 124 def __init__(self, nodeIdentifier, subscriber, state, options=None, … … 168 169 def __init__(self, id=None, payload=None): 169 170 """ 170 171 @param id: optional item identifier 171 @type id: C{unicode}172 @type id: L{unicode} 172 173 @param payload: optional item payload. Either as a domish element, or 173 174 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}. 175 176 """ 176 177 177 178 domish.Element.__init__(self, (None, 'item')) … … 191 192 192 193 The set of instance variables used depends on the type of request. If 193 194 a variable is not applicable or not passed in the request, its value is 194 C{None}.195 L{None}. 195 196 196 197 @ivar verb: The type of publish-subscribe request. See C{_requestVerbMap}. 197 @type verb: C{str}.198 @type verb: L{str}. 198 199 199 200 @ivar affiliations: Affiliations to be modified. 200 @type affiliations: C{set}201 @type affiliations: L{set} 201 202 202 203 @ivar items: The items to be published, as L{domish.Element}s. 203 @type items: C{list}204 @type items: L{list} 204 205 205 206 @ivar itemIdentifiers: Identifiers of the items to be retrieved or 206 207 retracted. 207 @type itemIdentifiers: C{set}208 @type itemIdentifiers: L{set} 208 209 209 210 @ivar maxItems: Maximum number of items to retrieve. 210 @type maxItems: C{int}.211 @type maxItems: L{int}. 211 212 212 213 @ivar nodeIdentifier: Identifier of the node the request is about. 213 @type nodeIdentifier: C{unicode}214 @type nodeIdentifier: L{unicode} 214 215 215 216 @ivar nodeType: The type of node that should be created, or for which the 216 217 configuration is retrieved. C{'leaf'} or C{'collection'}. 217 @type nodeType: C{str}218 @type nodeType: L{str} 218 219 219 220 @ivar options: Configurations options for nodes, subscriptions and publish 220 221 requests. … … 224 225 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>} 225 226 226 227 @ivar subscriptionIdentifier: Identifier for a specific subscription. 227 @type subscriptionIdentifier: C{unicode}228 @type subscriptionIdentifier: L{unicode} 228 229 229 230 @ivar subscriptions: Subscriptions to be modified, as a set of 230 231 L{Subscription}. 231 @type subscriptions: C{set}232 @type subscriptions: L{set} 232 233 233 234 @ivar affiliations: Affiliations to be modified, as a dictionary of entity 234 235 (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} 237 238 """ 238 239 239 240 verb = None … … 274 275 } 275 276 276 277 # 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))) 278 279 279 280 # Map request verb to parameter handler names 280 281 _parameters = { … … 645 646 @param recipient: The entity to which the notification was sent. 646 647 @type recipient: L{wokkel.pubsub.ItemsEvent} 647 648 @param nodeIdentifier: Identifier of the node the event pertains to. 648 @type nodeIdentifier: C{unicode}649 @type nodeIdentifier: L{unicode} 649 650 @param headers: SHIM headers, see L{wokkel.shim.extractHeaders}. 650 @type headers: C{dict}651 @type headers: L{dict} 651 652 """ 652 653 653 654 def __init__(self, sender, recipient, nodeIdentifier, headers): … … 663 664 A publish-subscribe event that signifies new, updated and retracted items. 664 665 665 666 @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} 667 668 """ 668 669 669 670 def __init__(self, sender, recipient, nodeIdentifier, items, headers): … … 688 689 689 690 690 691 692 @implementer(IPubSubClient) 691 693 class PubSubClient(XMPPHandler): 692 694 """ 693 695 Publish subscribe client protocol. 694 696 """ 695 697 696 implements(IPubSubClient)697 698 698 def connectionInitialized(self): 699 699 self.xmlstream.addObserver('/message/event[@xmlns="%s"]' % 700 700 NS_PUBSUB_EVENT, self._onEvent) … … 770 770 @param service: The publish subscribe service to create the node at. 771 771 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 772 772 @param nodeIdentifier: Optional suggestion for the id of the node. 773 @type nodeIdentifier: C{unicode}773 @type nodeIdentifier: L{unicode} 774 774 @param options: Optional node configuration options. 775 @type options: C{dict}775 @type options: L{dict} 776 776 """ 777 777 request = PubSubRequest('create') 778 778 request.recipient = service … … 805 805 @param service: The publish subscribe service to delete the node from. 806 806 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 807 807 @param nodeIdentifier: The identifier of the node. 808 @type nodeIdentifier: C{unicode}808 @type nodeIdentifier: L{unicode} 809 809 """ 810 810 request = PubSubRequest('delete') 811 811 request.recipient = service … … 823 823 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 824 824 825 825 @param nodeIdentifier: The identifier of the node. 826 @type nodeIdentifier: C{unicode}826 @type nodeIdentifier: L{unicode} 827 827 828 828 @param subscriber: The entity to subscribe to the node. This entity 829 829 will get notifications of new published items. 830 830 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>} 831 831 832 832 @param options: Subscription options. 833 @type options: C{dict}833 @type options: L{dict} 834 834 835 835 @return: Deferred that fires with L{Subscription} or errbacks with 836 836 L{SubscriptionPending} or L{SubscriptionUnconfigured}. … … 875 875 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 876 876 877 877 @param nodeIdentifier: The identifier of the node. 878 @type nodeIdentifier: C{unicode}878 @type nodeIdentifier: L{unicode} 879 879 880 880 @param subscriber: The entity to unsubscribe from the node. 881 881 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>} 882 882 883 883 @param subscriptionIdentifier: Optional subscription identifier. 884 @type subscriptionIdentifier: C{unicode}884 @type subscriptionIdentifier: L{unicode} 885 885 """ 886 886 request = PubSubRequest('unsubscribe') 887 887 request.recipient = service … … 899 899 @param service: The publish subscribe service that keeps the node. 900 900 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 901 901 @param nodeIdentifier: The identifier of the node. 902 @type nodeIdentifier: C{unicode}902 @type nodeIdentifier: L{unicode} 903 903 @param items: Optional list of L{Item}s to publish. 904 @type items: C{list}904 @type items: L{list} 905 905 """ 906 906 request = PubSubRequest('publish') 907 907 request.recipient = service … … 920 920 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 921 921 922 922 @param nodeIdentifier: The identifier of the node. 923 @type nodeIdentifier: C{unicode}923 @type nodeIdentifier: L{unicode} 924 924 925 925 @param maxItems: Optional limit on the number of retrieved items. 926 @type maxItems: C{int}926 @type maxItems: L{int} 927 927 928 928 @param subscriptionIdentifier: Optional subscription identifier. In 929 929 case the node has been subscribed to multiple times, this narrows 930 930 the results to the specific subscription. 931 @type subscriptionIdentifier: C{unicode}931 @type subscriptionIdentifier: L{unicode} 932 932 """ 933 933 request = PubSubRequest('items') 934 934 request.recipient = service … … 959 959 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 960 960 961 961 @param nodeIdentifier: The identifier of the node. 962 @type nodeIdentifier: C{unicode}962 @type nodeIdentifier: L{unicode} 963 963 964 964 @param subscriber: The entity subscribed to the node. 965 965 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>} 966 966 967 967 @param subscriptionIdentifier: Optional subscription identifier. 968 @type subscriptionIdentifier: C{unicode}968 @type subscriptionIdentifier: L{unicode} 969 969 970 970 @rtype: L{data_form.Form} 971 971 """ … … 996 996 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 997 997 998 998 @param nodeIdentifier: The identifier of the node. 999 @type nodeIdentifier: C{unicode}999 @type nodeIdentifier: L{unicode} 1000 1000 1001 1001 @param subscriber: The entity subscribed to the node. 1002 1002 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>} 1003 1003 1004 1004 @param options: Subscription options. 1005 @type options: C{dict}.1005 @type options: L{dict}. 1006 1006 1007 1007 @param subscriptionIdentifier: Optional subscription identifier. 1008 @type subscriptionIdentifier: C{unicode}1008 @type subscriptionIdentifier: L{unicode} 1009 1009 """ 1010 1010 request = PubSubRequest('optionsSet') 1011 1011 request.recipient = service … … 1024 1024 1025 1025 1026 1026 1027 @implementer(IPubSubService, disco.IDisco) 1027 1028 class PubSubService(XMPPHandler, IQHandlerMixin): 1028 1029 """ 1029 1030 Protocol implementation for a XMPP Publish Subscribe Service. … … 1048 1049 @ivar discoIdentity: Service discovery identity as a dictionary with 1049 1050 keys C{'category'}, C{'type'} and C{'name'}. 1050 1051 @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} 1053 1054 """ 1054 1055 1055 implements(IPubSubService, disco.IDisco)1056 1057 1056 iqHandlers = { 1058 1057 '/*': '_onPubSubRequest', 1059 1058 } … … 1351 1350 if request.nodeIdentifier: 1352 1351 affiliations['node'] = request.nodeIdentifier 1353 1352 1354 for entity, affiliation in result.iteritems():1353 for entity, affiliation in iteritems(result): 1355 1354 item = affiliations.addElement('affiliation') 1356 1355 item['jid'] = entity.full() 1357 1356 item['affiliation'] = affiliation … … 1450 1449 1451 1450 1452 1451 1452 @implementer(IPubSubResource) 1453 1453 class PubSubResource(object): 1454 1454 1455 implements(IPubSubResource)1456 1457 1455 features = [] 1458 1456 discoIdentity = disco.DiscoIdentity('pubsub', 1459 1457 'service', -
wokkel/test/test_pubsub.py
diff --git a/wokkel/test/test_pubsub.py b/wokkel/test/test_pubsub.py
a b 2913 2913 2914 2914 def configureSet(request): 2915 2915 self.assertEquals(['pubsub#deliver_payloads'], 2916 request.options.keys())2916 list(request.options.keys())) 2917 2917 2918 2918 self.resource.getConfigurationOptions = getConfigurationOptions 2919 2919 self.resource.configureSet = configureSet
Note: See TracBrowser
for help on using the repository browser.