# Path: mozsvc/util.py
# def resolve_name(name, package=None):
#     """Resolve dotted name into a python object.
# 
#     This function resolves a dotted name as a reference to a python object,
#     returning whatever object happens to live at that path.  It's a simple
#     convenience wrapper around pyramid's DottedNameResolver.
# 
#     The optional argument 'package' specifies the package name for relative
#     imports.  If not specified, only absolute paths will be supported.
#     """
#     return DottedNameResolver(package).resolve(name)


from zope.interface import providedBy
from mozsvc.util import resolve_name


def load_from_config(section_name, config):
    """Load the plugin from the given section in a Config object.

    This function loads a plugin using the settings specified in a Config
    object section.  The key "backend" must be present in the section and
    gives the dotted name of the plugin class to load.  Any other keys in
    the secton will be passed as keyword arguments to the class.
    """
    kwargs = dict(config.items(section_name))
    klass = resolve_name(kwargs.pop("backend"))
    return klass(**kwargs)


def load_from_settings(section_name, settings):
    """Load the plugin from the given section in a settings dict.

    This function loads a plugin using prefixed settings from the pyramid
    settings dict.  Any keys in the settings dict that start with the
    given section name plus a dot will be used.

    This a compatability function for use when a Config object is not
    available; load_from_config will usually be faster.
    """
    kwargs = {}
    prefix = section_name + "."
    for name, value in settings.items():
        if name.startswith(prefix):
            kwargs[name[len(prefix):]] = value

# Path: mozsvc/util.py
# def resolve_name(name, package=None):
#     """Resolve dotted name into a python object.
# 
#     This function resolves a dotted name as a reference to a python object,
#     returning whatever object happens to live at that path.  It's a simple
#     convenience wrapper around pyramid's DottedNameResolver.
# 
#     The optional argument 'package' specifies the package name for relative
#     imports.  If not specified, only absolute paths will be supported.
#     """
#     return DottedNameResolver(package).resolve(name)


# Path: mozsvc/plugin.py
from zope.interface import providedBy
from mozsvc.util import resolve_name



def load_from_config(section_name, config):
    """Load the plugin from the given section in a Config object.

    This function loads a plugin using the settings specified in a Config
    object section.  The key "backend" must be present in the section and
    gives the dotted name of the plugin class to load.  Any other keys in
    the secton will be passed as keyword arguments to the class.
    """
    kwargs = dict(config.items(section_name))
    klass = resolve_name(kwargs.pop("backend"))
    return klass(**kwargs)


def load_from_settings(section_name, settings):
    """Load the plugin from the given section in a settings dict.

    This function loads a plugin using prefixed settings from the pyramid
    settings dict.  Any keys in the settings dict that start with the
    given section name plus a dot will be used.

    This a compatability function for use when a Config object is not
    available; load_from_config will usually be faster.
    """
    kwargs = {}
    prefix = section_name + "."
    for name, value in settings.items():
        if name.startswith(prefix):
            kwargs[name[len(prefix):]] = value

    klass = resolve_name(kwargs.pop("backend"))