booglybob / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

.bmp files traceback with py3 #719

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Using pyglet rda7a1f6dcccf from default repo installed in python 3 so 2to3 is 
performed.

Running the pyglet's tests tests/image/BMP_*.py gives a traceback, by example

D:\tmp\pyglet\pyglet_tests_py3\tests\image>py -3.3 BMP_RGB_1BPP_LOAD.py
E
======================================================================
ERROR: test_load (__main__.TEST_SUITE)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\tmp\pyglet\pyglet_tests_py3\tests\image\base_load.py", line 76, in te
st_load
    self.load_image()
  File "D:\tmp\pyglet\pyglet_tests_py3\tests\image\base_load.py", line 65, in lo
ad_image
    self.image = image.load(self.texture_file, decoder=self.decoder)
  File "C:\Python33\lib\site-packages\pyglet\image\__init__.py", line 187, in lo
ad
    return decoder.decode(file, filename)
  File "C:\Python33\lib\site-packages\pyglet\image\codecs\bmp.py", line 162, in
decode
    'Not a Windows bitmap file: %r' % (filename or file))
pyglet.image.codecs.ImageDecodeException: Not a Windows bitmap file: 'D:\\tmp\\p
yglet\\pyglet_tests_py3\\tests\\image\\rgb_1bpp.bmp'

Problem and fix
---------------

In pyglet/image/codecs/bmp.py the code tries to check the .bmp signature by 
comparing some bytes from the file with the str 'BM', which will fail in py3.

Changing to b'BM' makes that a bytes vs bytes comparison and fixes the problem.

After that all the BMP_*.py run fine both in py 3.3.1 and 2.6.6

Diff:
D:\hg_externals\pyglet_dev>hg diff
diff -r da7a1f6dcccf pyglet/image/codecs/bmp.py
--- a/pyglet/image/codecs/bmp.py        Sat Mar 29 18:05:58 2014 +0000
+++ b/pyglet/image/codecs/bmp.py        Mon Mar 31 09:25:05 2014 -0300
@@ -157,7 +157,7 @@
         bytes = file.read()
         buffer = ctypes.c_buffer(bytes)

-        if bytes[:2] != 'BM':
+        if bytes[:2] != b'BM':
             raise ImageDecodeException(
                 'Not a Windows bitmap file: %r' % (filename or file))

Original issue reported on code.google.com by ccanepacc@gmail.com on 31 Mar 2014 at 12:35

GoogleCodeExporter commented 8 years ago
OK, most tests won't work with Python 3. Thanks for the report and the patch!

Original comment by useboxnet on 1 Apr 2014 at 6:00

GoogleCodeExporter commented 8 years ago
This issue was closed by revision fd8b20db3bc8.

Original comment by useboxnet on 1 Apr 2014 at 4:54