Changeset 13:42b22edb29bb in ralphm-patches


Ignore:
Timestamp:
Apr 22, 2009, 4:20:10 PM (12 years ago)
Author:
Ralph Meijer <ralphm@…>
Branch:
default
Message:

Make these backwards compatible.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pubsub_request.patch

    r7 r13  
    1111that is passed to the corresponding handler methods.
    1212
    13 diff -r 556fc011f965 wokkel/generic.py
    14 --- a/wokkel/generic.py Tue Apr 07 11:16:01 2009 +0200
    15 +++ b/wokkel/generic.py Tue Apr 07 11:17:21 2009 +0200
     13diff -r e35e291de060 wokkel/generic.py
     14--- a/wokkel/generic.py Wed Apr 22 01:48:41 2009 -0700
     15+++ b/wokkel/generic.py Wed Apr 22 14:48:14 2009 +0200
    1616@@ -10,7 +10,7 @@
    1717 from zope.interface import implements
     
    6161     protocol = xmlstream.XmlStream
    6262 
    63 diff -r 556fc011f965 wokkel/iwokkel.py
    64 --- a/wokkel/iwokkel.py Tue Apr 07 11:16:01 2009 +0200
    65 +++ b/wokkel/iwokkel.py Tue Apr 07 11:17:21 2009 +0200
    66 @@ -278,6 +278,7 @@
    67                               C{list} of L{domish.Element})
    68          """
    69  
    70 +
    71      def notifyDelete(service, nodeIdentifier, subscribers,
    72                       redirectURI=None):
    73          """
    74 @@ -295,77 +296,60 @@
    75          @type redirectURI: C{str}
    76          """
    77  
    78 -    def publish(requestor, service, nodeIdentifier, items):
    79 +
    80 +    def publish(request):
    81          """
    82          Called when a publish request has been received.
    83  
    84 -        @param requestor: The entity the request originated from.
    85 -        @type requestor: L{jid.JID}
    86 -        @param service: The entity the request was addressed to.
    87 -        @type service: L{jid.JID}
    88 -        @param nodeIdentifier: The identifier of the node to publish to.
    89 -        @type nodeIdentifier: C{unicode}
    90 -        @param items: The items to be published as L{domish} elements.
    91 -        @type items: C{list} of C{domish.Element}
    92 +        @param request: The publish-subscribe request.
    93 +        @type request: L{wokkel.pubsub.PubSubRequest}
    94          @return: deferred that fires on success.
    95          @rtype: L{defer.Deferred}
    96          """
    97  
    98 -    def subscribe(requestor, service, nodeIdentifier, subscriber):
    99 +
    100 +    def subscribe(request):
    101          """
    102          Called when a subscribe request has been received.
    103  
    104 -        @param requestor: The entity the request originated from.
    105 -        @type requestor: L{jid.JID}
    106 -        @param service: The entity the request was addressed to.
    107 -        @type service: L{jid.JID}
    108 -        @param nodeIdentifier: The identifier of the node to subscribe to.
    109 -        @type nodeIdentifier: C{unicode}
    110 -        @param subscriber: The entity to be subscribed.
    111 -        @type subscriber: L{jid.JID}
    112 +        @param request: The publish-subscribe request.
    113 +        @type request: L{wokkel.pubsub.PubSubRequest}
    114          @return: A deferred that fires with a
    115                   L{Subscription<wokkel.pubsub.Subscription>}.
    116          @rtype: L{defer.Deferred}
    117          """
    118  
    119 -    def unsubscribe(requestor, service, nodeIdentifier, subscriber):
    120 +
    121 +    def unsubscribe(request):
    122          """
    123          Called when a subscribe request has been received.
    124  
    125 -        @param requestor: The entity the request originated from.
    126 -        @type requestor: L{jid.JID}
    127 -        @param service: The entity the request was addressed to.
    128 -        @type service: L{jid.JID}
    129 -        @param nodeIdentifier: The identifier of the node to unsubscribe from.
    130 -        @type nodeIdentifier: C{unicode}
    131 -        @param subscriber: The entity to be unsubscribed.
    132 -        @type subscriber: L{jid.JID}
    133 +        @param request: The publish-subscribe request.
    134 +        @type request: L{wokkel.pubsub.PubSubRequest}
    135          @return: A deferred that fires with C{None} when unsubscription has
    136                   succeeded.
    137          @rtype: L{defer.Deferred}
    138          """
    139  
    140 -    def subscriptions(requestor, service):
    141 +
    142 +    def subscriptions(request):
    143          """
    144          Called when a subscriptions retrieval request has been received.
    145  
    146 -        @param requestor: The entity the request originated from.
    147 -        @type requestor: L{jid.JID}
    148 -        @param service: The entity the request was addressed to.
    149 -        @type service: L{jid.JID}
    150 +        @param request: The publish-subscribe request.
    151 +        @type request: L{wokkel.pubsub.PubSubRequest}
    152          @return: A deferred that fires with a C{list} of subscriptions as
    153                   L{Subscription<wokkel.pubsub.Subscription>}.
    154          @rtype: L{defer.Deferred}
    155          """
    156  
    157 -    def affiliations(requestor, service):
    158 +
    159 +    def affiliations(request):
    160          """
    161          Called when a affiliations retrieval request has been received.
    162  
    163 -        @param requestor: The entity the request originated from.
    164 -        @type requestor: L{jid.JID}
    165 -        @param service: The entity the request was addressed to.
    166 -        @type service: L{jid.JID}
    167 +        @param request: The publish-subscribe request.
    168 +        @type request: L{wokkel.pubsub.PubSubRequest}
    169          @return: A deferred that fires with a C{list} of affiliations as
    170                   C{tuple}s of (node identifier as C{unicode}, affiliation state
    171                   as C{str}). The affiliation can be C{'owner'}, C{'publisher'},
    172 @@ -373,24 +357,19 @@
    173          @rtype: L{defer.Deferred}
    174          """
    175  
    176 -    def create(requestor, service, nodeIdentifier):
    177 +
    178 +    def create(request):
    179          """
    180          Called when a node creation request has been received.
    181  
    182 -        @param requestor: The entity the request originated from.
    183 -        @type requestor: L{jid.JID}
    184 -        @param service: The entity the request was addressed to.
    185 -        @type service: L{jid.JID}
    186 -        @param nodeIdentifier: The suggestion for the identifier of the node to
    187 -                               be created. If the request did not include a
    188 -                               suggestion for the node identifier, the value
    189 -                               is C{None}.
    190 -        @type nodeIdentifier: C{unicode} or C{NoneType}
    191 +        @param request: The publish-subscribe request.
    192 +        @type request: L{wokkel.pubsub.PubSubRequest}
    193          @return: A deferred that fires with a C{unicode} that represents
    194                   the identifier of the new node.
    195          @rtype: L{defer.Deferred}
    196          """
    197  
    198 +
    199      def getConfigurationOptions():
    200          """
    201          Retrieve all known node configuration options.
    202 @@ -426,17 +405,13 @@
    203          @rtype: C{dict}.
    204          """
    205  
    206 -    def getDefaultConfiguration(requestor, service, nodeType):
    207 +
    208 +    def getDefaultConfiguration(request):
    209          """
    210          Called when a default node configuration request has been received.
    211  
    212 -        @param requestor: The entity the request originated from.
    213 -        @type requestor: L{jid.JID}
    214 -        @param service: The entity the request was addressed to.
    215 -        @type service: L{jid.JID}
    216 -        @param nodeType: The type of node for which the configuration is
    217 -                         retrieved, C{'leaf'} or C{'collection'}.
    218 -        @type nodeType: C{str}
    219 +        @param request: The publish-subscribe request.
    220 +        @type request: L{wokkel.pubsub.PubSubRequest}
    221          @return: A deferred that fires with a C{dict} representing the default
    222                   node configuration. Keys are C{str}s that represent the
    223                   field name. Values can be of types C{unicode}, C{int} or
    224 @@ -444,85 +419,74 @@
    225          @rtype: L{defer.Deferred}
    226          """
    227  
    228 -    def getConfiguration(requestor, service, nodeIdentifier):
    229 +
    230 +    def getConfiguration(request):
    231          """
    232          Called when a node configuration retrieval request has been received.
    233  
    234 -        @param requestor: The entity the request originated from.
    235 -        @type requestor: L{jid.JID}
    236 -        @param service: The entity the request was addressed to.
    237 -        @type service: L{jid.JID}
    238 -        @param nodeIdentifier: The identifier of the node to retrieve the
    239 -                               configuration from.
    240 -        @type nodeIdentifier: C{unicode}
    241 +        @param request: The publish-subscribe request.
    242 +        @type request: L{wokkel.pubsub.PubSubRequest}
    243          @return: A deferred that fires with a C{dict} representing the node
    244                   configuration. Keys are C{str}s that represent the field name.
    245                   Values can be of types C{unicode}, C{int} or C{bool}.
    246          @rtype: L{defer.Deferred}
    247          """
    248  
    249 -    def setConfiguration(requestor, service, nodeIdentifier, options):
    250 +
    251 +    def setConfiguration(request):
    252          """
    253          Called when a node configuration change request has been received.
    254  
    255 -        @param requestor: The entity the request originated from.
    256 -        @type requestor: L{jid.JID}
    257 -        @param service: The entity the request was addressed to.
    258 -        @type service: L{jid.JID}
    259 -        @param nodeIdentifier: The identifier of the node to change the
    260 -                               configuration of.
    261 -        @type nodeIdentifier: C{unicode}
    262 +        @param request: The publish-subscribe request.
    263 +        @type request: L{wokkel.pubsub.PubSubRequest}
    264          @return: A deferred that fires with C{None} when the node's
    265                   configuration has been changed.
    266          @rtype: L{defer.Deferred}
    267          """
    268  
    269 -    def items(requestor, service, nodeIdentifier, maxItems, itemIdentifiers):
    270 +
    271 +    def items(request):
    272          """
    273          Called when a items retrieval request has been received.
    274  
    275 -        @param requestor: The entity the request originated from.
    276 -        @type requestor: L{jid.JID}
    277 -        @param service: The entity the request was addressed to.
    278 -        @type service: L{jid.JID}
    279 -        @param nodeIdentifier: The identifier of the node to retrieve items
    280 -                               from.
    281 -        @type nodeIdentifier: C{unicode}
    282 +        @param request: The publish-subscribe request.
    283 +        @type request: L{wokkel.pubsub.PubSubRequest}
    284 +        @return: A deferred that fires with a C{list} of L{pubsub.Item}.
    285 +        @rtype: L{defer.Deferred}
    286          """
    287  
    288 -    def retract(requestor, service, nodeIdentifier, itemIdentifiers):
    289 +
    290 +    def retract(request):
    291          """
    292          Called when a item retraction request has been received.
    293  
    294 -        @param requestor: The entity the request originated from.
    295 -        @type requestor: L{jid.JID}
    296 -        @param service: The entity the request was addressed to.
    297 -        @type service: L{jid.JID}
    298 -        @param nodeIdentifier: The identifier of the node to retract items
    299 -                               from.
    300 -        @type nodeIdentifier: C{unicode}
    301 +        @param request: The publish-subscribe request.
    302 +        @type request: L{wokkel.pubsub.PubSubRequest}
    303 +        @return: A deferred that fires with C{None} when the given items have
    304 +                 been retracted.
    305 +        @rtype: L{defer.Deferred}
    306          """
    307  
    308 -    def purge(requestor, service, nodeIdentifier):
    309 +
    310 +    def purge(request):
    311          """
    312          Called when a node purge request has been received.
    313  
    314 -        @param requestor: The entity the request originated from.
    315 -        @type requestor: L{jid.JID}
    316 -        @param service: The entity the request was addressed to.
    317 -        @type service: L{jid.JID}
    318 -        @param nodeIdentifier: The identifier of the node to be purged.
    319 -        @type nodeIdentifier: C{unicode}
    320 +        @param request: The publish-subscribe request.
    321 +        @type request: L{wokkel.pubsub.PubSubRequest}
    322 +        @return: A deferred that fires with C{None} when the node has been
    323 +                 purged.
    324 +        @rtype: L{defer.Deferred}
    325          """
    326  
    327 -    def delete(requestor, service, nodeIdentifier):
    328 +
    329 +    def delete(request):
    330          """
    331          Called when a node deletion request has been received.
    332  
    333 -        @param requestor: The entity the request originated from.
    334 -        @type requestor: L{jid.JID}
    335 -        @param service: The entity the request was addressed to.
    336 -        @type service: L{jid.JID}
    337 -        @param nodeIdentifier: The identifier of the node to be delete.
    338 -        @type nodeIdentifier: C{unicode}
    339 +        @param request: The publish-subscribe request.
    340 +        @type request: L{wokkel.pubsub.PubSubRequest}
    341 +        @return: A deferred that fires with C{None} when the node has been
    342 +                 deleted.
    343 +        @rtype: L{defer.Deferred}
    344          """
    345 diff -r 556fc011f965 wokkel/pubsub.py
    346 --- a/wokkel/pubsub.py  Tue Apr 07 11:16:01 2009 +0200
    347 +++ b/wokkel/pubsub.py  Tue Apr 07 11:17:21 2009 +0200
     63diff -r e35e291de060 wokkel/pubsub.py
     64--- a/wokkel/pubsub.py  Wed Apr 22 01:48:41 2009 -0700
     65+++ b/wokkel/pubsub.py  Wed Apr 22 14:48:14 2009 +0200
    34866@@ -16,7 +16,7 @@
    34967 from twisted.words.protocols.jabber import jid, error, xmlstream
     
    981699 
    982700     def getDiscoInfo(self, requestor, target, nodeIdentifier):
    983 @@ -585,92 +862,17 @@
     701@@ -585,92 +862,18 @@
    984702         return d
    985703 
     
    1003721-                continue
    1004722+    def _on_publish(self, request):
    1005 +        return self.publish(request)
     723+        return self.publish(request.sender, request.recipient,
     724+                            request.nodeIdentifier, request.items)
    1006725 
    1007726-        return form
     
    1081800         def toResponse(result):
    1082801             response = domish.Element((NS_PUBSUB, "pubsub"))
    1083 @@ -681,28 +883,24 @@
     802@@ -681,28 +884,26 @@
    1084803             subscription["subscription"] = result.state
    1085804             return response
    1086805 
    1087806-        d = self.subscribe(requestor, service, nodeIdentifier, subscriber)
    1088 +        d = self.subscribe(request)
     807+        d = self.subscribe(request.sender, request.recipient,
     808+                           request.nodeIdentifier, request.subscriber)
    1089809         d.addCallback(toResponse)
    1090810         return d
     
    1095815-                iq, 'unsubscribe', 'nodeOrEmpty', 'jid')
    1096816+    def _on_unsubscribe(self, request):
    1097 +        return self.unsubscribe(request)
     817+        return self.unsubscribe(request.sender, request.recipient,
     818+                                request.nodeIdentifier, request.subscriber)
    1098819 
    1099820-        return self.unsubscribe(requestor, service, nodeIdentifier, subscriber)
     
    1116837         def toResponse(result):
    1117838             response = domish.Element((NS_PUBSUB, 'pubsub'))
    1118 @@ -714,13 +912,12 @@
     839@@ -714,13 +915,12 @@
    1119840                 item['subscription'] = subscription.state
    1120841             return response
    1121842 
    1122843-        d = self.subscriptions(requestor, service)
    1123 +        d = self.subscriptions(request)
     844+        d = self.subscriptions(request.sender, request.recipient)
    1124845         d.addCallback(toResponse)
    1125846         return d
     
    1132853         def toResponse(result):
    1133854             response = domish.Element((NS_PUBSUB, 'pubsub'))
    1134 @@ -733,17 +930,15 @@
     855@@ -733,17 +933,15 @@
    1135856 
    1136857             return response
    1137858 
    1138859-        d = self.affiliations(requestor, service)
    1139 +        d = self.affiliations(request)
     860+        d = self.affiliations(request.sender, request.recipient)
    1140861         d.addCallback(toResponse)
    1141862         return d
     
    1153874                 create = response.addElement('create')
    1154875                 create['node'] = result
    1155 @@ -751,7 +946,7 @@
     876@@ -751,7 +949,8 @@
    1156877             else:
    1157878                 return None
    1158879 
    1159880-        d = self.create(requestor, service, nodeIdentifier)
    1160 +        d = self.create(request)
     881+        d = self.create(request.sender, request.recipient,
     882+                        request.nodeIdentifier)
    1161883         d.addCallback(toResponse)
    1162884         return d
    1163885 
    1164 @@ -771,6 +966,7 @@
     886@@ -771,6 +970,7 @@
    1165887             fields.append(data_form.Field.fromDict(option))
    1166888         return fields
     
    1170892         options = self.getConfigurationOptions()
    1171893         fields = self._makeFields(options, values)
    1172 @@ -780,6 +976,7 @@
     894@@ -780,6 +980,7 @@
    1173895 
    1174896         return form
     
    1178900         options = self.getConfigurationOptions()
    1179901         processedValues = {}
    1180 @@ -805,8 +1002,7 @@
     902@@ -805,8 +1006,7 @@
    1181903         return processedValues
    1182904 
     
    1188910         def toResponse(options):
    1189911             response = domish.Element((NS_PUBSUB_OWNER, "pubsub"))
    1190 @@ -814,127 +1010,82 @@
     912@@ -814,127 +1014,91 @@
    1191913             default.addChild(self._formFromConfiguration(options).toElement())
    1192914             return response
     
    1201923 
    1202924-        d = self.getDefaultConfiguration(requestor, service, nodeType)
    1203 +        d = self.getDefaultConfiguration(request)
     925+        d = self.getDefaultConfiguration(request.sender, request.recipient,
     926+                                         request.nodeType)
    1204927         d.addCallback(toResponse)
    1205928         return d
     
    1226949 
    1227950-        d = self.getConfiguration(requestor, service, nodeIdentifier)
    1228 +        d = self.getConfiguration(request)
     951+        d = self.getConfiguration(request.sender, request.recipient,
     952+                                  request.nodeIdentifier)
    1229953         d.addCallback(toResponse)
    1230954         return d
     
    1237961+        if request.options:
    1238962+            request.options = self._checkConfiguration(request.options)
    1239 +            return self.setConfiguration(request)
     963+            return self.setConfiguration(request.sender, request.recipient,
     964+                                         request.nodeIdentifier,
     965+                                         request.options)
    1240966+        else:
    1241967+            return None
     
    12841010-        d = self.items(requestor, service, nodeIdentifier, maxItems,
    12851011-                       itemIdentifiers)
    1286 +        d = self.items(request)
     1012+        d = self.items(request.sender, request.recipient,
     1013+                       request.nodeIdentifier, request.maxItems,
     1014+                       request.itemIdentifiers)
    12871015         d.addCallback(toResponse)
    12881016         return d
     
    12931021-                iq, 'retract', 'node')
    12941022+    def _on_retract(self, request):
    1295 +        return self.retract(request)
     1023+        return self.retract(request.sender, request.recipient,
     1024+                            request.nodeIdentifier, request.itemIdentifiers)
    12961025 
    12971026-        itemIdentifiers = []
     
    13061035-                            itemIdentifiers)
    13071036+    def _on_purge(self, request):
    1308 +        return self.purge(request)
     1037+        return self.purge(request.sender, request.recipient,
     1038+                          request.nodeIdentifier)
    13091039 
    13101040 
     
    13141044-        return self.purge(requestor, service, nodeIdentifier)
    13151045+    def _on_delete(self, request):
    1316 +        return self.delete(request)
     1046+        return self.delete(request.sender, request.recipient,
     1047+                           request.nodeIdentifier)
    13171048 
    13181049 
     
    13431074 
    13441075     # public methods
    1345 @@ -990,27 +1141,27 @@
    1346          return []
    1347  
    1348  
    1349 -    def publish(self, requestor, service, nodeIdentifier, items):
    1350 +    def publish(self, request):
    1351          raise Unsupported('publish')
    1352  
    1353  
    1354 -    def subscribe(self, requestor, service, nodeIdentifier, subscriber):
    1355 +    def subscribe(self, request):
    1356          raise Unsupported('subscribe')
    1357  
    1358  
    1359 -    def unsubscribe(self, requestor, service, nodeIdentifier, subscriber):
    1360 +    def unsubscribe(self, request):
    1361          raise Unsupported('subscribe')
    1362  
    1363  
    1364 -    def subscriptions(self, requestor, service):
    1365 +    def subscriptions(self, request):
    1366          raise Unsupported('retrieve-subscriptions')
    1367  
    1368  
    1369 -    def affiliations(self, requestor, service):
    1370 +    def affiliations(self, request):
    1371          raise Unsupported('retrieve-affiliations')
    1372  
    1373  
    1374 -    def create(self, requestor, service, nodeIdentifier):
    1375 +    def create(self, request):
    1376          raise Unsupported('create-nodes')
    1377  
    1378  
    1379 @@ -1018,30 +1169,29 @@
    1380          return {}
    1381  
    1382  
    1383 -    def getDefaultConfiguration(self, requestor, service, nodeType):
    1384 +    def getDefaultConfiguration(self, request):
    1385          raise Unsupported('retrieve-default')
    1386  
    1387  
    1388 -    def getConfiguration(self, requestor, service, nodeIdentifier):
    1389 +    def getConfiguration(self, request):
    1390          raise Unsupported('config-node')
    1391  
    1392  
    1393 -    def setConfiguration(self, requestor, service, nodeIdentifier, options):
    1394 +    def setConfiguration(self, request):
    1395          raise Unsupported('config-node')
    1396  
    1397  
    1398 -    def items(self, requestor, service, nodeIdentifier, maxItems,
    1399 -                    itemIdentifiers):
    1400 +    def items(self, request):
    1401          raise Unsupported('retrieve-items')
    1402  
    1403  
    1404 -    def retract(self, requestor, service, nodeIdentifier, itemIdentifiers):
    1405 +    def retract(self, request):
    1406          raise Unsupported('retract-items')
    1407  
    1408  
    1409 -    def purge(self, requestor, service, nodeIdentifier):
    1410 +    def purge(self, request):
    1411          raise Unsupported('purge-nodes')
    1412  
    1413  
    1414 -    def delete(self, requestor, service, nodeIdentifier):
    1415 +    def delete(self, request):
    1416          raise Unsupported('delete-nodes')
    1417 diff -r 556fc011f965 wokkel/test/test_pubsub.py
    1418 --- a/wokkel/test/test_pubsub.py        Tue Apr 07 11:16:01 2009 +0200
    1419 +++ b/wokkel/test/test_pubsub.py        Tue Apr 07 11:17:21 2009 +0200
     1076diff -r e35e291de060 wokkel/test/test_pubsub.py
     1077--- a/wokkel/test/test_pubsub.py        Wed Apr 22 01:48:41 2009 -0700
     1078+++ b/wokkel/test/test_pubsub.py        Wed Apr 22 14:48:14 2009 +0200
    14201079@@ -15,6 +15,7 @@
    14211080 from twisted.words.protocols.jabber.xmlstream import toResponse
     
    21161775         """
    21171776         A publish request should result in L{PubSubService.publish} being
    2118 @@ -606,27 +1232,147 @@
    2119          </iq>
     1777@@ -607,26 +1233,146 @@
    21201778         """
    21211779 
    2122 -        def publish(requestor, service, nodeIdentifier, items):
     1780         def publish(requestor, service, nodeIdentifier, items):
    21231781-            self.assertEqual(JID('user@example.org'), requestor)
    21241782-            self.assertEqual(JID('pubsub.example.org'), service)
    21251783-            self.assertEqual('test', nodeIdentifier)
    21261784-            self.assertEqual([], items)
    2127 +        def publish(request):
    21281785             return defer.succeed(None)
    21291786 
     
    21471804+        """
    21481805+
    2149 +        def subscribe(request):
    2150 +            return defer.succeed(pubsub.Subscription(request.nodeIdentifier,
    2151 +                                                     request.subscriber,
     1806+        def subscribe(requestor, service, nodeIdentifier, subscriber):
     1807+            return defer.succeed(pubsub.Subscription(nodeIdentifier,
     1808+                                                     subscriber,
    21521809+                                                     'subscribed'))
    21531810+
     
    21821839+        """
    21831840+
    2184 +        def subscribe(request):
    2185 +            return defer.succeed(pubsub.Subscription(request.nodeIdentifier,
    2186 +                                                     request.subscriber,
     1841+        def subscribe(requestor, service, nodeIdentifier, subscriber):
     1842+            return defer.succeed(pubsub.Subscription(nodeIdentifier,
     1843+                                                     subscriber,
    21871844+                                                     'subscribed'))
    21881845+
     
    22111868+        """
    22121869+
    2213 +        def unsubscribe(request):
     1870+        def unsubscribe(requestor, service, nodeIdentifier, subscriber):
    22141871+            return defer.succeed(None)
    22151872+
     
    22711928         </iq>
    22721929         """
    2273 @@ -672,14 +1418,141 @@
    2274              self.assertEqual('subscribed', subscription['subscription'])
    2275  
    2276  
    2277 -        def subscriptions(requestor, service):
     1930@@ -673,13 +1419,140 @@
     1931 
     1932 
     1933         def subscriptions(requestor, service):
    22781934-            self.assertEqual(JID('user@example.org'), requestor)
    22791935-            self.assertEqual(JID('pubsub.example.org'), service)
    2280 +        def subscriptions(request):
    22811936             subscription = pubsub.Subscription('test', JID('user@example.org'),
    22821937                                                'subscribed')
     
    23191974+
    23201975+
    2321 +        def affiliations(request):
     1976+        def affiliations(requestor, service):
    23221977+            affiliation = ('test', 'owner')
    23231978+            return defer.succeed([affiliation])
     
    23441999+        """
    23452000+
    2346 +        def create(request):
    2347 +            return defer.succeed(request.nodeIdentifier)
     2001+        def create(requestor, service, nodeIdentifier):
     2002+            return defer.succeed(nodeIdentifier)
    23482003+
    23492004+        def cb(element):
     
    23712026+        """
    23722027+
    2373 +        def create(request):
     2028+        def create(requestor, service, nodeIdentifier):
    23742029+            return defer.succeed(u'myrenamednode')
    23752030+
     
    24022057+        """
    24032058+
    2404 +        def create(request):
     2059+        def create(requestor, service, nodeIdentifier):
    24052060+            return defer.succeed(u'random')
    24062061+
     
    24162071         d.addCallback(cb)
    24172072         return d
    2418 @@ -710,10 +1583,7 @@
    2419                       "label": "Deliver payloads with event notifications"}
     2073@@ -711,9 +1584,6 @@
    24202074                 }
    24212075 
    2422 -        def getDefaultConfiguration(requestor, service, nodeType):
     2076         def getDefaultConfiguration(requestor, service, nodeType):
    24232077-            self.assertEqual(JID('user@example.org'), requestor)
    24242078-            self.assertEqual(JID('pubsub.example.org'), service)
    24252079-            self.assertEqual('leaf', nodeType)
    2426 +        def getDefaultConfiguration(request):
    24272080             return defer.succeed({})
    24282081 
     
    24632116+                }
    24642117+
    2465 +        def getDefaultConfiguration(request):
     2118+        def getDefaultConfiguration(requestor, service, nodeType):
    24662119+            return defer.succeed({})
    24672120+
     
    24972150+        """
    24982151+
    2499 +        def getDefaultConfiguration(request):
     2152+        def getDefaultConfiguration(requestor, service, nodeType):
    25002153+            self.fail("Unexpected call to getConfiguration")
    25012154+
     
    25142167         """
    25152168         On a node configuration get request L{PubSubService.getConfiguration}
    2516 @@ -759,14 +1708,11 @@
    2517                       "label": "Owner of the node"}
     2169@@ -760,13 +1709,10 @@
    25182170                 }
    25192171 
    2520 -        def getConfiguration(requestor, service, nodeIdentifier):
     2172         def getConfiguration(requestor, service, nodeIdentifier):
    25212173-            self.assertEqual(JID('user@example.org'), requestor)
    25222174-            self.assertEqual(JID('pubsub.example.org'), service)
    25232175-            self.assertEqual('test', nodeIdentifier)
    25242176-
    2525 +        def getConfiguration(request):
    25262177             return defer.succeed({'pubsub#deliver_payloads': '0',
    25272178                                   'pubsub#persist_items': '1',
     
    25452196         d.addCallback(cb)
    25462197         return d
    2547 @@ -834,16 +1784,14 @@
    2548                       "label": "Deliver payloads with event notifications"}
     2198@@ -835,15 +1785,13 @@
    25492199                 }
    25502200 
    2551 -        def setConfiguration(requestor, service, nodeIdentifier, options):
     2201         def setConfiguration(requestor, service, nodeIdentifier, options):
    25522202-            self.assertEqual(JID('user@example.org'), requestor)
    25532203-            self.assertEqual(JID('pubsub.example.org'), service)
    25542204-            self.assertEqual('test', nodeIdentifier)
    2555 +        def setConfiguration(request):
    25562205             self.assertEqual({'pubsub#deliver_payloads': False,
    2557 -                              'pubsub#persist_items': True}, options)
    2558 +                              'pubsub#persist_items': True}, request.options)
     2206                               'pubsub#persist_items': True}, options)
    25592207             return defer.succeed(None)
    25602208 
     
    25652213 
    25662214 
    2567 @@ -868,10 +1816,11 @@
    2568          </iq>
    2569          """
    2570  
    2571 -        def setConfiguration(requestor, service, nodeIdentifier, options):
    2572 +        def setConfiguration(request):
     2215@@ -872,6 +1820,7 @@
    25732216             self.fail("Unexpected call to setConfiguration")
    25742217 
     
    25782221 
    25792222 
    2580 @@ -907,14 +1856,47 @@
    2581                       "label": "Deliver payloads with event notifications"}
    2582                  }
    2583  
    2584 -        def setConfiguration(requestor, service, nodeIdentifier, options):
    2585 -            self.assertEquals(['pubsub#deliver_payloads'], options.keys())
    2586 +        def setConfiguration(request):
    2587 +            self.assertEquals(['pubsub#deliver_payloads'],
    2588 +                              request.options.keys())
     2223@@ -912,9 +1861,41 @@
    25892224 
    25902225         self.service.getConfigurationOptions = getConfigurationOptions
     
    26282263         """
    26292264         On a items request, return all items for the given node.
    2630 @@ -928,12 +1910,7 @@
     2265@@ -928,12 +1909,8 @@
    26312266         </iq>
    26322267         """
     
    26382273-            self.assertIdentical(None, maxItems)
    26392274-            self.assertEqual([], items)
    2640 +        def items(request):
     2275+        def items(requestor, service, nodeIdentifier, maxItems,
     2276+                  itemIdentifiers):
    26412277             return defer.succeed([pubsub.Item('current')])
    26422278 
    26432279         def cb(element):
    2644 @@ -970,11 +1947,7 @@
    2645          </iq>
     2280@@ -971,10 +1948,6 @@
    26462281         """
    26472282 
    2648 -        def retract(requestor, service, nodeIdentifier, itemIdentifiers):
     2283         def retract(requestor, service, nodeIdentifier, itemIdentifiers):
    26492284-            self.assertEqual(JID('user@example.org'), requestor)
    26502285-            self.assertEqual(JID('pubsub.example.org'), service)
    26512286-            self.assertEqual('test', nodeIdentifier)
    26522287-            self.assertEqual(['item1', 'item2'], itemIdentifiers)
    2653 +        def retract(request):
    26542288             return defer.succeed(None)
    26552289 
    26562290         self.service.retract = retract
    2657 @@ -996,10 +1969,7 @@
    2658          </iq>
     2291@@ -997,9 +1970,6 @@
    26592292         """
    26602293 
    2661 -        def purge(requestor, service, nodeIdentifier):
     2294         def purge(requestor, service, nodeIdentifier):
    26622295-            self.assertEqual(JID('user@example.org'), requestor)
    26632296-            self.assertEqual(JID('pubsub.example.org'), service)
    26642297-            self.assertEqual('test', nodeIdentifier)
    2665 +        def purge(request):
    26662298             return defer.succeed(None)
    26672299 
    26682300         self.service.purge = purge
    2669 @@ -1021,10 +1991,7 @@
    2670          </iq>
     2301@@ -1022,9 +1992,6 @@
    26712302         """
    26722303 
    2673 -        def delete(requestor, service, nodeIdentifier):
     2304         def delete(requestor, service, nodeIdentifier):
    26742305-            self.assertEqual(JID('user@example.org'), requestor)
    26752306-            self.assertEqual(JID('pubsub.example.org'), service)
    26762307-            self.assertEqual('test', nodeIdentifier)
    2677 +        def delete(request):
    26782308             return defer.succeed(None)
    26792309 
  • pubsub_resource.patch

    r12 r13  
    1 diff -r ce121b9d0797 wokkel/iwokkel.py
    2 --- a/wokkel/iwokkel.py Fri Apr 10 15:36:22 2009 +0200
    3 +++ b/wokkel/iwokkel.py Fri Apr 10 17:31:54 2009 +0200
    4 @@ -297,75 +297,46 @@
    5          """
    6  
    7  
    8 -    def publish(request):
     1diff -r 29f67459352b wokkel/iwokkel.py
     2--- a/wokkel/iwokkel.py Wed Apr 22 14:48:20 2009 +0200
     3+++ b/wokkel/iwokkel.py Wed Apr 22 16:14:56 2009 +0200
     4@@ -278,6 +278,7 @@
     5                              C{list} of L{domish.Element})
     6         """
     7 
     8+
     9     def notifyDelete(service, nodeIdentifier, subscribers,
     10                      redirectURI=None):
     11         """
     12@@ -526,3 +527,243 @@
     13         @param nodeIdentifier: The identifier of the node to be delete.
     14         @type nodeIdentifier: C{unicode}
     15         """
     16+
     17+
     18+
    919+class IPubSubResource(Interface):
    1020+
    1121+    def locateResource(request):
    12          """
    13 -        Called when a publish request has been received.
     22+        """
    1423+        Locate a resource that will handle the request.
    15  
    16          @param request: The publish-subscribe request.
    17          @type request: L{wokkel.pubsub.PubSubRequest}
    18 -        @return: deferred that fires on success.
     24+
     25+        @param request: The publish-subscribe request.
     26+        @type request: L{wokkel.pubsub.PubSubRequest}
    1927+        """
    2028+
     
    3442+                 respectively the node type and a dictionary with the meta
    3543+                 data for that node.
    36          @rtype: L{defer.Deferred}
    37          """
    38  
    39  
    40 -    def subscribe(request):
     44+        @rtype: L{defer.Deferred}
     45+        """
     46+
     47+
    4148+    def getNodes(requestor, service, nodeIdentifier):
    42          """
    43 -        Called when a subscribe request has been received.
     49+        """
    4450+        Get all nodes contained by this node.
    45  
    46 -        @param request: The publish-subscribe request.
    47 -        @type request: L{wokkel.pubsub.PubSubRequest}
    48 -        @return: A deferred that fires with a
    49 -                 L{Subscription<wokkel.pubsub.Subscription>}.
    50 -        @rtype: L{defer.Deferred}
    51 -        """
    52 -
    53 -
    54 -    def unsubscribe(request):
    55 -        """
    56 -        Called when a subscribe request has been received.
    57 -
    58 -        @param request: The publish-subscribe request.
    59 -        @type request: L{wokkel.pubsub.PubSubRequest}
    60 -        @return: A deferred that fires with C{None} when unsubscription has
    61 -                 succeeded.
    62 -        @rtype: L{defer.Deferred}
    63 -        """
    64 -
    65 -
    66 -    def subscriptions(request):
    67 -        """
    68 -        Called when a subscriptions retrieval request has been received.
    69 -
    70 -        @param request: The publish-subscribe request.
    71 -        @type request: L{wokkel.pubsub.PubSubRequest}
    72 -        @return: A deferred that fires with a C{list} of subscriptions as
    73 -                 L{Subscription<wokkel.pubsub.Subscription>}.
    74 -        @rtype: L{defer.Deferred}
    75 -        """
    76 -
    77 -
    78 -    def affiliations(request):
    79 -        """
    80 -        Called when a affiliations retrieval request has been received.
    81 -
    82 -        @param request: The publish-subscribe request.
    83 -        @type request: L{wokkel.pubsub.PubSubRequest}
    84 -        @return: A deferred that fires with a C{list} of affiliations as
    85 -                 C{tuple}s of (node identifier as C{unicode}, affiliation state
    86 -                 as C{str}). The affiliation can be C{'owner'}, C{'publisher'},
    87 -                 or C{'outcast'}.
    88 -        @rtype: L{defer.Deferred}
    89 -        """
    90 -
    91 -
    92 -    def create(request):
    93 -        """
    94 -        Called when a node creation request has been received.
    95 -
    96 -        @param request: The publish-subscribe request.
    97 -        @type request: L{wokkel.pubsub.PubSubRequest}
    98 -        @return: A deferred that fires with a C{unicode} that represents
    99 -                 the identifier of the new node.
     51+
    10052+        @param requestor: The entity the request originated from.
    10153+        @type requestor: L{jid.JID}
     
    10557+        @type nodeIdentifier: L{unicode}
    10658+        @return: A deferred that fires with a list of child node identifiers.
    107          @rtype: L{defer.Deferred}
    108          """
    109  
    110 @@ -406,7 +377,80 @@
    111          """
    112  
    113  
    114 -    def getDefaultConfiguration(request):
     59+        @rtype: L{defer.Deferred}
     60+        """
     61+
     62+
     63+    def getConfigurationOptions():
     64+        """
     65+        Retrieve all known node configuration options.
     66+
     67+        The returned dictionary holds the possible node configuration options
     68+        by option name. The value of each entry represents the specifics for
     69+        that option in a dictionary:
     70+
     71+         - C{'type'} (C{str}): The option's type (see
     72+           L{Field<wokkel.data_form.Field>}'s doc string for possible values).
     73+         - C{'label'} (C{unicode}): A human readable label for this option.
     74+         - C{'options'} (C{dict}): Optional list of possible values for this
     75+           option.
     76+
     77+        Example::
     78+
     79+            {
     80+            "pubsub#persist_items":
     81+                {"type": "boolean",
     82+                 "label": "Persist items to storage"},
     83+            "pubsub#deliver_payloads":
     84+                {"type": "boolean",
     85+                 "label": "Deliver payloads with event notifications"},
     86+            "pubsub#send_last_published_item":
     87+                {"type": "list-single",
     88+                 "label": "When to send the last published item",
     89+                 "options": {
     90+                     "never": "Never",
     91+                     "on_sub": "When a new subscription is processed"}
     92+                }
     93+            }
     94+
     95+        @rtype: C{dict}.
     96+        """
     97+
     98+
    11599+    def publish(request):
    116100+        """
     
    187171+
    188172+    def default(request):
    189          """
    190          Called when a default node configuration request has been received.
    191  
    192 @@ -420,7 +464,7 @@
    193          """
    194  
    195  
    196 -    def getConfiguration(request):
     173+        """
     174+        Called when a default node configuration request has been received.
     175+
     176+        @param request: The publish-subscribe request.
     177+        @type request: L{wokkel.pubsub.PubSubRequest}
     178+        @return: A deferred that fires with a C{dict} representing the default
     179+                 node configuration. Keys are C{str}s that represent the
     180+                 field name. Values can be of types C{unicode}, C{int} or
     181+                 C{bool}.
     182+        @rtype: L{defer.Deferred}
     183+        """
     184+
     185+
    197186+    def configureGet(request):
    198          """
    199          Called when a node configuration retrieval request has been received.
    200  
    201 @@ -433,7 +477,7 @@
    202          """
    203  
    204  
    205 -    def setConfiguration(request):
     187+        """
     188+        Called when a node configuration retrieval request has been received.
     189+
     190+        @param request: The publish-subscribe request.
     191+        @type request: L{wokkel.pubsub.PubSubRequest}
     192+        @return: A deferred that fires with a C{dict} representing the node
     193+                 configuration. Keys are C{str}s that represent the field name.
     194+                 Values can be of types C{unicode}, C{int} or C{bool}.
     195+        @rtype: L{defer.Deferred}
     196+        """
     197+
     198+
    206199+    def configureSet(request):
    207          """
    208          Called when a node configuration change request has been received.
    209  
    210 diff -r ce121b9d0797 wokkel/pubsub.py
    211 --- a/wokkel/pubsub.py  Fri Apr 10 15:36:22 2009 +0200
    212 +++ b/wokkel/pubsub.py  Fri Apr 10 17:31:54 2009 +0200
     200+        """
     201+        Called when a node configuration change request has been received.
     202+
     203+        @param request: The publish-subscribe request.
     204+        @type request: L{wokkel.pubsub.PubSubRequest}
     205+        @return: A deferred that fires with C{None} when the node's
     206+                 configuration has been changed.
     207+        @rtype: L{defer.Deferred}
     208+        """
     209+
     210+
     211+    def items(request):
     212+        """
     213+        Called when a items retrieval request has been received.
     214+
     215+        @param request: The publish-subscribe request.
     216+        @type request: L{wokkel.pubsub.PubSubRequest}
     217+        @return: A deferred that fires with a C{list} of L{pubsub.Item}.
     218+        @rtype: L{defer.Deferred}
     219+        """
     220+
     221+
     222+    def retract(request):
     223+        """
     224+        Called when a item retraction request has been received.
     225+
     226+        @param request: The publish-subscribe request.
     227+        @type request: L{wokkel.pubsub.PubSubRequest}
     228+        @return: A deferred that fires with C{None} when the given items have
     229+                 been retracted.
     230+        @rtype: L{defer.Deferred}
     231+        """
     232+
     233+
     234+    def purge(request):
     235+        """
     236+        Called when a node purge request has been received.
     237+
     238+        @param request: The publish-subscribe request.
     239+        @type request: L{wokkel.pubsub.PubSubRequest}
     240+        @return: A deferred that fires with C{None} when the node has been
     241+                 purged.
     242+        @rtype: L{defer.Deferred}
     243+        """
     244+
     245+
     246+    def delete(request):
     247+        """
     248+        Called when a node deletion request has been received.
     249+
     250+        @param request: The publish-subscribe request.
     251+        @type request: L{wokkel.pubsub.PubSubRequest}
     252+        @return: A deferred that fires with C{None} when the node has been
     253+                 deleted.
     254+        @rtype: L{defer.Deferred}
     255+        """
     256diff -r 29f67459352b wokkel/pubsub.py
     257--- a/wokkel/pubsub.py  Wed Apr 22 14:48:20 2009 +0200
     258+++ b/wokkel/pubsub.py  Wed Apr 22 16:14:56 2009 +0200
    213259@@ -13,12 +13,13 @@
    214260 from zope.interface import implements
     
    255301     }
    256302 
    257 @@ -806,13 +812,10 @@
     303@@ -806,8 +812,35 @@
    258304             '/*': '_onPubSubRequest',
    259305             }
    260306 
     307+    _legacyHandlers = {
     308+        'publish': ('publish', ['sender', 'recipient',
     309+                                'nodeIdentifier', 'items']),
     310+        'subscribe': ('subscribe', ['sender', 'recipient',
     311+                                    'nodeIdentifier', 'subscriber']),
     312+        'unsubscribe': ('unsubscribe', ['sender', 'recipient',
     313+                                        'nodeIdentifier', 'subscriber']),
     314+        'subscriptions': ('subscriptions', ['sender', 'recipient']),
     315+        'affiliations': ('affiliations', ['sender', 'recipient']),
     316+        'create': ('create', ['sender', 'recipient', 'nodeIdentifier']),
     317+        'getConfigurationOptions': ('getConfigurationOptions', []),
     318+        'default': ('getDefaultConfiguration',
     319+                    ['sender', 'recipient', 'nodeType']),
     320+        'configureGet': ('getConfiguration', ['sender', 'recipient',
     321+                                              'nodeIdentifier']),
     322+        'configureSet': ('setConfiguration', ['sender', 'recipient',
     323+                                              'nodeIdentifier', 'options']),
     324+        'items': ('items', ['sender', 'recipient', 'nodeIdentifier',
     325+                            'maxItems', 'itemIdentifiers']),
     326+        'retract': ('retract', ['sender', 'recipient', 'nodeIdentifier',
     327+                                'itemIdentifiers']),
     328+        'purge': ('purge', ['sender', 'recipient', 'nodeIdentifier']),
     329+        'delete': ('delete', ['sender', 'recipient', 'nodeIdentifier']),
     330+    }
     331 
     332-    def __init__(self):
    261333+    hideNodes = False
    262  
    263 -    def __init__(self):
    264 -        self.discoIdentity = {'category': 'pubsub',
    265 -                              'type': 'generic',
    266 -                              'name': 'Generic Publish-Subscribe Service'}
    267 -
    268 -        self.pubSubFeatures = []
    269 +    def __init__(self, resource):
     334+
     335+    def __init__(self, resource=None):
    270336+        self.resource = resource
    271  
    272  
    273      def connectionMade(self):
    274 @@ -820,19 +823,9 @@
     337         self.discoIdentity = {'category': 'pubsub',
     338                               'type': 'generic',
     339                               'name': 'Generic Publish-Subscribe Service'}
     340@@ -820,19 +853,9 @@
    275341 
    276342 
     
    294360             (nodeType, metaData) = nodeInfo['type'], nodeInfo['meta-data']
    295361             info.append(disco.DiscoIdentity('pubsub', nodeType))
    296 @@ -852,17 +845,33 @@
     362@@ -852,17 +875,49 @@
    297363 
    298364                 info.append(form)
     
    306372+
    307373+        request = PubSubRequest('discoInfo')
    308 +        resource = self.resource.locateResource(request)
     374+
     375+        if self.resource is not None:
     376+            resource = self.resource.locateResource(request)
     377+            identity = resource.discoIdentity
     378+            features = resource.features
     379+            getInfo = resource.getInfo
     380+        else:
     381+            category, idType, name = self.discoIdentity
     382+            identity = disco.DiscoIdentity(category, idType, name)
     383+            features = self.pubSubFeatures
     384+            getInfo = self.getNodeInfo
    309385+
    310386+        if not nodeIdentifier:
    311 +            info.append(resource.discoIdentity)
     387+            info.append(identity)
    312388+            info.append(disco.DiscoFeature(disco.NS_DISCO_ITEMS))
    313389+            info.extend([disco.DiscoFeature("%s#%s" % (NS_PUBSUB, feature))
    314 +                         for feature in resource.features])
    315 +
    316 +        d = resource.getInfo(requestor, target, nodeIdentifier or '')
     390+                         for feature in features])
     391+
     392+        d = getInfo(requestor, target, nodeIdentifier or '')
    317393+        d.addCallback(toInfo, info)
    318394+        d.addErrback(log.err)
     
    322398     def getDiscoItems(self, requestor, target, nodeIdentifier):
    323399-        if nodeIdentifier or self.hideNodes:
    324 +        request = PubSubRequest('discoInfo')
    325 +        resource = self.resource.locateResource(request)
    326 +
     400-            return defer.succeed([])
    327401+        if self.hideNodes:
    328              return defer.succeed([])
     402+            d = defer.succeed([])
     403+        elif self.resource is not None:
     404+            request = PubSubRequest('discoInfo')
     405+            resource = self.resource.locateResource(request)
     406+            d = resource.getNodes(requestor, target, nodeIdentifier)
     407+        elif nodeIdentifier:
     408+            d = self.getNodes(requestor, target)
     409+        else:
     410+            d = defer.succeed([])
     411+           
    329412 
    330413-        d = self.getNodes(requestor, target)
    331 +        d = resource.getNodes(requestor, target, nodeIdentifier)
     414+
    332415         d.addCallback(lambda nodes: [disco.DiscoItem(target, node)
    333416                                      for node in nodes])
    334417         return d
    335 @@ -870,91 +879,80 @@
     418@@ -870,95 +925,90 @@
    336419 
    337420     def _onPubSubRequest(self, iq):
     
    339422-        handler = getattr(self, '_on_%s' % request.verb)
    340423-        return handler(request)
    341 +        resource = self.resource.locateResource(request)
    342  
     424 
     425+        if self.resource is not None:
     426+            resource = self.resource.locateResource(request)
     427+        else:
     428+            resource = self
     429 
     430-    def _on_publish(self, request):
     431-        return self.publish(request.sender, request.recipient,
     432-                            request.nodeIdentifier, request.items)
    343433+        # Preprocess the request, knowing the handling resource
    344434+        try:
     
    351441+                return defer.succeed(None)
    352442 
    353 -    def _on_publish(self, request):
    354 -        return self.publish(request)
    355443+        # Process the request itself,
    356 +        try:
    357 +            handler = getattr(resource, request.verb)
    358 +        except AttributeError:
    359 +            # fix lookup feature
    360 +            text = "Request verb: %s" % request.verb
    361 +            return defer.fail(Unsupported('', text))
    362  
    363 +        d = handler(request)
     444+        if resource is not self:
     445+            try:
     446+                handler = getattr(resource, request.verb)
     447+            except AttributeError:
     448+                # fix lookup feature
     449+                text = "Request verb: %s" % request.verb
     450+                return defer.fail(Unsupported('', text))
    364451 
    365452-    def _on_subscribe(self, request):
    366 +        # If needed, translate the result into a response
    367 +        try:
    368 +            cb = getattr(self, '_toResponse_%s' % request.verb)
    369 +        except AttributeError:
    370 +            pass
     453+            d = handler(request)
    371454+        else:
    372 +            d.addCallback(cb, resource, request)
     455+            handlerName, argNames = self._legacyHandlers[request.verb]
     456+            handler = getattr(self, handlerName)
     457+            args = [getattr(request, arg) for arg in argNames]
     458+            d = handler(*args)
    373459 
    374460-        def toResponse(result):
     
    380466-            subscription["subscription"] = result.state
    381467-            return response
    382 -
    383 -        d = self.subscribe(request)
     468+        # If needed, translate the result into a response
     469+        try:
     470+            cb = getattr(self, '_toResponse_%s' % request.verb)
     471+        except AttributeError:
     472+            pass
     473+        else:
     474+            d.addCallback(cb, resource, request)
     475 
     476-        d = self.subscribe(request.sender, request.recipient,
     477-                           request.nodeIdentifier, request.subscriber)
    384478-        d.addCallback(toResponse)
    385479         return d
     
    387481 
    388482-    def _on_unsubscribe(self, request):
    389 -        return self.unsubscribe(request)
     483-        return self.unsubscribe(request.sender, request.recipient,
     484-                                request.nodeIdentifier, request.subscriber)
    390485+    def _toResponse_subscribe(self, result, resource, request):
    391486+        response = domish.Element((NS_PUBSUB, "pubsub"))
     
    440535             return response
    441536-
    442 -        d = self.subscriptions(request)
     537-        d = self.subscriptions(request.sender, request.recipient)
    443538-        d.addCallback(toResponse)
    444539-        return d
     
    458553-            return response
    459554-
    460 -        d = self.affiliations(request)
     555-        d = self.affiliations(request.sender, request.recipient)
    461556-        d.addCallback(toResponse)
    462557-        return d
     
    474569-                return None
    475570-
    476 -        d = self.create(request)
     571-        d = self.create(request.sender, request.recipient,
     572-                        request.nodeIdentifier)
    477573-        d.addCallback(toResponse)
    478574-        return d
     
    482578 
    483579     def _makeFields(self, options, values):
    484 @@ -973,8 +971,8 @@
     580@@ -977,8 +1027,8 @@
    485581         return fields
    486582 
     
    493589         form = data_form.Form(formType="form",
    494590                               formNamespace=NS_PUBSUB_NODE_CONFIG,
    495 @@ -983,8 +981,8 @@
     591@@ -987,8 +1037,8 @@
    496592         return form
    497593 
     
    504600 
    505601         for key, value in values.iteritems():
    506 @@ -1008,93 +1006,52 @@
     602@@ -1012,102 +1062,52 @@
    507603         return processedValues
    508604 
     
    530626+        return response
    531627 
    532 -        d = self.getDefaultConfiguration(request)
     628-        d = self.getDefaultConfiguration(request.sender, request.recipient,
     629-                                         request.nodeType)
    533630-        d.addCallback(toResponse)
    534631-        return d
     
    555652-            return response
    556653 
    557 -        d = self.getConfiguration(request)
     654-        d = self.getConfiguration(request.sender, request.recipient,
     655-                                  request.nodeIdentifier)
    558656-        d.addCallback(toResponse)
    559657-        return d
     
    564662         if request.options:
    565663-            request.options = self._checkConfiguration(request.options)
    566 -            return self.setConfiguration(request)
     664-            return self.setConfiguration(request.sender, request.recipient,
     665-                                         request.nodeIdentifier,
     666-                                         request.options)
    567667+            request.options = self._checkConfiguration(resource,
    568668+                                                       request.options)
     
    592692-            return response
    593693-
    594 -        d = self.items(request)
     694-        d = self.items(request.sender, request.recipient,
     695-                       request.nodeIdentifier, request.maxItems,
     696-                       request.itemIdentifiers)
    595697-        d.addCallback(toResponse)
    596698-        return d
     
    598700-
    599701-    def _on_retract(self, request):
    600 -        return self.retract(request)
     702-        return self.retract(request.sender, request.recipient,
     703-                            request.nodeIdentifier, request.itemIdentifiers)
    601704-
    602705-
    603706-    def _on_purge(self, request):
    604 -        return self.purge(request)
     707-        return self.purge(request.sender, request.recipient,
     708-                          request.nodeIdentifier)
    605709-
    606710-
    607711-    def _on_delete(self, request):
    608 -        return self.delete(request)
     712-        return self.delete(request.sender, request.recipient,
     713-                           request.nodeIdentifier)
    609714-
    610715-
     
    628733     def _createNotification(self, eventType, service, nodeIdentifier,
    629734                                   subscriber, subscriptions=None):
    630 @@ -1118,6 +1075,8 @@
     735@@ -1131,6 +1131,8 @@
    631736 
    632737         return message
     
    637742         for subscriber, subscriptions, items in notifications:
    638743             message = self._createNotification('items', service,
    639 @@ -1139,65 +1098,96 @@
    640              self.send(message)
    641  
    642  
    643 -    def getNodeInfo(self, requestor, service, nodeIdentifier):
    644 -        return None
    645  
     744@@ -1215,3 +1217,98 @@
     745 
     746     def delete(self, requestor, service, nodeIdentifier):
     747         raise Unsupported('delete-nodes')
     748+
     749+
     750+
    646751+class PubSubResource(object):
    647  
    648 -    def getNodes(self, requestor, service):
    649 -        return []
     752+
    650753+    implements(IPubSubResource)
    651  
     754+
    652755+    features = []
    653756+    discoIdentity = disco.DiscoIdentity('pubsub',
    654757+                                        'service',
    655758+                                        'Publish-Subscribe Service')
    656  
    657 -    def publish(self, request):
    658 -        raise Unsupported('publish')
    659  
     759+
     760+
    660761+    def locateResource(self, request):
    661762+        return self
    662  
    663 -    def subscribe(self, request):
    664 -        raise Unsupported('subscribe')
    665  
     763+
     764+
    666765+    def getInfo(self, requestor, service, nodeIdentifier):
    667766+        return defer.succeed(None)
    668  
    669 -    def unsubscribe(self, request):
    670 -        raise Unsupported('subscribe')
    671  
    672 -
    673 -    def subscriptions(self, request):
    674 -        raise Unsupported('retrieve-subscriptions')
    675 -
    676 -
    677 -    def affiliations(self, request):
    678 -        raise Unsupported('retrieve-affiliations')
    679 -
    680 -
    681 -    def create(self, request):
    682 -        raise Unsupported('create-nodes')
     767+
     768+
    683769+    def getNodes(self, requestor, service, nodeIdentifier):
    684770+        return defer.succeed([])
    685  
    686  
    687      def getConfigurationOptions(self):
    688          return {}
    689  
    690  
    691 -    def getDefaultConfiguration(self, request):
    692 -        raise Unsupported('retrieve-default')
     771+
     772+
     773+    def getConfigurationOptions(self):
     774+        return {}
     775+
     776+
    693777+    def publish(self, request):
    694778+        return defer.fail(Unsupported('publish'))
    695  
    696  
    697 -    def getConfiguration(self, request):
    698 -        raise Unsupported('config-node')
     779+
     780+
    699781+    def subscribe(self, request):
    700782+        return defer.fail(Unsupported('subscribe'))
    701  
    702  
    703 -    def setConfiguration(self, request):
    704 -        raise Unsupported('config-node')
     783+
     784+
    705785+    def unsubscribe(self, request):
    706786+        return defer.fail(Unsupported('subscribe'))
     
    729809+    def configureSet(self, request):
    730810+        return defer.fail(Unsupported('config-node'))
    731  
    732  
    733      def items(self, request):
    734 -        raise Unsupported('retrieve-items')
     811+
     812+
     813+    def items(self, request):
    735814+        return defer.fail(Unsupported('retrieve-items'))
    736  
    737  
    738      def retract(self, request):
    739 -        raise Unsupported('retract-items')
     815+
     816+
     817+    def retract(self, request):
    740818+        return defer.fail(Unsupported('retract-items'))
    741  
    742  
    743      def purge(self, request):
    744 -        raise Unsupported('purge-nodes')
     819+
     820+
     821+    def purge(self, request):
    745822+        return defer.fail(Unsupported('purge-nodes'))
    746  
    747  
    748      def delete(self, request):
    749 -        raise Unsupported('delete-nodes')
     823+
     824+
     825+    def delete(self, request):
    750826+        return defer.fail(Unsupported('delete-nodes'))
    751827+
     
    765841+    def subscriptionsSet(self, request):
    766842+        return defer.fail(Unsupported('manage-subscriptions'))
    767 diff -r ce121b9d0797 wokkel/test/test_pubsub.py
    768 --- a/wokkel/test/test_pubsub.py        Fri Apr 10 15:36:22 2009 +0200
    769 +++ b/wokkel/test/test_pubsub.py        Fri Apr 10 17:31:54 2009 +0200
     843diff -r 29f67459352b wokkel/test/test_pubsub.py
     844--- a/wokkel/test/test_pubsub.py        Wed Apr 22 14:48:20 2009 +0200
     845+++ b/wokkel/test/test_pubsub.py        Wed Apr 22 16:14:56 2009 +0200
    770846@@ -1222,7 +1222,8 @@
    771847 
     
    914990         A publish request should result in L{PubSubService.publish} being
    915991         called.
    916 @@ -1338,12 +1419,12 @@
    917          def publish(request):
     992@@ -1335,15 +1416,15 @@
     993         </iq>
     994         """
     995 
     996-        def publish(requestor, service, nodeIdentifier, items):
     997+        def publish(request):
    918998             return defer.succeed(None)
    919999 
     
    9301010         A successful subscription should return the current subscription.
    9311011         """
     1012@@ -1357,9 +1438,9 @@
     1013         </iq>
     1014         """
     1015 
     1016-        def subscribe(requestor, service, nodeIdentifier, subscriber):
     1017-            return defer.succeed(pubsub.Subscription(nodeIdentifier,
     1018-                                                     subscriber,
     1019+        def subscribe(request):
     1020+            return defer.succeed(pubsub.Subscription(request.nodeIdentifier,
     1021+                                                     request.subscriber,
     1022                                                      'subscribed'))
     1023 
     1024         def cb(element):
    9321025@@ -1371,14 +1452,14 @@
    9331026             self.assertEqual('user@example.org/Home', subscription['jid'])
     
    9481041         A successful subscription on root node should return no node attribute.
    9491042         """
    950 @@ -1400,14 +1481,14 @@
     1043@@ -1392,22 +1473,22 @@
     1044         </iq>
     1045         """
     1046 
     1047-        def subscribe(requestor, service, nodeIdentifier, subscriber):
     1048-            return defer.succeed(pubsub.Subscription(nodeIdentifier,
     1049-                                                     subscriber,
     1050+        def subscribe(request):
     1051+            return defer.succeed(pubsub.Subscription(request.nodeIdentifier,
     1052+                                                     request.subscriber,
     1053                                                      'subscribed'))
     1054 
    9511055         def cb(element):
    9521056             self.assertFalse(element.subscription.hasAttribute('node'))
     
    9661070         A successful unsubscription should return an empty response.
    9671071         """
    968 @@ -1427,14 +1508,14 @@
     1072@@ -1421,20 +1502,20 @@
     1073         </iq>
     1074         """
     1075 
     1076-        def unsubscribe(requestor, service, nodeIdentifier, subscriber):
     1077+        def unsubscribe(request):
     1078             return defer.succeed(None)
     1079 
    9691080         def cb(element):
    9701081             self.assertIdentical(None, element)
     
    10191130 
    10201131-
    1021 -        def subscriptions(request):
     1132-        def subscriptions(requestor, service):
    10221133-            subscription = pubsub.Subscription('test', JID('user@example.org'),
    10231134-                                               'subscribed')
     
    10541165 
    10551166-
    1056 -        def affiliations(request):
     1167-        def affiliations(requestor, service):
    10571168-            affiliation = ('test', 'owner')
    10581169-            return defer.succeed([affiliation])
     
    10721183         Replies to create node requests don't return the created node.
    10731184         """
    1074 @@ -1593,14 +1672,14 @@
     1185@@ -1587,20 +1666,20 @@
     1186         </iq>
     1187         """
     1188 
     1189-        def create(requestor, service, nodeIdentifier):
     1190-            return defer.succeed(nodeIdentifier)
     1191+        def create(request):
     1192+            return defer.succeed(request.nodeIdentifier)
     1193 
    10751194         def cb(element):
    10761195             self.assertIdentical(None, element)
     
    10901209         Replies to create node requests return the created node if changed.
    10911210         """
     1211@@ -1614,7 +1693,7 @@
     1212         </iq>
     1213         """
     1214 
     1215-        def create(requestor, service, nodeIdentifier):
     1216+        def create(request):
     1217             return defer.succeed(u'myrenamednode')
     1218 
     1219         def cb(element):
    10921220@@ -1624,14 +1703,14 @@
    10931221             self.assertEqual(u'myrenamednode',
     
    11081236         Replies to create instant node requests return the created node.
    11091237         """
     1238@@ -1645,7 +1724,7 @@
     1239         </iq>
     1240         """
     1241 
     1242-        def create(requestor, service, nodeIdentifier):
     1243+        def create(request):
     1244             return defer.succeed(u'random')
     1245 
     1246         def cb(element):
    11101247@@ -1654,14 +1733,14 @@
    11111248             self.assertEqual(NS_PUBSUB, element.create.uri)
     
    11301267                 }
    11311268 
    1132 -        def getDefaultConfiguration(request):
     1269-        def getDefaultConfiguration(requestor, service, nodeType):
    11331270+        def default(request):
    11341271             return defer.succeed({})
     
    11591296                 }
    11601297 
    1161 -        def getDefaultConfiguration(request):
     1298-        def getDefaultConfiguration(requestor, service, nodeType):
    11621299+        def default(request):
    11631300             return defer.succeed({})
     
    11851322         """
    11861323 
    1187 -        def getDefaultConfiguration(request):
     1324-        def getDefaultConfiguration(requestor, service, nodeType):
    11881325+        def default(request):
    11891326             self.fail("Unexpected call to getConfiguration")
     
    12171354                 }
    12181355 
    1219 -        def getConfiguration(request):
     1356-        def getConfiguration(requestor, service, nodeIdentifier):
    12201357+        def configureGet(request):
    12211358             return defer.succeed({'pubsub#deliver_payloads': '0',
     
    12511388                 }
    12521389 
    1253 -        def setConfiguration(request):
     1390-        def setConfiguration(requestor, service, nodeIdentifier, options):
    12541391+        def configureSet(request):
    12551392             self.assertEqual({'pubsub#deliver_payloads': False,
    1256                                'pubsub#persist_items': True}, request.options)
     1393-                              'pubsub#persist_items': True}, options)
     1394+                              'pubsub#persist_items': True}, request.options)
    12571395             return defer.succeed(None)
    12581396 
     
    12801418         """
    12811419 
    1282 -        def setConfiguration(request):
     1420-        def setConfiguration(requestor, service, nodeIdentifier, options):
    12831421+        def configureSet(request):
    12841422             self.fail("Unexpected call to setConfiguration")
     
    12961434         On a node configuration set request unknown fields should be ignored.
    12971435         """
    1298 @@ -1959,17 +2038,17 @@
     1436@@ -1959,16 +2038,17 @@
    12991437                      "label": "Deliver payloads with event notifications"}
    13001438                 }
    13011439 
    1302 -        def setConfiguration(request):
     1440-        def setConfiguration(requestor, service, nodeIdentifier, options):
     1441-            self.assertEquals(['pubsub#deliver_payloads'], options.keys())
    13031442+        def configureSet(request):
    1304              self.assertEquals(['pubsub#deliver_payloads'],
    1305                                request.options.keys())
     1443+            self.assertEquals(['pubsub#deliver_payloads'],
     1444+                              request.options.keys())
    13061445 
    13071446-        self.service.getConfigurationOptions = getConfigurationOptions
     
    13191458         On a node configuration set request unknown fields should be ignored.
    13201459         """
    1321 @@ -2000,7 +2079,7 @@
     1460@@ -1999,7 +2079,7 @@
    13221461         return d
    13231462 
     
    13281467         On a items request, return all items for the given node.
    13291468         """
     1469@@ -2012,8 +2092,7 @@
     1470         </iq>
     1471         """
     1472 
     1473-        def items(requestor, service, nodeIdentifier, maxItems,
     1474-                  itemIdentifiers):
     1475+        def items(request):
     1476             return defer.succeed([pubsub.Item('current')])
     1477 
     1478         def cb(element):
    13301479@@ -2026,16 +2105,17 @@
    13311480             self.assertEqual(NS_PUBSUB, item.uri)
     
    13501499 
    13511500         xml = """
    1352 @@ -2053,13 +2133,14 @@
    1353          def retract(request):
     1501@@ -2050,16 +2130,17 @@
     1502         </iq>
     1503         """
     1504 
     1505-        def retract(requestor, service, nodeIdentifier, itemIdentifiers):
     1506+        def retract(request):
    13541507             return defer.succeed(None)
    13551508 
     
    13681521         """
    13691522 
    1370 @@ -2075,13 +2156,14 @@
    1371          def purge(request):
     1523@@ -2072,16 +2153,17 @@
     1524         </iq>
     1525         """
     1526 
     1527-        def purge(requestor, service, nodeIdentifier):
     1528+        def purge(request):
    13721529             return defer.succeed(None)
    13731530 
     
    13861543         """
    13871544 
    1388 @@ -2097,7 +2179,8 @@
    1389          def delete(request):
     1545@@ -2094,10 +2176,11 @@
     1546         </iq>
     1547         """
     1548 
     1549-        def delete(requestor, service, nodeIdentifier):
     1550+        def delete(request):
    13901551             return defer.succeed(None)
    13911552 
     
    14321593         Setting subscription options is not supported.
    14331594         """
    1434 @@ -2256,18 +2339,38 @@
    1435          return d
    1436  
    1437  
     1595@@ -2256,6 +2339,15 @@
     1596         return d
     1597 
     1598 
     1599+
     1600+class PubSubServiceWithoutResourceTest(unittest.TestCase, TestableRequestHandlerMixin):
     1601+
     1602+    def setUp(self):
     1603+        self.stub = XmlStreamStub()
     1604+        self.service = pubsub.PubSubService()
     1605+        self.service.send = self.stub.xmlstream.send
     1606+
     1607+
     1608     def test_publish(self):
     1609         """
     1610         Non-overridden L{PubSubService.publish} yields unsupported error.
     1611@@ -2604,3 +2696,257 @@
     1612         self.assertFailure(d, error.StanzaError)
     1613         d.addCallback(cb)
     1614         return d
     1615+
     1616+
    14381617+
    14391618+class PubSubResourceTest(unittest.TestCase):
     
    14641643+
    14651644+
    1466      def test_publish(self):
    1467          """
    1468 -        Non-overridden L{PubSubService.publish} yields unsupported error.
    1469 -        """
    1470 -
    1471 -        xml = """
    1472 -        <iq type='set' to='pubsub.example.org'
    1473 -                       from='user@example.org'>
    1474 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1475 -            <publish node='mynode'/>
    1476 -          </pubsub>
    1477 -        </iq>
     1645+    def test_publish(self):
     1646+        """
    14781647+        Non-overridden L{PubSubResource.publish} yields unsupported
    14791648+        error.
    1480          """
    1481  
    1482          def cb(result):
    1483 @@ -2276,7 +2379,7 @@
    1484              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1485              self.assertEquals('publish', result.appCondition['feature'])
    1486  
    1487 -        d = self.handleRequest(xml)
     1649+        """
     1650+
     1651+        def cb(result):
     1652+            self.assertEquals('feature-not-implemented', result.condition)
     1653+            self.assertEquals('unsupported', result.appCondition.name)
     1654+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1655+            self.assertEquals('publish', result.appCondition['feature'])
     1656+
    14881657+        d = self.resource.publish(pubsub.PubSubRequest())
    1489          self.assertFailure(d, error.StanzaError)
    1490          d.addCallback(cb)
    1491          return d
    1492 @@ -2284,16 +2387,7 @@
    1493  
    1494      def test_subscribe(self):
    1495          """
    1496 -        Non-overridden L{PubSubService.subscribe} yields unsupported error.
    1497 -        """
    1498 -
    1499 -        xml = """
    1500 -        <iq type='set' to='pubsub.example.org'
    1501 -                       from='user@example.org'>
    1502 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1503 -            <subscribe node='test' jid='user@example.org/Home'/>
    1504 -          </pubsub>
    1505 -        </iq>
     1658+        self.assertFailure(d, error.StanzaError)
     1659+        d.addCallback(cb)
     1660+        return d
     1661+
     1662+
     1663+    def test_subscribe(self):
     1664+        """
    15061665+        Non-overridden subscriptions yields unsupported error.
    1507          """
    1508  
    1509          def cb(result):
    1510 @@ -2302,7 +2396,7 @@
    1511              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1512              self.assertEquals('subscribe', result.appCondition['feature'])
    1513  
    1514 -        d = self.handleRequest(xml)
     1666+        """
     1667+
     1668+        def cb(result):
     1669+            self.assertEquals('feature-not-implemented', result.condition)
     1670+            self.assertEquals('unsupported', result.appCondition.name)
     1671+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1672+            self.assertEquals('subscribe', result.appCondition['feature'])
     1673+
    15151674+        d = self.resource.subscribe(pubsub.PubSubRequest())
    1516          self.assertFailure(d, error.StanzaError)
    1517          d.addCallback(cb)
    1518          return d
    1519 @@ -2310,16 +2404,7 @@
    1520  
    1521      def test_unsubscribe(self):
    1522          """
    1523 -        Non-overridden L{PubSubService.unsubscribe} yields unsupported error.
    1524 -        """
    1525 -
    1526 -        xml = """
    1527 -        <iq type='set' to='pubsub.example.org'
    1528 -                       from='user@example.org'>
    1529 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1530 -            <unsubscribe node='test' jid='user@example.org/Home'/>
    1531 -          </pubsub>
    1532 -        </iq>
     1675+        self.assertFailure(d, error.StanzaError)
     1676+        d.addCallback(cb)
     1677+        return d
     1678+
     1679+
     1680+    def test_unsubscribe(self):
     1681+        """
    15331682+        Non-overridden unsubscribe yields unsupported error.
    1534          """
    1535  
    1536          def cb(result):
    1537 @@ -2328,7 +2413,7 @@
    1538              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1539              self.assertEquals('subscribe', result.appCondition['feature'])
    1540  
    1541 -        d = self.handleRequest(xml)
     1683+        """
     1684+
     1685+        def cb(result):
     1686+            self.assertEquals('feature-not-implemented', result.condition)
     1687+            self.assertEquals('unsupported', result.appCondition.name)
     1688+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1689+            self.assertEquals('subscribe', result.appCondition['feature'])
     1690+
    15421691+        d = self.resource.unsubscribe(pubsub.PubSubRequest())
    1543          self.assertFailure(d, error.StanzaError)
    1544          d.addCallback(cb)
    1545          return d
    1546 @@ -2336,16 +2421,7 @@
    1547  
    1548      def test_subscriptions(self):
    1549          """
    1550 -        Non-overridden L{PubSubService.subscriptions} yields unsupported error.
    1551 -        """
    1552 -
    1553 -        xml = """
    1554 -        <iq type='get' to='pubsub.example.org'
    1555 -                       from='user@example.org'>
    1556 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1557 -            <subscriptions/>
    1558 -          </pubsub>
    1559 -        </iq>
     1692+        self.assertFailure(d, error.StanzaError)
     1693+        d.addCallback(cb)
     1694+        return d
     1695+
     1696+
     1697+    def test_subscriptions(self):
     1698+        """
    15601699+        Non-overridden subscriptions yields unsupported error.
    1561          """
    1562  
    1563          def cb(result):
    1564 @@ -2355,7 +2431,7 @@
    1565              self.assertEquals('retrieve-subscriptions',
    1566                                result.appCondition['feature'])
    1567  
    1568 -        d = self.handleRequest(xml)
     1700+        """
     1701+
     1702+        def cb(result):
     1703+            self.assertEquals('feature-not-implemented', result.condition)
     1704+            self.assertEquals('unsupported', result.appCondition.name)
     1705+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1706+            self.assertEquals('retrieve-subscriptions',
     1707+                              result.appCondition['feature'])
     1708+
    15691709+        d = self.resource.subscriptions(pubsub.PubSubRequest())
    1570          self.assertFailure(d, error.StanzaError)
    1571          d.addCallback(cb)
    1572          return d
    1573 @@ -2363,16 +2439,7 @@
    1574  
    1575      def test_affiliations(self):
    1576          """
    1577 -        Non-overridden L{PubSubService.affiliations} yields unsupported error.
    1578 -        """
    1579 -
    1580 -        xml = """
    1581 -        <iq type='get' to='pubsub.example.org'
    1582 -                       from='user@example.org'>
    1583 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1584 -            <affiliations/>
    1585 -          </pubsub>
    1586 -        </iq>
     1710+        self.assertFailure(d, error.StanzaError)
     1711+        d.addCallback(cb)
     1712+        return d
     1713+
     1714+
     1715+    def test_affiliations(self):
     1716+        """
    15871717+        Non-overridden affiliations yields unsupported error.
    1588          """
    1589  
    1590          def cb(result):
    1591 @@ -2382,7 +2449,7 @@
    1592              self.assertEquals('retrieve-affiliations',
    1593                                result.appCondition['feature'])
    1594  
    1595 -        d = self.handleRequest(xml)
     1718+        """
     1719+
     1720+        def cb(result):
     1721+            self.assertEquals('feature-not-implemented', result.condition)
     1722+            self.assertEquals('unsupported', result.appCondition.name)
     1723+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1724+            self.assertEquals('retrieve-affiliations',
     1725+                              result.appCondition['feature'])
     1726+
    15961727+        d = self.resource.affiliations(pubsub.PubSubRequest())
    1597          self.assertFailure(d, error.StanzaError)
    1598          d.addCallback(cb)
    1599          return d
    1600 @@ -2390,16 +2457,7 @@
    1601  
    1602      def test_create(self):
    1603          """
    1604 -        Non-overridden L{PubSubService.create} yields unsupported error.
    1605 -        """
    1606 -
    1607 -        xml = """
    1608 -        <iq type='set' to='pubsub.example.org'
    1609 -                       from='user@example.org'>
    1610 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1611 -            <create node='mynode'/>
    1612 -          </pubsub>
    1613 -        </iq>
     1728+        self.assertFailure(d, error.StanzaError)
     1729+        d.addCallback(cb)
     1730+        return d
     1731+
     1732+
     1733+    def test_create(self):
     1734+        """
    16141735+        Non-overridden create yields unsupported error.
    1615          """
    1616  
    1617          def cb(result):
    1618 @@ -2408,87 +2466,51 @@
    1619              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1620              self.assertEquals('create-nodes', result.appCondition['feature'])
    1621  
    1622 -        d = self.handleRequest(xml)
     1736+        """
     1737+
     1738+        def cb(result):
     1739+            self.assertEquals('feature-not-implemented', result.condition)
     1740+            self.assertEquals('unsupported', result.appCondition.name)
     1741+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1742+            self.assertEquals('create-nodes', result.appCondition['feature'])
     1743+
    16231744+        d = self.resource.create(pubsub.PubSubRequest())
    1624          self.assertFailure(d, error.StanzaError)
    1625          d.addCallback(cb)
    1626          return d
    1627  
    1628  
    1629 -    def test_getDefaultConfiguration(self):
     1745+        self.assertFailure(d, error.StanzaError)
     1746+        d.addCallback(cb)
     1747+        return d
     1748+
     1749+
    16301750+    def test_default(self):
    1631          """
    1632 -        Non-overridden L{PubSubService.getDefaultConfiguration} yields
    1633 -        unsupported error.
    1634 -        """
    1635 -
    1636 -        xml = """
    1637 -        <iq type='get' to='pubsub.example.org'
    1638 -                       from='user@example.org'>
    1639 -          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
    1640 -            <default/>
    1641 -          </pubsub>
    1642 -        </iq>
     1751+        """
    16431752+        Non-overridden default yields unsupported error.
    1644          """
    1645  
    1646          def cb(result):
    1647              self.assertEquals('feature-not-implemented', result.condition)
    1648              self.assertEquals('unsupported', result.appCondition.name)
    1649              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1650 -            self.assertEquals('retrieve-default', result.appCondition['feature'])
     1753+        """
     1754+
     1755+        def cb(result):
     1756+            self.assertEquals('feature-not-implemented', result.condition)
     1757+            self.assertEquals('unsupported', result.appCondition.name)
     1758+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    16511759+            self.assertEquals('retrieve-default',
    16521760+                              result.appCondition['feature'])
    1653  
    1654 -        d = self.handleRequest(xml)
     1761+
    16551762+        d = self.resource.default(pubsub.PubSubRequest())
    1656          self.assertFailure(d, error.StanzaError)
    1657          d.addCallback(cb)
    1658          return d
    1659  
    1660  
    1661 -    def test_getConfiguration(self):
     1763+        self.assertFailure(d, error.StanzaError)
     1764+        d.addCallback(cb)
     1765+        return d
     1766+
     1767+
    16621768+    def test_configureGet(self):
    1663          """
    1664 -        Non-overridden L{PubSubService.getConfiguration} yields unsupported
     1769+        """
    16651770+        Non-overridden configureGet yields unsupported
    1666          error.
    1667          """
    1668  
    1669 -        xml = """
    1670 -        <iq type='get' to='pubsub.example.org'
    1671 -                       from='user@example.org'>
    1672 -          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
    1673 -            <configure/>
    1674 -          </pubsub>
    1675 -        </iq>
    1676 -        """
    1677 -
    1678          def cb(result):
    1679              self.assertEquals('feature-not-implemented', result.condition)
    1680              self.assertEquals('unsupported', result.appCondition.name)
    1681              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1682              self.assertEquals('config-node', result.appCondition['feature'])
    1683  
    1684 -        d = self.handleRequest(xml)
     1771+        error.
     1772+        """
     1773+
     1774+        def cb(result):
     1775+            self.assertEquals('feature-not-implemented', result.condition)
     1776+            self.assertEquals('unsupported', result.appCondition.name)
     1777+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1778+            self.assertEquals('config-node', result.appCondition['feature'])
     1779+
    16851780+        d = self.resource.configureGet(pubsub.PubSubRequest())
    1686          self.assertFailure(d, error.StanzaError)
    1687          d.addCallback(cb)
    1688          return d
    1689  
    1690  
    1691 -    def test_setConfiguration(self):
     1781+        self.assertFailure(d, error.StanzaError)
     1782+        d.addCallback(cb)
     1783+        return d
     1784+
     1785+
    16921786+    def test_configureSet(self):
    1693          """
    1694 -        Non-overridden L{PubSubService.setConfiguration} yields unsupported
    1695 -        error.
    1696 -        """
    1697 -
    1698 -        xml = """
    1699 -        <iq type='set' to='pubsub.example.org'
    1700 -                       from='user@example.org'>
    1701 -          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
    1702 -            <configure node='test'>
    1703 -              <x xmlns='jabber:x:data' type='submit'>
    1704 -                <field var='FORM_TYPE' type='hidden'>
    1705 -                  <value>http://jabber.org/protocol/pubsub#node_config</value>
    1706 -                </field>
    1707 -                <field var='pubsub#deliver_payloads'><value>0</value></field>
    1708 -                <field var='pubsub#persist_items'><value>1</value></field>
    1709 -              </x>
    1710 -            </configure>
    1711 -          </pubsub>
    1712 -        </iq>
     1787+        """
    17131788+        Non-overridden configureSet yields unsupported error.
    1714          """
    1715  
    1716          def cb(result):
    1717 @@ -2497,7 +2519,7 @@
    1718              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1719              self.assertEquals('config-node', result.appCondition['feature'])
    1720  
    1721 -        d = self.handleRequest(xml)
     1789+        """
     1790+
     1791+        def cb(result):
     1792+            self.assertEquals('feature-not-implemented', result.condition)
     1793+            self.assertEquals('unsupported', result.appCondition.name)
     1794+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1795+            self.assertEquals('config-node', result.appCondition['feature'])
     1796+
    17221797+        d = self.resource.configureSet(pubsub.PubSubRequest())
    1723          self.assertFailure(d, error.StanzaError)
    1724          d.addCallback(cb)
    1725          return d
    1726 @@ -2505,15 +2527,7 @@
    1727  
    1728      def test_items(self):
    1729          """
    1730 -        Non-overridden L{PubSubService.items} yields unsupported error.
    1731 -        """
    1732 -        xml = """
    1733 -        <iq type='get' to='pubsub.example.org'
    1734 -                       from='user@example.org'>
    1735 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1736 -            <items node='test'/>
    1737 -          </pubsub>
    1738 -        </iq>
     1798+        self.assertFailure(d, error.StanzaError)
     1799+        d.addCallback(cb)
     1800+        return d
     1801+
     1802+
     1803+    def test_items(self):
     1804+        """
    17391805+        Non-overridden items yields unsupported error.
    1740          """
    1741  
    1742          def cb(result):
    1743 @@ -2522,7 +2536,7 @@
    1744              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1745              self.assertEquals('retrieve-items', result.appCondition['feature'])
    1746  
    1747 -        d = self.handleRequest(xml)
     1806+        """
     1807+
     1808+        def cb(result):
     1809+            self.assertEquals('feature-not-implemented', result.condition)
     1810+            self.assertEquals('unsupported', result.appCondition.name)
     1811+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1812+            self.assertEquals('retrieve-items', result.appCondition['feature'])
     1813+
    17481814+        d = self.resource.items(pubsub.PubSubRequest())
    1749          self.assertFailure(d, error.StanzaError)
    1750          d.addCallback(cb)
    1751          return d
    1752 @@ -2530,18 +2544,7 @@
    1753  
    1754      def test_retract(self):
    1755          """
    1756 -        Non-overridden L{PubSubService.retract} yields unsupported error.
    1757 -        """
    1758 -        xml = """
    1759 -        <iq type='set' to='pubsub.example.org'
    1760 -                       from='user@example.org'>
    1761 -          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    1762 -            <retract node='test'>
    1763 -              <item id='item1'/>
    1764 -              <item id='item2'/>
    1765 -            </retract>
    1766 -          </pubsub>
    1767 -        </iq>
     1815+        self.assertFailure(d, error.StanzaError)
     1816+        d.addCallback(cb)
     1817+        return d
     1818+
     1819+
     1820+    def test_retract(self):
     1821+        """
    17681822+        Non-overridden retract yields unsupported error.
    1769          """
    1770  
    1771          def cb(result):
    1772 @@ -2550,7 +2553,7 @@
    1773              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1774              self.assertEquals('retract-items', result.appCondition['feature'])
    1775  
    1776 -        d = self.handleRequest(xml)
     1823+        """
     1824+
     1825+        def cb(result):
     1826+            self.assertEquals('feature-not-implemented', result.condition)
     1827+            self.assertEquals('unsupported', result.appCondition.name)
     1828+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1829+            self.assertEquals('retract-items', result.appCondition['feature'])
     1830+
    17771831+        d = self.resource.retract(pubsub.PubSubRequest())
    1778          self.assertFailure(d, error.StanzaError)
    1779          d.addCallback(cb)
    1780          return d
    1781 @@ -2558,15 +2561,7 @@
    1782  
    1783      def test_purge(self):
    1784          """
    1785 -        Non-overridden L{PubSubService.purge} yields unsupported error.
    1786 -        """
    1787 -        xml = """
    1788 -        <iq type='set' to='pubsub.example.org'
    1789 -                       from='user@example.org'>
    1790 -          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
    1791 -            <purge node='test'/>
    1792 -          </pubsub>
    1793 -        </iq>
     1832+        self.assertFailure(d, error.StanzaError)
     1833+        d.addCallback(cb)
     1834+        return d
     1835+
     1836+
     1837+    def test_purge(self):
     1838+        """
    17941839+        Non-overridden purge yields unsupported error.
    1795          """
    1796  
    1797          def cb(result):
    1798 @@ -2575,7 +2570,7 @@
    1799              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1800              self.assertEquals('purge-nodes', result.appCondition['feature'])
    1801  
    1802 -        d = self.handleRequest(xml)
     1840+        """
     1841+
     1842+        def cb(result):
     1843+            self.assertEquals('feature-not-implemented', result.condition)
     1844+            self.assertEquals('unsupported', result.appCondition.name)
     1845+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1846+            self.assertEquals('purge-nodes', result.appCondition['feature'])
     1847+
    18031848+        d = self.resource.purge(pubsub.PubSubRequest())
    1804          self.assertFailure(d, error.StanzaError)
    1805          d.addCallback(cb)
    1806          return d
    1807 @@ -2583,15 +2578,7 @@
    1808  
    1809      def test_delete(self):
    1810          """
    1811 -        Non-overridden L{PubSubService.delete} yields unsupported error.
    1812 -        """
    1813 -        xml = """
    1814 -        <iq type='set' to='pubsub.example.org'
    1815 -                       from='user@example.org'>
    1816 -          <pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
    1817 -            <delete node='test'/>
    1818 -          </pubsub>
    1819 -        </iq>
     1849+        self.assertFailure(d, error.StanzaError)
     1850+        d.addCallback(cb)
     1851+        return d
     1852+
     1853+
     1854+    def test_delete(self):
     1855+        """
    18201856+        Non-overridden delete yields unsupported error.
    1821          """
    1822  
    1823          def cb(result):
    1824 @@ -2600,7 +2587,7 @@
    1825              self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
    1826              self.assertEquals('delete-nodes', result.appCondition['feature'])
    1827  
    1828 -        d = self.handleRequest(xml)
     1857+        """
     1858+
     1859+        def cb(result):
     1860+            self.assertEquals('feature-not-implemented', result.condition)
     1861+            self.assertEquals('unsupported', result.appCondition.name)
     1862+            self.assertEquals(NS_PUBSUB_ERRORS, result.appCondition.uri)
     1863+            self.assertEquals('delete-nodes', result.appCondition['feature'])
     1864+
    18291865+        d = self.resource.delete(pubsub.PubSubRequest())
    1830          self.assertFailure(d, error.StanzaError)
    1831          d.addCallback(cb)
    1832          return d
     1866+        self.assertFailure(d, error.StanzaError)
     1867+        d.addCallback(cb)
     1868+        return d
Note: See TracChangeset for help on using the changeset viewer.