Mercurial > public > sg101
diff core/download.py @ 981:ef1558941bc9
Additional tweaks to ssl_images.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 24 Oct 2015 21:29:07 -0500 |
parents | 3ebde23a59d0 |
children |
line wrap: on
line diff
--- a/core/download.py Thu Oct 15 18:35:56 2015 -0500 +++ b/core/download.py Sat Oct 24 21:29:07 2015 -0500 @@ -5,6 +5,7 @@ import os import shutil import tempfile +from urlparse import urlparse import requests @@ -38,10 +39,15 @@ if not path: content_type = r.headers.get('content-type') suffix = mimetypes.guess_extension(content_type) if content_type else '' + + # mimetypes currently returns '.jpe' for jpeg; so fix that up here... if suffix == '.jpe': suffix = '.jpg' - elif suffix is None: - suffix = '' + elif not suffix: + # No content-type so guess based on extension if we can + p = urlparse(url) + suffix = os.path.splitext(p.path)[1] + fd, path = tempfile.mkstemp(suffix=suffix) os.close(fd)