Cleanup plugin import logic.

Checking for a 'xep' or 'rfc' attribute is more reliable
for detecting an old style plugin than 'name'.
This commit is contained in:
Lance Stout 2012-03-12 19:00:32 -07:00
parent 162e955bd6
commit cabf27424f

View file

@ -13,8 +13,9 @@
:license: MIT, see LICENSE for more details :license: MIT, see LICENSE for more details
""" """
import threading import sys
import logging import logging
import threading
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -77,17 +78,20 @@ def load_plugin(name, module=None):
if not module: if not module:
try: try:
module = 'sleekxmpp.plugins.%s' % name module = 'sleekxmpp.plugins.%s' % name
mod = __import__(module, fromlist=[str(name)]) __import__(module)
mod = sys.modules[module]
except: except:
module = 'sleekxmpp.features.%s' % name module = 'sleekxmpp.features.%s' % name
mod = __import__(module, fromlist=[str(name)]) __import__(module)
mod = sys.modules[module]
else: else:
mod = __import__(module, fromlist=[str(name)]) __import__(module)
mod = sys.modules[module]
# Add older style plugins to the registry. # Add older style plugins to the registry.
if hasattr(mod, name): if hasattr(mod, name):
plugin = getattr(mod, name) plugin = getattr(mod, name)
if not hasattr(plugin, 'name'): if hasattr(plugin, 'xep') or hasattr(plugin, 'rfc'):
plugin.name = name plugin.name = name
# Mark the plugin as an older style plugin so # Mark the plugin as an older style plugin so
# we can work around dependency issues. # we can work around dependency issues.