Revision: da7a1f6dcccf
Branch: default
Author: Juan J. Martínez <
j...@usebox.net>
Date: Sat Mar 29 18:05:58 2014 UTC
Log: Python 3 compatibility (bytes vs strings) in pypng
Patch backported from
https://github.com/drj11/pypng/pull/30
Thanks to Claudio Canepa for his help.
Fixes issue #717.
http://code.google.com/p/pyglet/source/detail?r=da7a1f6dcccf
Modified:
/pyglet/image/codecs/pypng.py
=======================================
--- /pyglet/image/codecs/pypng.py Sat Dec 7 19:02:32 2013 UTC
+++ /pyglet/image/codecs/pypng.py Sat Mar 29 18:05:58 2014 UTC
@@ -104,6 +104,12 @@
(1, 0, 2, 2),
(0, 1, 1, 2))
+# Conditionally convert to bytes. Works on Python 2 and Python 3.
+try:
+ bytes('', 'ascii')
+ def strtobytes(x): return bytes(x, 'iso8859-1')
+except (NameError, TypeError):
+ strtobytes = str
def interleave_planes(ipixels, apixels, ipsize, apsize):
"""
@@ -309,7 +315,7 @@
if len(data):
compressed = compressor.compress(data.tostring())
else:
- compressed = ''
+ compressed = strtobytes('')
flushed = compressor.flush()
if len(compressed) or len(flushed):
# print >> sys.stderr, len(data), len(compressed), len(flushed)