Convert pillow warnings to logging with filename, ref #394

This commit is contained in:
Simon Conseil
2020-08-06 22:49:06 -04:00
parent 1e0714d29a
commit 435768ccce

View File

@@ -67,17 +67,14 @@ def _read_image(file_path):
if isinstance(file_path, PILImage.Image):
return file_path
logger = logging.getLogger(__name__)
with warnings.catch_warnings(record=True) as caught_warnings:
im = PILImage.open(file_path)
for warning in caught_warnings:
if warning.category == PILImage.DecompressionBombWarning:
logger = logging.getLogger(__name__)
logger.info('PILImage reported a possible DecompressionBomb'
' for file {}'.format(file_path))
else:
warnings.showwarning(warning.message, warning.category,
warning.filename, warning.lineno)
for w in caught_warnings:
logger.warning(f'PILImage reported a warning for file {file_path}\n'
f'{w.category}: {w.message}')
return im