mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Since Python 3.3 IOError and WindowsError have been merged into OSError
This commit is contained in:
parent
a8a4b9bfdb
commit
dda6145fce
|
@ -5,5 +5,5 @@ from PIL import Image
|
||||||
def test_j2k_overflow(tmp_path):
|
def test_j2k_overflow(tmp_path):
|
||||||
im = Image.new("RGBA", (1024, 131584))
|
im = Image.new("RGBA", (1024, 131584))
|
||||||
target = str(tmp_path / "temp.jpc")
|
target = str(tmp_path / "temp.jpc")
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(target)
|
im.save(target)
|
||||||
|
|
|
@ -9,6 +9,6 @@ def test_libtiff_segfault():
|
||||||
libtiff >= 4.0.0
|
libtiff >= 4.0.0
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
with Image.open(TEST_FILE) as im:
|
with Image.open(TEST_FILE) as im:
|
||||||
im.load()
|
im.load()
|
||||||
|
|
|
@ -32,7 +32,7 @@ def test_load():
|
||||||
with Image.open(TEST_FILE) as im:
|
with Image.open(TEST_FILE) as im:
|
||||||
|
|
||||||
# Act / Assert: stub cannot load without an implemented handler
|
# Act / Assert: stub cannot load without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,5 +42,5 @@ def test_save(tmp_path):
|
||||||
tmpfile = str(tmp_path / "temp.bufr")
|
tmpfile = str(tmp_path / "temp.bufr")
|
||||||
|
|
||||||
# Act / Assert: stub cannot save without an implemented handler
|
# Act / Assert: stub cannot save without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(tmpfile)
|
im.save(tmpfile)
|
||||||
|
|
|
@ -138,7 +138,7 @@ def test_short_header():
|
||||||
def short_header():
|
def short_header():
|
||||||
Image.open(BytesIO(img_file[:119]))
|
Image.open(BytesIO(img_file[:119]))
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
short_header()
|
short_header()
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def test_short_file():
|
||||||
with Image.open(BytesIO(img_file[:-100])) as im:
|
with Image.open(BytesIO(img_file[:-100])) as im:
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
short_file()
|
short_file()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ def test_load():
|
||||||
with Image.open(TEST_FILE) as im:
|
with Image.open(TEST_FILE) as im:
|
||||||
|
|
||||||
# Act / Assert: stub cannot load without an implemented handler
|
# Act / Assert: stub cannot load without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ def test_save():
|
||||||
dummy_filename = "dummy.filename"
|
dummy_filename = "dummy.filename"
|
||||||
|
|
||||||
# Act / Assert: stub cannot save without an implemented handler
|
# Act / Assert: stub cannot save without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(dummy_filename)
|
im.save(dummy_filename)
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
FitsStubImagePlugin._save(im, dummy_fp, dummy_filename)
|
FitsStubImagePlugin._save(im, dummy_fp, dummy_filename)
|
||||||
|
|
|
@ -19,5 +19,5 @@ def test_invalid_file():
|
||||||
|
|
||||||
|
|
||||||
def test_fpx_invalid_number_of_bands():
|
def test_fpx_invalid_number_of_bands():
|
||||||
with pytest.raises(IOError, match="Invalid number of bands"):
|
with pytest.raises(OSError, match="Invalid number of bands"):
|
||||||
Image.open("Tests/images/input_bw_five_bands.fpx")
|
Image.open("Tests/images/input_bw_five_bands.fpx")
|
||||||
|
|
|
@ -32,7 +32,7 @@ def test_load():
|
||||||
with Image.open(TEST_FILE) as im:
|
with Image.open(TEST_FILE) as im:
|
||||||
|
|
||||||
# Act / Assert: stub cannot load without an implemented handler
|
# Act / Assert: stub cannot load without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,5 +42,5 @@ def test_save(tmp_path):
|
||||||
tmpfile = str(tmp_path / "temp.grib")
|
tmpfile = str(tmp_path / "temp.grib")
|
||||||
|
|
||||||
# Act / Assert: stub cannot save without an implemented handler
|
# Act / Assert: stub cannot save without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(tmpfile)
|
im.save(tmpfile)
|
||||||
|
|
|
@ -30,7 +30,7 @@ def test_load():
|
||||||
with Image.open(TEST_FILE) as im:
|
with Image.open(TEST_FILE) as im:
|
||||||
|
|
||||||
# Act / Assert: stub cannot load without an implemented handler
|
# Act / Assert: stub cannot load without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ def test_save():
|
||||||
dummy_filename = "dummy.filename"
|
dummy_filename = "dummy.filename"
|
||||||
|
|
||||||
# Act / Assert: stub cannot save without an implemented handler
|
# Act / Assert: stub cannot save without an implemented handler
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(dummy_filename)
|
im.save(dummy_filename)
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Hdf5StubImagePlugin._save(im, dummy_fp, dummy_filename)
|
Hdf5StubImagePlugin._save(im, dummy_fp, dummy_filename)
|
||||||
|
|
|
@ -147,7 +147,7 @@ class TestFileJpeg:
|
||||||
with Image.open("Tests/images/icc_profile_big.jpg") as im:
|
with Image.open("Tests/images/icc_profile_big.jpg") as im:
|
||||||
f = str(tmp_path / "temp.jpg")
|
f = str(tmp_path / "temp.jpg")
|
||||||
icc_profile = im.info["icc_profile"]
|
icc_profile = im.info["icc_profile"]
|
||||||
# Should not raise IOError for image with icc larger than image size.
|
# Should not raise OSError for image with icc larger than image size.
|
||||||
im.save(
|
im.save(
|
||||||
f,
|
f,
|
||||||
format="JPEG",
|
format="JPEG",
|
||||||
|
@ -379,14 +379,14 @@ class TestFileJpeg:
|
||||||
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
ImageFile.LOAD_TRUNCATED_IMAGES = False
|
||||||
assert im.getbbox() is not None
|
assert im.getbbox() is not None
|
||||||
|
|
||||||
def test_truncated_jpeg_throws_IOError(self):
|
def test_truncated_jpeg_throws_oserror(self):
|
||||||
filename = "Tests/images/truncated_jpeg.jpg"
|
filename = "Tests/images/truncated_jpeg.jpg"
|
||||||
with Image.open(filename) as im:
|
with Image.open(filename) as im:
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
# Test that the error is raised if loaded a second time
|
# Test that the error is raised if loaded a second time
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
def test_qtables(self, tmp_path):
|
def test_qtables(self, tmp_path):
|
||||||
|
@ -552,7 +552,7 @@ class TestFileJpeg:
|
||||||
out = BytesIO()
|
out = BytesIO()
|
||||||
for mode in ["LA", "La", "RGBA", "RGBa", "P"]:
|
for mode in ["LA", "La", "RGBA", "RGBa", "P"]:
|
||||||
img = Image.new(mode, (20, 20))
|
img = Image.new(mode, (20, 20))
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
img.save(out, "JPEG")
|
img.save(out, "JPEG")
|
||||||
|
|
||||||
def test_save_tiff_with_dpi(self, tmp_path):
|
def test_save_tiff_with_dpi(self, tmp_path):
|
||||||
|
@ -702,7 +702,7 @@ class TestFileCloseW32:
|
||||||
im = Image.open(tmpfile)
|
im = Image.open(tmpfile)
|
||||||
fp = im.fp
|
fp = im.fp
|
||||||
assert not fp.closed
|
assert not fp.closed
|
||||||
with pytest.raises(WindowsError):
|
with pytest.raises(OSError):
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
im.load()
|
im.load()
|
||||||
assert fp.closed
|
assert fp.closed
|
||||||
|
|
|
@ -218,7 +218,7 @@ def test_16bit_jp2_roundtrips():
|
||||||
|
|
||||||
def test_unbound_local():
|
def test_unbound_local():
|
||||||
# prepatch, a malformed jp2 file could cause an UnboundLocalError exception.
|
# prepatch, a malformed jp2 file could cause an UnboundLocalError exception.
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open("Tests/images/unbound_variable.jp2")
|
Image.open("Tests/images/unbound_variable.jp2")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -479,11 +479,11 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
im = hopper("RGB")
|
im = hopper("RGB")
|
||||||
out = str(tmp_path / "temp.tif")
|
out = str(tmp_path / "temp.tif")
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(out, compression="tiff_ccitt")
|
im.save(out, compression="tiff_ccitt")
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(out, compression="group3")
|
im.save(out, compression="group3")
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(out, compression="group4")
|
im.save(out, compression="group4")
|
||||||
|
|
||||||
def test_fp_leak(self):
|
def test_fp_leak(self):
|
||||||
|
@ -831,7 +831,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||||
def test_realloc_overflow(self):
|
def test_realloc_overflow(self):
|
||||||
TiffImagePlugin.READ_LIBTIFF = True
|
TiffImagePlugin.READ_LIBTIFF = True
|
||||||
with Image.open("Tests/images/tiff_overflow_rows_per_strip.tif") as im:
|
with Image.open("Tests/images/tiff_overflow_rows_per_strip.tif") as im:
|
||||||
with pytest.raises(IOError) as e:
|
with pytest.raises(OSError) as e:
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
# Assert that the error code is IMAGING_CODEC_MEMORY
|
# Assert that the error code is IMAGING_CODEC_MEMORY
|
||||||
|
|
|
@ -86,5 +86,5 @@ def test_cannot_save_wrong_mode(tmp_path):
|
||||||
filename = str(tmp_path / "temp.msp")
|
filename = str(tmp_path / "temp.msp")
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(filename)
|
im.save(filename)
|
||||||
|
|
|
@ -72,19 +72,19 @@ def test_p_mode(tmp_path):
|
||||||
roundtrip(tmp_path, mode)
|
roundtrip(tmp_path, mode)
|
||||||
|
|
||||||
|
|
||||||
def test_l_ioerror(tmp_path):
|
def test_l_oserror(tmp_path):
|
||||||
# Arrange
|
# Arrange
|
||||||
mode = "L"
|
mode = "L"
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
helper_save_as_palm(tmp_path, mode)
|
helper_save_as_palm(tmp_path, mode)
|
||||||
|
|
||||||
|
|
||||||
def test_rgb_ioerror(tmp_path):
|
def test_rgb_oserror(tmp_path):
|
||||||
# Arrange
|
# Arrange
|
||||||
mode = "RGB"
|
mode = "RGB"
|
||||||
|
|
||||||
# Act / Assert
|
# Act / Assert
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
helper_save_as_palm(tmp_path, mode)
|
helper_save_as_palm(tmp_path, mode)
|
||||||
|
|
|
@ -172,7 +172,7 @@ def test_pdf_open(tmp_path):
|
||||||
def test_pdf_append_fails_on_nonexistent_file():
|
def test_pdf_append_fails_on_nonexistent_file():
|
||||||
im = hopper("RGB")
|
im = hopper("RGB")
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(os.path.join(temp_dir, "nonexistent.pdf"), append=True)
|
im.save(os.path.join(temp_dir, "nonexistent.pdf"), append=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ class TestFilePng:
|
||||||
# file was checked into Subversion as a text file.
|
# file was checked into Subversion as a text file.
|
||||||
|
|
||||||
test_file = "Tests/images/broken.png"
|
test_file = "Tests/images/broken.png"
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open(test_file)
|
Image.open(test_file)
|
||||||
|
|
||||||
def test_bad_text(self):
|
def test_bad_text(self):
|
||||||
|
@ -334,7 +334,7 @@ class TestFilePng:
|
||||||
def test_verify_struct_error(self):
|
def test_verify_struct_error(self):
|
||||||
# Check open/load/verify exception (#1755)
|
# Check open/load/verify exception (#1755)
|
||||||
|
|
||||||
# offsets to test, -10: breaks in i32() in read. (IOError)
|
# offsets to test, -10: breaks in i32() in read. (OSError)
|
||||||
# -13: breaks in crc, txt chunk.
|
# -13: breaks in crc, txt chunk.
|
||||||
# -14: malformed chunk
|
# -14: malformed chunk
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ class TestFilePng:
|
||||||
|
|
||||||
with Image.open(BytesIO(test_file)) as im:
|
with Image.open(BytesIO(test_file)) as im:
|
||||||
assert im.fp is not None
|
assert im.fp is not None
|
||||||
with pytest.raises((IOError, SyntaxError)):
|
with pytest.raises((OSError, SyntaxError)):
|
||||||
im.verify()
|
im.verify()
|
||||||
|
|
||||||
def test_verify_ignores_crc_error(self):
|
def test_verify_ignores_crc_error(self):
|
||||||
|
@ -463,7 +463,7 @@ class TestFilePng:
|
||||||
data = b"\x89" + fd.read()
|
data = b"\x89" + fd.read()
|
||||||
|
|
||||||
pngfile = BytesIO(data)
|
pngfile = BytesIO(data)
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open(pngfile)
|
Image.open(pngfile)
|
||||||
|
|
||||||
def test_trns_rgb(self):
|
def test_trns_rgb(self):
|
||||||
|
@ -575,13 +575,13 @@ class TestFilePng:
|
||||||
|
|
||||||
# Raises a SyntaxError in load_end
|
# Raises a SyntaxError in load_end
|
||||||
with Image.open("Tests/images/broken_data_stream.png") as im:
|
with Image.open("Tests/images/broken_data_stream.png") as im:
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
assert isinstance(im.text, dict)
|
assert isinstance(im.text, dict)
|
||||||
|
|
||||||
# Raises a UnicodeDecodeError in load_end
|
# Raises a UnicodeDecodeError in load_end
|
||||||
with Image.open("Tests/images/truncated_image.png") as im:
|
with Image.open("Tests/images/truncated_image.png") as im:
|
||||||
# The file is truncated
|
# The file is truncated
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.text()
|
im.text()
|
||||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||||
assert isinstance(im.text, dict)
|
assert isinstance(im.text, dict)
|
||||||
|
|
|
@ -64,7 +64,7 @@ def test_neg_ppm():
|
||||||
# has been removed. The default opener doesn't accept negative
|
# has been removed. The default opener doesn't accept negative
|
||||||
# sizes.
|
# sizes.
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open("Tests/images/negative_size.ppm")
|
Image.open("Tests/images/negative_size.ppm")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -125,5 +125,5 @@ def test_combined_larger_than_size():
|
||||||
|
|
||||||
# If we instead take the 'size' of the extra data field as the source of truth,
|
# If we instead take the 'size' of the extra data field as the source of truth,
|
||||||
# then the seek can't be negative
|
# then the seek can't be negative
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open("Tests/images/combined_larger_than_size.psd")
|
Image.open("Tests/images/combined_larger_than_size.psd")
|
||||||
|
|
|
@ -134,7 +134,7 @@ def test_is_int_not_a_number():
|
||||||
def test_invalid_file():
|
def test_invalid_file():
|
||||||
invalid_file = "Tests/images/invalid.spider"
|
invalid_file = "Tests/images/invalid.spider"
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open(invalid_file)
|
Image.open(invalid_file)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -196,7 +196,7 @@ class TestFileTiff:
|
||||||
def test_save_unsupported_mode(self, tmp_path):
|
def test_save_unsupported_mode(self, tmp_path):
|
||||||
im = hopper("HSV")
|
im = hopper("HSV")
|
||||||
outfile = str(tmp_path / "temp.tif")
|
outfile = str(tmp_path / "temp.tif")
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(outfile)
|
im.save(outfile)
|
||||||
|
|
||||||
def test_little_endian(self):
|
def test_little_endian(self):
|
||||||
|
@ -249,7 +249,7 @@ class TestFileTiff:
|
||||||
assert im.getextrema() == (-3.140936851501465, 3.140684127807617)
|
assert im.getextrema() == (-3.140936851501465, 3.140684127807617)
|
||||||
|
|
||||||
def test_unknown_pixel_mode(self):
|
def test_unknown_pixel_mode(self):
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image.open("Tests/images/hopper_unknown_pixel_mode.tif")
|
Image.open("Tests/images/hopper_unknown_pixel_mode.tif")
|
||||||
|
|
||||||
def test_n_frames(self):
|
def test_n_frames(self):
|
||||||
|
@ -614,7 +614,7 @@ class TestFileTiffW32:
|
||||||
im = Image.open(tmpfile)
|
im = Image.open(tmpfile)
|
||||||
fp = im.fp
|
fp = im.fp
|
||||||
assert not fp.closed
|
assert not fp.closed
|
||||||
with pytest.raises(WindowsError):
|
with pytest.raises(OSError):
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
im.load()
|
im.load()
|
||||||
assert fp.closed
|
assert fp.closed
|
||||||
|
|
|
@ -22,7 +22,7 @@ class TestUnsupportedWebp:
|
||||||
WebPImagePlugin.SUPPORTED = False
|
WebPImagePlugin.SUPPORTED = False
|
||||||
|
|
||||||
file_path = "Tests/images/hopper.webp"
|
file_path = "Tests/images/hopper.webp"
|
||||||
pytest.warns(UserWarning, lambda: pytest.raises(IOError, Image.open, file_path))
|
pytest.warns(UserWarning, lambda: pytest.raises(OSError, Image.open, file_path))
|
||||||
|
|
||||||
if HAVE_WEBP:
|
if HAVE_WEBP:
|
||||||
WebPImagePlugin.SUPPORTED = True
|
WebPImagePlugin.SUPPORTED = True
|
||||||
|
|
|
@ -74,5 +74,5 @@ def test_save(tmp_path):
|
||||||
|
|
||||||
for ext in [".wmf", ".emf"]:
|
for ext in [".wmf", ".emf"]:
|
||||||
tmpfile = str(tmp_path / ("temp" + ext))
|
tmpfile = str(tmp_path / ("temp" + ext))
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.save(tmpfile)
|
im.save(tmpfile)
|
||||||
|
|
|
@ -57,7 +57,7 @@ class TestImage:
|
||||||
assert str(e.value) == "unrecognized image mode"
|
assert str(e.value) == "unrecognized image mode"
|
||||||
|
|
||||||
def test_exception_inheritance(self):
|
def test_exception_inheritance(self):
|
||||||
assert issubclass(UnidentifiedImageError, IOError)
|
assert issubclass(UnidentifiedImageError, OSError)
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
|
||||||
|
@ -687,5 +687,5 @@ class TestRegistry:
|
||||||
assert enc.args == ("RGB", "args", "extra")
|
assert enc.args == ("RGB", "args", "extra")
|
||||||
|
|
||||||
def test_encode_registry_fail(self):
|
def test_encode_registry_fail(self):
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
Image._getencoder("RGB", "DoesNotExist", ("args",), extra=("extra",))
|
Image._getencoder("RGB", "DoesNotExist", ("args",), extra=("extra",))
|
||||||
|
|
|
@ -71,7 +71,7 @@ class TestImageFile:
|
||||||
im1, im2 = roundtrip("JPEG") # lossy compression
|
im1, im2 = roundtrip("JPEG") # lossy compression
|
||||||
assert_image(im1, im2.mode, im2.size)
|
assert_image(im1, im2.mode, im2.size)
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
roundtrip("PDF")
|
roundtrip("PDF")
|
||||||
|
|
||||||
def test_ico(self):
|
def test_ico(self):
|
||||||
|
@ -93,9 +93,9 @@ class TestImageFile:
|
||||||
|
|
||||||
assert_image_equal(im1, im2)
|
assert_image_equal(im1, im2)
|
||||||
|
|
||||||
def test_raise_ioerror(self):
|
def test_raise_oserror(self):
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
ImageFile.raise_ioerror(1)
|
ImageFile.raise_oserror(1)
|
||||||
|
|
||||||
def test_raise_typeerror(self):
|
def test_raise_typeerror(self):
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
|
@ -107,17 +107,17 @@ class TestImageFile:
|
||||||
input = f.read()
|
input = f.read()
|
||||||
p = ImageFile.Parser()
|
p = ImageFile.Parser()
|
||||||
p.feed(input)
|
p.feed(input)
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
p.close()
|
p.close()
|
||||||
|
|
||||||
@skip_unless_feature("zlib")
|
@skip_unless_feature("zlib")
|
||||||
def test_truncated_with_errors(self):
|
def test_truncated_with_errors(self):
|
||||||
with Image.open("Tests/images/truncated_image.png") as im:
|
with Image.open("Tests/images/truncated_image.png") as im:
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
# Test that the error is raised if loaded a second time
|
# Test that the error is raised if loaded a second time
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
@skip_unless_feature("zlib")
|
@skip_unless_feature("zlib")
|
||||||
|
@ -132,7 +132,7 @@ class TestImageFile:
|
||||||
@skip_unless_feature("zlib")
|
@skip_unless_feature("zlib")
|
||||||
def test_broken_datastream_with_errors(self):
|
def test_broken_datastream_with_errors(self):
|
||||||
with Image.open("Tests/images/broken_data_stream.png") as im:
|
with Image.open("Tests/images/broken_data_stream.png") as im:
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
@skip_unless_feature("zlib")
|
@skip_unless_feature("zlib")
|
||||||
|
|
|
@ -393,14 +393,14 @@ class TestImageFont:
|
||||||
filename = "somefilenamethatdoesntexist.ttf"
|
filename = "somefilenamethatdoesntexist.ttf"
|
||||||
|
|
||||||
# Act/Assert
|
# Act/Assert
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
ImageFont.load_path(filename)
|
ImageFont.load_path(filename)
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
ImageFont.truetype(filename)
|
ImageFont.truetype(filename)
|
||||||
|
|
||||||
def test_load_non_font_bytes(self):
|
def test_load_non_font_bytes(self):
|
||||||
with open("Tests/images/hopper.jpg", "rb") as f:
|
with open("Tests/images/hopper.jpg", "rb") as f:
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
ImageFont.truetype(f)
|
ImageFont.truetype(f)
|
||||||
|
|
||||||
def test_default_font(self):
|
def test_default_font(self):
|
||||||
|
@ -615,9 +615,9 @@ class TestImageFont:
|
||||||
font.get_variation_axes()
|
font.get_variation_axes()
|
||||||
return
|
return
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
font.get_variation_names()
|
font.get_variation_names()
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
font.get_variation_axes()
|
font.get_variation_axes()
|
||||||
|
|
||||||
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf")
|
font = ImageFont.truetype("Tests/fonts/AdobeVFPrototype.ttf")
|
||||||
|
@ -669,7 +669,7 @@ class TestImageFont:
|
||||||
font.set_variation_by_name("Bold")
|
font.set_variation_by_name("Bold")
|
||||||
return
|
return
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
font.set_variation_by_name("Bold")
|
font.set_variation_by_name("Bold")
|
||||||
|
|
||||||
def _check_text(font, path, epsilon):
|
def _check_text(font, path, epsilon):
|
||||||
|
@ -701,7 +701,7 @@ class TestImageFont:
|
||||||
font.set_variation_by_axes([100])
|
font.set_variation_by_axes([100])
|
||||||
return
|
return
|
||||||
|
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
font.set_variation_by_axes([500, 50])
|
font.set_variation_by_axes([500, 50])
|
||||||
|
|
||||||
def _check_text(font, path, epsilon):
|
def _check_text(font, path, epsilon):
|
||||||
|
|
|
@ -31,23 +31,23 @@ class TestImageGrab:
|
||||||
|
|
||||||
im2 = ImageGrab.grab(xdisplay="")
|
im2 = ImageGrab.grab(xdisplay="")
|
||||||
assert_image(im2, im2.mode, im2.size)
|
assert_image(im2, im2.mode, im2.size)
|
||||||
except IOError as e:
|
except OSError as e:
|
||||||
pytest.skip(str(e))
|
pytest.skip(str(e))
|
||||||
|
|
||||||
@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
|
@pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB")
|
||||||
def test_grab_no_xcb(self):
|
def test_grab_no_xcb(self):
|
||||||
if sys.platform not in ("win32", "darwin"):
|
if sys.platform not in ("win32", "darwin"):
|
||||||
with pytest.raises(IOError) as e:
|
with pytest.raises(OSError) as e:
|
||||||
ImageGrab.grab()
|
ImageGrab.grab()
|
||||||
assert str(e.value).startswith("Pillow was built without XCB support")
|
assert str(e.value).startswith("Pillow was built without XCB support")
|
||||||
|
|
||||||
with pytest.raises(IOError) as e:
|
with pytest.raises(OSError) as e:
|
||||||
ImageGrab.grab(xdisplay="")
|
ImageGrab.grab(xdisplay="")
|
||||||
assert str(e.value).startswith("Pillow was built without XCB support")
|
assert str(e.value).startswith("Pillow was built without XCB support")
|
||||||
|
|
||||||
@pytest.mark.skipif(not Image.core.HAVE_XCB, reason="requires XCB")
|
@pytest.mark.skipif(not Image.core.HAVE_XCB, reason="requires XCB")
|
||||||
def test_grab_invalid_xdisplay(self):
|
def test_grab_invalid_xdisplay(self):
|
||||||
with pytest.raises(IOError) as e:
|
with pytest.raises(OSError) as e:
|
||||||
ImageGrab.grab(xdisplay="error.test:0.0")
|
ImageGrab.grab(xdisplay="error.test:0.0")
|
||||||
assert str(e.value).startswith("X connection failed")
|
assert str(e.value).startswith("X connection failed")
|
||||||
|
|
||||||
|
|
|
@ -145,5 +145,5 @@ def test_2bit_palette(tmp_path):
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_palette():
|
def test_invalid_palette():
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
ImagePalette.load("Tests/images/hopper.jpg")
|
ImagePalette.load("Tests/images/hopper.jpg")
|
||||||
|
|
|
@ -20,7 +20,7 @@ def test_overflow():
|
||||||
|
|
||||||
# This image hits the offset test.
|
# This image hits the offset test.
|
||||||
with Image.open("Tests/images/l2rgb_read.bmp") as im:
|
with Image.open("Tests/images/l2rgb_read.bmp") as im:
|
||||||
with pytest.raises((ValueError, MemoryError, IOError)):
|
with pytest.raises((ValueError, MemoryError, OSError)):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
||||||
Image.MAX_IMAGE_PIXELS = max_pixels
|
Image.MAX_IMAGE_PIXELS = max_pixels
|
||||||
|
|
|
@ -10,5 +10,5 @@ from PIL import Image
|
||||||
def test_crashes(test_file):
|
def test_crashes(test_file):
|
||||||
with open(test_file, "rb") as f:
|
with open(test_file, "rb") as f:
|
||||||
im = Image.open(f)
|
im = Image.open(f)
|
||||||
with pytest.raises(IOError):
|
with pytest.raises(OSError):
|
||||||
im.load()
|
im.load()
|
||||||
|
|
|
@ -1226,7 +1226,7 @@ The :py:meth:`~PIL.Image.Image.save` method can take the following keyword argum
|
||||||
|
|
||||||
**append**
|
**append**
|
||||||
Set to True to append pages to an existing PDF file. If the file doesn't
|
Set to True to append pages to an existing PDF file. If the file doesn't
|
||||||
exist, an :py:exc:`IOError` will be raised.
|
exist, an :py:exc:`OSError` will be raised.
|
||||||
|
|
||||||
.. versionadded:: 5.1.0
|
.. versionadded:: 5.1.0
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ bands in the image, and also the pixel type and depth. Common modes are “L”
|
||||||
(luminance) for greyscale images, “RGB” for true color images, and “CMYK” for
|
(luminance) for greyscale images, “RGB” for true color images, and “CMYK” for
|
||||||
pre-press images.
|
pre-press images.
|
||||||
|
|
||||||
If the file cannot be opened, an :py:exc:`IOError` exception is raised.
|
If the file cannot be opened, an :py:exc:`OSError` exception is raised.
|
||||||
|
|
||||||
Once you have an instance of the :py:class:`~PIL.Image.Image` class, you can use
|
Once you have an instance of the :py:class:`~PIL.Image.Image` class, you can use
|
||||||
the methods defined by this class to process and manipulate the image. For
|
the methods defined by this class to process and manipulate the image. For
|
||||||
|
@ -76,7 +76,7 @@ Convert files to JPEG
|
||||||
try:
|
try:
|
||||||
with Image.open(infile) as im:
|
with Image.open(infile) as im:
|
||||||
im.save(outfile)
|
im.save(outfile)
|
||||||
except IOError:
|
except OSError:
|
||||||
print("cannot convert", infile)
|
print("cannot convert", infile)
|
||||||
|
|
||||||
A second argument can be supplied to the :py:meth:`~PIL.Image.Image.save`
|
A second argument can be supplied to the :py:meth:`~PIL.Image.Image.save`
|
||||||
|
@ -100,7 +100,7 @@ Create JPEG thumbnails
|
||||||
with Image.open(infile) as im:
|
with Image.open(infile) as im:
|
||||||
im.thumbnail(size)
|
im.thumbnail(size)
|
||||||
im.save(outfile, "JPEG")
|
im.save(outfile, "JPEG")
|
||||||
except IOError:
|
except OSError:
|
||||||
print("cannot create thumbnail for", infile)
|
print("cannot create thumbnail for", infile)
|
||||||
|
|
||||||
It is important to note that the library doesn’t decode or load the raster data
|
It is important to note that the library doesn’t decode or load the raster data
|
||||||
|
@ -125,7 +125,7 @@ Identify Image Files
|
||||||
try:
|
try:
|
||||||
with Image.open(infile) as im:
|
with Image.open(infile) as im:
|
||||||
print(infile, im.format, "%dx%d" % im.size, im.mode)
|
print(infile, im.format, "%dx%d" % im.size, im.mode)
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
Cutting, pasting, and merging images
|
Cutting, pasting, and merging images
|
||||||
|
@ -450,7 +450,7 @@ context manager::
|
||||||
...
|
...
|
||||||
|
|
||||||
If everything goes well, the result is an :py:class:`PIL.Image.Image` object.
|
If everything goes well, the result is an :py:class:`PIL.Image.Image` object.
|
||||||
Otherwise, an :exc:`IOError` exception is raised.
|
Otherwise, an :exc:`OSError` exception is raised.
|
||||||
|
|
||||||
You can use a file-like object instead of the filename. The object must
|
You can use a file-like object instead of the filename. The object must
|
||||||
implement :py:meth:`~file.read`, :py:meth:`~file.seek` and
|
implement :py:meth:`~file.read`, :py:meth:`~file.seek` and
|
||||||
|
|
|
@ -85,7 +85,7 @@ Custom unidentified image error
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
Pillow will now throw a custom ``UnidentifiedImageError`` when an image cannot be
|
Pillow will now throw a custom ``UnidentifiedImageError`` when an image cannot be
|
||||||
identified. For backwards compatibility, this will inherit from ``IOError``.
|
identified. For backwards compatibility, this will inherit from ``OSError``.
|
||||||
|
|
||||||
New argument ``reducing_gap`` for Image.resize() and Image.thumbnail() methods
|
New argument ``reducing_gap`` for Image.resize() and Image.thumbnail() methods
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
@ -47,7 +47,7 @@ def testimage():
|
||||||
('PPM', 'RGB', (128, 128))
|
('PPM', 'RGB', (128, 128))
|
||||||
>>> try:
|
>>> try:
|
||||||
... _info(Image.open("Tests/images/hopper.jpg"))
|
... _info(Image.open("Tests/images/hopper.jpg"))
|
||||||
... except IOError as v:
|
... except OSError as v:
|
||||||
... print(v)
|
... print(v)
|
||||||
('JPEG', 'RGB', (128, 128))
|
('JPEG', 'RGB', (128, 128))
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -579,7 +579,7 @@ class pil_build_ext(build_ext):
|
||||||
try:
|
try:
|
||||||
listdir = os.listdir(directory)
|
listdir = os.listdir(directory)
|
||||||
except Exception:
|
except Exception:
|
||||||
# WindowsError, FileNotFoundError
|
# OSError, FileNotFoundError
|
||||||
continue
|
continue
|
||||||
for name in listdir:
|
for name in listdir:
|
||||||
if name.startswith("openjpeg-") and os.path.isfile(
|
if name.startswith("openjpeg-") and os.path.isfile(
|
||||||
|
|
|
@ -99,7 +99,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
||||||
colors = []
|
colors = []
|
||||||
bands = i32(s, 4)
|
bands = i32(s, 4)
|
||||||
if bands > 4:
|
if bands > 4:
|
||||||
raise IOError("Invalid number of bands")
|
raise OSError("Invalid number of bands")
|
||||||
for i in range(bands):
|
for i in range(bands):
|
||||||
# note: for now, we ignore the "uncalibrated" flag
|
# note: for now, we ignore the "uncalibrated" flag
|
||||||
colors.append(i32(s, 8 + i * 4) & 0x7FFFFFFF)
|
colors.append(i32(s, 8 + i * 4) & 0x7FFFFFFF)
|
||||||
|
|
|
@ -74,7 +74,7 @@ def open(fp, mode="r"):
|
||||||
:param mode: Optional mode. In this version, if the mode argument
|
:param mode: Optional mode. In this version, if the mode argument
|
||||||
is given, it must be "r".
|
is given, it must be "r".
|
||||||
:returns: An image instance.
|
:returns: An image instance.
|
||||||
:raises IOError: If the image could not be read.
|
:raises OSError: If the image could not be read.
|
||||||
"""
|
"""
|
||||||
if mode != "r":
|
if mode != "r":
|
||||||
raise ValueError("bad mode")
|
raise ValueError("bad mode")
|
||||||
|
|
|
@ -255,7 +255,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
# raise IOError, "illegal GIF tag `%x`" % i8(s)
|
# raise OSError, "illegal GIF tag `%x`" % i8(s)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.disposal_method < 2:
|
if self.disposal_method < 2:
|
||||||
|
|
|
@ -2080,7 +2080,7 @@ class Image:
|
||||||
:returns: None
|
:returns: None
|
||||||
:exception ValueError: If the output format could not be determined
|
:exception ValueError: If the output format could not be determined
|
||||||
from the file name. Use the format option to solve this.
|
from the file name. Use the format option to solve this.
|
||||||
:exception IOError: If the file could not be written. The file
|
:exception OSError: If the file could not be written. The file
|
||||||
may have been created, and may contain partial data.
|
may have been created, and may contain partial data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,12 @@ ERRORS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def raise_ioerror(error):
|
#
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# Helpers
|
||||||
|
|
||||||
|
|
||||||
|
def raise_oserror(error):
|
||||||
try:
|
try:
|
||||||
message = Image.core.getcodecstatus(error)
|
message = Image.core.getcodecstatus(error)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -59,11 +64,6 @@ def raise_ioerror(error):
|
||||||
raise OSError(message + " when reading image file")
|
raise OSError(message + " when reading image file")
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# --------------------------------------------------------------------
|
|
||||||
# Helpers
|
|
||||||
|
|
||||||
|
|
||||||
def _tilesort(t):
|
def _tilesort(t):
|
||||||
# sort on offset
|
# sort on offset
|
||||||
return t[2]
|
return t[2]
|
||||||
|
@ -267,7 +267,7 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
if not self.map and not LOAD_TRUNCATED_IMAGES and err_code < 0:
|
if not self.map and not LOAD_TRUNCATED_IMAGES and err_code < 0:
|
||||||
# still raised if decoder fails to return anything
|
# still raised if decoder fails to return anything
|
||||||
raise_ioerror(err_code)
|
raise_oserror(err_code)
|
||||||
|
|
||||||
return Image.Image.load(self)
|
return Image.Image.load(self)
|
||||||
|
|
||||||
|
@ -358,7 +358,7 @@ class Parser:
|
||||||
(Consumer) Feed data to the parser.
|
(Consumer) Feed data to the parser.
|
||||||
|
|
||||||
:param data: A string buffer.
|
:param data: A string buffer.
|
||||||
:exception IOError: If the parser failed to parse the image file.
|
:exception OSError: If the parser failed to parse the image file.
|
||||||
"""
|
"""
|
||||||
# collect data
|
# collect data
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ class Parser:
|
||||||
if e < 0:
|
if e < 0:
|
||||||
# decoding error
|
# decoding error
|
||||||
self.image = None
|
self.image = None
|
||||||
raise_ioerror(e)
|
raise_oserror(e)
|
||||||
else:
|
else:
|
||||||
# end of image
|
# end of image
|
||||||
return
|
return
|
||||||
|
@ -444,7 +444,7 @@ class Parser:
|
||||||
(Consumer) Close the stream.
|
(Consumer) Close the stream.
|
||||||
|
|
||||||
:returns: An image object.
|
:returns: An image object.
|
||||||
:exception IOError: If the parser failed to parse the image file either
|
:exception OSError: If the parser failed to parse the image file either
|
||||||
because it cannot be identified or cannot be
|
because it cannot be identified or cannot be
|
||||||
decoded.
|
decoded.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -499,7 +499,7 @@ class FreeTypeFont:
|
||||||
def get_variation_names(self):
|
def get_variation_names(self):
|
||||||
"""
|
"""
|
||||||
:returns: A list of the named styles in a variation font.
|
:returns: A list of the named styles in a variation font.
|
||||||
:exception IOError: If the font is not a variation font.
|
:exception OSError: If the font is not a variation font.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
names = self.font.getvarnames()
|
names = self.font.getvarnames()
|
||||||
|
@ -510,7 +510,7 @@ class FreeTypeFont:
|
||||||
def set_variation_by_name(self, name):
|
def set_variation_by_name(self, name):
|
||||||
"""
|
"""
|
||||||
:param name: The name of the style.
|
:param name: The name of the style.
|
||||||
:exception IOError: If the font is not a variation font.
|
:exception OSError: If the font is not a variation font.
|
||||||
"""
|
"""
|
||||||
names = self.get_variation_names()
|
names = self.get_variation_names()
|
||||||
if not isinstance(name, bytes):
|
if not isinstance(name, bytes):
|
||||||
|
@ -529,7 +529,7 @@ class FreeTypeFont:
|
||||||
def get_variation_axes(self):
|
def get_variation_axes(self):
|
||||||
"""
|
"""
|
||||||
:returns: A list of the axes in a variation font.
|
:returns: A list of the axes in a variation font.
|
||||||
:exception IOError: If the font is not a variation font.
|
:exception OSError: If the font is not a variation font.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
axes = self.font.getvaraxes()
|
axes = self.font.getvaraxes()
|
||||||
|
@ -542,7 +542,7 @@ class FreeTypeFont:
|
||||||
def set_variation_by_axes(self, axes):
|
def set_variation_by_axes(self, axes):
|
||||||
"""
|
"""
|
||||||
:param axes: A list of values for each axis.
|
:param axes: A list of values for each axis.
|
||||||
:exception IOError: If the font is not a variation font.
|
:exception OSError: If the font is not a variation font.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.font.setvaraxes(axes)
|
self.font.setvaraxes(axes)
|
||||||
|
@ -586,7 +586,7 @@ def load(filename):
|
||||||
|
|
||||||
:param filename: Name of font file.
|
:param filename: Name of font file.
|
||||||
:return: A font object.
|
:return: A font object.
|
||||||
:exception IOError: If the file could not be read.
|
:exception OSError: If the file could not be read.
|
||||||
"""
|
"""
|
||||||
f = ImageFont()
|
f = ImageFont()
|
||||||
f._load_pilfont(filename)
|
f._load_pilfont(filename)
|
||||||
|
@ -638,7 +638,7 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
|
||||||
:param layout_engine: Which layout engine to use, if available:
|
:param layout_engine: Which layout engine to use, if available:
|
||||||
`ImageFont.LAYOUT_BASIC` or `ImageFont.LAYOUT_RAQM`.
|
`ImageFont.LAYOUT_BASIC` or `ImageFont.LAYOUT_RAQM`.
|
||||||
:return: A font object.
|
:return: A font object.
|
||||||
:exception IOError: If the file could not be read.
|
:exception OSError: If the file could not be read.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def freetype(font):
|
def freetype(font):
|
||||||
|
@ -698,7 +698,7 @@ def load_path(filename):
|
||||||
|
|
||||||
:param filename: Name of font file.
|
:param filename: Name of font file.
|
||||||
:return: A font object.
|
:return: A font object.
|
||||||
:exception IOError: If the file could not be read.
|
:exception OSError: If the file could not be read.
|
||||||
"""
|
"""
|
||||||
for directory in sys.path:
|
for directory in sys.path:
|
||||||
if isDirectory(directory):
|
if isDirectory(directory):
|
||||||
|
|
|
@ -60,7 +60,7 @@ def grab(bbox=None, include_layered_windows=False, all_screens=False, xdisplay=N
|
||||||
return im
|
return im
|
||||||
# use xdisplay=None for default display on non-win32/macOS systems
|
# use xdisplay=None for default display on non-win32/macOS systems
|
||||||
if not Image.core.HAVE_XCB:
|
if not Image.core.HAVE_XCB:
|
||||||
raise IOError("Pillow was built without XCB support")
|
raise OSError("Pillow was built without XCB support")
|
||||||
size, data = Image.core.grabscreen_x11(xdisplay)
|
size, data = Image.core.grabscreen_x11(xdisplay)
|
||||||
im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
|
im = Image.frombytes("RGB", size, data, "raw", "BGRX", size[0] * 4, 1)
|
||||||
if bbox:
|
if bbox:
|
||||||
|
|
|
@ -1123,7 +1123,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
if hasattr(self.fp, "flush"):
|
if hasattr(self.fp, "flush"):
|
||||||
self.fp.flush()
|
self.fp.flush()
|
||||||
except OSError:
|
except OSError:
|
||||||
# io.BytesIO have a fileno, but returns an IOError if
|
# io.BytesIO have a fileno, but returns an OSError if
|
||||||
# it doesn't use a file descriptor.
|
# it doesn't use a file descriptor.
|
||||||
fp = False
|
fp = False
|
||||||
|
|
||||||
|
@ -1147,7 +1147,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
# underlying string for stringio.
|
# underlying string for stringio.
|
||||||
#
|
#
|
||||||
# Rearranging for supporting byteio items, since they have a fileno
|
# Rearranging for supporting byteio items, since they have a fileno
|
||||||
# that returns an IOError if there's no underlying fp. Easier to
|
# that returns an OSError if there's no underlying fp. Easier to
|
||||||
# deal with here by reordering.
|
# deal with here by reordering.
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print("have getvalue. just sending in a string from getvalue")
|
print("have getvalue. just sending in a string from getvalue")
|
||||||
|
|
|
@ -131,5 +131,5 @@ _plugins = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class UnidentifiedImageError(IOError):
|
class UnidentifiedImageError(OSError):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -268,9 +268,9 @@ static const char* readonly = "image is readonly";
|
||||||
/* static const char* no_content = "image has no content"; */
|
/* static const char* no_content = "image has no content"; */
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ImagingError_IOError(void)
|
ImagingError_OSError(void)
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_IOError, "error when accessing file");
|
PyErr_SetString(PyExc_OSError, "error when accessing file");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ cms_profile_open(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
hProfile = cmsOpenProfileFromFile(sProfile, "r");
|
hProfile = cmsOpenProfileFromFile(sProfile, "r");
|
||||||
if (!hProfile) {
|
if (!hProfile) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot open profile file");
|
PyErr_SetString(PyExc_OSError, "cannot open profile file");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ cms_profile_fromstring(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
|
hProfile = cmsOpenProfileFromMem(pProfile, nProfile);
|
||||||
if (!hProfile) {
|
if (!hProfile) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot open profile from string");
|
PyErr_SetString(PyExc_OSError, "cannot open profile from string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,18 +150,18 @@ cms_profile_tobytes(PyObject* self, PyObject* args)
|
||||||
profile = ((CmsProfileObject*)CmsProfile)->profile;
|
profile = ((CmsProfileObject*)CmsProfile)->profile;
|
||||||
|
|
||||||
if (!cmsSaveProfileToMem(profile, pProfile, &nProfile)) {
|
if (!cmsSaveProfileToMem(profile, pProfile, &nProfile)) {
|
||||||
PyErr_SetString(PyExc_IOError, "Could not determine profile size");
|
PyErr_SetString(PyExc_OSError, "Could not determine profile size");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pProfile = (char*)malloc(nProfile);
|
pProfile = (char*)malloc(nProfile);
|
||||||
if (!pProfile) {
|
if (!pProfile) {
|
||||||
PyErr_SetString(PyExc_IOError, "Out of Memory");
|
PyErr_SetString(PyExc_OSError, "Out of Memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cmsSaveProfileToMem(profile, pProfile, &nProfile)) {
|
if (!cmsSaveProfileToMem(profile, pProfile, &nProfile)) {
|
||||||
PyErr_SetString(PyExc_IOError, "Could not get profile");
|
PyErr_SetString(PyExc_OSError, "Could not get profile");
|
||||||
free(pProfile);
|
free(pProfile);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +655,7 @@ _profile_read_mlu(CmsProfileObject* self, cmsTagSignature info)
|
||||||
|
|
||||||
buf = malloc(len);
|
buf = malloc(len);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
PyErr_SetString(PyExc_IOError, "Out of Memory");
|
PyErr_SetString(PyExc_OSError, "Out of Memory");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Just in case the next call fails. */
|
/* Just in case the next call fails. */
|
||||||
|
|
|
@ -139,11 +139,11 @@ geterror(int code)
|
||||||
|
|
||||||
for (i = 0; ft_errors[i].message; i++)
|
for (i = 0; ft_errors[i].message; i++)
|
||||||
if (ft_errors[i].code == code) {
|
if (ft_errors[i].code == code) {
|
||||||
PyErr_SetString(PyExc_IOError, ft_errors[i].message);
|
PyErr_SetString(PyExc_OSError, ft_errors[i].message);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyErr_SetString(PyExc_IOError, "unknown freetype error");
|
PyErr_SetString(PyExc_OSError, "unknown freetype error");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
|
||||||
|
|
||||||
if (!library) {
|
if (!library) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_IOError,
|
PyExc_OSError,
|
||||||
"failed to initialize FreeType library"
|
"failed to initialize FreeType library"
|
||||||
);
|
);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -70,7 +70,7 @@ PyObject* HandleMuxError(WebPMuxError err, char* chunk) {
|
||||||
|
|
||||||
case WEBP_MUX_BAD_DATA:
|
case WEBP_MUX_BAD_DATA:
|
||||||
case WEBP_MUX_NOT_ENOUGH_DATA:
|
case WEBP_MUX_NOT_ENOUGH_DATA:
|
||||||
PyErr_SetString(PyExc_IOError, message);
|
PyErr_SetString(PyExc_OSError, message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -423,7 +423,7 @@ PyObject* _anim_decoder_get_next(PyObject* self)
|
||||||
WebPAnimDecoderObject* decp = (WebPAnimDecoderObject*)self;
|
WebPAnimDecoderObject* decp = (WebPAnimDecoderObject*)self;
|
||||||
|
|
||||||
if (!WebPAnimDecoderGetNext(decp->dec, &buf, ×tamp)) {
|
if (!WebPAnimDecoderGetNext(decp->dec, &buf, ×tamp)) {
|
||||||
PyErr_SetString(PyExc_IOError, "failed to read next frame");
|
PyErr_SetString(PyExc_OSError, "failed to read next frame");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ _getdc(ImagingDisplayObject* display, PyObject* args)
|
||||||
|
|
||||||
dc = GetDC(window);
|
dc = GetDC(window);
|
||||||
if (!dc) {
|
if (!dc) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot create dc");
|
PyErr_SetString(PyExc_OSError, "cannot create dc");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ PyImaging_GrabScreenWin32(PyObject* self, PyObject* args)
|
||||||
return Py_BuildValue("(ii)(ii)N", x, y, width, height, buffer);
|
return Py_BuildValue("(ii)(ii)N", x, y, width, height, buffer);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
PyErr_SetString(PyExc_IOError, "screen grab failed");
|
PyErr_SetString(PyExc_OSError, "screen grab failed");
|
||||||
|
|
||||||
DeleteDC(screen_copy);
|
DeleteDC(screen_copy);
|
||||||
DeleteDC(screen);
|
DeleteDC(screen);
|
||||||
|
@ -677,7 +677,7 @@ PyImaging_CreateWindowWin32(PyObject* self, PyObject* args)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!wnd) {
|
if (!wnd) {
|
||||||
PyErr_SetString(PyExc_IOError, "failed to create window");
|
PyErr_SetString(PyExc_OSError, "failed to create window");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +755,7 @@ PyImaging_DrawWmf(PyObject* self, PyObject* args)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!meta) {
|
if (!meta) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot load metafile");
|
PyErr_SetString(PyExc_OSError, "cannot load metafile");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -774,12 +774,12 @@ PyImaging_DrawWmf(PyObject* self, PyObject* args)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!bitmap) {
|
if (!bitmap) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot create bitmap");
|
PyErr_SetString(PyExc_OSError, "cannot create bitmap");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SelectObject(dc, bitmap)) {
|
if (!SelectObject(dc, bitmap)) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot select bitmap");
|
PyErr_SetString(PyExc_OSError, "cannot select bitmap");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,7 +793,7 @@ PyImaging_DrawWmf(PyObject* self, PyObject* args)
|
||||||
FillRect(dc, &rect, GetStockObject(WHITE_BRUSH));
|
FillRect(dc, &rect, GetStockObject(WHITE_BRUSH));
|
||||||
|
|
||||||
if (!PlayEnhMetaFile(dc, meta, &rect)) {
|
if (!PlayEnhMetaFile(dc, meta, &rect)) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot render metafile");
|
PyErr_SetString(PyExc_OSError, "cannot render metafile");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -845,7 +845,7 @@ PyImaging_GrabScreenX11(PyObject* self, PyObject* args)
|
||||||
|
|
||||||
connection = xcb_connect(display_name, &screen_number);
|
connection = xcb_connect(display_name, &screen_number);
|
||||||
if (xcb_connection_has_error(connection)) {
|
if (xcb_connection_has_error(connection)) {
|
||||||
PyErr_Format(PyExc_IOError, "X connection failed: error %i", xcb_connection_has_error(connection));
|
PyErr_Format(PyExc_OSError, "X connection failed: error %i", xcb_connection_has_error(connection));
|
||||||
xcb_disconnect(connection);
|
xcb_disconnect(connection);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -860,7 +860,7 @@ PyImaging_GrabScreenX11(PyObject* self, PyObject* args)
|
||||||
if (screen == NULL || screen->root == 0) {
|
if (screen == NULL || screen->root == 0) {
|
||||||
// this case is usually caught with "X connection failed: error 6" above
|
// this case is usually caught with "X connection failed: error 6" above
|
||||||
xcb_disconnect(connection);
|
xcb_disconnect(connection);
|
||||||
PyErr_SetString(PyExc_IOError, "X screen not found");
|
PyErr_SetString(PyExc_OSError, "X screen not found");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -874,7 +874,7 @@ PyImaging_GrabScreenX11(PyObject* self, PyObject* args)
|
||||||
0, 0, width, height, 0x00ffffff),
|
0, 0, width, height, 0x00ffffff),
|
||||||
&error);
|
&error);
|
||||||
if (reply == NULL) {
|
if (reply == NULL) {
|
||||||
PyErr_Format(PyExc_IOError, "X get_image failed: error %i (%i, %i, %i)",
|
PyErr_Format(PyExc_OSError, "X get_image failed: error %i (%i, %i, %i)",
|
||||||
error->error_code, error->major_code, error->minor_code, error->resource_id);
|
error->error_code, error->major_code, error->minor_code, error->resource_id);
|
||||||
free(error);
|
free(error);
|
||||||
xcb_disconnect(connection);
|
xcb_disconnect(connection);
|
||||||
|
@ -887,7 +887,7 @@ PyImaging_GrabScreenX11(PyObject* self, PyObject* args)
|
||||||
buffer = PyBytes_FromStringAndSize((char*)xcb_get_image_data(reply),
|
buffer = PyBytes_FromStringAndSize((char*)xcb_get_image_data(reply),
|
||||||
xcb_get_image_data_length(reply));
|
xcb_get_image_data_length(reply));
|
||||||
} else {
|
} else {
|
||||||
PyErr_Format(PyExc_IOError, "unsupported bit depth: %i", reply->depth);
|
PyErr_Format(PyExc_OSError, "unsupported bit depth: %i", reply->depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(reply);
|
free(reply);
|
||||||
|
|
|
@ -201,7 +201,7 @@ _encode_to_file(ImagingEncoderObject* encoder, PyObject* args)
|
||||||
if (write(fh, buf, status) < 0) {
|
if (write(fh, buf, status) < 0) {
|
||||||
ImagingSectionLeave(&cookie);
|
ImagingSectionLeave(&cookie);
|
||||||
free(buf);
|
free(buf);
|
||||||
return PyErr_SetFromErrno(PyExc_IOError);
|
return PyErr_SetFromErrno(PyExc_OSError);
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (encoder->state.errcode == 0);
|
} while (encoder->state.errcode == 0);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
/* exception state */
|
/* exception state */
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ImagingError_IOError(void)
|
ImagingError_OSError(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "*** exception: file access error\n");
|
fprintf(stderr, "*** exception: file access error\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -59,7 +59,7 @@ ImagingSavePPM(Imaging im, const char* outfile)
|
||||||
|
|
||||||
fp = fopen(outfile, "wb");
|
fp = fopen(outfile, "wb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
(void) ImagingError_IOError();
|
(void) ImagingError_OSError();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -229,7 +229,7 @@ extern void ImagingSectionLeave(ImagingSectionCookie* cookie);
|
||||||
/* Exceptions */
|
/* Exceptions */
|
||||||
/* ---------- */
|
/* ---------- */
|
||||||
|
|
||||||
extern void* ImagingError_IOError(void);
|
extern void* ImagingError_OSError(void);
|
||||||
extern void* ImagingError_MemoryError(void);
|
extern void* ImagingError_MemoryError(void);
|
||||||
extern void* ImagingError_ModeError(void); /* maps to ValueError by default */
|
extern void* ImagingError_ModeError(void); /* maps to ValueError by default */
|
||||||
extern void* ImagingError_Mismatch(void); /* maps to ValueError by default */
|
extern void* ImagingError_Mismatch(void); /* maps to ValueError by default */
|
||||||
|
|
|
@ -70,7 +70,7 @@ PyImaging_MapperNew(const char* filename, int readonly)
|
||||||
FILE_ATTRIBUTE_NORMAL,
|
FILE_ATTRIBUTE_NORMAL,
|
||||||
NULL);
|
NULL);
|
||||||
if (mapper->hFile == (HANDLE)-1) {
|
if (mapper->hFile == (HANDLE)-1) {
|
||||||
PyErr_SetString(PyExc_IOError, "cannot open file");
|
PyErr_SetString(PyExc_OSError, "cannot open file");
|
||||||
Py_DECREF(mapper);
|
Py_DECREF(mapper);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ PyImaging_MapperNew(const char* filename, int readonly)
|
||||||
0, 0, NULL);
|
0, 0, NULL);
|
||||||
if (mapper->hMap == (HANDLE)-1) {
|
if (mapper->hMap == (HANDLE)-1) {
|
||||||
CloseHandle(mapper->hFile);
|
CloseHandle(mapper->hFile);
|
||||||
PyErr_SetString(PyExc_IOError, "cannot map file");
|
PyErr_SetString(PyExc_OSError, "cannot map file");
|
||||||
Py_DECREF(mapper);
|
Py_DECREF(mapper);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ mapping_readimage(ImagingMapperObject* mapper, PyObject* args)
|
||||||
size = ysize * stride;
|
size = ysize * stride;
|
||||||
|
|
||||||
if (mapper->offset + size > mapper->size) {
|
if (mapper->offset + size > mapper->size) {
|
||||||
PyErr_SetString(PyExc_IOError, "image file truncated");
|
PyErr_SetString(PyExc_OSError, "image file truncated");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user