How to use the patchy.core.NotFoundError function in patchy

To help you get started, we’ve selected a few patchy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ashleywaite / django-more / patchy / core.py View on Github external
return resolve_exposing(name)
    except ImportError as err:
        if '.' not in name:
            raise NotFoundError('{n} is not a valid module name'.format(n=name)) from err

    try:
        # Try to get an attribute of a module
        mod, attr = name.rsplit('.', maxsplit=1)
        package = resolve_exposing(mod)
        cls = getattr(package, attr)
        assert(isinstance(cls, type))
        return cls
    except ImportError as err:
        raise NotFoundError('{n} is not a valid class or module name'.format(n=name)) from err
    except AttributeError as err:
        raise NotFoundError('{a} does not exist within {m}'.format(a=attr, m=mod)) from err
    except AssertionError as err:
        raise ResolveError('{a} in {m} is not a valid class'.format(a=attr, m=mod)) from err
github ashleywaite / django-more / patchy / core.py View on Github external
def resolve(name, package=None):
    """ Turn a dotted name into a module or class reference """
    if isinstance(package, str):
        package = resolve_exposing(package)

    if package:
        name = resolve_name('.{}'.format(name), package.__name__)

    try:
        # Try to get a module
        return resolve_exposing(name)
    except ImportError as err:
        if '.' not in name:
            raise NotFoundError('{n} is not a valid module name'.format(n=name)) from err

    try:
        # Try to get an attribute of a module
        mod, attr = name.rsplit('.', maxsplit=1)
        package = resolve_exposing(mod)
        cls = getattr(package, attr)
        assert(isinstance(cls, type))
        return cls
    except ImportError as err:
        raise NotFoundError('{n} is not a valid class or module name'.format(n=name)) from err
    except AttributeError as err:
        raise NotFoundError('{a} does not exist within {m}'.format(a=attr, m=mod)) from err
    except AssertionError as err:
        raise ResolveError('{a} in {m} is not a valid class'.format(a=attr, m=mod)) from err