Created
May 28, 2020 03:50
-
-
Save ducva/7ff12016b76a660dcec02bf291740d05 to your computer and use it in GitHub Desktop.
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
| class Authed: | |
| def __init__(self, func: typing.Callable[[str], None]): | |
| self.func = func | |
| self.checked_times = 0 | |
| def __call__(self, arg: str): | |
| print('checking auth....OK') | |
| self.checked_times += 1 | |
| if self.checked_times >= 5: | |
| print('run out of time') | |
| else: | |
| self.func(arg) | |
| print('post process....OK') | |
| @Authed | |
| def orig_func(arg1: str): | |
| print(f"arg1: {arg1}") | |
| if __name__ == "__main__": | |
| orig_func("Hello World!") | |
| orig_func("test: Hello World!") | |
| orig_func("Hello World!") | |
| orig_func("test: Hello World!") | |
| orig_func("Hello World!") | |
| orig_func("test: Hello World!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment