Make PngImagePlugin.add_text() zip argument type bool

Always used as a bool, but was previously defined as 0/1. Use modern
idiomatic Python by using the bool type for bool arguments.
This commit is contained in:
Jon Dufresne 2017-12-16 09:13:45 -08:00
parent 92bb1b5f06
commit 8844e2dd71
3 changed files with 5 additions and 5 deletions

View File

@ -249,7 +249,7 @@ class PngInfo(object):
self.add(b"iTXt", key + b"\0\0\0" + lang + b"\0" + tkey + b"\0" +
value)
def add_text(self, key, value, zip=0):
def add_text(self, key, value, zip=False):
"""Appends a text chunk.
:param key: latin-1 encodable text key name
@ -259,14 +259,14 @@ class PngInfo(object):
"""
if isinstance(value, iTXt):
return self.add_itxt(key, value, value.lang, value.tkey, bool(zip))
return self.add_itxt(key, value, value.lang, value.tkey, zip=zip)
# The tEXt chunk stores latin-1 text
if not isinstance(value, bytes):
try:
value = value.encode('latin-1', 'strict')
except UnicodeError:
return self.add_itxt(key, value, zip=bool(zip))
return self.add_itxt(key, value, zip=zip)
if not isinstance(key, bytes):
key = key.encode('latin-1', 'strict')

View File

@ -41,7 +41,7 @@ class TestPngDos(PillowTestCase):
info = PngImagePlugin.PngInfo()
for x in range(64):
info.add_text('t%s' % x, compressed_data, 1)
info.add_text('t%s' % x, compressed_data, zip=True)
info.add_itxt('i%s' % x, compressed_data, zip=True)
b = BytesIO()

View File

@ -360,7 +360,7 @@ class TestFilePng(PillowTestCase):
info = PngImagePlugin.PngInfo()
info.add_text("TXT", "VALUE")
info.add_text("ZIP", "VALUE", 1)
info.add_text("ZIP", "VALUE", zip=True)
im = roundtrip(im, pnginfo=info)
self.assertEqual(im.info, {'TXT': 'VALUE', 'ZIP': 'VALUE'})