From 89f9489e4c2632a2d311a75b465211b698c5096a Mon Sep 17 00:00:00 2001 From: Mitchell Yuwono Date: Tue, 28 Feb 2017 12:37:12 +1100 Subject: [PATCH] update check_arguments to use decorator library (#62) --- requirements.txt | 1 + src/main/python/covata/delta/utils.py | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/requirements.txt b/requirements.txt index 9032044..fc8b6ca 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ cryptography >= 1.7.2 # Apache Software License requests >= 2.13.0 # Apache Software License +decorator >= 4.0.11 # New BSD License \ No newline at end of file diff --git a/src/main/python/covata/delta/utils.py b/src/main/python/covata/delta/utils.py index 5d342ec..c58b0c2 100644 --- a/src/main/python/covata/delta/utils.py +++ b/src/main/python/covata/delta/utils.py @@ -13,23 +13,21 @@ # limitations under the License. import inspect -import functools +from decorator import decorator def check_arguments(arguments, validation_function, fail_message): - def decorator(function): - @functools.wraps(function) - def _f(*args, **kwargs): - keys, _, _, _ = inspect.getargspec(function) - ins = dict(zip(keys, args)) - ins.update(kwargs) - generator = ((x, y) for x, y in ins.items() if x in arguments) - for arg, value in generator: - if not validation_function(value): - raise ValueError("{} {}".format(arg, fail_message)) - return function(*args, **kwargs) - return _f - return decorator + @decorator + def _f(function, *args, **kwargs): + keys, _, _, _ = inspect.getargspec(function) + ins = dict(zip(keys, args)) + ins.update(kwargs) + generator = ((x, y) for x, y in ins.items() if x in arguments) + for arg, value in generator: + if not validation_function(value): + raise ValueError("{} {}".format(arg, fail_message)) + return function(*args, **kwargs) + return _f def check_id(arguments):