Fix for Python 3 and warning for unknown mimetype

This commit is contained in:
Andrew Snowden
2015-10-27 10:15:48 +02:00
parent a7e8845d61
commit aa335301f3
+10 -3
View File
@@ -4,7 +4,10 @@ import logging
import os
import re
import gzip
import cStringIO
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
import mimetypes
from collections import defaultdict
@@ -216,12 +219,16 @@ def _write_files(s3, app, static_url_loc, static_folder, files, bucket,
# When we use GZIP we have to explicitly set the content type
(mimetype, encoding) = mimetypes.guess_type(file_path,
False)
h["content-type"] = mimetype
if mimetype:
h["content-type"] = mimetype
else:
logger.warn("Unable to detect mimetype for %s" %
file_path)
with open(file_path) as fp:
metadata, params = split_metadata_params(merge_two_dicts(app.config['S3_HEADERS'], h))
if should_gzip:
compressed = cStringIO.StringIO()
compressed = StringIO()
z = gzip.GzipFile(os.path.basename(file_path), 'wb', 9,
compressed)
z.write(fp.read())