Fix previous commits to work with python 2 and python 3

Also, parse_options_header seems to interpret filename* so we better
test the actual value used in the headers (and since it's valid
in any order, use a set to compare)
This commit is contained in:
Antonio Larrosa 2017-03-24 20:05:01 +01:00
parent 0049922f2e
commit 6ef45f30ab
2 changed files with 6 additions and 5 deletions

View file

@ -536,7 +536,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
raise TypeError('filename unavailable, required for '
'sending as attachment')
filename_dict = {
'filename': unidecode(attachment_filename),
'filename': unidecode(text_type(attachment_filename)),
'filename*': "UTF-8''%s" % url_quote(attachment_filename)}
headers.add('Content-Disposition', 'attachment',
**filename_dict)

View file

@ -565,10 +565,11 @@ class TestSendfile(object):
with app.test_request_context():
with open(os.path.join(app.root_path, 'static/index.html')) as f:
rv = flask.send_file(f, as_attachment=True,
attachment_filename='Ñandúpingüino.txt')
value, options = \
parse_options_header(rv.headers['Content-Disposition'])
assert options == {'filename': 'Nandu/pinguino.txt', 'filename*': "UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"}
attachment_filename=u'Ñandúpingüino.txt')
content_disposition = set(rv.headers['Content-Disposition'].split(';'))
assert content_disposition == set(['attachment',
' filename="Nandu/pinguino.txt"',
" filename*=UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"])
rv.close()
def test_static_file(self):