From 4bd7b72aa0ca3a09ab99e1a3b41753df81de6af9 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Sun, 27 May 2012 20:14:17 +0200 Subject: Initial commit --- brevisurl/utils.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 brevisurl/utils.py (limited to 'brevisurl/utils.py') 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 -- cgit v1.2.3