Browse Source

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)
pull/2223/head
Antonio Larrosa 8 years ago
parent
commit
6ef45f30ab
  1. 2
      flask/helpers.py
  2. 9
      tests/test_helpers.py

2
flask/helpers.py

@ -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)

9
tests/test_helpers.py

@ -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):

Loading…
Cancel
Save