Merge pull request #3825 from radarhere/path

Fixed opening mmap image through Path on Windows
This commit is contained in:
Hugo 2019-05-04 18:51:23 +03:00 committed by GitHub
commit 9a25b3c797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -76,6 +76,10 @@ class TestImage(PillowTestCase):
@unittest.skipUnless(Image.HAS_PATHLIB, "requires pathlib/pathlib2")
def test_pathlib(self):
from PIL.Image import Path
im = Image.open(Path("Tests/images/multipage-mmap.tiff"))
self.assertEqual(im.mode, "P")
self.assertEqual(im.size, (10, 10))
im = Image.open(Path("Tests/images/hopper.jpg"))
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128))

View File

@ -2643,10 +2643,10 @@ def open(fp, mode="r"):
exclusive_fp = False
filename = ""
if isPath(fp):
filename = fp
elif HAS_PATHLIB and isinstance(fp, Path):
if HAS_PATHLIB and isinstance(fp, Path):
filename = str(fp.resolve())
elif isPath(fp):
filename = fp
if filename:
fp = builtins.open(filename, "rb")