# Path: marvinbot/defaults.py
# DEFAULT_PRIORITY = 2
# 
# Path: marvinbot/errors.py
# class PluginLoadException(Exception):
#     pass
# 
# Path: marvinbot/signals.py



from flask import Blueprint
from marvinbot.defaults import DEFAULT_PRIORITY
from marvinbot.errors import PluginLoadException
from marvinbot.signals import plugin_loaded
from urllib.parse import quote_plus
import importlib
import logging

log = logging.getLogger(__name__)


__all__ = ['load_module', 'load_plugins', 'Plugin']


def load_module(modspec, config, adapter=None, webapp=None):
    enabled = config.pop('enabled', True)
    short_name = config.get('short_name')
    mod = importlib.import_module(modspec)
    if hasattr(mod, 'plugin'):
        plugin = mod.plugin
    else:
        plugin = Plugin(short_name, modspec, adapter)

    plugin.name = short_name or plugin.name or modspec
    plugin.config = config
    plugin.adapter = adapter
    plugin.enabled = enabled
    plugin.modspec = modspec

    if adapter:
        adapter.add_plugin(plugin)
    plugin.load()

    if webapp:
        web_interface = plugin.provide_blueprint(config)
        if adapter:
            web_interface.adapter = adapter

# Path: marvinbot/defaults.py
# DEFAULT_PRIORITY = 2
# 
# Path: marvinbot/errors.py
# class PluginLoadException(Exception):
#     pass
# 
# Path: marvinbot/signals.py



# Path: marvinbot/plugins.py
from flask import Blueprint
from marvinbot.defaults import DEFAULT_PRIORITY
from marvinbot.errors import PluginLoadException
from marvinbot.signals import plugin_loaded
from urllib.parse import quote_plus
import importlib
import logging


log = logging.getLogger(__name__)


__all__ = ['load_module', 'load_plugins', 'Plugin']


def load_module(modspec, config, adapter=None, webapp=None):
    enabled = config.pop('enabled', True)
    short_name = config.get('short_name')
    mod = importlib.import_module(modspec)
    if hasattr(mod, 'plugin'):
        plugin = mod.plugin
    else:
        plugin = Plugin(short_name, modspec, adapter)

    plugin.name = short_name or plugin.name or modspec
    plugin.config = config
    plugin.adapter = adapter
    plugin.enabled = enabled
    plugin.modspec = modspec

    if adapter:
        adapter.add_plugin(plugin)
    plugin.load()

    if webapp:
        web_interface = plugin.provide_blueprint(config)
        if adapter:
            web_interface.adapter = adapter

        if web_interface: