Explorar el Código

improve guess_mime_using_file

pull/8/head
lilydjwg hace 5 años
padre
commit
90c3293803
Se han modificado 1 ficheros con 5 adiciones y 1 borrados
  1. +5
    -1
      main.py

+ 5
- 1
main.py Ver fichero

@ -34,12 +34,16 @@ def guess_mime_using_file(path):
mime = mime.rstrip(';')
encoding = encoding.split('=')[-1]
# older file doesn't know webp
if mime == 'application/octet-stream':
result = subprocess.check_output(['file', path]).decode()
_, desc = result.split(None, 1)
if 'Web/P image' in desc:
return 'image/webp', 'binary'
return 'image/webp', None
# Tornado will treat non-gzip encoding as application/octet-stream
if encoding != 'gzip':
encoding = None
return mime, encoding
mimetypes.guess_type = guess_mime_using_file


Cargando…
Cancelar
Guardar