12345678910111213141516171819202122232425262728 |
- from functools import wraps
- def with_app_context(func):
- @wraps(func)
- def wrapper(self, *args, **kwargs):
- with self.app.app_context():
- return func(self, *args, **kwargs)
- return wrapper
- def singleton(cls):
- _instance = {}
- def inner():
- if cls not in _instance:
- _instance[cls] = cls()
- return _instance[cls]
- return inner
- def singleton_keys(cls):
- _instances = {}
- def wrapper(*args, **kwargs):
- if cls not in _instances:
- _instances[cls] = cls(*args, **kwargs) # Pass the arguments to the class constructor
- return _instances[cls]
- return wrapper
|