- extra_args = {
- u"ContentType": u"text/plain"
- }
- text_html_extra_args = {
- u"ContentType": u"text/html",
- u"ContentEncoding": MimeTypes().guess_type(src_fpath)[1]
- }
- text_plain_extra_args = {
- u"ContentType": u"text/plain",
- u"ContentEncoding": MimeTypes().guess_type(src_fpath)[1]
- }
- app_xml_extra_args = {
- u"ContentType": u"application/xml",
- u"ContentEncoding": MimeTypes().guess_type(src_fpath)[1]
- }
-
- mime = MimeTypes().guess_type(src_fpath)[0]
- encoding = MimeTypes().guess_type(src_fpath)[1]
-
- if mime is None and encoding is None:
- extra_args = extra_args
- elif mime is None or mime in u"text/plain":
- extra_args = text_plain_extra_args
- elif mime in u"text/html":
- extra_args = text_html_extra_args
- elif mime in u"application/xml":
- extra_args = app_xml_extra_args
- else:
- extra_args = extra_args
+ def is_gzip_file(filepath):
+ with open(filepath, u"rb") as test_f:
+ return test_f.read(2) == b"\x1f\x8b"
+
+ if os.path.isdir(src_fpath):
+ return
+ if os.path.isfile(src_fpath):
+ file_name, file_extension = os.path.splitext(src_fpath)
+ content_encoding = u""
+ content_type = u"application/octet-stream"
+ if is_gzip_file(src_fpath):
+ file_name, file_extension = os.path.splitext(file_name)
+ content_encoding = "gzip"
+ content_type = FILE_TYPE.get(
+ file_extension.strip("."),
+ u"application/octet-stream"
+ )
+
+ extra_args = dict()
+ extra_args[u"ContentType"] = content_type
+ if content_encoding:
+ extra_args[u"ContentEncoding"] = content_encoding