From 2f60820f4c1bdfce75f30ddc53d97587a3256dcf Mon Sep 17 00:00:00 2001 From: R David Murray Date: Thu, 26 Jun 2014 12:27:57 -0400 Subject: [PATCH] #20295: Teach imghdr to recognize OpenEXR format images. Patch by Martin Vignali, test by Claudiu Popa. --- Doc/library/imghdr.rst | 5 +++++ Doc/whatsnew/3.5.rst | 6 ++++++ Lib/imghdr.py | 6 ++++++ Lib/test/imghdrdata/python.exr | Bin 0 -> 2635 bytes Lib/test/test_imghdr.py | 1 + Misc/NEWS | 2 ++ 6 files changed, 20 insertions(+) create mode 100644 Lib/test/imghdrdata/python.exr diff --git a/Doc/library/imghdr.rst b/Doc/library/imghdr.rst index 06faa883d3f8..c60df24c5a17 100644 --- a/Doc/library/imghdr.rst +++ b/Doc/library/imghdr.rst @@ -50,6 +50,11 @@ from :func:`what`: +------------+-----------------------------------+ | ``'webp'`` | WebP files | +------------+-----------------------------------+ +| ``'exr'`` | OpenEXR Files | ++------------+-----------------------------------+ + +.. versionadded:: 3.5 + The *exr* format was added. .. versionchanged:: 3.5 The *webp* type was added. diff --git a/Doc/whatsnew/3.5.rst b/Doc/whatsnew/3.5.rst index 1b4253ce7280..9fff48cf55f9 100644 --- a/Doc/whatsnew/3.5.rst +++ b/Doc/whatsnew/3.5.rst @@ -141,6 +141,12 @@ doctest *module* contains no docstrings instead of raising :exc:`ValueError` (contributed by Glenn Jones in :issue:`15916`). +imghdr +------ + +* :func:`~imghdr.what` now recognizes the `OpenEXR `_ + format (contributed by Martin vignali and Cladui Popa in :issue:`20295`). + importlib --------- diff --git a/Lib/imghdr.py b/Lib/imghdr.py index fe77e495fb6a..b26792539d5b 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -116,6 +116,12 @@ def test_webp(h, f): tests.append(test_webp) +def test_exr(h, f): + if h.startswith(b'\x76\x2f\x31\x01'): + return 'exr' + +tests.append(test_exr) + #--------------------# # Small test program # #--------------------# diff --git a/Lib/test/imghdrdata/python.exr b/Lib/test/imghdr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clbxb^xI1Bw#M0|g3PY{F6NQSQ%5IatS0#4%>Fl-M18Lba<7 zx4+7LQ3NeU2J8EH$$=8{LW|SvZj;}i_l*sCUN#IDv;Xf?%i-t?dh$vSoc0i$$~BLp I5B)FYZ}0KvRR910 literal 0 Hc-jL100001 diff --git a/Lib/test/test_imghdr.py b/Lib/test/test_imghdr.py index e2a1acab3228..b54daf8e2ca1 100644 --- a/Lib/test/test_imghdr.py +++ b/Lib/test/test_imghdr.py @@ -18,6 +18,7 @@ TEST_FILES = ( ('python.tiff', 'tiff'), ('python.xbm', 'xbm'), ('python.webp', 'webp'), + ('python.exr', 'exr'), ) class UnseekableIO(io.FileIO): diff --git a/Misc/NEWS b/Misc/NEWS index 9ae200a61e67..1cd7d58ff058 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -103,6 +103,8 @@ Core and Builtins Library ------- +- Issue #20295: imghdr now recognizes OpenEXR format images. + - Issue #21729: Used the "with" statement in the dbm.dumb module to ensure files closing. Patch by Claudiu Popa. -- 2.47.3