comparison wokkel/pubsub.py @ 22:5246a9186b91

tmp (wokkel.pubsub): PubSubRequest class can be overriden everywhere, including PubSubClient
author Goffi <goffi@goffi.org>
date Tue, 05 Jan 2016 23:20:22 +0100
parents 54f834e40341
children 79e36496994a
comparison
equal deleted inserted replaced
21:54f834e40341 22:5246a9186b91
757 757
758 class PubSubClient(XMPPHandler): 758 class PubSubClient(XMPPHandler):
759 """ 759 """
760 Publish subscribe client protocol. 760 Publish subscribe client protocol.
761 """ 761 """
762
763 implements(IPubSubClient) 762 implements(IPubSubClient)
763
764 _request_class = PubSubRequest
764 765
765 def connectionInitialized(self): 766 def connectionInitialized(self):
766 self.xmlstream.addObserver('/message/event[@xmlns="%s"]' % 767 self.xmlstream.addObserver('/message/event[@xmlns="%s"]' %
767 NS_PUBSUB_EVENT, self._onEvent) 768 NS_PUBSUB_EVENT, self._onEvent)
768 769
839 @param nodeIdentifier: Optional suggestion for the id of the node. 840 @param nodeIdentifier: Optional suggestion for the id of the node.
840 @type nodeIdentifier: C{unicode} 841 @type nodeIdentifier: C{unicode}
841 @param options: Optional node configuration options. 842 @param options: Optional node configuration options.
842 @type options: C{dict} 843 @type options: C{dict}
843 """ 844 """
844 request = PubSubRequest('create') 845 request = self._request_class('create')
845 request.recipient = service 846 request.recipient = service
846 request.nodeIdentifier = nodeIdentifier 847 request.nodeIdentifier = nodeIdentifier
847 request.sender = sender 848 request.sender = sender
848 849
849 if options: 850 if options:
872 @param service: The publish subscribe service to delete the node from. 873 @param service: The publish subscribe service to delete the node from.
873 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} 874 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>}
874 @param nodeIdentifier: The identifier of the node. 875 @param nodeIdentifier: The identifier of the node.
875 @type nodeIdentifier: C{unicode} 876 @type nodeIdentifier: C{unicode}
876 """ 877 """
877 request = PubSubRequest('delete') 878 request = self._request_class('delete')
878 request.recipient = service 879 request.recipient = service
879 request.nodeIdentifier = nodeIdentifier 880 request.nodeIdentifier = nodeIdentifier
880 request.sender = sender 881 request.sender = sender
881 return request.send(self.xmlstream) 882 return request.send(self.xmlstream)
882 883
901 902
902 @return: Deferred that fires with L{Subscription} or errbacks with 903 @return: Deferred that fires with L{Subscription} or errbacks with
903 L{SubscriptionPending} or L{SubscriptionUnconfigured}. 904 L{SubscriptionPending} or L{SubscriptionUnconfigured}.
904 @rtype: L{defer.Deferred} 905 @rtype: L{defer.Deferred}
905 """ 906 """
906 request = PubSubRequest('subscribe') 907 request = self._request_class('subscribe')
907 request.recipient = service 908 request.recipient = service
908 request.nodeIdentifier = nodeIdentifier 909 request.nodeIdentifier = nodeIdentifier
909 request.subscriber = subscriber 910 request.subscriber = subscriber
910 request.sender = sender 911 request.sender = sender
911 912
948 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>} 949 @type subscriber: L{JID<twisted.words.protocols.jabber.jid.JID>}
949 950
950 @param subscriptionIdentifier: Optional subscription identifier. 951 @param subscriptionIdentifier: Optional subscription identifier.
951 @type subscriptionIdentifier: C{unicode} 952 @type subscriptionIdentifier: C{unicode}
952 """ 953 """
953 request = PubSubRequest('unsubscribe') 954 request = self._request_class('unsubscribe')
954 request.recipient = service 955 request.recipient = service
955 request.nodeIdentifier = nodeIdentifier 956 request.nodeIdentifier = nodeIdentifier
956 request.subscriber = subscriber 957 request.subscriber = subscriber
957 request.subscriptionIdentifier = subscriptionIdentifier 958 request.subscriptionIdentifier = subscriptionIdentifier
958 request.sender = sender 959 request.sender = sender
968 @param nodeIdentifier: The identifier of the node. 969 @param nodeIdentifier: The identifier of the node.
969 @type nodeIdentifier: C{unicode} 970 @type nodeIdentifier: C{unicode}
970 @param items: Optional list of L{Item}s to publish. 971 @param items: Optional list of L{Item}s to publish.
971 @type items: C{list} 972 @type items: C{list}
972 """ 973 """
973 request = PubSubRequest('publish') 974 request = self._request_class('publish')
974 request.recipient = service 975 request.recipient = service
975 request.nodeIdentifier = nodeIdentifier 976 request.nodeIdentifier = nodeIdentifier
976 request.items = items 977 request.items = items
977 request.sender = sender 978 request.sender = sender
978 return request.send(self.xmlstream) 979 return request.send(self.xmlstream)
998 @param subscriptionIdentifier: Optional subscription identifier. In 999 @param subscriptionIdentifier: Optional subscription identifier. In
999 case the node has been subscribed to multiple times, this narrows 1000 case the node has been subscribed to multiple times, this narrows
1000 the results to the specific subscription. 1001 the results to the specific subscription.
1001 @type subscriptionIdentifier: C{unicode} 1002 @type subscriptionIdentifier: C{unicode}
1002 """ 1003 """
1003 request = PubSubRequest('items') 1004 request = self._request_class('items')
1004 request.recipient = service 1005 request.recipient = service
1005 request.nodeIdentifier = nodeIdentifier 1006 request.nodeIdentifier = nodeIdentifier
1006 if maxItems: 1007 if maxItems:
1007 request.maxItems = str(int(maxItems)) 1008 request.maxItems = str(int(maxItems))
1008 request.subscriptionIdentifier = subscriptionIdentifier 1009 request.subscriptionIdentifier = subscriptionIdentifier
1031 @param itemIdentifiers: Identifiers of the items to be retracted. 1032 @param itemIdentifiers: Identifiers of the items to be retracted.
1032 @type itemIdentifiers: C{set} 1033 @type itemIdentifiers: C{set}
1033 @param notify: True if notification is required 1034 @param notify: True if notification is required
1034 @type notify: C{unicode} 1035 @type notify: C{unicode}
1035 """ 1036 """
1036 request = PubSubRequest('retract') 1037 request = self._request_class('retract')
1037 request.recipient = service 1038 request.recipient = service
1038 request.nodeIdentifier = nodeIdentifier 1039 request.nodeIdentifier = nodeIdentifier
1039 request.itemIdentifiers = itemIdentifiers 1040 request.itemIdentifiers = itemIdentifiers
1040 request.notify = notify 1041 request.notify = notify
1041 request.sender = sender 1042 request.sender = sender
1058 @param subscriptionIdentifier: Optional subscription identifier. 1059 @param subscriptionIdentifier: Optional subscription identifier.
1059 @type subscriptionIdentifier: C{unicode} 1060 @type subscriptionIdentifier: C{unicode}
1060 1061
1061 @rtype: L{data_form.Form} 1062 @rtype: L{data_form.Form}
1062 """ 1063 """
1063 request = PubSubRequest('optionsGet') 1064 request = self._request_class('optionsGet')
1064 request.recipient = service 1065 request.recipient = service
1065 request.nodeIdentifier = nodeIdentifier 1066 request.nodeIdentifier = nodeIdentifier
1066 request.subscriber = subscriber 1067 request.subscriber = subscriber
1067 request.subscriptionIdentifier = subscriptionIdentifier 1068 request.subscriptionIdentifier = subscriptionIdentifier
1068 request.sender = sender 1069 request.sender = sender
1096 @type options: C{dict}. 1097 @type options: C{dict}.
1097 1098
1098 @param subscriptionIdentifier: Optional subscription identifier. 1099 @param subscriptionIdentifier: Optional subscription identifier.
1099 @type subscriptionIdentifier: C{unicode} 1100 @type subscriptionIdentifier: C{unicode}
1100 """ 1101 """
1101 request = PubSubRequest('optionsSet') 1102 request = self._request_class('optionsSet')
1102 request.recipient = service 1103 request.recipient = service
1103 request.nodeIdentifier = nodeIdentifier 1104 request.nodeIdentifier = nodeIdentifier
1104 request.subscriber = subscriber 1105 request.subscriber = subscriber
1105 request.subscriptionIdentifier = subscriptionIdentifier 1106 request.subscriptionIdentifier = subscriptionIdentifier
1106 request.sender = sender 1107 request.sender = sender
1216 1217
1217 return 1218 return
1218 1219
1219 info = [] 1220 info = []
1220 1221
1221 request = PubSubRequest('discoInfo') 1222 request = self._request_class('discoInfo')
1222 1223
1223 if self.resource is not None: 1224 if self.resource is not None:
1224 resource = self.resource.locateResource(request) 1225 resource = self.resource.locateResource(request)
1225 identity = resource.discoIdentity 1226 identity = resource.discoIdentity
1226 features = resource.features 1227 features = resource.features
1248 1249
1249 def getDiscoItems(self, requestor, target, nodeIdentifier=''): 1250 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
1250 if self.hideNodes: 1251 if self.hideNodes:
1251 d = defer.succeed([]) 1252 d = defer.succeed([])
1252 elif self.resource is not None: 1253 elif self.resource is not None:
1253 request = PubSubRequest('discoInfo') 1254 request = self._request_class('discoInfo')
1254 resource = self.resource.locateResource(request) 1255 resource = self.resource.locateResource(request)
1255 d = resource.getNodes(requestor, target, nodeIdentifier) 1256 d = resource.getNodes(requestor, target, nodeIdentifier)
1256 elif nodeIdentifier: 1257 elif nodeIdentifier:
1257 d = self.getNodes(requestor, target) 1258 d = self.getNodes(requestor, target)
1258 else: 1259 else: