Commit graph

103 commits

Author SHA1 Message Date
David Lord
8817c77eb0 update requirements (#3823) 2020-11-01 05:30:02 -08:00
Bogdan Opanchuk
849cf2c2a9 Break reference cycle created by default in Flask instances.
Flask instances with static folders were creating a reference cycle
via their "static" view function (which held a strong reference back
to the Flask instance to call its `send_static_file` method). This
prevented CPython from freeing the memory for a Flask instance
when all external references to it were released.

Now use a weakref for the back reference to avoid this.

Co-authored-by: Joshua Bronson <jab@users.noreply.github.com>
2020-10-03 10:05:05 -04:00
Christopher Nguyen
95653896a4 change make_response to use headers.update 2020-07-23 16:53:39 -07:00
Joshua Bronson
f81846c68b Restore support for using pathlib.Path for static_folder.
* No longer causes AttributeError: 'PosixPath' object has no
  attribute 'rstrip'.

* This was broken by e6178fe489
  which was released in 1.1.2.

* Add a regression test that now passes.

See #3557.
2020-07-06 08:55:19 -04:00
David Lord
296ef35943 remove unused module docstrings 2020-04-04 12:28:08 -07:00
David Lord
f5038c4c39 f-strings everywhere 2020-04-04 12:10:00 -07:00
David Lord
67bb43b738 apply pyupgrade 2020-04-04 12:10:00 -07:00
David Lord
1e5e3aae8a remove more compat code 2020-04-04 12:10:00 -07:00
David Lord
24723fa6e8 remove _compat module 2020-04-04 12:10:00 -07:00
David Lord
376a64137c Merge remote-tracking branch 'origin/1.1.x' 2020-02-15 10:40:32 -08:00
frostming
c4de6a0bfc strip the ending slash for static_url_path 2020-02-10 18:19:25 -08:00
Marc Hernandez Cabot
ed93b738ed fix docstring and remove redundant parentheses 2020-02-10 17:03:52 -08:00
raymond-devries
5ffacfc010 Feature request #3445. 2020-02-10 13:09:53 -08:00
David Lord
1ee9405ff3 Merge branch '1.0.x' 2019-07-01 10:54:31 -07:00
Anthony Sottile
f65c6d3860 Fixes for PEP451 import loaders and pytest 5.x
- pytest 5.x drops python2 compatibility and therefore only implements PEP 451
- pytest 5.x made the repr of `ExcInfo` less confusing (fixed tests depending
  on the old format)
2019-07-01 10:43:06 -07:00
David Lord
ff0c92a1c7 Merge branch '1.0.x' 2019-06-23 16:57:52 -07:00
David Lord
e066e9f9e3 standardize license and copyright 2019-06-22 13:09:09 -07:00
Elad Moshe
26cde0536c wait until app ctx is ready before matching url
`RequestContext.match_request` is moved from `__init__` to `push`. This
causes matching to happen later, when the app context is available.
This enables URL converters that use things such as the database.
2019-06-13 08:32:23 -07:00
David Lord
43f66251ad Merge branch '1.0.x' 2019-06-12 10:41:11 -07:00
David Lord
090bc4470e fix tests failing with server name warnings
After pallets/werkzeug#1577, mismatched configured and real server
names will show a warning in addition to raising 404. This caused
tests that did this deliberately to fail.

This patch removes the pytest fixture we were using to fail on
warnings, instead using the standard `-Werror` option. This speeds
up the tests by ~3x.
2019-06-10 14:05:33 -07:00
David Lord
2cf5d51523 fix string concats left over by black 2019-06-01 09:22:20 -07:00
David Lord
e66fe2e8e7 apply reorder-python-imports pre-commit config 2019-06-01 09:07:20 -07:00
Jon S. Stumpf
4dc9c68d19 address flake8 issues 2019-06-01 06:31:35 -07:00
John Zeringue
d610a559d1 Better error message when view return type is not supported
Before, returning a `bool` from a route caused the error

```
[2019-05-31 10:08:42,216] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2070, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 269, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 26, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/test.py", line 1119, in run_wsgi_app
    app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2393, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1906, in full_dispatch_request
    return self.finalize_request(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1921, in finalize_request
    response = self.make_response(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2078, in make_response
    reraise(TypeError, new_error, sys.exc_info()[2])
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/_compat.py", line 39, in reraise
    raise value.with_traceback(tb)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2070, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 269, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/wrappers/base_response.py", line 26, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "/Users/johnzeringue/Documents/ts-open/flask/env/lib/python3.7/site-packages/werkzeug/test.py", line 1119, in run_wsgi_app
    app_rv = app(environ, start_response)
TypeError: 'bool' object is not callable
The view function did not return a valid response. The return type must be a string, tuple, Response instance, or WSGI callable, but it was a bool.
```

Now, it returns the more readable

```
[2019-05-31 10:36:19,500] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2400, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1907, in full_dispatch_request
    return self.finalize_request(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 1922, in finalize_request
    response = self.make_response(rv)
  File "/Users/johnzeringue/Documents/ts-open/flask/flask/app.py", line 2085, in make_response
    " {rv.__class__.__name__}.".format(rv=rv))
TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a bool.
```

Fixes #3214
2019-05-31 11:58:49 -04:00
Daniel Pope
ad9807891d Fix style issues on master using Black 2019-05-31 11:57:28 +01:00
David Lord
cfedcd308e strip static url trailing slash at assignment 2019-05-25 11:18:40 -07:00
Pete Beardmore
37b5569e92 fix 'static_url_path' defaulting for empty paths
-prefix a path delimiter iff there's a path to delimit
-ensures a valid default static route rule is created on application
intialisation for the case 'static_folder=""' and implicit
'static_url_path'
2019-05-25 07:03:36 -07:00
pgjones
9e0bd76d2a Allow dictionary return values as JSON
This supports an increasingly common usecase whereby JSON is the
primary response (rather than a templated string). Given Flask has a
short syntax for HTML reponses, it seems fitting that it should also
do so for JSON responses. In practice it allows,

     @app.route("/")
     def index():
         return {
             "api_stuff": "values",
         }
2019-05-24 09:48:55 -07:00
vorelq
c33ec49db6 Fix 0 port value being overriden by default
By explicitly comparing port value with None,
instead of using its bool() value.
2019-05-19 11:36:47 -07:00
Eruvanos
36362454c3 support dataclass in JSONEncoder 2019-05-18 21:37:54 -07:00
Frankie Liu
c7432f50cb Remove ending slash from static_url_path 2019-05-18 21:23:14 -07:00
David Baumgold
85ce588b3b Reformat with black
https://github.com/python/black
2019-05-06 16:28:58 -04:00
David Lord
77335fb105 clear KeyError in production for Werkzeug 0.15 2019-01-05 12:49:59 -08:00
David Lord
271d9e697a trap key errors in debug, not all 400 errors 2018-04-28 06:51:08 -07:00
David Lord
aaab1e46f2 add Response.max_cookie_size config 2018-04-10 11:17:18 -07:00
David Lord
4f8661e6e3 use subdomain arg in url_map.bind_to_environ
rename new subdomain test, parametrize
test allowing subdomains as well as ips
add subdomain_matching param to docs
add some references to docs
add version changed to create_url_adapter
2018-02-23 08:39:31 -08:00
Armin Ronacher
1e81474e7e Do not enable subdomain matching by default
Updated tests for new subdomain matching
Added a test to validate matching behavior
2018-02-23 07:53:27 -08:00
David Lord
aa4db37a7f revert copyright year to project start
add copyright header to files
2018-02-08 12:43:30 -08:00
David Lord
e431e8809d clean up samesite docs 2018-01-23 15:11:50 -08:00
Fadhel_Chaabane
c65bdc0c9f New Feature: Added Support for cookie's SameSite attribute. 2018-01-23 13:57:50 +00:00
David Lord
57b2807ea8 improve documentation for session attributes
add test for session attributes
2018-01-04 12:56:18 -08:00
David Lord
9acb1d2412 simplify logging configuration
single default handler and formatter
don't remove handlers
configure level once using setLevel
document logging
reorganize logging tests
2017-07-31 12:49:03 -07:00
William Horton
d404a911b7 Remove unused import from test_basic (#2403) 2017-06-30 17:28:48 +02:00
David Lord
d590d6024d clean up secret key docs
consistent key across docs and examples
consistent key across tests, set in conftest
2017-06-28 07:58:06 -07:00
David Lord
24cfe1b9b1 remove deprecated Flask.static_path 2017-06-26 07:45:29 -07:00
David Lord
08c8401539 failing test 2017-06-05 06:14:13 -07:00
David Lord
9c93ba2fa2 add tests for flask.json.tag 2017-06-02 10:01:30 -07:00
David Lord
7fd443c9ef Merge branch 'master' into json-object-hook 2017-06-01 06:40:27 -07:00
David Lord
35d32d265a show nice message when registering error handler for unknown code
clean up error handler docs
closes #1837
2017-05-31 18:04:08 -07:00
David Lord
c79abcb86c set description for trap as well as debug
test for key error description
2017-05-29 19:41:07 -07:00