Advertisement
193030

Python decorators

Jan 24th, 2022
878
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement