Skip to content

Instantly share code, notes, and snippets.

@ducva
Last active May 28, 2020 03:25
Show Gist options
  • Save ducva/275be28640de409ad1eb4775accb0e3c to your computer and use it in GitHub Desktop.
Save ducva/275be28640de409ad1eb4775accb0e3c to your computer and use it in GitHub Desktop.
def filter_message(prefix: str):
def inner_check(func: typing.Callable[[str], None]):
def inner_deeper_check(arg: str):
if arg.startswith(prefix):
print('Checking prefix....OK')
func(arg)
print('post process...OK')
else:
print('Checking prefix....Failed')
print('access denied')
return inner_deeper_check
return inner_check
@filter_message(prefix="test")
def orig_func(arg1: str):
print(f"arg1: {arg1}")
if __name__ == "__main__":
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