You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7KB

  1. from . import compat
  2. have_greenlet = False
  3. if compat.py3k:
  4. try:
  5. import greenlet # noqa F401
  6. except ImportError:
  7. pass
  8. else:
  9. have_greenlet = True
  10. from ._concurrency_py3k import await_only
  11. from ._concurrency_py3k import await_fallback
  12. from ._concurrency_py3k import greenlet_spawn
  13. from ._concurrency_py3k import is_exit_exception
  14. from ._concurrency_py3k import AsyncAdaptedLock
  15. from ._concurrency_py3k import _util_async_run # noqa F401
  16. from ._concurrency_py3k import (
  17. _util_async_run_coroutine_function,
  18. ) # noqa F401, E501
  19. from ._concurrency_py3k import asyncio # noqa F401
  20. if not have_greenlet:
  21. asyncio = None # noqa F811
  22. def _not_implemented():
  23. # this conditional is to prevent pylance from considering
  24. # greenlet_spawn() etc as "no return" and dimming out code below it
  25. if have_greenlet:
  26. return None
  27. if not compat.py3k:
  28. raise ValueError("Cannot use this function in py2.")
  29. else:
  30. raise ValueError(
  31. "the greenlet library is required to use this function."
  32. )
  33. def is_exit_exception(e): # noqa F811
  34. return not isinstance(e, Exception)
  35. def await_only(thing): # noqa F811
  36. _not_implemented()
  37. def await_fallback(thing): # noqa F81
  38. return thing
  39. def greenlet_spawn(fn, *args, **kw): # noqa F81
  40. _not_implemented()
  41. def AsyncAdaptedLock(*args, **kw): # noqa F81
  42. _not_implemented()
  43. def _util_async_run(fn, *arg, **kw): # noqa F81
  44. return fn(*arg, **kw)
  45. def _util_async_run_coroutine_function(fn, *arg, **kw): # noqa F81
  46. _not_implemented()