Skip to content

Commit

Permalink
Merge pull request #2890 from jdufresne/add-text-bool
Browse files Browse the repository at this point in the history
Make PngImagePlugin.add_text() zip argument type bool
  • Loading branch information
wiredfool committed Dec 19, 2017
2 parents c94484e + 8844e2d commit 09c8b06
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def add_itxt(self, key, value, lang="", tkey="", zip=False):
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
Expand All @@ -259,14 +259,14 @@ def add_text(self, key, value, zip=0):
"""
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')
Expand Down
2 changes: 1 addition & 1 deletion Tests/check_png_dos.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_dos_total_memory(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def test_roundtrip_text(self):

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'})
Expand Down

0 comments on commit 09c8b06

Please sign in to comment.