diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 1954c52ee..06014c884 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -121,8 +121,14 @@ import struct import atexit # type stuff -import collections import numbers +try: + # Python 3 + from collections.abc import Callable +except ImportError: + # Python 2.7 + from collections import Callable + # works everywhere, win for pypy, not cpython USE_CFFI_ACCESS = hasattr(sys, 'pypy_version_info') @@ -1142,7 +1148,7 @@ class Image(object): self.load() - if isinstance(filter, collections.Callable): + if isinstance(filter, Callable): filter = filter() if not hasattr(filter, "filter"): raise TypeError("filter argument should be ImageFilter.Filter " + diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 167f0cba1..6f032f49d 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -58,6 +58,13 @@ import warnings from .TiffTags import TYPES +try: + # Python 3 + from collections.abc import MutableMapping +except ImportError: + # Python 2.7 + from collections import MutableMapping + __version__ = "1.3.5" DEBUG = False # Needs to be merged with the new logging approach. @@ -398,7 +405,7 @@ class IFDRational(Rational): __round__ = _delegate('__round__') -class ImageFileDirectory_v2(collections.MutableMapping): +class ImageFileDirectory_v2(MutableMapping): """This class represents a TIFF tag directory. To speed things up, we don't decode tags unless they're asked for.