Advertisement
193030

Python decorators

Jan 24th, 2022
1,006
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. user = {"username ": "joesey", "access_level" : "admin"}
  2.  
  3. def make_secure(func):
  4.     def secure_function():
  5.         if user["access_level"] == "admin":
  6.             return func()
  7.         else:
  8.             return f"No admin permission for {user['username']}"
  9.     return secure_function()
  10.  
  11. @make_secure # get_admin_password = make_secure(get_admin_password)
  12. def get_admin_password():
  13.     return 1234
  14.  
  15. print(get_admin_password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement