diff twisted/plugins/pubsub.py @ 417:412d26a9b2c2

import sat/wokkel modules only when making service: when importing some sat/wokkel module, a reactor is installed. This can cause trouble when using sat_pubsub along with other twisted plugin installing a specific reactor (which is the case for SàT backend and Libervia). This patch works around it by importing those modules only when making the service.
author Goffi <goffi@goffi.org>
date Tue, 08 Oct 2019 12:04:13 +0200
parents ccb2a22ea0fc
children 89736353f6be
line wrap: on
line diff
--- a/twisted/plugins/pubsub.py	Sun Aug 25 12:26:35 2019 +0200
+++ b/twisted/plugins/pubsub.py	Tue Oct 08 12:04:13 2019 +0200
@@ -59,23 +59,8 @@
 from twisted.words.protocols.jabber.jid import JID
 from twisted.plugin import IPlugin
 
-from wokkel.component import Component
-from wokkel.disco import DiscoHandler
-from wokkel.generic import FallbackHandler, VersionHandler
-from wokkel.iwokkel import IPubSubResource
-from wokkel import data_form
-from wokkel import pubsub
-from wokkel import rsm
-from wokkel import mam
 from zope.interface import implementer
 
-from sat_pubsub import const
-from sat_pubsub import mam as pubsub_mam
-from sat_pubsub import pubsub_admin
-from sat_pubsub.backend import BackendService, ExtraDiscoHandler
-from sat_pubsub.schema import SchemaHandler
-from sat_pubsub.privilege import PrivilegesHandler
-from sat_pubsub.delegation import DelegationsHandler
 from os.path import expanduser, realpath
 import configparser
 
@@ -178,6 +163,22 @@
     options = Options
 
     def makeService(self, config):
+        from wokkel.component import Component
+        from wokkel.disco import DiscoHandler
+        from wokkel.generic import FallbackHandler, VersionHandler
+        from wokkel.iwokkel import IPubSubResource
+        from wokkel import data_form
+        from wokkel import pubsub
+        from wokkel import rsm
+        from wokkel import mam
+        from sat_pubsub import const
+        from sat_pubsub import mam as pubsub_mam
+        from sat_pubsub import pubsub_admin
+        from sat_pubsub.backend import BackendService, ExtraDiscoHandler
+        from sat_pubsub.schema import SchemaHandler
+        from sat_pubsub.privilege import PrivilegesHandler
+        from sat_pubsub.delegation import DelegationsHandler
+
         if not config['jid'] or not config['xmpp_pwd']:
             raise usage.UsageError("You must specify jid and xmpp_pwd")
         s = service.MultiService()