Pārlūkot izejas kodu

improve guess_mime_using_file

pull/8/head
lilydjwg pirms 5 gadiem
vecāks
revīzija
90c3293803
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. +5
    -1
      main.py

+ 5
- 1
main.py Parādīt failu

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


Notiek ielāde…
Atcelt
Saglabāt