mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-31 16:07:30 +03:00 
			
		
		
		
	Merge branch 'master' into rm-2.7
This commit is contained in:
		
						commit
						a949d7882e
					
				|  | @ -5,6 +5,9 @@ Changelog (Pillow) | |||
| 7.0.0 (unreleased) | ||||
| ------------------ | ||||
| 
 | ||||
| - Remove deprecated __version__ from plugins #4197 | ||||
|   [hugovk, radarhere] | ||||
| 
 | ||||
| - Fixed freeing unallocated pointer when resizing with height too large #4116 | ||||
|   [radarhere] | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| from PIL import GdImageFile | ||||
| from PIL import GdImageFile, UnidentifiedImageError | ||||
| 
 | ||||
| from .helper import PillowTestCase | ||||
| 
 | ||||
|  | @ -17,4 +17,4 @@ class TestFileGd(PillowTestCase): | |||
|     def test_invalid_file(self): | ||||
|         invalid_file = "Tests/images/flower.jpg" | ||||
| 
 | ||||
|         self.assertRaises(IOError, GdImageFile.open, invalid_file) | ||||
|         self.assertRaises(UnidentifiedImageError, GdImageFile.open, invalid_file) | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ import os | |||
| import shutil | ||||
| import tempfile | ||||
| 
 | ||||
| from PIL import Image | ||||
| from PIL import Image, UnidentifiedImageError | ||||
| 
 | ||||
| from .helper import PillowTestCase, hopper, is_win32, unittest | ||||
| 
 | ||||
|  | @ -47,6 +47,9 @@ class TestImage(PillowTestCase): | |||
|                 Image.new(mode, (1, 1)) | ||||
|             self.assertEqual(str(e.exception), "unrecognized image mode") | ||||
| 
 | ||||
|     def test_exception_inheritance(self): | ||||
|         self.assertTrue(issubclass(UnidentifiedImageError, IOError)) | ||||
| 
 | ||||
|     def test_sanity(self): | ||||
| 
 | ||||
|         im = Image.new("L", (100, 100)) | ||||
|  | @ -82,7 +85,7 @@ class TestImage(PillowTestCase): | |||
|         import io | ||||
| 
 | ||||
|         im = io.BytesIO(b"") | ||||
|         self.assertRaises(IOError, Image.open, im) | ||||
|         self.assertRaises(UnidentifiedImageError, Image.open, im) | ||||
| 
 | ||||
|     def test_bad_mode(self): | ||||
|         self.assertRaises(ValueError, Image.open, "filename", "bad mode") | ||||
|  |  | |||
|  | @ -63,11 +63,11 @@ TODO | |||
| API Additions | ||||
| ============= | ||||
| 
 | ||||
| TODO | ||||
| ^^^^ | ||||
| 
 | ||||
| TODO | ||||
| Custom unidentified image error | ||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||||
| 
 | ||||
| Pillow will now throw a custom ``UnidentifiedImageError`` when an image cannot be | ||||
| identified. For backwards compatibility, this will inherit from ``IOError``. | ||||
| 
 | ||||
| Other Changes | ||||
| ============= | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ | |||
| # purposes only. | ||||
| 
 | ||||
| 
 | ||||
| from . import ImageFile, ImagePalette | ||||
| from . import ImageFile, ImagePalette, UnidentifiedImageError | ||||
| from ._binary import i8, i16be as i16, i32be as i32 | ||||
| 
 | ||||
| ## | ||||
|  | @ -82,4 +82,4 @@ def open(fp, mode="r"): | |||
|     try: | ||||
|         return GdImageFile(fp) | ||||
|     except SyntaxError: | ||||
|         raise OSError("cannot identify this image file") | ||||
|         raise UnidentifiedImageError("cannot identify this image file") | ||||
|  |  | |||
|  | @ -41,7 +41,7 @@ from pathlib import Path | |||
| # VERSION was removed in Pillow 6.0.0. | ||||
| # PILLOW_VERSION was removed in Pillow 7.0.0. | ||||
| # Use __version__ instead. | ||||
| from . import ImageMode, TiffTags, __version__, _plugins | ||||
| from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins | ||||
| from ._binary import i8, i32le | ||||
| from ._util import deferred_error, isPath | ||||
| 
 | ||||
|  | @ -2743,7 +2743,9 @@ def open(fp, mode="r"): | |||
|         fp.close() | ||||
|     for message in accept_warnings: | ||||
|         warnings.warn(message) | ||||
|     raise OSError("cannot identify image file %r" % (filename if filename else fp)) | ||||
|     raise UnidentifiedImageError( | ||||
|         "cannot identify image file %r" % (filename if filename else fp) | ||||
|     ) | ||||
| 
 | ||||
| 
 | ||||
| # | ||||
|  |  | |||
|  | @ -70,3 +70,7 @@ _plugins = [ | |||
|     "XpmImagePlugin", | ||||
|     "XVThumbImagePlugin", | ||||
| ] | ||||
| 
 | ||||
| 
 | ||||
| class UnidentifiedImageError(IOError): | ||||
|     pass | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user