mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Fixed loading profile with non-ASCII path on Windows
This commit is contained in:
parent
2e029d9a79
commit
c196af6ddb
|
@ -1,6 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -436,6 +437,19 @@ def test_extended_information():
|
||||||
assert p.xcolor_space == "RGB "
|
assert p.xcolor_space == "RGB "
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_ascii_path(tmp_path):
|
||||||
|
skip_missing()
|
||||||
|
tempfile = str(tmp_path / ("temp_" + chr(128) + ".icc"))
|
||||||
|
try:
|
||||||
|
shutil.copy(SRGB, tempfile)
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
pytest.skip("Non-ASCII path could not be created")
|
||||||
|
|
||||||
|
o = ImageCms.getOpenProfile(tempfile)
|
||||||
|
p = o.profile
|
||||||
|
assert p.model == "IEC 61966-2-1 Default RGB Colour Space - sRGB"
|
||||||
|
|
||||||
|
|
||||||
def test_profile_typesafety():
|
def test_profile_typesafety():
|
||||||
"""Profile init type safety
|
"""Profile init type safety
|
||||||
|
|
||||||
|
|
|
@ -111,12 +111,12 @@ class TestImageFont:
|
||||||
with open(FONT_PATH, "rb") as f:
|
with open(FONT_PATH, "rb") as f:
|
||||||
self._render(f)
|
self._render(f)
|
||||||
|
|
||||||
def test_non_unicode_path(self, tmp_path):
|
def test_non_ascii_path(self, tmp_path):
|
||||||
tempfile = str(tmp_path / ("temp_" + chr(128) + ".ttf"))
|
tempfile = str(tmp_path / ("temp_" + chr(128) + ".ttf"))
|
||||||
try:
|
try:
|
||||||
shutil.copy(FONT_PATH, tempfile)
|
shutil.copy(FONT_PATH, tempfile)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
pytest.skip("Unicode path could not be created")
|
pytest.skip("Non-ASCII path could not be created")
|
||||||
|
|
||||||
ImageFont.truetype(tempfile, FONT_SIZE)
|
ImageFont.truetype(tempfile, FONT_SIZE)
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,14 @@ class ImageCmsProfile:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(profile, str):
|
if isinstance(profile, str):
|
||||||
|
if sys.platform == "win32":
|
||||||
|
profile_bytes_path = profile.encode()
|
||||||
|
try:
|
||||||
|
profile_bytes_path.decode("ascii")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
with open(profile, "rb") as f:
|
||||||
|
self._set(core.profile_frombytes(f.read()))
|
||||||
|
return
|
||||||
self._set(core.profile_open(profile), profile)
|
self._set(core.profile_open(profile), profile)
|
||||||
elif hasattr(profile, "read"):
|
elif hasattr(profile, "read"):
|
||||||
self._set(core.profile_frombytes(profile.read()))
|
self._set(core.profile_frombytes(profile.read()))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user