Skip to content

Commit

Permalink
Use mimetype of encoding if there is one
Browse files Browse the repository at this point in the history
Fixes: #113
Signed-off-by: Alfred Wingate <parona@protonmail.com>
  • Loading branch information
parona-source committed Feb 8, 2024
1 parent bb0ae5d commit 0bf49ea
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions bugz/utils.py
Expand Up @@ -24,8 +24,23 @@


def get_content_type(filename):
return mimetypes.guess_type(filename)[0] or 'application/octet-stream'

# Keep in sync with Lib/mimetypes.py
encoding_map = {
'bzip2': 'application/x-bzip2',
'compress': 'application/x-compress',
'gzip': 'application/gzip',
'xz': 'application/x-xz',
}
# Last addition was brotli, rest have been since 3.4
if sys.version_info[0:2] >= (3, 9):
encoding_map['br'] = 'application/x-brotli'

(mimetype,encoding) = mimetypes.guess_type(filename) or ('application/octet-stream',None)

# guess_type returns encoding of the file separately from the encoded file. Leading .txt.gz having
# the mime of text/plain, this isn't desirable so return the mimetype of the encoding
# https://github.com/williamh/pybugz/issues/113
return mimetype if encoding is None else encoding_map[encoding]

def raw_input_block():
""" Allows multiple line input until a Ctrl+D is detected.
Expand Down

0 comments on commit 0bf49ea

Please sign in to comment.