Skip to content
Myr

Fix previous commits to work with python 2 and python 3

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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)

authored by Antonio Larrosa · committed by Antonio Larrosa · parent 0049922 · Browse files · 2 files+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+6 added−5 removed

  • tests:+5 added−4 removed
  • other:+1 added−1 removed

2 files+6 added−5 removed

modified:flask/helpers.py+1 added-1 removed
534 unmodified lines
535 if attachment_filename is None:536 raise TypeError('filename unavailable, required for '537 'sending as attachment')538 filename_dict = {539 'filename': unidecode(attachment_filename),539 'filename': unidecode(text_type(attachment_filename)),540 'filename*': "UTF-8''%s" % url_quote(attachment_filename)}541 headers.add('Content-Disposition', 'attachment',542 **filename_dict)543
421 unmodified lines
modified:tests/test_helpers.py+5 added-4 removed
563 unmodified lines
564 app = flask.Flask(__name__)565 with app.test_request_context():566 with open(os.path.join(app.root_path, 'static/index.html')) as f:567 rv = flask.send_file(f, as_attachment=True,568 attachment_filename='Ñandú/pingüino.txt')569 value, options = \570 parse_options_header(rv.headers['Content-Disposition'])571 assert options == {'filename': 'Nandu/pinguino.txt', 'filename*': "UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"}568 attachment_filename=u'Ñandú/pingüino.txt')569 content_disposition = set(rv.headers['Content-Disposition'].split(';'))570 assert content_disposition == set(['attachment',571 ' filename="Nandu/pinguino.txt"',572 " filename*=UTF-8''%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt"])573 rv.close()574575 def test_static_file(self):576 app = flask.Flask(__name__)
325 unmodified lines