From b3357b58bb62264b7a96a17525b20f382c58bee1 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Oct 21 2016 11:11:25 +0000 Subject: Fix detecting the mimetype in py3 --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 065542b..6aefbdb 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -654,8 +654,6 @@ def view_raw_file( # First commit in the repo diff = commit.tree.diff_to_tree(swap=True) data = diff.patch - if six.PY3: - data = data.encode('utf-8').decode('utf-8') if not data: flask.abort(404, 'No content found') @@ -666,18 +664,17 @@ def view_raw_file( headers = {} if not mimetype: try: - if not isinstance(data, six.string_types): - data = data.decode('utf-8') + data = data.decode('utf-8') + mimetype = 'text/plain' except UnicodeDecodeError: mimetype = 'application/octet-stream' - - else: + except AttributeError: mimetype = 'text/plain' elif 'html' in mimetype: mimetype = 'application/octet-stream' headers['Content-Disposition'] = 'attachment' - if mimetype.startswith('text/') and not encoding: + if mimetype and mimetype.startswith('text/') and not encoding: encoding = encoding_utils.guess_encoding(ktc.to_bytes(data)) if encoding: