changeset 149:043f2e5ce8cd

Change all calls to jid.JID to jid.internJID to avoid redoing stringprep. Clean up source to prevent line wrapping.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 31 Aug 2005 12:59:27 +0000
parents b03e5ad81173
children 35977eb964e6
files idavoll/pubsub.py
diffstat 1 files changed, 47 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/pubsub.py	Wed Aug 31 12:58:50 2005 +0000
+++ b/idavoll/pubsub.py	Wed Aug 31 12:59:27 2005 +0000
@@ -169,7 +169,8 @@
         return d
 
     def _add_meta_data(self, meta_data, node_type, result_list):
-        form = data_form.Form(type="result", form_type=NS_PUBSUB + "#meta-data")
+        form = data_form.Form(type="result",
+                              form_type=NS_PUBSUB + "#meta-data")
 
         for meta_datum in meta_data:
             try:
@@ -195,7 +196,9 @@
                                     for node in nodes])
         return d
 
-components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService)
+components.registerAdapter(ComponentServiceFromService,
+                           backend.IBackendService,
+                           component.IService)
 
 class ComponentServiceFromNotificationService(Service):
 
@@ -222,7 +225,9 @@
         items.children.extend(itemlist)
         self.send(message)
 
-components.registerAdapter(ComponentServiceFromNotificationService, backend.INotificationService, component.IService)
+components.registerAdapter(ComponentServiceFromNotificationService,
+                           backend.INotificationService,
+                           component.IService)
 
 class ComponentServiceFromPublishService(Service):
 
@@ -252,9 +257,11 @@
                 items.append(child)
 
         return self.backend.publish(node, items,
-                                    jid.JID(iq["from"]).userhostJID())
+                                    jid.internJID(iq["from"]).userhostJID())
 
-components.registerAdapter(ComponentServiceFromPublishService, backend.IPublishService, component.IService)
+components.registerAdapter(ComponentServiceFromPublishService,
+                           backend.IPublishService,
+                           component.IService)
 
 class ComponentServiceFromSubscriptionService(Service):
 
@@ -278,11 +285,11 @@
     def _onSubscribe(self, iq):
         try:
             node_id = iq.pubsub.subscribe["node"]
-            subscriber = jid.JID(iq.pubsub.subscribe["jid"])
+            subscriber = jid.internJID(iq.pubsub.subscribe["jid"])
         except KeyError:
             raise BadRequest
 
-        requestor = jid.JID(iq["from"]).userhostJID()
+        requestor = jid.internJID(iq["from"]).userhostJID()
         d = self.backend.subscribe(node_id, subscriber, requestor)
         d.addCallback(self.return_subscription, subscriber)
         return d
@@ -302,11 +309,11 @@
     def _onUnsubscribe(self, iq):
         try:
             node_id = iq.pubsub.unsubscribe["node"]
-            subscriber = jid.JID(iq.pubsub.unsubscribe["jid"])
+            subscriber = jid.internJID(iq.pubsub.unsubscribe["jid"])
         except KeyError:
             raise BadRequest
 
-        requestor = jid.JID(iq["from"]).userhostJID()
+        requestor = jid.internJID(iq["from"]).userhostJID()
         return self.backend.unsubscribe(node_id, subscriber, requestor)
 
     def onOptionsGet(self, iq):
@@ -321,7 +328,9 @@
     def _onOptionsSet(self, iq):
         raise OptionsUnavailable
 
-components.registerAdapter(ComponentServiceFromSubscriptionService, backend.ISubscriptionService, component.IService)
+components.registerAdapter(ComponentServiceFromSubscriptionService,
+                           backend.ISubscriptionService,
+                           component.IService)
 
 class ComponentServiceFromNodeCreationService(Service):
 
@@ -348,7 +357,7 @@
     def _onCreate(self, iq):
         node = iq.pubsub.create.getAttribute("node")
 
