From 435768ccce6ef1372b43897a0e5ef8720b39737f Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Thu, 6 Aug 2020 22:49:06 -0400 Subject: [PATCH] Convert pillow warnings to logging with filename, ref #394 --- sigal/image.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/sigal/image.py b/sigal/image.py index 28c3b54..3e3df5d 100644 --- a/sigal/image.py +++ b/sigal/image.py @@ -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