diff --git a/PIL/Image.py b/PIL/Image.py index f49834e5b47..e368ef18779 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -2512,6 +2512,16 @@ def register_extension(id, extension): EXTENSION[extension.lower()] = id.upper() +def registered_extensions(): + """ + Returns a dictionary containing all file extensions belonging + to registered plugins + """ + if not bool(EXTENSION): + init() + return EXTENSION + + # -------------------------------------------------------------------- # Simple display support. User code may override this. diff --git a/Tests/test_image.py b/Tests/test_image.py index f1457a85bb6..70bc638773c 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -196,6 +196,35 @@ def test_alpha_composite(self): img_colors = sorted(img.getcolors()) self.assertEqual(img_colors, expected_colors) + def test_registered_extensions_uninitialized(self): + # Arrange + Image._initialized = 0 + extension = Image.EXTENSION + Image.EXTENSION = {} + + # Act + Image.registered_extensions() + + # Assert + self.assertEqual(Image._initialized, 2) + + # Restore the original state and assert + Image.EXTENSION = extension + self.assertTrue(Image.EXTENSION) + + def test_registered_extensions(self): + # Arrange + # Open an image to trigger plugin registration + Image.open('Tests/images/rgb.jpg') + + # Act + extensions = Image.registered_extensions() + + # Assert + self.assertTrue(bool(extensions)) + for ext in ['.cur', '.icns', '.tif', '.tiff']: + self.assertIn(ext, extensions) + def test_effect_mandelbrot(self): # Arrange size = (512, 512)