-        owner = jid.JID(iq["from"]).userhostJID()
+        owner = jid.internJID(iq["from"]).userhostJID()
 
         d = self.backend.create_node(node, owner)
         d.addCallback(self._return_create_response, iq)
@@ -400,7 +409,7 @@
         except KeyError:
             raise BadRequest
 
-        requestor = jid.JID(iq["from"]).userhostJID()
+        requestor = jid.internJID(iq["from"]).userhostJID()
 
         for element in iq.pubsub.configure.elements():
             if element.name != 'x' or element.uri != data_form.NS_X_DATA:
@@ -434,7 +443,9 @@
 
         return options
 
-components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService)
+components.registerAdapter(ComponentServiceFromNodeCreationService,
+                           backend.INodeCreationService,
+                           component.IService)
 
 class ComponentServiceFromAffiliationsService(Service):
 
@@ -453,7 +464,8 @@
         self.handler_wrapper(self._onAffiliations, iq)
 
     def _onAffiliations(self, iq):
-        d = self.backend.get_affiliations(jid.JID(iq["from"]).userhostJID())
+        entity = jid.internJID(iq["from"]).userhostJID()
+        d = self.backend.get_affiliations(entity)
         d.addCallback(self._return_affiliations_response, iq)
         return d
 
@@ -468,7 +480,9 @@
             entity['subscription'] = r['subscription'] or 'none'
         return [reply]
 
-components.registerAdapter(ComponentServiceFromAffiliationsService, backend.IAffiliationsService, component.IService)
+components.registerAdapter(ComponentServiceFromAffiliationsService,
+                           backend.IAffiliationsService,
+                           component.IService)
 
 class ComponentServiceFromItemRetrievalService(Service):
 
@@ -508,7 +522,9 @@
                 except KeyError:
                     raise BadRequest
        
-        d = self.backend.get_items(node_id, jid.JID(iq["from"]), max_items,
+        d = self.backend.get_items(node_id,
+                                   jid.internJID(iq["from"]),
+                                   max_items,
                                    item_ids)
         d.addCallback(self._return_items_response, node_id)
         return d
@@ -522,7 +538,9 @@
 
         return [reply]
 
-components.registerAdapter(ComponentServiceFromItemRetrievalService, backend.IItemRetrievalService, component.IService)
+components.registerAdapter(ComponentServiceFromItemRetrievalService,
+                           backend.IItemRetrievalService,
+                           component.IService)
 
 class ComponentServiceFromRetractionService(Service):
 
@@ -557,8 +575,8 @@
                 except KeyError:
                     raise BadRequest
 
-        return self.backend.retract_item(node, item_ids,
-                                    jid.JID(iq["from"]).userhostJID())
+        requestor = jid.internJID(iq["from"]).userhostJID()
+        return self.backend.retract_item(node, item_ids, requestor)
 
     def onPurge(self, iq):
         self.handler_wrapper(self._onPurge, iq)
@@ -569,9 +587,12 @@
         except KeyError:
             raise BadRequest
 
-        return self.backend.purge_node(node, jid.JID(iq["from"]).userhostJID())
+        return self.backend.purge_node(node,
+                           jid.internJID(iq["from"]).userhostJID())
 
-components.registerAdapter(ComponentServiceFromRetractionService, backend.IRetractionService, component.IService)
+components.registerAdapter(ComponentServiceFromRetractionService,
+                           backend.IRetractionService,
+                           component.IService)
 
 class ComponentServiceFromNodeDeletionService(Service):
 
@@ -620,6 +641,9 @@
         except KeyError:
             raise BadRequest
 
-        return self.backend.delete_node(node, jid.JID(iq["from"]).userhostJID())
+        return self.backend.delete_node(node,
+                            jid.internJID(iq["from"]).userhostJID())
 
-components.registerAdapter(ComponentServiceFromNodeDeletionService, backend.INodeDeletionService, component.IService)
+components.registerAdapter(ComponentServiceFromNodeDeletionService,
+                           backend.INodeDeletionService,
+                           component.IService)