diff options
author | Lance Stout <lancestout@gmail.com> | 2012-03-12 09:43:24 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-03-12 19:32:20 -0700 |
commit | f8f2b541db2c7d53e96ff972fc3349fa4c1ea05d (patch) | |
tree | f39f1ca22371088f72d96503d2fac30fe43cf47a /sleekxmpp/basexmpp.py | |
parent | 9d645ad5cd06cabc20cd1b0067a2b16a0c1e7814 (diff) | |
download | slixmpp-f8f2b541db2c7d53e96ff972fc3349fa4c1ea05d.tar.gz slixmpp-f8f2b541db2c7d53e96ff972fc3349fa4c1ea05d.tar.bz2 slixmpp-f8f2b541db2c7d53e96ff972fc3349fa4c1ea05d.tar.xz slixmpp-f8f2b541db2c7d53e96ff972fc3349fa4c1ea05d.zip |
Handle loading plugins on demand.
Plugins that are referenced as dependencies, but have not been
registered now will be imported. Newer plugins should register
themselves automatically, but older style plugins will be
explicitly registered after import.
Diffstat (limited to 'sleekxmpp/basexmpp.py')
-rw-r--r-- | sleekxmpp/basexmpp.py | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/sleekxmpp/basexmpp.py b/sleekxmpp/basexmpp.py index c0e5f9bd..dc1f6b94 100644 --- a/sleekxmpp/basexmpp.py +++ b/sleekxmpp/basexmpp.py @@ -32,7 +32,7 @@ from sleekxmpp.xmlstream.matcher import MatchXPath from sleekxmpp.xmlstream.handler import Callback from sleekxmpp.features import * -from sleekxmpp.plugins import PluginManager, register_plugin +from sleekxmpp.plugins import PluginManager, register_plugin, load_plugin log = logging.getLogger(__name__) @@ -218,34 +218,7 @@ class BaseXMPP(XMLStream): pconfig = self.plugin_config.get(plugin, {}) if not self.plugin.registered(plugin): - # Use old-style plugin - try: - #Import the given module that contains the plugin. - if not module: - try: - module = sleekxmpp.plugins - module = __import__( - str("%s.%s" % (module.__name__, plugin)), - globals(), locals(), [str(plugin)]) - except ImportError: - module = sleekxmpp.features - module = __import__( - str("%s.%s" % (module.__name__, plugin)), - globals(), locals(), [str(plugin)]) - if isinstance(module, str): - # We probably want to load a module from outside - # the sleekxmpp package, so leave out the globals(). - module = __import__(module, fromlist=[plugin]) - - plugin_class = getattr(module, plugin) - - if not hasattr(plugin_class, 'name'): - plugin_class.name = plugin - register_plugin(plugin_class, name=plugin) - except: - log.exception("Unable to load plugin: %s", plugin) - return - + load_plugin(plugin, module) self.plugin.enable(plugin, pconfig) def register_plugins(self): |