Add support for PathLike objects in static file helpers

See: https://www.python.org/dev/peps/pep-0519/

This is mostly encountered with pathlib in python 3, but this API
suggests any PathLike object can be treated like a filepath with
`__fspath__` function.
This commit is contained in:
Matt Robenolt 2019-01-03 17:17:45 -08:00 committed by David Lord
parent f7d50d4b67
commit 25de45cbb6
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
4 changed files with 62 additions and 5 deletions

View file

@ -97,3 +97,12 @@ if hasattr(sys, 'pypy_version_info'):
BROKEN_PYPY_CTXMGR_EXIT = True
except AssertionError:
pass
try:
from os import fspath
except ImportError:
# Backwards compatibility as proposed in PEP 0519:
# https://www.python.org/dev/peps/pep-0519/#backwards-compatibility
def fspath(path):
return path.__fspath__() if hasattr(path, '__fspath__') else path