Skip to content

Commit

Permalink
Merge branch '0.10-maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Feb 8, 2014
2 parents 6f44ca7 + d094d5b commit 23d9b33
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -32,6 +32,7 @@ Version 0.10.2
- Fixed an issue with query parameters getting removed from requests in
the test client when absolute URLs were requested.
- Made `@before_first_request` into a decorator as intended.
- Fixed an etags bug when sending a file streams with a name.

Version 0.10.1
--------------
Expand Down
21 changes: 13 additions & 8 deletions flask/helpers.py
Expand Up @@ -538,14 +538,19 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
rv.expires = int(time() + cache_timeout)

if add_etags and filename is not None:
rv.set_etag('flask-%s-%s-%s' % (
os.path.getmtime(filename),
os.path.getsize(filename),
adler32(
filename.encode('utf-8') if isinstance(filename, text_type)
else filename
) & 0xffffffff
))
try:
rv.set_etag('flask-%s-%s-%s' % (
os.path.getmtime(filename),
os.path.getsize(filename),
adler32(
filename.encode('utf-8') if isinstance(filename, text_type)
else filename
) & 0xffffffff
))
except OSError:
warn('Access %s failed, maybe it does not exist, so ignore etags in '
'headers' % filename, stacklevel=2)

if conditional:
rv = rv.make_conditional(request)
# make sure we don't send x-sendfile for servers that
Expand Down
12 changes: 12 additions & 0 deletions flask/testsuite/helpers.py
Expand Up @@ -303,6 +303,18 @@ def test_send_file_object(self):
rv.close()
# etags
self.assert_equal(len(captured), 1)
with catch_warnings() as captured:
class PyStringIO(StringIO):
pass
f = PyStringIO('Test')
f.name = 'test.txt'
rv = flask.send_file(f)
rv.direct_passthrough = False
self.assert_equal(rv.data, b'Test')
self.assert_equal(rv.mimetype, 'text/plain')
rv.close()
# attachment_filename and etags
self.assert_equal(len(captured), 3)
with catch_warnings() as captured:
f = StringIO('Test')
rv = flask.send_file(f, mimetype='text/plain')
Expand Down
4 changes: 2 additions & 2 deletions flask/testsuite/testing.py
Expand Up @@ -207,8 +207,8 @@ def action():
with app.test_client() as c:
rv = c.post('http://domain.com/action?vodka=42', data={'gin': 43})
self.assert_equal(rv.status_code, 200)
self.assert_('gin' in flask.request.form)
self.assert_('vodka' in flask.request.args)
self.assert_true('gin' in flask.request.form)
self.assert_true('vodka' in flask.request.args)


class SubdomainTestCase(FlaskTestCase):
Expand Down

0 comments on commit 23d9b33

Please sign in to comment.