From fe765eb69492e1ae9cf8c5f75bad7bbfc0c935dc Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 15 2015 13:51:05 +0000 Subject: More attempt to figure out if a file is a binary or an image --- diff --git a/pagure/lib/__init__.py b/pagure/lib/__init__.py index 7b1e7c2..a5b21f8 100644 --- a/pagure/lib/__init__.py +++ b/pagure/lib/__init__.py @@ -2372,6 +2372,24 @@ def is_binary(text): """ Returns wether we think this text correspond to a binary file or not """ btext = bytes(text) + + import imghdr + print 'imghdr', imghdr.what('foo', h=btext) + if imghdr.what('foo', h=text): + return True + + import StringIO + from PIL import Image + try: + im = Image.open(text) + im = Image.open(StringIO.StringIO(text)) + if im: + return True + except IOError, err: + print 'ERROR', err + pass + print btext + if b'\x00' in btext: return True