From 93e11befc562e9c66f1e0243edf7683750f309c0 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Fri, 18 Mar 2016 13:03:23 +0100 Subject: [PATCH] [utils.py] Errors in utils.import_attr are more understandable. --- cas_server/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cas_server/utils.py b/cas_server/utils.py index 24127b3..7fa6e70 100644 --- a/cas_server/utils.py +++ b/cas_server/utils.py @@ -39,8 +39,15 @@ def import_attr(path): """transform a python module.attr path to the attr""" if not isinstance(path, str): return string + if "." not in path: + ValueError("%r should be of the form `module.attr` and we just got `attr`" % path) module, attr = path.rsplit('.', 1) - return getattr(import_module(module), attr) + try: + return getattr(import_module(module), attr) + except ImportError: + raise ImportError("Module %r not found" % module) + except AttributeError: + raise AttributeError("Module %r has not attribut %r" % (module, attr)) def redirect_params(url_name, params=None):