On 8/10/07, Victor Stinner <[EMAIL PROTECTED]> wrote: > 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?
Try h[0:1] == b'P'. Slicing will ensure it stays as a bytes object, rather than just giving the integer it contains. -- Adam Olsen, aka Rhamphoryncus _______________________________________________ Python-3000 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com
