Browse Source

Merge branch '0.10-maintenance'

pull/880/merge
Armin Ronacher 11 years ago
parent
commit
23d9b33e92
  1. 1
      CHANGES
  2. 5
      flask/helpers.py
  3. 12
      flask/testsuite/helpers.py
  4. 4
      flask/testsuite/testing.py

1
CHANGES

@ -32,6 +32,7 @@ Version 0.10.2
- Fixed an issue with query parameters getting removed from requests in - Fixed an issue with query parameters getting removed from requests in
the test client when absolute URLs were requested. the test client when absolute URLs were requested.
- Made `@before_first_request` into a decorator as intended. - 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 Version 0.10.1
-------------- --------------

5
flask/helpers.py

@ -538,6 +538,7 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
rv.expires = int(time() + cache_timeout) rv.expires = int(time() + cache_timeout)
if add_etags and filename is not None: if add_etags and filename is not None:
try:
rv.set_etag('flask-%s-%s-%s' % ( rv.set_etag('flask-%s-%s-%s' % (
os.path.getmtime(filename), os.path.getmtime(filename),
os.path.getsize(filename), os.path.getsize(filename),
@ -546,6 +547,10 @@ def send_file(filename_or_fp, mimetype=None, as_attachment=False,
else filename else filename
) & 0xffffffff ) & 0xffffffff
)) ))
except OSError:
warn('Access %s failed, maybe it does not exist, so ignore etags in '
'headers' % filename, stacklevel=2)
if conditional: if conditional:
rv = rv.make_conditional(request) rv = rv.make_conditional(request)
# make sure we don't send x-sendfile for servers that # make sure we don't send x-sendfile for servers that

12
flask/testsuite/helpers.py

@ -303,6 +303,18 @@ class SendfileTestCase(FlaskTestCase):
rv.close() rv.close()
# etags # etags
self.assert_equal(len(captured), 1) 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: with catch_warnings() as captured:
f = StringIO('Test') f = StringIO('Test')
rv = flask.send_file(f, mimetype='text/plain') rv = flask.send_file(f, mimetype='text/plain')

4
flask/testsuite/testing.py

@ -207,8 +207,8 @@ class TestToolsTestCase(FlaskTestCase):
with app.test_client() as c: with app.test_client() as c:
rv = c.post('http://domain.com/action?vodka=42', data={'gin': 43}) rv = c.post('http://domain.com/action?vodka=42', data={'gin': 43})
self.assert_equal(rv.status_code, 200) self.assert_equal(rv.status_code, 200)
self.assert_('gin' in flask.request.form) self.assert_true('gin' in flask.request.form)
self.assert_('vodka' in flask.request.args) self.assert_true('vodka' in flask.request.args)
class SubdomainTestCase(FlaskTestCase): class SubdomainTestCase(FlaskTestCase):

Loading…
Cancel
Save