forked from orbit-oss/flask
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:
parent
0049922f2e
commit
6ef45f30ab
2 changed files with 6 additions and 5 deletions
|
|
@ -536,7 +536,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
|
||||||
raise TypeError('filename unavailable, required for '
|
raise TypeError('filename unavailable, required for '
|
||||||
'sending as attachment')
|
'sending as attachment')
|
||||||
filename_dict = {
|
filename_dict = {
|
||||||
'filename': unidecode(attachment_filename),
|
'filename': unidecode(text_type(attachment_filename)),
|
||||||
'filename*': "UTF-8''%s" % url_quote(attachment_filename)}
|
'filename*': "UTF-8''%s" % url_quote(attachment_filename)}
|
||||||
headers.add('Content-Disposition', 'attachment',
|
headers.add('Content-Disposition', 'attachment',
|
||||||
**filename_dict)
|
**filename_dict)
|
||||||
|
|
|
||||||
|
|
@ -565,10 +565,11 @@ class TestSendfile(object):
|
||||||
with app.test_request_context():
|
with app.test_request_context():
|
||||||
with open(os.path.join(app.root_path, 'static/index.html')) as f:
|
with open(os.path.join(app.root_path, 'static/index.html')) as f:
|
||||||
rv = flask.send_file(f, as_attachment=True,
|
rv = flask.send_file(f, as_attachment=True,
|
||||||
attachment_filename='Ñandú/pingüino.txt')
|
attachment_filename=u'Ñandú/pingüino.txt')
|
||||||
value, options = \
|
content_disposition = set(rv.headers['Content-Disposition'].split(';'))
|
||||||
parse_options_header(rv.headers['Content-Disposition'])
|
assert content_disposition == set(['attachment',
|
||||||
assert options == {'filename': 'Nandu/pinguino.txt', 'filename*': "UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"}
|
' filename="Nandu/pinguino.txt"',
|
||||||
|
" filename*=UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"])
|
||||||
rv.close()
|
rv.close()
|
||||||
|
|
||||||
def test_static_file(self):
|
def test_static_file(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue