Skip to content

Commit

Permalink
Remove Python 2-compatibility code
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 7, 2019
1 parent 7e3156e commit 865b17d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 23 deletions.
4 changes: 1 addition & 3 deletions Tests/test_file_png.py
Expand Up @@ -448,9 +448,7 @@ def test_nonunicode_text(self):
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))
Expand Down
5 changes: 1 addition & 4 deletions Tests/test_imagefont.py
Expand Up @@ -463,10 +463,7 @@ def test_unicode_pilfont(self):
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"
Expand Down
6 changes: 1 addition & 5 deletions src/PIL/ImageQt.py
Expand Up @@ -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)

Expand Down
12 changes: 2 additions & 10 deletions src/PIL/PdfParser.py
Expand Up @@ -7,11 +7,6 @@
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")
Expand Down Expand Up @@ -256,13 +251,10 @@ def __bytes__(self):
__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

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -1027,7 +1027,7 @@ def _seek(self, frame):
"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)
Expand Down

0 comments on commit 865b17d

Please sign in to comment.