diff options
author | Michele Simionato <michele.simionato@gmail.com> | 2018-04-15 11:49:20 +0200 |
---|---|---|
committer | Michele Simionato <michele.simionato@gmail.com> | 2018-04-15 11:49:20 +0200 |
commit | 521ed6fca86db449e902580a2d2d08e99ed1241b (patch) | |
tree | 7ed5fcf90808b686e4c8e985433871c83dd5cd7f | |
parent | 2a5ee16f7f0051beecd6a7c56900442be0a1b413 (diff) | |
download | python-decorator-git-521ed6fca86db449e902580a2d2d08e99ed1241b.tar.gz |
Additional test
-rw-r--r-- | src/tests/documentation.py | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/tests/documentation.py b/src/tests/documentation.py index c010c58..3a013dc 100644 --- a/src/tests/documentation.py +++ b/src/tests/documentation.py @@ -1503,17 +1503,16 @@ class PermissionError(Exception): pass -def restricted(user_class): - def restricted(func, *args, **kw): - "Restrict access to a given class of users" - userclass = get_userclass() - if issubclass(userclass, user_class): - return func(*args, **kw) - else: - raise PermissionError( - '%s does not have the permission to run %s!' - % (userclass.__name__, func.__name__)) - return decorator(restricted) +@decorator +def restricted(func, user_class=User, *args, **kw): + "Restrict access to a given class of users" + userclass = get_userclass() + if issubclass(userclass, user_class): + return func(*args, **kw) + else: + raise PermissionError( + '%s does not have the permission to run %s!' + % (userclass.__name__, func.__name__)) class Action(object): @@ -1525,15 +1524,15 @@ class Action(object): ... PermissionError: User does not have the permission to run insert! """ - @restricted(User) + @restricted(user_class=User) def view(self): pass - @restricted(PowerUser) + @restricted(user_class=PowerUser) def insert(self): pass - @restricted(Admin) + @restricted(user_class=Admin) def delete(self): pass |