From 20dcf76cef33345e67a44166c9cca54e506bd16b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 9 Dec 2015 19:20:29 +1100 Subject: [PATCH 1/2] Added null handler to loggers --- PIL/Image.py | 1 + PIL/ImageFile.py | 1 + PIL/PcxImagePlugin.py | 1 + PIL/PngImagePlugin.py | 1 + PIL/PyAccess.py | 1 + Tests/test_file_libtiff.py | 1 + Tests/test_file_tiff.py | 1 + 7 files changed, 7 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index af6dac1c4..3865e9c0f 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -32,6 +32,7 @@ import logging import warnings logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) class DecompressionBombWarning(RuntimeWarning): diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index f26a7260e..88952649d 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -36,6 +36,7 @@ import sys import struct logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) MAXBLOCK = 65536 diff --git a/PIL/PcxImagePlugin.py b/PIL/PcxImagePlugin.py index 9440d5362..ef057ed11 100644 --- a/PIL/PcxImagePlugin.py +++ b/PIL/PcxImagePlugin.py @@ -31,6 +31,7 @@ import logging from PIL import Image, ImageFile, ImagePalette, _binary logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) i8 = _binary.i8 i16 = _binary.i16le diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index d6778821b..ec7c4c59b 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -42,6 +42,7 @@ from PIL import Image, ImageFile, ImagePalette, _binary __version__ = "0.9" logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) i8 = _binary.i8 i16 = _binary.i16be diff --git a/PIL/PyAccess.py b/PIL/PyAccess.py index 0d4c8b235..8c1e4558d 100644 --- a/PIL/PyAccess.py +++ b/PIL/PyAccess.py @@ -29,6 +29,7 @@ from cffi import FFI logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) defs = """ diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index f900b97cf..2abf605b4 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -10,6 +10,7 @@ import os from PIL import Image, TiffImagePlugin logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) class LibTiffTestCase(PillowTestCase): diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 308783fb3..9141668c3 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -7,6 +7,7 @@ from helper import unittest, PillowTestCase, hopper, py3 from PIL import Image, TiffImagePlugin logger = logging.getLogger(__name__) +logger.addHandler(logging.NullHandler()) class TestFileTiff(PillowTestCase): From 937bf7807beeb40cbdf2d4186904bd3dc5063afe Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 9 Dec 2015 20:08:00 +1100 Subject: [PATCH 2/2] Added NullHandler class for Python 2.6 --- PIL/Image.py | 7 ++++++- PIL/ImageFile.py | 2 ++ PIL/PcxImagePlugin.py | 3 +++ PIL/PngImagePlugin.py | 3 +++ PIL/PyAccess.py | 3 +++ Tests/test_file_libtiff.py | 3 +++ Tests/test_file_tiff.py | 3 +++ 7 files changed, 23 insertions(+), 1 deletion(-) diff --git a/PIL/Image.py b/PIL/Image.py index 3865e9c0f..e83899cce 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -28,7 +28,13 @@ from __future__ import print_function from PIL import VERSION, PILLOW_VERSION, _plugins +import sys import logging +if sys.version_info < (2, 7): + class NullHandler(logging.Handler): + def emit(self, record): + pass + logging.NullHandler = NullHandler import warnings logger = logging.getLogger(__name__) @@ -112,7 +118,6 @@ from PIL._util import isStringType from PIL._util import deferred_error import os -import sys import io import struct diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index 88952649d..38d709b64 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -36,6 +36,8 @@ import sys import struct logger = logging.getLogger(__name__) +if sys.version_info < (2, 7): + logging.NullHandler = Image.NullHandler logger.addHandler(logging.NullHandler()) MAXBLOCK = 65536 diff --git a/PIL/PcxImagePlugin.py b/PIL/PcxImagePlugin.py index ef057ed11..f443c5ec4 100644 --- a/PIL/PcxImagePlugin.py +++ b/PIL/PcxImagePlugin.py @@ -27,10 +27,13 @@ from __future__ import print_function +import sys import logging from PIL import Image, ImageFile, ImagePalette, _binary logger = logging.getLogger(__name__) +if sys.version_info < (2, 7): + logging.NullHandler = Image.NullHandler logger.addHandler(logging.NullHandler()) i8 = _binary.i8 diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index ec7c4c59b..92156c0e4 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -33,6 +33,7 @@ from __future__ import print_function +import sys import logging import re import zlib @@ -42,6 +43,8 @@ from PIL import Image, ImageFile, ImagePalette, _binary __version__ = "0.9" logger = logging.getLogger(__name__) +if sys.version_info < (2, 7): + logging.NullHandler = Image.NullHandler logger.addHandler(logging.NullHandler()) i8 = _binary.i8 diff --git a/PIL/PyAccess.py b/PIL/PyAccess.py index 8c1e4558d..5e4c77750 100644 --- a/PIL/PyAccess.py +++ b/PIL/PyAccess.py @@ -29,6 +29,9 @@ from cffi import FFI logger = logging.getLogger(__name__) +if sys.version_info < (2, 7): + from PIL import Image + logging.NullHandler = Image.NullHandler logger.addHandler(logging.NullHandler()) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 2abf605b4..59190a4c0 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -3,6 +3,7 @@ from helper import unittest, PillowTestCase, hopper, py3 from ctypes import c_float import io +import sys import logging import itertools import os @@ -10,6 +11,8 @@ import os from PIL import Image, TiffImagePlugin logger = logging.getLogger(__name__) +if sys.version_info < (2, 7): + logging.NullHandler = Image.NullHandler logger.addHandler(logging.NullHandler()) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 9141668c3..a39600e9e 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -1,4 +1,5 @@ from __future__ import print_function +import sys import logging import struct @@ -7,6 +8,8 @@ from helper import unittest, PillowTestCase, hopper, py3 from PIL import Image, TiffImagePlugin logger = logging.getLogger(__name__) +if sys.version_info < (2, 7): + logging.NullHandler = Image.NullHandler logger.addHandler(logging.NullHandler())