Remove Python 2-compatibility code

This commit is contained in:
Hugo 2019-10-07 15:34:12 +03:00
parent 7e3156eb17
commit 865b17d5cf
5 changed files with 6 additions and 23 deletions

View File

@ -448,9 +448,7 @@ class TestFilePng(PillowTestCase):
self.assertIsInstance(im.info["Text"], str)
def test_unicode_text(self):
# Check preservation of non-ASCII characters on Python 3
# This cannot really be meaningfully tested on Python 2,
# since it didn't preserve charsets to begin with.
# Check preservation of non-ASCII characters
def rt_text(value):
im = Image.new("RGB", (32, 32))

View File

@ -463,10 +463,7 @@ class TestImageFont(PillowTestCase):
with self.assertRaises(UnicodeEncodeError):
font.getsize("")
@unittest.skipIf(
sys.version.startswith("2") or hasattr(sys, "pypy_translation_info"),
"requires CPython 3.3+",
)
@unittest.skipIf(hasattr(sys, "pypy_translation_info"), "requires CPython")
def test_unicode_extended(self):
# issue #3777
text = "A\u278A\U0001F12B"

View File

@ -65,11 +65,7 @@ def fromqimage(im):
im.save(buffer, "ppm")
b = BytesIO()
try:
b.write(buffer.data())
except TypeError:
# workaround for Python 2
b.write(str(buffer.data()))
b.write(buffer.data())
buffer.close()
b.seek(0)

View File

@ -7,11 +7,6 @@ import re
import time
import zlib
try:
from UserDict import UserDict # Python 2.x
except ImportError:
UserDict = collections.UserDict # Python 3.x
def make_bytes(s):
return s.encode("us-ascii")
@ -256,13 +251,10 @@ class PdfArray(list):
__str__ = __bytes__
class PdfDict(UserDict):
class PdfDict(collections.UserDict):
def __setattr__(self, key, value):
if key == "data":
if hasattr(UserDict, "__setattr__"):
UserDict.__setattr__(self, key, value)
else:
self.__dict__[key] = value
collections.UserDict.__setattr__(self, key, value)
else:
self[key.encode("us-ascii")] = value

View File

@ -1027,7 +1027,7 @@ class TiffImageFile(ImageFile.ImageFile):
"Seeking to frame %s, on frame %s, __next %s, location: %s"
% (frame, self.__frame, self.__next, self.fp.tell())
)
# reset python3 buffered io handle in case fp
# reset buffered io handle in case fp
# was passed to libtiff, invalidating the buffer
self.fp.tell()
self.fp.seek(self.__next)