Commit Graph

124 Commits

Author SHA1 Message Date
David Lord 69f9845ef2
add json provider interface 2022-07-13 07:42:52 -07:00
David Lord 82c2e0366c
remove uses of LocalStack 2022-07-08 11:13:09 -07:00
Grey Li ca2bfbb0ac
Support returning list as JSON 2022-07-02 21:41:32 -07:00
David Lord 84c722044a
new debug/test preserve context implementation 2022-07-01 12:01:44 -07:00
pgjones 762382e436
view functions can return generators as responses directly 2022-06-18 11:25:05 -07:00
Kevin Kirsche ed42e92928
session expiration datetime is UTC timezone-aware 2022-06-17 12:01:48 -07:00
David Lord 96c97dec09
deprecate before_first_request 2022-06-06 10:04:05 -07:00
David Lord e044b00047
avoid triggering setupmethod late in tests 2022-05-23 09:09:12 -07:00
Qingpeng Li 1e5dd43022
refactor error checks in register_error_handler
Co-authored-by: David Lord <davidism@gmail.com>
2022-05-03 11:52:11 -06:00
David Lord ef6c2b9e4a
clean up pytest.raises tests 2022-04-28 09:32:31 -07:00
David Lord c9a1f7ad65
don't intercept 307/308 routing redirects
These don't change the request body, so the debug error is no longer relevant.
2022-03-23 08:25:22 -07:00
David Lord e37e87140e
Merge branch '2.0.x' 2022-02-09 07:37:43 -08:00
David Lord 426a1e25b7
fix pytest 7 warnings 2022-02-08 12:26:25 -08:00
David Lord e609dddd60
drop Python 3.6 2021-11-11 16:11:43 -08:00
David Lord 8648750997
Merge branch '1.1.x' into 2.0.x 2021-05-13 18:47:06 -07:00
brettlangdon 3ace642ef3
Use compat fspath instead of os.fspath
When 7ba35c4 was cherry-picked it introduced the
usage of os.fspath which is not supported on
Python <3.6
2021-05-13 18:17:00 -07:00
David Lord 7c5261407d
blueprint name may not contain a dot 2021-05-13 14:31:50 -07:00
pgjones 705e52684a
Add syntatic sugar for route registration
This takes a popular API whereby instead of passing the HTTP method as
an argument to route it is instead used as the method name i.e.

    @app.route("/", methods=["POST"])

is now writeable as,

    @app.post("/")

This is simply syntatic sugar, it doesn't do anything else, but makes
it slightly easier for users.

I've included all the methods that are relevant and aren't auto
generated i.e. not connect, head, options, and trace.
2021-03-08 08:55:14 -08:00
Grey Li eb41e7e417 Silence pytest warnings for exception propagation test 2021-01-03 13:57:45 +08:00
Mathurshan Vimalesvaran 22987b6817
include samesite and secure when removing session cookie (#3726) 2020-11-04 18:16:05 -08:00
David Lord 373f0dd82e
update requirements (#3823) 2020-11-01 05:30:02 -08:00
Bogdan Opanchuk 8efea0ccbb
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 7b09a0904c
change make_response to use headers.update 2020-07-23 16:53:39 -07:00
Joshua Bronson b724832872 Cherry-pick 7ba35c4 from master (support pathlib.Path for static_folder) 2020-07-06 13:47:57 -04:00
Joshua Bronson 7ba35c4d4f 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 f2f027d1fb
remove unused module docstrings 2020-04-04 12:28:08 -07:00
David Lord 2ae740dd49
f-strings everywhere 2020-04-04 12:10:00 -07:00
David Lord 524fd0bc8c
apply pyupgrade 2020-04-04 12:10:00 -07:00
David Lord 57d628ca74
remove more compat code 2020-04-04 12:10:00 -07:00
David Lord 662c245795
remove _compat module 2020-04-04 12:10:00 -07:00
David Lord 64ba43411f
Merge remote-tracking branch 'origin/1.1.x' 2020-02-15 10:40:32 -08:00
frostming d4076cf07c
strip the ending slash for static_url_path 2020-02-10 18:19:25 -08:00
Marc Hernandez Cabot 5da342e4dd
fix docstring and remove redundant parentheses 2020-02-10 17:03:52 -08:00
raymond-devries 900fa2f795 Feature request #3445. 2020-02-10 13:09:53 -08:00
David Lord b05a685a03
Merge branch '1.0.x' 2019-07-01 10:54:31 -07:00
Anthony Sottile a5ecdfa7a5
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 1351d0a565
Merge branch '1.0.x' 2019-06-23 16:57:52 -07:00
David Lord e666f7a69c
standardize license and copyright 2019-06-22 13:09:09 -07:00
Elad Moshe 1ff98a2d21
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 29111a3259
Merge branch '1.0.x' 2019-06-12 10:41:11 -07:00
David Lord dbd4520ccb
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 53c893b646
fix string concats left over by black 2019-06-01 09:22:20 -07:00
David Lord 43483683b2
apply reorder-python-imports pre-commit config 2019-06-01 09:07:20 -07:00
Jon S. Stumpf b46f5942a5
address flake8 issues 2019-06-01 06:31:35 -07:00
John Zeringue 8bb7185284 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 a5ff3cd01b Fix style issues on master using Black 2019-05-31 11:57:28 +01:00
David Lord ed9ab2d3b6
strip static url trailing slash at assignment 2019-05-25 11:18:40 -07:00
Pete Beardmore a12bf290da
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 7bf8366970
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 e1cc16f8be
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