[Python-3000] Fix imghdr module for bytes
Victor Stinner
victor.stinner at haypocalc.com
Sat Aug 11 02:35:43 CEST 2007
Hi,
I just see that function what() of imghdr module requires str type for
argument h which is totally wrong! An image file is composed of bytes and not
characters.
Attached patch should fix it. Notes:
- I used .startswith() instead of h[:len(s)] == s
- I used h[0] == ord(b'P') instead of h[0] == b'P' because the second syntax
doesn't work (see my other email "bytes: compare bytes to integer")
- str is allowed but doesn't work: what() always returns None
I dislike "h[0] == ord(b'P')", in Python 2.x it's simply "h[0] == 'P'". A
shorter syntax would be "h[0] == 80" but I prefer explicit test. It's maybe
stupid, we manipulate bytes and not character, so "h[0] == 80" is
acceptable... maybe with a comment?
imghdr is included in unit tests?
Victor Stinner
http://hachoir.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: py3k-imghdr.patch
Type: text/x-diff
Size: 2512 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20070811/de5fac37/attachment.bin
More information about the Python-3000
mailing list