utils.py 612 B

12345678910111213141516171819202122232425
  1. # flake8: noqa
  2. try:
  3. from .utils_py3 import __aenter__
  4. from .utils_py3 import __aexit__
  5. from .utils_py3 import __aiter__
  6. from .utils_py3 import __anext__
  7. from .utils_py3 import __await__
  8. from .utils_py3 import await_
  9. except (ImportError, SyntaxError):
  10. await_ = None
  11. def identity(obj):
  12. return obj
  13. class cached_property(object):
  14. def __init__(self, func):
  15. self.func = func
  16. def __get__(self, obj, cls):
  17. if obj is None:
  18. return self
  19. value = obj.__dict__[self.func.__name__] = self.func(obj)
  20. return value