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

View File

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

View File

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

View File

@ -7,11 +7,6 @@ import re
import time import time
import zlib import zlib
try:
from UserDict import UserDict # Python 2.x
except ImportError:
UserDict = collections.UserDict # Python 3.x
def make_bytes(s): def make_bytes(s):
return s.encode("us-ascii") return s.encode("us-ascii")
@ -256,13 +251,10 @@ class PdfArray(list):
__str__ = __bytes__ __str__ = __bytes__
class PdfDict(UserDict): class PdfDict(collections.UserDict):
def __setattr__(self, key, value): def __setattr__(self, key, value):
if key == "data": if key == "data":
if hasattr(UserDict, "__setattr__"): collections.UserDict.__setattr__(self, key, value)
UserDict.__setattr__(self, key, value)
else:
self.__dict__[key] = value
else: else:
self[key.encode("us-ascii")] = value 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" "Seeking to frame %s, on frame %s, __next %s, location: %s"
% (frame, self.__frame, self.__next, self.fp.tell()) % (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 # was passed to libtiff, invalidating the buffer
self.fp.tell() self.fp.tell()
self.fp.seek(self.__next) self.fp.seek(self.__next)