ospath.py 794 B

123456789101112131415161718192021222324252627282930
  1. """Async executor versions of file functions from the os.path module."""
  2. import asyncio
  3. from functools import partial, wraps
  4. from os import path
  5. def wrap(func):
  6. @wraps(func)
  7. async def run(*args, loop=None, executor=None, **kwargs):
  8. if loop is None:
  9. loop = asyncio.get_running_loop()
  10. pfunc = partial(func, *args, **kwargs)
  11. return await loop.run_in_executor(executor, pfunc)
  12. return run
  13. exists = wrap(path.exists)
  14. isfile = wrap(path.isfile)
  15. isdir = wrap(path.isdir)
  16. islink = wrap(path.islink)
  17. ismount = wrap(path.ismount)
  18. getsize = wrap(path.getsize)
  19. getmtime = wrap(path.getmtime)
  20. getatime = wrap(path.getatime)
  21. getctime = wrap(path.getctime)
  22. samefile = wrap(path.samefile)
  23. sameopenfile = wrap(path.sameopenfile)
  24. abspath = wrap(path.abspath)