Created
June 21, 2020 16:34
-
-
Save kurzweil777/955da44480bfc61dce2e6291b0a6d877 to your computer and use it in GitHub Desktop.
Exercise from Py_Course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create an @authenticated decorator that only allows the function to run is user1 has 'valid' set to True: | |
| user1 = { | |
| 'name': 'Sorna', | |
| 'valid': True # changing this will either run or not run the message_friends function. | |
| } | |
| def authenticated(fn): | |
| def check(*args, **kwargs): | |
| if dict(*args).get('valid'): | |
| return fn(*args, **kwargs) | |
| else: | |
| print(f'Authorization for {dict(*args).get("name")} is not valid') | |
| return check | |
| @authenticated | |
| def message_friends(user): | |
| print('message has been sent') | |
| message_friends(user1) # message has been sent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment