From 06b091c130c359370abd267ecad553e8a6b0ee9d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 23 May 2023 02:01:53 +0200 Subject: [PATCH] gh-104773: PEP 594: Remove the imghdr module * Remove the Lib/test/imghdrdata/ directory. * Copy 5 pictures (gif, png, ppm, pgm, xbm) from removed Lib/test/imghdrdata/ to a new Lib/test/tkinterdata/ directory. --- Doc/library/imghdr.rst | 86 --------- Doc/library/superseded.rst | 1 - Doc/whatsnew/3.11.rst | 2 +- Doc/whatsnew/3.12.rst | 2 +- Doc/whatsnew/3.13.rst | 8 + Doc/whatsnew/3.5.rst | 2 +- Lib/imghdr.py | 180 ------------------ Lib/test/imghdrdata/python-raw.jpg | Bin 525 -> 0 bytes Lib/test/imghdrdata/python.bmp | Bin 1162 -> 0 bytes Lib/test/imghdrdata/python.exr | Bin 2635 -> 0 bytes Lib/test/imghdrdata/python.jpg | Bin 543 -> 0 bytes Lib/test/imghdrdata/python.pbm | 3 - Lib/test/imghdrdata/python.ras | Bin 1056 -> 0 bytes Lib/test/imghdrdata/python.sgi | Bin 1967 -> 0 bytes Lib/test/imghdrdata/python.tiff | Bin 1326 -> 0 bytes Lib/test/imghdrdata/python.webp | Bin 432 -> 0 bytes Lib/test/test_imghdr.py | 144 -------------- Lib/test/test_tkinter/test_images.py | 8 +- Lib/test/test_tkinter/widget_tests.py | 2 +- .../{imghdrdata => tkinterdata}/python.gif | Bin .../{imghdrdata => tkinterdata}/python.pgm | Bin .../{imghdrdata => tkinterdata}/python.png | Bin .../{imghdrdata => tkinterdata}/python.ppm | Bin .../{imghdrdata => tkinterdata}/python.xbm | 0 Makefile.pre.in | 2 +- ...-05-23-02-13-11.gh-issue-104773.JNiEjv.rst | 2 + Python/stdlib_module_names.h | 1 - 27 files changed, 19 insertions(+), 424 deletions(-) delete mode 100644 Doc/library/imghdr.rst delete mode 100644 Lib/imghdr.py delete mode 100644 Lib/test/imghdrdata/python-raw.jpg delete mode 100644 Lib/test/imghdrdata/python.bmp delete mode 100644 Lib/test/imghdrdata/python.exr delete mode 100644 Lib/test/imghdrdata/python.jpg delete mode 100644 Lib/test/imghdrdata/python.pbm delete mode 100644 Lib/test/imghdrdata/python.ras delete mode 100644 Lib/test/imghdrdata/python.sgi delete mode 100644 Lib/test/imghdrdata/python.tiff delete mode 100644 Lib/test/imghdrdata/python.webp delete mode 100644 Lib/test/test_imghdr.py rename Lib/test/{imghdrdata => tkinterdata}/python.gif (100%) rename Lib/test/{imghdrdata => tkinterdata}/python.pgm (100%) rename Lib/test/{imghdrdata => tkinterdata}/python.png (100%) rename Lib/test/{imghdrdata => tkinterdata}/python.ppm (100%) rename Lib/test/{imghdrdata => tkinterdata}/python.xbm (100%) create mode 100644 Misc/NEWS.d/next/Library/2023-05-23-02-13-11.gh-issue-104773.JNiEjv.rst diff --git a/Doc/library/imghdr.rst b/Doc/library/imghdr.rst deleted file mode 100644 index 630fd7019f94de..00000000000000 --- a/Doc/library/imghdr.rst +++ /dev/null @@ -1,86 +0,0 @@ -:mod:`imghdr` --- Determine the type of an image -================================================ - -.. module:: imghdr - :synopsis: Determine the type of image contained in a file or byte stream. - :deprecated: - -**Source code:** :source:`Lib/imghdr.py` - -.. deprecated-removed:: 3.11 3.13 - The :mod:`imghdr` module is deprecated - (see :pep:`PEP 594 <594#imghdr>` for details and alternatives). - --------------- - -The :mod:`imghdr` module determines the type of image contained in a file or -byte stream. - -The :mod:`imghdr` module defines the following function: - - -.. function:: what(file, h=None) - - Test the image data contained in the file named *file* and return a - string describing the image type. If *h* is provided, the *file* - argument is ignored and *h* is assumed to contain the byte stream to test. - - .. versionchanged:: 3.6 - Accepts a :term:`path-like object`. - -The following image types are recognized, as listed below with the return value -from :func:`what`: - -+------------+-----------------------------------+ -| Value | Image format | -+============+===================================+ -| ``'rgb'`` | SGI ImgLib Files | -+------------+-----------------------------------+ -| ``'gif'`` | GIF 87a and 89a Files | -+------------+-----------------------------------+ -| ``'pbm'`` | Portable Bitmap Files | -+------------+-----------------------------------+ -| ``'pgm'`` | Portable Graymap Files | -+------------+-----------------------------------+ -| ``'ppm'`` | Portable Pixmap Files | -+------------+-----------------------------------+ -| ``'tiff'`` | TIFF Files | -+------------+-----------------------------------+ -| ``'rast'`` | Sun Raster Files | -+------------+-----------------------------------+ -| ``'xbm'`` | X Bitmap Files | -+------------+-----------------------------------+ -| ``'jpeg'`` | JPEG data in JFIF or Exif formats | -+------------+-----------------------------------+ -| ``'bmp'`` | BMP files | -+------------+-----------------------------------+ -| ``'png'`` | Portable Network Graphics | -+------------+-----------------------------------+ -| ``'webp'`` | WebP files | -+------------+-----------------------------------+ -| ``'exr'`` | OpenEXR Files | -+------------+-----------------------------------+ - -.. versionadded:: 3.5 - The *exr* and *webp* formats were added. - - -You can extend the list of file types :mod:`imghdr` can recognize by appending -to this variable: - - -.. data:: tests - - A list of functions performing the individual tests. Each function takes two - arguments: the byte-stream and an open file-like object. When :func:`what` is - called with a byte-stream, the file-like object will be ``None``. - - The test function should return a string describing the image type if the test - succeeded, or ``None`` if it failed. - -Example:: - - >>> import imghdr - >>> imghdr.what('bass.gif') - 'gif' - diff --git a/Doc/library/superseded.rst b/Doc/library/superseded.rst index 24e74110a319f9..bd17039bc6f6b6 100644 --- a/Doc/library/superseded.rst +++ b/Doc/library/superseded.rst @@ -10,5 +10,4 @@ backwards compatibility. They have been superseded by other modules. .. toctree:: - imghdr.rst optparse.rst diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 7186ba5521f957..066070eda7dba3 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1735,7 +1735,7 @@ Modules +---------------------+---------------------+---------------------+---------------------+---------------------+ | :mod:`!audioop` | :mod:`!crypt` | :mod:`!nis` | :mod:`!sndhdr` | :mod:`!uu` | +---------------------+---------------------+---------------------+---------------------+---------------------+ - | :mod:`!cgi` | :mod:`imghdr` | :mod:`!nntplib` | :mod:`!spwd` | :mod:`!xdrlib` | + | :mod:`!cgi` | :mod:`!imghdr` | :mod:`!nntplib` | :mod:`!spwd` | :mod:`!xdrlib` | +---------------------+---------------------+---------------------+---------------------+---------------------+ | :mod:`!cgitb` | :mod:`!mailcap` | :mod:`!ossaudiodev` | :mod:`!sunau` | | +---------------------+---------------------+---------------------+---------------------+---------------------+ diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index 5266f5ffb93737..c8fd77f0fdb4a9 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -924,7 +924,7 @@ Modules (see :pep:`594`): * :mod:`!cgitb` * :mod:`!chunk` * :mod:`!crypt` -* :mod:`imghdr` +* :mod:`!imghdr` * :mod:`!mailcap` * :mod:`!msilib` * :mod:`!nis` diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 0e78a080c4304b..28c98554fdbfdb 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -244,6 +244,14 @@ Removed :class:`typing.TypedDict` types, deprecated in Python 3.11. (Contributed by Tomas Roun in :gh:`104786`.) +* :pep:`594`: Remove the :mod:`!imghdr` module, deprecated in Python 3.11: + use the projects + `filetype `_, + `puremagic `_, + or `python-magic `_ instead. + (Contributed by Victor Stinner in :gh:`104773`.) + + Porting to Python 3.13 ====================== diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index cd8f6e2cd9b595..ccf71bf08e8608 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -1252,7 +1252,7 @@ Oberkirch in :issue:`21800`.) imghdr ------ -The :func:`~imghdr.what` function now recognizes the +The :func:`~!imghdr.what` function now recognizes the `OpenEXR `_ format (contributed by Martin Vignali and Claudiu Popa in :issue:`20295`), and the `WebP `_ format diff --git a/Lib/imghdr.py b/Lib/imghdr.py deleted file mode 100644 index 33868883470764..00000000000000 --- a/Lib/imghdr.py +++ /dev/null @@ -1,180 +0,0 @@ -"""Recognize image file formats based on their first few bytes.""" - -from os import PathLike -import warnings - -__all__ = ["what"] - - -warnings._deprecated(__name__, remove=(3, 13)) - - -#-------------------------# -# Recognize image headers # -#-------------------------# - -def what(file, h=None): - """Return the type of image contained in a file or byte stream.""" - f = None - try: - if h is None: - if isinstance(file, (str, PathLike)): - f = open(file, 'rb') - h = f.read(32) - else: - location = file.tell() - h = file.read(32) - file.seek(location) - for tf in tests: - res = tf(h, f) - if res: - return res - finally: - if f: f.close() - return None - - -#---------------------------------# -# Subroutines per image file type # -#---------------------------------# - -tests = [] - -def test_jpeg(h, f): - """Test for JPEG data with JFIF or Exif markers; and raw JPEG.""" - if h[6:10] in (b'JFIF', b'Exif'): - return 'jpeg' - elif h[:4] == b'\xff\xd8\xff\xdb': - return 'jpeg' - -tests.append(test_jpeg) - -def test_png(h, f): - """Verify if the image is a PNG.""" - if h.startswith(b'\211PNG\r\n\032\n'): - return 'png' - -tests.append(test_png) - -def test_gif(h, f): - """Verify if the image is a GIF ('87 or '89 variants).""" - if h[:6] in (b'GIF87a', b'GIF89a'): - return 'gif' - -tests.append(test_gif) - -def test_tiff(h, f): - """Verify if the image is a TIFF (can be in Motorola or Intel byte order).""" - if h[:2] in (b'MM', b'II'): - return 'tiff' - -tests.append(test_tiff) - -def test_rgb(h, f): - """test for the SGI image library.""" - if h.startswith(b'\001\332'): - return 'rgb' - -tests.append(test_rgb) - -def test_pbm(h, f): - """Verify if the image is a PBM (portable bitmap).""" - if len(h) >= 3 and \ - h[0] == ord(b'P') and h[1] in b'14' and h[2] in b' \t\n\r': - return 'pbm' - -tests.append(test_pbm) - -def test_pgm(h, f): - """Verify if the image is a PGM (portable graymap).""" - if len(h) >= 3 and \ - h[0] == ord(b'P') and h[1] in b'25' and h[2] in b' \t\n\r': - return 'pgm' - -tests.append(test_pgm) - -def test_ppm(h, f): - """Verify if the image is a PPM (portable pixmap).""" - if len(h) >= 3 and \ - h[0] == ord(b'P') and h[1] in b'36' and h[2] in b' \t\n\r': - return 'ppm' - -tests.append(test_ppm) - -def test_rast(h, f): - """test for the Sun raster file.""" - if h.startswith(b'\x59\xA6\x6A\x95'): - return 'rast' - -tests.append(test_rast) - -def test_xbm(h, f): - """Verify if the image is a X bitmap (X10 or X11).""" - if h.startswith(b'#define '): - return 'xbm' - -tests.append(test_xbm) - -def test_bmp(h, f): - """Verify if the image is a BMP file.""" - if h.startswith(b'BM'): - return 'bmp' - -tests.append(test_bmp) - -def test_webp(h, f): - """Verify if the image is a WebP.""" - if h.startswith(b'RIFF') and h[8:12] == b'WEBP': - return 'webp' - -tests.append(test_webp) - -def test_exr(h, f): - """verify is the image ia a OpenEXR fileOpenEXR.""" - if h.startswith(b'\x76\x2f\x31\x01'): - return 'exr' - -tests.append(test_exr) - -#--------------------# -# Small test program # -#--------------------# - -def test(): - import sys - recursive = 0 - if sys.argv[1:] and sys.argv[1] == '-r': - del sys.argv[1:2] - recursive = 1 - try: - if sys.argv[1:]: - testall(sys.argv[1:], recursive, 1) - else: - testall(['.'], recursive, 1) - except KeyboardInterrupt: - sys.stderr.write('\n[Interrupted]\n') - sys.exit(1) - -def testall(list, recursive, toplevel): - import sys - import os - for filename in list: - if os.path.isdir(filename): - print(filename + '/:', end=' ') - if recursive or toplevel: - print('recursing down:') - import glob - names = glob.glob(os.path.join(glob.escape(filename), '*')) - testall(names, recursive, 0) - else: - print('*** directory (use -r) ***') - else: - print(filename + ':', end=' ') - sys.stdout.flush() - try: - print(what(filename)) - except OSError: - print('*** not found ***') - -if __name__ == '__main__': - test() diff --git a/Lib/test/imghdrdata/python-raw.jpg b/Lib/test/imghdrdata/python-raw.jpg deleted file mode 100644 index 11940b3410ddf052a996d705006236172e153c25..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 525 zcmex=y%&ai23_z|RGYc!5B7=~js90j-!~eG!c$gW1&R`Z~uxAiib}37`_~0{Pp(|5m zJ_{y4QBB>qE9ySbOP zKJvD_{#YsalT_xtD}`PbTbf>YcWM=8%AM6!wEp;hr&P(BcMGFR`>uMdNsVspZfvbq z)SQvNGJDES&s6`NCt5WHy&JVYRNee!(@+<>kM~>BLWeUip3Sn2+3vjgdR1z~#+!kP z9s5&uT>f}CgGKYeg@3zkm>$@Kuy5IWvpVFN`tQ8^QxZg)l7xGA1kKPeXYDMiOn73{ ZnSZ#cZ+TG9D}~;D6_WDoYwQ2t1OUankdy!b diff --git a/Lib/test/imghdrdata/python.bmp b/Lib/test/imghdrdata/python.bmp deleted file mode 100644 index 675f95191a45fdb3ae845996d6871b86286f848a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1162 zcmZ{kYempK|q2sSaMQcOvV!f#cTTaT5pwGN1$s5CJv=mUkMll5Jgcy;ItSC?Tnd^`$!ZyO|7%HXiN}owe^9#6tKCr10S#!uzCDIGzdHNjmWMc9{p|zePQa{W;AvB4VXGT z`>Y5WM+&f)Y5BJ0OR`&Y#e7pvBu<7?XPJl`HRPB@gg%1MhyQDN3OWN`{bX)5G|R z)Zkw1O;Wu2St}P^;?17p-|QWcLE;K)~*-(-^GMc0W0vFmLgqB#t_8FRmYt=IheKYf;2%Ew2~5z(0uc Bxh4Pr diff --git a/Lib/test/imghdrdata/python.exr b/Lib/test/imghdrdata/python.exr deleted file mode 100644 index 773c81ee1fb850cdbb6cccd3ae5edabb80146481..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2635 zcmcJROK2NM7{@2=N@|-p=|Qy*&7%~@59(Nt9qrD{DhX+Ai$Y5vmGPwyR7-LMiexOs zO(7|QBFmSQLUHU%A5d)h)E0`IT#^`yB17rp;>J*toManH+guzM3T?lco%Qb8Dm`_U z-I?7P&G(!C_n$$NfzZCk5JIEp6S-U}TYyG3Qz)XB;oBLs51zd6n%^((`4Zdn<=mbx zXf%Ied?HmSWb!#zTTGu!6cZzvTr&R-dOLq9oIy|Xh_W1ln%~JxVLY37_dmyFGr82+ ziDYU5*)0)eJaZ|PJyRG@jTX-(ikUo0XY+|7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P3(1`fX8p^CuZbqNQ(CtZT;AGbYjjQ{`u diff --git a/Lib/test/imghdrdata/python.tiff b/Lib/test/imghdrdata/python.tiff deleted file mode 100644 index 39d0bfcec02533ade8934a8796aebb8990c9d389..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1326 zcmZ{kYe(N;1=o3>C6iK^NjBVVur+_Bv`_wuaafkG@48y9bf^^$>oj7DD%5;{sDlOE7sh%6W8^ zHdQL~>Z@h?%35i9sZpXmZwyK=V=V6HA{sU;lGCVYLVIt4=!0B-{U`qtBV%3@DGgv|wwpgepN!VX?X zuM16{8&xT|rbbb}n^B6)`JN@ai;Xy^`8kqNWB#&- zgHJmF#34StwlYyJCWfFy(}0;bbRJ7kRA&T=p1%qegj$B8b?b1$8thpa^KedR6Wd`- ze-K0XWzWx3xlVjc$L3-)?<%wt%)z;p*q58of$d3FBAXm{KBj#a@Ua2og?v64if!`O zVoW}CP;#Loi$%D97{*RGJBs;9e7+@*+OvEFE(6tc^oEg~Ep!#U=uxxlrSfvR8njyW fXuf-=%w_kUu8C|tS<3P=v-PRE3}1bkRx9`m*;LyH diff --git a/Lib/test/imghdrdata/python.webp b/Lib/test/imghdrdata/python.webp deleted file mode 100644 index e824ec7fb1c7fa85716d27454e9d1715a896d4b4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 432 zcmV;h0Z;x?Nk&Gf0RRA3MM6+kP&il$0000G0000F000jF06|PpNW%aC00AeWsF5V) zdgmBl=ie%sh?xI$agE?6Fyi5hcQVMq5nO{SFzB#&6^?jOHNglB0#A~lYOqxq9M-mN zMlVjrc09K2cl)m?t|6lTNzwg}koUSoNhBLOC6P4q6m1U2)8!T*^a~Wekl};38Zw?X zf`1(;eol4>`-q;ik?)yvM(8qv+xW~#viC(WeIWfd7mOh?RxPF0Ya_f}@)trH( z*>09~iWo5uimEJ7H2N@t-@0p1QYp19&*@YY3IPBB09H^qAie+q0FVLzodGHk01yBJ z05m1A0(3A>2!#xM104t~{pbMx{dA!H0-GO-_d|S~H}=vDuhaiEXyWdty~%GI^s2>U zuDYL>gx^7;JK9_1@A%8{y?^1a`ak6f?DV^4U;nBp*?-Aw=Z5C2m$~G|^phiuU)_&6 zRUm(rPy9Lf|8LT31L&W;gP3M*vDFj*b{FQc{#}aXpGUv5`oI1i9rF^8{#?(&`uP~c az0c1dkvX6N{h9$wF)ZG^*?X$20000=+R1SM diff --git a/Lib/test/test_imghdr.py b/Lib/test/test_imghdr.py deleted file mode 100644 index 208c8eee455e7b..00000000000000 --- a/Lib/test/test_imghdr.py +++ /dev/null @@ -1,144 +0,0 @@ -import io -import os -import pathlib -import unittest -import warnings -from test.support import findfile, warnings_helper -from test.support.os_helper import TESTFN, unlink - -imghdr = warnings_helper.import_deprecated("imghdr") - - -TEST_FILES = ( - ('python.png', 'png'), - ('python.gif', 'gif'), - ('python.bmp', 'bmp'), - ('python.ppm', 'ppm'), - ('python.pgm', 'pgm'), - ('python.pbm', 'pbm'), - ('python.jpg', 'jpeg'), - ('python-raw.jpg', 'jpeg'), # raw JPEG without JFIF/EXIF markers - ('python.ras', 'rast'), - ('python.sgi', 'rgb'), - ('python.tiff', 'tiff'), - ('python.xbm', 'xbm'), - ('python.webp', 'webp'), - ('python.exr', 'exr'), -) - -class UnseekableIO(io.FileIO): - def tell(self): - raise io.UnsupportedOperation - - def seek(self, *args, **kwargs): - raise io.UnsupportedOperation - -class TestImghdr(unittest.TestCase): - @classmethod - def setUpClass(cls): - cls.testfile = findfile('python.png', subdir='imghdrdata') - with open(cls.testfile, 'rb') as stream: - cls.testdata = stream.read() - - def tearDown(self): - unlink(TESTFN) - - def test_data(self): - for filename, expected in TEST_FILES: - filename = findfile(filename, subdir='imghdrdata') - self.assertEqual(imghdr.what(filename), expected) - with open(filename, 'rb') as stream: - self.assertEqual(imghdr.what(stream), expected) - with open(filename, 'rb') as stream: - data = stream.read() - self.assertEqual(imghdr.what(None, data), expected) - self.assertEqual(imghdr.what(None, bytearray(data)), expected) - - def test_pathlike_filename(self): - for filename, expected in TEST_FILES: - with self.subTest(filename=filename): - filename = findfile(filename, subdir='imghdrdata') - self.assertEqual(imghdr.what(pathlib.Path(filename)), expected) - - def test_register_test(self): - def test_jumbo(h, file): - if h.startswith(b'eggs'): - return 'ham' - imghdr.tests.append(test_jumbo) - self.addCleanup(imghdr.tests.pop) - self.assertEqual(imghdr.what(None, b'eggs'), 'ham') - - def test_file_pos(self): - with open(TESTFN, 'wb') as stream: - stream.write(b'ababagalamaga') - pos = stream.tell() - stream.write(self.testdata) - with open(TESTFN, 'rb') as stream: - stream.seek(pos) - self.assertEqual(imghdr.what(stream), 'png') - self.assertEqual(stream.tell(), pos) - - def test_bad_args(self): - with self.assertRaises(TypeError): - imghdr.what() - with self.assertRaises(AttributeError): - imghdr.what(None) - with self.assertRaises(TypeError): - imghdr.what(self.testfile, 1) - with self.assertRaises(AttributeError): - imghdr.what(os.fsencode(self.testfile)) - with open(self.testfile, 'rb') as f: - with self.assertRaises(AttributeError): - imghdr.what(f.fileno()) - - def test_invalid_headers(self): - for header in (b'\211PN\r\n', - b'\001\331', - b'\x59\xA6', - b'cutecat', - b'000000JFI', - b'GIF80'): - self.assertIsNone(imghdr.what(None, header)) - - def test_string_data(self): - with warnings.catch_warnings(): - warnings.simplefilter("ignore", BytesWarning) - for filename, _ in TEST_FILES: - filename = findfile(filename, subdir='imghdrdata') - with open(filename, 'rb') as stream: - data = stream.read().decode('latin1') - with self.assertRaises(TypeError): - imghdr.what(io.StringIO(data)) - with self.assertRaises(TypeError): - imghdr.what(None, data) - - def test_missing_file(self): - with self.assertRaises(FileNotFoundError): - imghdr.what('missing') - - def test_closed_file(self): - stream = open(self.testfile, 'rb') - stream.close() - with self.assertRaises(ValueError) as cm: - imghdr.what(stream) - stream = io.BytesIO(self.testdata) - stream.close() - with self.assertRaises(ValueError) as cm: - imghdr.what(stream) - - def test_unseekable(self): - with open(TESTFN, 'wb') as stream: - stream.write(self.testdata) - with UnseekableIO(TESTFN, 'rb') as stream: - with self.assertRaises(io.UnsupportedOperation): - imghdr.what(stream) - - def test_output_stream(self): - with open(TESTFN, 'wb') as stream: - stream.write(self.testdata) - stream.seek(0) - with self.assertRaises(OSError) as cm: - imghdr.what(stream) - -if __name__ == '__main__': - unittest.main() diff --git a/Lib/test/test_tkinter/test_images.py b/Lib/test/test_tkinter/test_images.py index b6f8b79ae689fa..c07de867ce04b7 100644 --- a/Lib/test/test_tkinter/test_images.py +++ b/Lib/test/test_tkinter/test_images.py @@ -66,7 +66,7 @@ class BitmapImageTest(AbstractTkTest, unittest.TestCase): @classmethod def setUpClass(cls): AbstractTkTest.setUpClass.__func__(cls) - cls.testfile = support.findfile('python.xbm', subdir='imghdrdata') + cls.testfile = support.findfile('python.xbm', subdir='tkinterdata') def test_create_from_file(self): image = tkinter.BitmapImage('::img::test', master=self.root, @@ -150,7 +150,7 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase): @classmethod def setUpClass(cls): AbstractTkTest.setUpClass.__func__(cls) - cls.testfile = support.findfile('python.gif', subdir='imghdrdata') + cls.testfile = support.findfile('python.gif', subdir='tkinterdata') def create(self): return tkinter.PhotoImage('::img::test', master=self.root, @@ -163,7 +163,7 @@ def colorlist(self, *args): return tkinter._join(args) def check_create_from_file(self, ext): - testfile = support.findfile('python.' + ext, subdir='imghdrdata') + testfile = support.findfile('python.' + ext, subdir='tkinterdata') image = tkinter.PhotoImage('::img::test', master=self.root, file=testfile) self.assertEqual(str(image), '::img::test') @@ -178,7 +178,7 @@ def check_create_from_file(self, ext): self.assertNotIn('::img::test', self.root.image_names()) def check_create_from_data(self, ext): - testfile = support.findfile('python.' + ext, subdir='imghdrdata') + testfile = support.findfile('python.' + ext, subdir='tkinterdata') with open(testfile, 'rb') as f: data = f.read() image = tkinter.PhotoImage('::img::test', master=self.root, diff --git a/Lib/test/test_tkinter/widget_tests.py b/Lib/test/test_tkinter/widget_tests.py index 85b0511aba3c7a..f60087a6e9f385 100644 --- a/Lib/test/test_tkinter/widget_tests.py +++ b/Lib/test/test_tkinter/widget_tests.py @@ -250,7 +250,7 @@ def test_configure_bitmap(self): widget = self.create() self.checkParam(widget, 'bitmap', 'questhead') self.checkParam(widget, 'bitmap', 'gray50') - filename = test.support.findfile('python.xbm', subdir='imghdrdata') + filename = test.support.findfile('python.xbm', subdir='tkinterdata') self.checkParam(widget, 'bitmap', '@' + filename) # Cocoa Tk widgets don't detect invalid -bitmap values # See https://core.tcl.tk/tk/info/31cd33dbf0 diff --git a/Lib/test/imghdrdata/python.gif b/Lib/test/tkinterdata/python.gif similarity index 100% rename from Lib/test/imghdrdata/python.gif rename to Lib/test/tkinterdata/python.gif diff --git a/Lib/test/imghdrdata/python.pgm b/Lib/test/tkinterdata/python.pgm similarity index 100% rename from Lib/test/imghdrdata/python.pgm rename to Lib/test/tkinterdata/python.pgm diff --git a/Lib/test/imghdrdata/python.png b/Lib/test/tkinterdata/python.png similarity index 100% rename from Lib/test/imghdrdata/python.png rename to Lib/test/tkinterdata/python.png diff --git a/Lib/test/imghdrdata/python.ppm b/Lib/test/tkinterdata/python.ppm similarity index 100% rename from Lib/test/imghdrdata/python.ppm rename to Lib/test/tkinterdata/python.ppm diff --git a/Lib/test/imghdrdata/python.xbm b/Lib/test/tkinterdata/python.xbm similarity index 100% rename from Lib/test/imghdrdata/python.xbm rename to Lib/test/tkinterdata/python.xbm diff --git a/Makefile.pre.in b/Makefile.pre.in index b277092f20079d..7ae94ff02cd285 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -2116,7 +2116,6 @@ TESTSUBDIRS= idlelib/idle_test \ test/decimaltestdata \ test/dtracedata \ test/encoded_modules \ - test/imghdrdata \ test/leakers \ test/libregrtest \ test/subprocessdata \ @@ -2210,6 +2209,7 @@ TESTSUBDIRS= idlelib/idle_test \ test/test_zipfile \ test/test_zoneinfo \ test/test_zoneinfo/data \ + test/tkinterdata \ test/tracedmodules \ test/typinganndata \ test/xmltestdata \ diff --git a/Misc/NEWS.d/next/Library/2023-05-23-02-13-11.gh-issue-104773.JNiEjv.rst b/Misc/NEWS.d/next/Library/2023-05-23-02-13-11.gh-issue-104773.JNiEjv.rst new file mode 100644 index 00000000000000..213b6f5b764258 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-05-23-02-13-11.gh-issue-104773.JNiEjv.rst @@ -0,0 +1,2 @@ +:pep:`594`: Remove the :mod:`!imghdr` module, deprecated in Python 3.11. +Patch by Victor Stinner. diff --git a/Python/stdlib_module_names.h b/Python/stdlib_module_names.h index 5af120d2542822..925b8b3230fce3 100644 --- a/Python/stdlib_module_names.h +++ b/Python/stdlib_module_names.h @@ -156,7 +156,6 @@ static const char* _Py_stdlib_module_names[] = { "http", "idlelib", "imaplib", -"imghdr", "importlib", "inspect", "io",