_util.py 804 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. import sys
  3. py3 = sys.version_info.major >= 3
  4. py36 = sys.version_info[0:2] >= (3, 6)
  5. if py3:
  6. def isStringType(t):
  7. return isinstance(t, str)
  8. if py36:
  9. from pathlib import Path
  10. def isPath(f):
  11. return isinstance(f, (bytes, str, Path))
  12. else:
  13. def isPath(f):
  14. return isinstance(f, (bytes, str))
  15. else:
  16. def isStringType(t):
  17. return isinstance(t, basestring) # noqa: F821
  18. def isPath(f):
  19. return isinstance(f, basestring) # noqa: F821
  20. # Checks if an object is a string, and that it points to a directory.
  21. def isDirectory(f):
  22. return isPath(f) and os.path.isdir(f)
  23. class deferred_error(object):
  24. def __init__(self, ex):
  25. self.ex = ex
  26. def __getattr__(self, elt):
  27. raise self.ex