mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Allow pathlib.Path in Image.open on Python 2.7
Although the pathlib backport for Python 2.7 may be deprecated: https://pypi.python.org/pypi/pathlib/ It is still used by many projects. Therefore, changing to a Try/Except pattern for checking for pathlib is not any more obtrusive that the current >= Python 3.4 check and allows users to use the backport without issue.
This commit is contained in:
parent
6e7553fb0f
commit
e981c41b47
12
PIL/Image.py
12
PIL/Image.py
|
@ -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")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user