Sfoglia il codice sorgente

improve guess_mime_using_file

pull/8/head
lilydjwg 5 anni fa
parent
commit
90c3293803
1 ha cambiato i file con 5 aggiunte e 1 eliminazioni
  1. +5
    -1
      main.py

+ 5
- 1
main.py Vedi File

@ -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


Caricamento…
Annulla
Salva