Merge pull request #2890 from jdufresne/add-text-bool

Make PngImagePlugin.add_text() zip argument type bool
This commit is contained in:
wiredfool 2017-12-19 15:50:01 +00:00 committed by GitHub
commit 09c8b06f4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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" + self.add(b"iTXt", key + b"\0\0\0" + lang + b"\0" + tkey + b"\0" +
value) value)
def add_text(self, key, value, zip=0): def add_text(self, key, value, zip=False):
"""Appends a text chunk. """Appends a text chunk.
:param key: latin-1 encodable text key name :param key: latin-1 encodable text key name
@ -259,14 +259,14 @@ class PngInfo(object):
""" """
if isinstance(value, iTXt): 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 # The tEXt chunk stores latin-1 text
if not isinstance(value, bytes): if not isinstance(value, bytes):
try: try:
value = value.encode('latin-1', 'strict') value = value.encode('latin-1', 'strict')
except UnicodeError: except UnicodeError:
return self.add_itxt(key, value, zip=bool(zip)) return self.add_itxt(key, value, zip=zip)
if not isinstance(key, bytes): if not isinstance(key, bytes):
key = key.encode('latin-1', 'strict') key = key.encode('latin-1', 'strict')

View File

@ -41,7 +41,7 @@ class TestPngDos(PillowTestCase):
info = PngImagePlugin.PngInfo() info = PngImagePlugin.PngInfo()
for x in range(64): 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) info.add_itxt('i%s' % x, compressed_data, zip=True)
b = BytesIO() b = BytesIO()

View File

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