Created
February 26, 2024 14:18
-
-
Save dario61081/5d3b2cf59e7fda23d106ef5403e11830 to your computer and use it in GitHub Desktop.
decoradores varios
This file contains 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
from functools import wraps | |
def require_permission(func): | |
@wraps(func) | |
def eval_permission(permission: str, *args, **kwargs): | |
return func(*args, **kwargs) | |
return eval_permission | |
def singleton(cls): | |
""" | |
Convert to singleton | |
""" | |
instance = [None] | |
def wrapper(*arg, **kwargs): | |
if instance[0] is None: | |
instance[0] = cls(*arg, **kwargs) | |
return instance[0] | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment