Merge pull request #2110 from patricksnape/allow_pathlib_py2

Allow pathlib.Path in Image.open on Python 2.7
This commit is contained in:
Hugo 2016-09-20 17:54:11 +03:00 committed by GitHub
commit bc354d10c2

View File

@ -2279,10 +2279,14 @@ def open(fp, mode="r"):
filename = ""
if isPath(fp):
filename = fp
elif sys.version_info >= (3, 4):
from pathlib import Path
if isinstance(fp, Path):
filename = str(fp.resolve())
else:
try:
from pathlib import Path
if isinstance(fp, Path):
filename = str(fp.resolve())
except ImportError:
pass
if filename:
fp = builtins.open(filename, "rb")