__init__.py 654 B

12345678910111213141516171819202122232425262728
  1. from functools import wraps
  2. def with_app_context(func):
  3. @wraps(func)
  4. def wrapper(self, *args, **kwargs):
  5. with self.app.app_context():
  6. return func(self, *args, **kwargs)
  7. return wrapper
  8. def singleton(cls):
  9. _instance = {}
  10. def inner():
  11. if cls not in _instance:
  12. _instance[cls] = cls()
  13. return _instance[cls]
  14. return inner
  15. def singleton_keys(cls):
  16. _instances = {}
  17. def wrapper(*args, **kwargs):
  18. if cls not in _instances:
  19. _instances[cls] = cls(*args, **kwargs) # Pass the arguments to the class constructor
  20. return _instances[cls]
  21. return wrapper