diff options
| author | Vladimir Gorej | 2012-05-27 20:14:17 +0200 | 
|---|---|---|
| committer | Vladimir Gorej | 2012-05-27 20:14:17 +0200 | 
| commit | 4bd7b72aa0ca3a09ab99e1a3b41753df81de6af9 (patch) | |
| tree | 6328ed9894666eefc1f0d6b6c7b28a87b1fb4d31 /brevisurl/utils.py | |
| download | django-brevisurl-4bd7b72aa0ca3a09ab99e1a3b41753df81de6af9.tar.bz2 | |
Initial commit
Diffstat (limited to 'brevisurl/utils.py')
| -rw-r--r-- | brevisurl/utils.py | 18 | 
1 files changed, 18 insertions, 0 deletions
| diff --git a/brevisurl/utils.py b/brevisurl/utils.py new file mode 100644 index 0000000..e0c3d52 --- /dev/null +++ b/brevisurl/utils.py @@ -0,0 +1,18 @@ +from django.utils import importlib + + +def load_object(import_path): +    """Util for importing objects from import path. + +    :param import_path: import path of object to be imported e.g. module.submodule.Class +    :type import_path: string +    :returns: imported object +    :rtype: object +    :raises: ValueError, ImportError, AttributeError + +    """ +    if not (isinstance(import_path, basestring) and '.' in import_path): +        raise ValueError('There must be at least one dot in import path: "%s"', import_path) +    module_name, object_name = import_path.rsplit('.', 1) +    module = importlib.import_module(module_name) +    return getattr(module, object_name)
\ No newline at end of file | 
