Changeset 222:e1dafcc79586
- Timestamp:
- Oct 4, 2016, 9:39:09 AM (6 years ago)
- 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
- Location:
- wokkel
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
wokkel/pubsub.py
r220 r222 11 11 """ 12 12 13 from zope.interface import implements 13 from __future__ import division, absolute_import 14 15 from zope.interface import implementer 14 16 15 17 from twisted.internet import defer 16 18 from twisted.python import log 19 from twisted.python.compat import StringType, iteritems, unicode 17 20 from twisted.words.protocols.jabber import jid, error 18 21 from twisted.words.xish import domish … … 104 107 105 108 @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} 108 111 109 112 @ivar subscriber: The subscribing entity. … … 112 115 @ivar state: The subscription state. One of C{'subscribed'}, C{'pending'}, 113 116 C{'unconfigured'}. 114 @type state: C{unicode}117 @type state: L{unicode} 115 118 116 119 @ivar options: Optional list of subscription options. 117 @type options: C{dict}120 @type options: L{dict} 118 121 119 122 @ivar subscriptionIdentifier: Optional subscription identifier. 120 @type subscriptionIdentifier: C{unicode}123 @type subscriptionIdentifier: L{unicode} 121 124 """ 122 125 … … 169 172 """ 170 173 @param id: optional item identifier 171 @type id: C{unicode}174 @type id: L{unicode} 172 175 @param payload: optional item payload. Either as a domish element, or 173 176 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}. 175 178 """ 176 179 … … 179 182 self['id'] = id 180 183 if payload is not None: 181 if isinstance(payload, basestring):184 if isinstance(payload, StringType): 182 185 self.addRawXml(payload) 183 186 else: … … 192 195 The set of instance variables used depends on the type of request. If 193 196 a variable is not applicable or not passed in the request, its value is 194 C{None}.197 L{None}. 195 198 196 199 @ivar verb: The type of publish-subscribe request. See C{_requestVerbMap}. 197 @type verb: C{str}.200 @type verb: L{str}. 198 201 199 202 @ivar affiliations: Affiliations to be modified. 200 @type affiliations: C{set}203 @type affiliations: L{set} 201 204 202 205 @ivar items: The items to be published, as L{domish.Element}s. 203 @type items: C{list}206 @type items: L{list} 204 207 205 208 @ivar itemIdentifiers: Identifiers of the items to be retrieved or 206 209 retracted. 207 @type itemIdentifiers: C{set}210 @type itemIdentifiers: L{set} 208 211 209 212 @ivar maxItems: Maximum number of items to retrieve. 210 @type maxItems: C{int}.213 @type maxItems: L{int}. 211 214 212 215 @ivar nodeIdentifier: Identifier of the node the request is about. 213 @type nodeIdentifier: C{unicode}216 @type nodeIdentifier: L{unicode} 214 217 215 218 @ivar nodeType: The type of node that should be created, or for which the 216 219 configuration is retrieved. C{'leaf'} or C{'collection'}. 217 @type nodeType: C{str}220 @type nodeType: L{str} 218 221 219 222 @ivar options: Configurations options for nodes, subscriptions and publish … … 225 228 226 229 @ivar subscriptionIdentifier: Identifier for a specific subscription. 227 @type subscriptionIdentifier: C{unicode}230 @type subscriptionIdentifier: L{unicode} 228 231 229 232 @ivar subscriptions: Subscriptions to be modified, as a set of 230 233 L{Subscription}. 231 @type subscriptions: C{set}234 @type subscriptions: L{set} 232 235 233 236 @ivar affiliations: Affiliations to be modified, as a dictionary of entity 234 237 (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} 237 240 """ 238 241 … … 275 278 276 279 # 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))) 278 281 279 282 # Map request verb to parameter handler names … … 646 649 @type recipient: L{wokkel.pubsub.ItemsEvent} 647 650 @param nodeIdentifier: Identifier of the node the event pertains to. 648 @type nodeIdentifier: C{unicode}651 @type nodeIdentifier: L{unicode} 649 652 @param headers: SHIM headers, see L{wokkel.shim.extractHeaders}. 650 @type headers: C{dict}653 @type headers: L{dict} 651 654 """ 652 655 … … 664 667 665 668 @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} 667 670 """ 668 671 … … 689 692 690 693 694 @implementer(IPubSubClient) 691 695 class PubSubClient(XMPPHandler): 692 696 """ 693 697 Publish subscribe client protocol. 694 698 """ 695 696 implements(IPubSubClient)697 699 698 700 def connectionInitialized(self): … … 771 773 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 772 774 @param nodeIdentifier: Optional suggestion for the id of the node. 773 @type nodeIdentifier: C{unicode}775 @type nodeIdentifier: L{unicode} 774 776 @param options: Optional node configuration options. 775 @type options: C{dict}777 @type options: L{dict} 776 778 """ 777 779 request = PubSubRequest('create') … … 806 808 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 807 809 @param nodeIdentifier: The identifier of the node. 808 @type nodeIdentifier: C{unicode}810 @type nodeIdentifier: L{unicode} 809 811 """ 810 812 request = PubSubRequest('delete') … … 824 826 825 827 @param nodeIdentifier: The identifier of the node. 826 @type nodeIdentifier: C{unicode}828 @type nodeIdentifier: L{unicode} 827 829 828 830 @param subscriber: The entity to subscribe to the node. This entity … … 831 833 832 834 @param options: Subscription options. 833 @type options: C{dict}835 @type options: L{dict} 834 836 835 837 @return: Deferred that fires with L{Subscription} or errbacks with … … 876 878 877 879 @param nodeIdentifier: The identifier of the node. 878 @type nodeIdentifier: C{unicode}880 @type nodeIdentifier: L{unicode} 879 881 880 882 @param subscriber: The entity to unsubscribe from the node. … … 882 884 883 885 @param subscriptionIdentifier: Optional subscription identifier. 884 @type subscriptionIdentifier: C{unicode}886 @type subscriptionIdentifier: L{unicode} 885 887 """ 886 888 request = PubSubRequest('unsubscribe') … … 900 902 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 901 903 @param nodeIdentifier: The identifier of the node. 902 @type nodeIdentifier: C{unicode}904 @type nodeIdentifier: L{unicode} 903 905 @param items: Optional list of L{Item}s to publish. 904 @type items: C{list}906 @type items: L{list} 905 907 """ 906 908 request = PubSubRequest('publish') … … 921 923 922 924 @param nodeIdentifier: The identifier of the node. 923 @type nodeIdentifier: C{unicode}925 @type nodeIdentifier: L{unicode} 924 926 925 927 @param maxItems: Optional limit on the number of retrieved items. 926 @type maxItems: C{int}928 @type maxItems: L{int} 927 929 928 930 @param itemIdentifiers: Identifiers of the items to be retrieved. … … 932 934 case the node has been subscribed to multiple times, this narrows 933 935 the results to the specific subscription. 934 @type subscriptionIdentifier: C{unicode}936 @type subscriptionIdentifier: L{unicode} 935 937 """ 936 938 request = PubSubRequest('items') … … 964 966 965 967 @param nodeIdentifier: The identifier of the node. 966 @type nodeIdentifier: C{unicode}968 @type nodeIdentifier: L{unicode} 967 969 968 970 @param subscriber: The entity subscribed to the node. … … 970 972 971 973 @param subscriptionIdentifier: Optional subscription identifier. 972 @type subscriptionIdentifier: C{unicode}974 @type subscriptionIdentifier: L{unicode} 973 975 974 976 @rtype: L{data_form.Form} … … 1001 1003 1002 1004 @param nodeIdentifier: The identifier of the node. 1003 @type nodeIdentifier: C{unicode}1005 @type nodeIdentifier: L{unicode} 1004 1006 1005 1007 @param subscriber: The entity subscribed to the node. … … 1007 1009 1008 1010 @param options: Subscription options. 1009 @type options: C{dict}.1011 @type options: L{dict}. 1010 1012 1011 1013 @param subscriptionIdentifier: Optional subscription identifier. 1012 @type subscriptionIdentifier: C{unicode}1014 @type subscriptionIdentifier: L{unicode} 1013 1015 """ 1014 1016 request = PubSubRequest('optionsSet') … … 1029 1031 1030 1032 1033 @implementer(IPubSubService, disco.IDisco) 1031 1034 class PubSubService(XMPPHandler, IQHandlerMixin): 1032 1035 """ … … 1053 1056 keys C{'category'}, C{'type'} and C{'name'}. 1054 1057 @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 """ 1060 1061 1061 1062 iqHandlers = { … … 1356 1357 affiliations['node'] = request.nodeIdentifier 1357 1358 1358 for entity, affiliation in result.iteritems():1359 for entity, affiliation in iteritems(result): 1359 1360 item = affiliations.addElement('affiliation') 1360 1361 item['jid'] = entity.full() … … 1455 1456 1456 1457 1458 @implementer(IPubSubResource) 1457 1459 class PubSubResource(object): 1458 1459 implements(IPubSubResource)1460 1460 1461 1461 features = [] -
wokkel/pubsub.py
r212 r222 914 914 915 915 916 def items(self, service, nodeIdentifier, maxItems=None, 916 def items(self, service, nodeIdentifier, maxItems=None, itemIdentifiers=None, 917 917 subscriptionIdentifier=None, sender=None): 918 918 """ … … 927 927 @param maxItems: Optional limit on the number of retrieved items. 928 928 @type maxItems: L{int} 929 930 @param itemIdentifiers: Identifiers of the items to be retrieved. 931 @type itemIdentifiers: C{set} 929 932 930 933 @param subscriptionIdentifier: Optional subscription identifier. In … … 940 943 request.subscriptionIdentifier = subscriptionIdentifier 941 944 request.sender = sender 945 request.itemIdentifiers = itemIdentifiers 942 946 943 947 def cb(iq): -
wokkel/test/test_pubsub.py
r220 r222 5 5 Tests for L{wokkel.pubsub} 6 6 """ 7 8 from __future__ import division, absolute_import 7 9 8 10 from zope.interface import verify … … 113 115 element = subscription.toElement() 114 116 self.assertEqual('1234', element.getAttribute('subid')) 117 118 119 120 class 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]) 115 141 116 142 … … 2954 2980 def configureSet(request): 2955 2981 self.assertEquals(['pubsub#deliver_payloads'], 2956 request.options.keys())2982 list(request.options.keys())) 2957 2983 2958 2984 self.resource.getConfigurationOptions = getConfigurationOptions -
wokkel/test/test_pubsub.py
r212 r222 828 828 829 829 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 830 870 def test_itemsWithSubscriptionIdentifier(self): 831 871 """
Note: See TracChangeset
for help on using the changeset viewer.