docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
# stream_with_context pushes a third context, preserved by response return flask.stream_with_context("hello")
<mask> <mask> def test_client_pop_all_preserved(app, req_ctx, client): <mask> @app.route("/") <mask> def index(): <mask> # stream_with_context pushes a third context, preserved by client <mask> return flask.Response(flask.stream_with_context("hello")) <mask> <mask> # req_ctx fixtur...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa
tests/test_testing.py
# req_ctx fixture pushed an initial context
<mask> def index(): <mask> # stream_with_context pushes a third context, preserved by client <mask> return flask.Response(flask.stream_with_context("hello")) <mask> <mask> # req_ctx fixture pushed an initial context, not marked preserved <mask> with client: <mask> # request p...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa
tests/test_testing.py
rv = client.get("/")
<mask> <mask> # req_ctx fixture pushed an initial context, not marked preserved <mask> with client: <mask> # request pushes a second request context, preserved by client <mask> client.get("/") <mask> <mask> # only req_ctx fixture should still be pushed <mask> assert flask._requ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa
tests/test_testing.py
# close the response, releasing the context held by stream_with_context rv.close()
<mask> rv = client.get("/") <mask> <mask> # only req_ctx fixture should still be pushed <mask> assert flask._request_ctx_stack.top is req_ctx </s> new debug/test preserve context implementation </s> remove client.get("/") </s> add rv = client.get("/") </s> remove # req_ctx fix...
[ "keep", "add", "keep", "keep" ]
https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa
tests/test_testing.py
<mask> <mask> If an env var is already set it is not overwritten, so earlier files in the <mask> list are preferred over later files. <mask> <mask> Changes the current working directory to the location of the first file <mask> found, with the assumption that it is in the top level project direct...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84cbfc0698f429c93450cd6f1600e56b41a30247
src/flask/cli.py
<mask> new_dir = os.path.dirname(path) <mask> <mask> dotenv.load_dotenv(path) <mask> <mask> if new_dir and os.getcwd() != new_dir: <mask> os.chdir(new_dir) <mask> <mask> return new_dir is not None # at least one file was located and loaded <mask> <mask> <mask> def sh...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84cbfc0698f429c93450cd6f1600e56b41a30247
src/flask/cli.py
monkeypatch.chdir(test_path)
<mask> for item in ("FOO", "BAR", "SPAM"): <mask> monkeypatch._setitem.append((os.environ, item, notset)) <mask> <mask> monkeypatch.setenv("EGGS", "3") <mask> monkeypatch.chdir(os.path.join(test_path, "cliapp", "inner1")) <mask> assert load_dotenv() <mask> assert os.getcwd() == test_...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84cbfc0698f429c93450cd6f1600e56b41a30247
tests/test_cli.py
- Python 3.12 compatibility.
<mask> ------------- <mask> <mask> Unreleased <mask> <mask> <mask> Version 2.3.2 <mask> ------------- <mask> <mask> Released 2023-05-01 </s> use importlib instead of pkgutil </s> remove loader = pkgutil.get_loader(root_mod_name) </s> add spec = importlib.util.find_spec(root_mod_name) loader =...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84e11a1e827c0f55f9b9ee15952eddcf8a6492e0
CHANGES.rst
import importlib.util
<mask> from __future__ import annotations <mask> <mask> import os <mask> import socket <mask> import sys <mask> import typing as t <mask> import warnings </s> use importlib instead of pkgutil </s> remove import pkgutil </s> add </s> remove import pkgutil </s> add </s> remove loader = pkgutil.get_loader...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84e11a1e827c0f55f9b9ee15952eddcf8a6492e0
src/flask/helpers.py
<mask> from __future__ import annotations <mask> <mask> import os <mask> import pkgutil <mask> import socket <mask> import sys <mask> import typing as t <mask> import warnings <mask> from datetime import datetime </s> use importlib instead of pkgutil </s> remove import pkgutil </s> add </s> remove load...
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84e11a1e827c0f55f9b9ee15952eddcf8a6492e0
src/flask/helpers.py
spec = importlib.util.find_spec(import_name) loader = spec.loader if spec is not None else None
<mask> if mod is not None and hasattr(mod, "__file__") and mod.__file__ is not None: <mask> return os.path.dirname(os.path.abspath(mod.__file__)) <mask> <mask> # Next attempt: check the loader. <mask> loader = pkgutil.get_loader(import_name) <mask> <mask> # Loader does not exist or we'r...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84e11a1e827c0f55f9b9ee15952eddcf8a6492e0
src/flask/helpers.py
<mask> <mask> import importlib.util <mask> import os <mask> import pathlib <mask> import pkgutil <mask> import sys <mask> import typing as t <mask> from collections import defaultdict <mask> from datetime import timedelta <mask> from functools import update_wrapper </s> use importlib instead of pkgutil </s>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84e11a1e827c0f55f9b9ee15952eddcf8a6492e0
src/flask/scaffold.py
spec = importlib.util.find_spec(root_mod_name) loader = spec.loader if spec is not None else None
<mask> else: <mask> return os.path.dirname(root_spec.origin) <mask> <mask> # we were unable to find the `package_path` using PEP 451 loaders <mask> loader = pkgutil.get_loader(root_mod_name) <mask> <mask> if loader is None or root_mod_name == "__main__": <mask> # import...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84e11a1e827c0f55f9b9ee15952eddcf8a6492e0
src/flask/scaffold.py
* Test status: https://dev.azure.com/pallets/pallets/_build?definitionId=2
<mask> * License: `BSD <https://github.com/pallets/flask/blob/master/LICENSE>`_ <mask> * Releases: https://pypi.org/project/Flask/ <mask> * Code: https://github.com/pallets/flask <mask> * Issue tracker: https://github.com/pallets/flask/issues <mask> * Test status: <mask> <mask> * Linux, Mac: https://travis-ci...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
README.rst
py{37,36,35,27,py3,py} py37-{simplejson,devel,lowest}
<mask> [tox] <mask> envlist = <mask> py{37,36,35,34,27,py} <mask> py{37,27,py}-simplejson <mask> py{37,27,py}-devel <mask> py{37,27,py}-lowest <mask> docs-html <mask> coverage-report <mask> <mask> [testenv] <mask> passenv = LANG </s> azure pipelines ci on 1.0.x branch </s> remove ...
[ "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
coverage
<mask> py{37,27,py}-simplejson <mask> py{37,27,py}-devel <mask> py{37,27,py}-lowest <mask> docs-html <mask> coverage-report <mask> <mask> [testenv] <mask> passenv = LANG <mask> deps = <mask> pytest>=3 </s> azure pipelines ci on 1.0.x branch </s> remove py{37,36,35,34,27,py} p...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
pytest
<mask> <mask> [testenv] <mask> passenv = LANG <mask> deps = <mask> pytest>=3 <mask> coverage <mask> greenlet <mask> blinker <mask> python-dotenv <mask> </s> azure pipelines ci on 1.0.x branch </s> remove coverage-report </s> add coverage </s> remove py{37,36,35,34,27,py} ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
coverage run -p -m pytest --tb=short {posargs:tests examples} [testenv:nightly] # courtesy Python nightly test, don't fail the build in CI ignore_outcome = true commands = pip install -q -e examples/tutorial[test] pip install -q -e examples/javascript[test] coverage run -p -m pytest --tb=short --junitx...
<mask> pip install -q -e examples/tutorial[test] <mask> pip install -q -e examples/javascript[test] <mask> <mask> # pytest-cov doesn't seem to play nice with -p <mask> coverage run -p -m pytest tests examples <mask> <mask> [testenv:docs-html] <mask> deps = <mask> -r docs/requirements.txt ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
[testenv:coverage]
<mask> deps = <mask> -r docs/requirements.txt <mask> commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html <mask> <mask> [testenv:coverage-report] <mask> deps = coverage <mask> skip_install = true <mask> commands = <mask> coverage combine <mask> coverage report </s> az...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
<mask> deps = coverage <mask> skip_install = true <mask> commands = <mask> coverage combine <mask> coverage report <mask> coverage html <mask> <mask> [testenv:codecov] <mask> passenv = CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* <mask> deps = codecov </s> azure pipelines ci on 1.0.x branch </s> remov...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
coverage report
<mask> commands = <mask> coverage combine <mask> coverage html <mask> <mask> [testenv:coverage-ci] <mask> passenv = CODECOV_TOKEN <mask> deps = <mask> coverage <mask> codecov </s> azure pipelines ci on 1.0.x branch </s> remove [testenv:codecov] passenv = CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_*...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
[testenv:coverage-ci] passenv = CODECOV_TOKEN deps = coverage codecov
<mask> coverage combine <mask> coverage report <mask> coverage html <mask> <mask> [testenv:codecov] <mask> passenv = CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* <mask> deps = codecov <mask> skip_install = true <mask> commands = <mask> coverage combine <mask> coverage report <mask> codeco...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
<mask> deps = codecov <mask> skip_install = true <mask> commands = <mask> coverage combine <mask> coverage report <mask> codecov </s> azure pipelines ci on 1.0.x branch </s> remove [testenv:codecov] passenv = CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* deps = codecov </s> add [testenv:coverage-ci] passen...
[ "keep", "keep", "keep", "keep", "replace", "keep" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
coverage xml coverage report
<mask> skip_install = true <mask> commands = <mask> coverage combine <mask> codecov </s> azure pipelines ci on 1.0.x branch </s> remove coverage report </s> add </s> remove [testenv:codecov] passenv = CI TRAVIS TRAVIS_* APPVEYOR APPVEYOR_* deps = codecov </s> add [testenv:coverage-ci] passenv = CODE...
[ "keep", "keep", "keep", "add" ]
https://github.com/pallets/flask/commit/84f8e1634fed25de6ab065899234535d531e44ab
tox.ini
.. data:: current_app Points to the application handling the request. This is useful for extensions that want to support multiple applications running side by side.
<mask> Useful Functions and Classes <mask> ---------------------------- <mask> <mask> .. autofunction:: url_for <mask> <mask> .. function:: abort(code) <mask> </s> Fixed some documentation issues. This fixes #41. </s> remove @app.route('/') </s> add @app.route('/', methods=['GET', 'POST']) </s> remo...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/854e0e26d16408760072308c44b9160a9fb39abd
docs/api.rst
`yourapplication.py` and you are not using a module, but a :ref:`package <larger-applications>`. Distributing resources with standard modules is
<mask> Flask itself, and all the libraries you can find on the cheeseshop <mask> are distributed with either distribute, the older setuptools or distutils. <mask> <mask> In this case we assume your application is called <mask> `yourapplication.py` and you are not using a module, but a `package <mask> <larger-app...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/854e0e26d16408760072308c44b9160a9fb39abd
docs/patterns/distribute.rst
@app.route('/', methods=['GET', 'POST'])
<mask> def allowed_file(filename): <mask> return '.' in filename and \ <mask> filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS <mask> <mask> @app.route('/') <mask> def upload_file(): <mask> if request.method == 'POST': <mask> file = request.files['file'] ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/854e0e26d16408760072308c44b9160a9fb39abd
docs/patterns/fileuploads.rst
In order to use the interactive debugger, debugging must be enabled both on
<mask> <mask> Note that :func:`run_simple <werkzeug.serving.run_simple>` is not intended for <mask> use in production. Use a :ref:`full-blown WSGI server <deployment>`. <mask> <mask> In order to use the interactive debuggger, debugging must be enabled both on <mask> the application and the simple server, here ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8570633214e4749972963ef622b4c86fa8b379fc
docs/patterns/appdispatch.rst
The majority of the upgrade pain is in the lower-level libraries like
<mask> that most libraries (including Werkzeug and Flask) might not quite as stable <mask> on Python 3 yet. You might therefore sometimes run into bugs that are <mask> usually encoding-related. <mask> <mask> The majority of the upgrade pain is in the lower-level libararies like <mask> Flask and Werkzeug and not ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8570633214e4749972963ef622b4c86fa8b379fc
docs/python3.rst
The :command:`flask` command line script (:ref:`cli`) is strongly recommended for
<mask> <mask> Command Line <mask> ------------ <mask> <mask> The :command:`flask` command line script (:ref:`cli`) is strongly recommende for <mask> development because it provides a superior reload experience due to how it <mask> loads the application. The basic usage is like this:: <mask> <mask> $ fl...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8570633214e4749972963ef622b4c86fa8b379fc
docs/server.rst
Now we should start working on the templates. If we were to request the URLs
<mask> <mask> Step 6: The Templates <mask> ===================== <mask> <mask> Now we should start working on the templates. If we were torequest the URLs <mask> now, we would only get an exception that Flask cannot find the templates. The <mask> templates are using `Jinja2`_ syntax and have autoescaping ena...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8570633214e4749972963ef622b4c86fa8b379fc
docs/tutorial/templates.rst
guessing scheme where the shortname for the module was taken from the
<mask> applications automatically, but there might be some cases where it fails <mask> to upgrade. What changed? <mask> <mask> - Blueprints need explicit names. Modules had an automatic name <mask> guesssing scheme where the shortname for the module was taken from the <mask> last part of the import m...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8570633214e4749972963ef622b4c86fa8b379fc
docs/upgrading.rst
how other systems handle request pre- and post-processing. If you
<mask> Flask 0.6 comes with a backwards incompatible change which affects the <mask> order of after-request handlers. Previously they were called in the order <mask> of the registration, now they are called in reverse order. This change <mask> was made so that Flask behaves more like people expected it to work an...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8570633214e4749972963ef622b4c86fa8b379fc
docs/upgrading.rst
- Bump minimum Werkzeug version to >= 0.15. - Drop support for Python 3.4.
<mask> Unreleased <mask> <mask> - :meth:`flask.RequestContext.copy` includes the current session <mask> object in the request context copy. This prevents ``session`` <mask> pointing to an out-of-date object. (`#2935`_) <mask> - Using built-in RequestContext, unprintable Unicode characters in <mask> ...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
CHANGES.rst
- Flask's ``JSONMixin`` for the request and response wrappers was moved into Werkzeug. Use Werkzeug's version with Flask-specific support. This bumps the Werkzeug dependency to >= 0.15. :issue:`3125`
<mask> ``ImmutableDict`` to allow easier configuration. Changes must still <mask> be made before creating the environment. :pr:`3190` <mask> <mask> .. _#2935: https://github.com/pallets/flask/issues/2935 <mask> .. _#2957: https://github.com/pallets/flask/issues/2957 <mask> .. _#2994: https://github.com/p...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
CHANGES.rst
.. _#3125: https://github.com/pallets/flask/pull/3125
<mask> .. _#2994: https://github.com/pallets/flask/pull/2994 <mask> .. _#3059: https://github.com/pallets/flask/pull/3059 <mask> .. _#3179: https://github.com/pallets/flask/pull/3179 <mask> <mask> <mask> Version 1.0.3 <mask> ------------- <mask> </s> Use Werkzeug's JSONMixin class and update tests Flask's ...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
CHANGES.rst
from werkzeug.wrappers.json import JSONMixin as _JSONMixin
<mask> <mask> from werkzeug.exceptions import BadRequest <mask> from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase <mask> <mask> from flask import json <mask> from flask.globals import current_app <mask> <mask> <mask> class JSONMixin(_JSONMixin): </s> Use Werkzeug's JSONMixin c...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
flask/wrappers.py
class JSONMixin(_JSONMixin): json_module = json
<mask> from flask import json <mask> from flask.globals import current_app <mask> <mask> <mask> class JSONMixin(object): <mask> """Common mixin for both request and response objects to provide JSON <mask> parsing capabilities. <mask> <mask> .. versionadded:: 1.0 <mask> """ <mask> <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
flask/wrappers.py
if current_app and current_app.debug:
<mask> <mask> return rv <mask> <mask> def on_json_loading_failed(self, e): <mask> """Called if :meth:`get_json` parsing fails and isn't silenced. If <mask> this method returns a value, it is used as the return value for <mask> :meth:`get_json`. The default implementation rai...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
flask/wrappers.py
"Werkzeug>=0.15",
<mask> zip_safe=False, <mask> platforms="any", <mask> python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*", <mask> install_requires=[ <mask> "Werkzeug>=0.14", <mask> "Jinja2>=2.10.1", <mask> "itsdangerous>=0.24", <mask> "click>=5.1", <mask> ], <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
setup.py
@pytest.mark.parametrize("debug", (True, False)) def test_bad_request_debug_message(self, app, client, debug): app.config["DEBUG"] = debug
<mask> data = json.dumps(value).encode(encoding) <mask> assert json.detect_encoding(data) == encoding <mask> assert json.loads(data) == value <mask> <mask> def test_ignore_cached_json(self, app): <mask> with app.test_request_context( <mask> "/", method="POST", dat...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
tests/test_helpers.py
contains = b"Failed to decode JSON object" in rv.data assert contains == debug
<mask> return None <mask> <mask> rv = client.post("/json", data=None, content_type="application/json") <mask> assert rv.status_code == 400 <mask> assert b"Failed to decode JSON object" not in rv.data <mask> <mask> def test_json_bad_requests(self, app, client): <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
tests/test_helpers.py
lowest: Werkzeug==0.15
<mask> greenlet <mask> blinker <mask> python-dotenv <mask> <mask> lowest: Werkzeug==0.14 <mask> lowest: Jinja2==2.10 <mask> lowest: itsdangerous==0.24 <mask> lowest: Click==5.1 <mask> <mask> devel: https://github.com/pallets/werkzeug/archive/master.tar.gz </s> Use Werkzeug's...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8590d65a57ad57c99a82fdf4e1c57921d7e1bdcd
tox.ini
An error handler is a normal view function that return a response, but instead of being registered for a route, it is registered for an exception or HTTP status code that would is raised while trying to handle a request.
<mask> <mask> You might want to show custom error pages to the user when an error occurs. <mask> This can be done by registering error handlers. <mask> <mask> Error handlers are normal :ref:`views` but instead of being registered for <mask> routes, they are registered for exceptions that are raised while trying...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
Register handlers by decorating a function with :meth:`~flask.Flask.errorhandler`. Or use :meth:`~flask.Flask.register_error_handler` to register the function later. Remember to set the error code when returning the response. ::
<mask> <mask> Registering <mask> ``````````` <mask> <mask> Register error handlers using :meth:`~flask.Flask.errorhandler` or <mask> :meth:`~flask.Flask.register_error_handler`:: <mask> <mask> @app.errorhandler(werkzeug.exceptions.BadRequest) <mask> def handle_bad_request(e): <mask> return ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
return 'bad request!', 400
<mask> :meth:`~flask.Flask.register_error_handler`:: <mask> <mask> @app.errorhandler(werkzeug.exceptions.BadRequest) <mask> def handle_bad_request(e): <mask> return 'bad request!' <mask> <mask> app.register_error_handler(400, lambda e: 'bad request!') <mask> <mask> Those two ways are equ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
# or, without the decorator app.register_error_handler(400, handle_bad_request)
<mask> @app.errorhandler(werkzeug.exceptions.BadRequest) <mask> def handle_bad_request(e): <mask> return 'bad request!' <mask> <mask> app.register_error_handler(400, lambda e: 'bad request!') <mask> <mask> Those two ways are equivalent, but the first one is more clear and leaves <mask> you...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
<mask> return 'bad request!' <mask> <mask> app.register_error_handler(400, lambda e: 'bad request!') <mask> <mask> Those two ways are equivalent, but the first one is more clear and leaves <mask> you with a function to call on your whim (and in tests). Note that <mask> :exc:`werkzeug.exceptions.HT...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
:exc:`~werkzeug.exceptions.BadRequest` and their HTTP codes are interchangeable when registering handlers. (``BadRequest.code == 400``)
<mask> <mask> Those two ways are equivalent, but the first one is more clear and leaves <mask> you with a function to call on your whim (and in tests). Note that <mask> :exc:`werkzeug.exceptions.HTTPException` subclasses like <mask> :exc:`~werkzeug.exceptions.BadRequest` from the example and their HTTP codes <m...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
Non-standard HTTP codes cannot be registered by code because they are not known by Werkzeug. Instead, define a subclass of :class:`~werkzeug.exceptions.HTTPException` with the appropriate code and register and raise that exception class. ::
<mask> :exc:`~werkzeug.exceptions.BadRequest` from the example and their HTTP codes <mask> are interchangeable when handed to the registration methods or decorator <mask> (``BadRequest.code == 400``). <mask> <mask> You are however not limited to :exc:`~werkzeug.exceptions.HTTPException` <mask> or HTTP status cod...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
class InsufficientStorage(werkzeug.exceptions.HTTPException): code = 507 description = 'Not enough storage space.' app.register_error_handler(InsuffcientStorage, handle_507)
<mask> You are however not limited to :exc:`~werkzeug.exceptions.HTTPException` <mask> or HTTP status codes but can register a handler for every exception class you <mask> like. <mask> <mask> .. versionchanged:: 0.11 <mask> <mask> Errorhandlers are now prioritized by specificity of the exception classes <m...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
raise InsufficientStorage() Handlers can be registered for any exception class, not just :exc:`~werkzeug.exceptions.HTTPException` subclasses or HTTP status codes. Handlers can be registered for a specific class, or for all subclasses of a parent class.
<mask> like. <mask> <mask> .. versionchanged:: 0.11 <mask> <mask> Errorhandlers are now prioritized by specificity of the exception classes <mask> they are registered for instead of the order they are registered in. <mask> <mask> Handling <mask> ```````` <mask> <mask> Once an exception instance is ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
When an exception is caught by Flask while handling a request, it is first looked up by code. If no handler is registered for the code, it is looked up by its class hierarchy; the most specific handler is chosen. If no handler is registered, :class:`~werkzeug.exceptions.HTTPException` subclasses show a generic message ...
<mask> <mask> Handling <mask> ```````` <mask> <mask> Once an exception instance is raised, its class hierarchy is traversed, <mask> and searched for in the exception classes for which handlers are registered. <mask> The most specific handler is selected. <mask> <mask> E.g. if an instance of :exc:`Connection...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
For example, if an instance of :exc:`ConnectionRefusedError` is raised, and a handler
<mask> Once an exception instance is raised, its class hierarchy is traversed, <mask> and searched for in the exception classes for which handlers are registered. <mask> The most specific handler is selected. <mask> <mask> E.g. if an instance of :exc:`ConnectionRefusedError` is raised, and a handler <mask> is re...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
the more specific :exc:`ConnectionRefusedError` handler is called with the exception instance to generate the response. Handlers registered on the blueprint take precedence over those registered globally on the application, assuming a blueprint is handling the request that raises the exception. However, the blueprint ...
<mask> The most specific handler is selected. <mask> <mask> E.g. if an instance of :exc:`ConnectionRefusedError` is raised, and a handler <mask> is registered for :exc:`ConnectionError` and :exc:`ConnectionRefusedError`, <mask> the more specific :exc:`ConnectionRefusedError` handler is called on the <mask> excep...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
docs/errorhandling.rst
"""Register a function to handle errors by code or exception class. A decorator that is used to register a function given an
<mask> return exc_class, None <mask> <mask> @setupmethod <mask> def errorhandler(self, code_or_exception): <mask> """A decorator that is used to register a function given an <mask> error code. Example:: <mask> <mask> @app.errorhandler(404) <mask> d...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
flask/app.py
<mask> @app.errorhandler(DatabaseError) <mask> def special_exception_handler(error): <mask> return 'Database connection failed', 500 <mask> <mask> You can also register a function as error handler without using <mask> the :meth:`errorhandler` decorator. Th...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
flask/app.py
@setupmethod
<mask> return f <mask> return decorator <mask> <mask> def register_error_handler(self, code_or_exception, f): <mask> """Alternative error attach function to the :meth:`errorhandler` <mask> decorator that is more straightforward to use for non decorator <mask> usag...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
flask/app.py
'Tried to register a handler for an exception instance {0!r}.' ' Handlers can only be registered for exception classes or' ' HTTP error codes.'.format(code_or_exception) )
<mask> :type f: callable <mask> """ <mask> if isinstance(code_or_exception, HTTPException): # old broken behavior <mask> raise ValueError( <mask> 'Tried to register a handler for an exception instance {0!r}. ' <mask> 'Handlers can only be regist...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
flask/app.py
try: exc_class, code = self._get_exc_class_and_code(code_or_exception) except KeyError: raise KeyError( "'{0}' is not a recognized HTTP error code. Use a subclass of" " HTTPException with that code instead.".format(code_or_exception) )
<mask> 'Tried to register a handler for an exception instance {0!r}. ' <mask> 'Handlers can only be registered for exception classes or HTTP error codes.' <mask> .format(code_or_exception)) <mask> <mask> exc_class, code = self._get_exc_class_and_code(code_or...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
flask/app.py
def test_error_handler_unknown_code(app): with pytest.raises(KeyError) as exc_info: app.register_error_handler(999, lambda e: ('999', 999)) assert 'Use a subclass' in exc_info.value.args[0]
<mask> assert rv.status_code == 403 <mask> assert b'forbidden' == rv.data <mask> <mask> <mask> def test_error_handling_processing(app, client): <mask> app.config['LOGGER_HANDLER_POLICY'] = 'never' <mask> app.testing = False <mask> <mask> @app.errorhandler(500) <mask> def internal_se...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/859d9a9d5c3da114132ec9f0e515e1fa8030f68f
tests/test_basic.py
_mod_route_re = re.compile(r'@([a-zA-Z0-9_][a-zA-Z0-9_]*)\.route')
<mask> _module_constructor_re = re.compile(r'([a-zA-Z0-9_][a-zA-Z0-9_]*)\s*=\s*Module' <mask> r'\(__name__\s*(?:,\s*(?:name\s*=\s*)?(%s))?' % <mask> _string_re_part) <mask> _error_handler_re = re.compile(r'%s\.error_handlers\[\s*(\d+)\s*\]' % _...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/flask-07-upgrade.py
<mask> lineterm=''): <mask> print line <mask> <mask> <mask> def fix_url_for(contents): <mask> def handle_match(match): <mask> prefix = match.group(1) <mask> endpoint = ast.literal_eval(match.group(2)) <mask> if endpoint.startswith('.'): <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/flask-07-upgrade.py
return new_contents, dict(modules_declared)
<mask> new_contents = rewrite_blueprint_imports(new_contents) <mask> <mask> for pattern, replacement in _blueprint_related: <mask> new_contents = pattern.sub(replacement, new_contents) <mask> return new_contents <mask> <mask> <mask> def upgrade_python_file(filename, contents, teardown...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/flask-07-upgrade.py
new_contents = contents
<mask> return new_contents <mask> <mask> <mask> def upgrade_python_file(filename, contents, teardown): <mask> new_contents = fix_url_for(contents) <mask> if teardown: <mask> new_contents = fix_teardown_funcs(new_contents) <mask> new_contents = rewrite_for_blueprints(new_contents, filen...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/flask-07-upgrade.py
new_contents, modules = rewrite_for_blueprints(new_contents, filename) new_contents = fix_url_for(new_contents, modules)
<mask> def upgrade_python_file(filename, contents, teardown): <mask> new_contents = fix_url_for(contents) <mask> if teardown: <mask> new_contents = fix_teardown_funcs(new_contents) <mask> new_contents = rewrite_for_blueprints(new_contents, filename) <mask> new_contents = _error_handler_re....
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/flask-07-upgrade.py
new_contents = fix_url_for(contents, None)
<mask> make_diff(filename, contents, new_contents) <mask> <mask> <mask> def upgrade_template_file(filename, contents): <mask> new_contents = fix_url_for(contents) <mask> make_diff(filename, contents, new_contents) <mask> <mask> <mask> def walk_path(path): <mask> this_file = os.path.realpat...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/flask-07-upgrade.py
from flask import Flask, Module, render_template, url_for
<mask> from flask import Flask, Module, render_template <mask> <mask> <mask> mod = Module(__name__) <mask> mod2 = Module(__name__, 'testmod2') <mask> mod3 = Module(__name__, name='somemod', subdomain='meh') </s> Updated upgrade script to no longer change url_for that don't need to be changed </s> remove ne...
[ "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/testproj/test.py
@app.route('/') def index_foo(): x1 = url_for('somemod.index') x2 = url_for('.index') return render_template('test/index.html')
<mask> <mask> <mask> @mod.route('/') <mask> def index(): <mask> x1 = url_for('somemod.index') <mask> x2 = url_for('.index') </s> Updated upgrade script to no longer change url_for that don't need to be changed </s> remove new_contents = fix_url_for(contents) </s> add new_contents = fix_url_for...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/testproj/test.py
x1 = url_for('somemod.index') x2 = url_for('.index')
<mask> @mod.route('/') <mask> def index(): <mask> return render_template('test/index.html') <mask> <mask> <mask> @mod2.route('/') </s> Updated upgrade script to no longer change url_for that don't need to be changed </s> remove def fix_url_for(contents): def handle_match(match): prefix = match....
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85efa3f89571d66071b86110bf7b615e38234aa8
scripts/testproj/test.py
mtime = None
<mask> :param cache_timeout: the timeout in seconds for the headers. <mask> """ <mask> if isinstance(filename_or_fp, basestring): <mask> filename = filename_or_fp <mask> file = None <mask> else: <mask> file = filename_or_fp <mask> filename = getattr(file, 'name', ...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85ff63c32e7237280bff3293481a371fb3da180c
flask/helpers.py
mtime = os.path.getmtime(filename)
<mask> data = None <mask> else: <mask> if file is None: <mask> file = open(filename, 'rb') <mask> data = wrap_file(request.environ, file) <mask> <mask> rv = current_app.response_class(data, mimetype=mimetype, headers=headers, <mask> ...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85ff63c32e7237280bff3293481a371fb3da180c
flask/helpers.py
# if we know the file modification date, we can store it as the # current time to better support conditional requests. Werkzeug # as of 0.6.1 will override this value however in the conditional # response with the current time. This will be fixed in Werkzeug # with a new release, however many WSGI...
<mask> <mask> rv = current_app.response_class(data, mimetype=mimetype, headers=headers, <mask> direct_passthrough=True) <mask> <mask> rv.cache_control.public = True <mask> if cache_timeout: <mask> rv.cache_control.max_age = cache_timeout <mask> r...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85ff63c32e7237280bff3293481a371fb3da180c
flask/helpers.py
from werkzeug import parse_date, parse_options_header, http_date
<mask> import tempfile <mask> from logging import StreamHandler <mask> from contextlib import contextmanager <mask> from datetime import datetime <mask> from werkzeug import parse_date, parse_options_header <mask> from werkzeug.exceptions import NotFound <mask> from jinja2 import TemplateNotFound <mask> from cS...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/85ff63c32e7237280bff3293481a371fb3da180c
tests/flask_tests.py
This state starts when the :class:`Flask` object is instantiated, and it implicitly ends when the first request comes in. While the application is in this state, a few assumptions are true:
<mask> <mask> 1. The application setup state, in which the application implicitly is <mask> on the module level. <mask> <mask> This state starts when the :class:`Flask` object is instantiated, and <mask> it implicitly ends when the first request comes in. While the <mask> application is in this state, a ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
- the programmer can modify the application object safely. - no request handling happened so far - you have to have a reference to the application object in order to modify it, there is no magic proxy that can give you a reference to the application object you're currently creating or ...
<mask> This state starts when the :class:`Flask` object is instantiated, and <mask> it implicitly ends when the first request comes in. While the <mask> application is in this state, a few assumptions are true: <mask> <mask> - the programmer can modify the application object safely. <mask> - no request ha...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
2. In contrast, in the request handling state, a couple of other rules
<mask> - you have to have a reference to the application object in order to <mask> modify it, there is no magic proxy that can give you a reference to <mask> the application object you're currently creating or modifying. <mask> <mask> 2. In contrast, in the request handling state, a couple of other rule...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
- while a request is active, the context local objects
<mask> <mask> 2. In contrast, in the request handling state, a couple of other rules <mask> exist: <mask> <mask> - while a request is active, the context local objects <mask> (:data:`flask.request` and others) point to the current request. <mask> - any code can get hold of these objects at any time. ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
- any code can get hold of these objects at any time.
<mask> exist: <mask> <mask> - while a request is active, the context local objects <mask> (:data:`flask.request` and others) point to the current request. <mask> - any code can get hold of these objects at any time. <mask> <mask> 3. There is also a third state somewhere in between 'module-level' and ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
3. There is also a third state somewhere in between 'module-level' and
<mask> - while a request is active, the context local objects <mask> (:data:`flask.request` and others) point to the current request. <mask> - any code can get hold of these objects at any time. <mask> <mask> 3. There is also a third state somewhere in between 'module-level' and <mask> 'request-handling...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
Sometimes you are dealing with an application in a way that is similar to how you interact with applications during request handling, but without there being an active request. Consider, for instance, that you're sitting in an interactive Python shell and interacting with the application, or a c...
<mask> <mask> 3. There is also a third state somewhere in between 'module-level' and <mask> 'request-handling': <mask> <mask> Sometimes you are dealing with an application in a way that is similar to <mask> how you interact with applications during request handling, but without <mask> there being an active r...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/863e5cca1b498fb3170981892e820df97f4200e7
docs/appcontext.rst
- Set ``Vary: Cookie`` header when the session is accessed, modified, or refreshed.
<mask> Unreleased <mask> <mask> - Update for compatibility with Werkzeug 2.3.3. <mask> <mask> <mask> Version 2.2.4 <mask> ------------- <mask> <mask> Released 2023-04-25 </s> set `Vary: Cookie` header consistently for session </s> remove # Add a "Vary: Cookie" header if the session was accessed ...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8646edca6f47e2cd57464081b3911218d4734f8d
CHANGES.rst
# Add a "Vary: Cookie" header if the session was accessed at all. if session.accessed: response.vary.add("Cookie")
<mask> samesite = self.get_cookie_samesite(app) <mask> httponly = self.get_cookie_httponly(app) <mask> <mask> # If the session is modified to be empty, remove the cookie. <mask> # If the session is empty, return without setting the cookie. <mask> if not session: <mask> ...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8646edca6f47e2cd57464081b3911218d4734f8d
src/flask/sessions.py
response.vary.add("Cookie")
<mask> secure=secure, <mask> samesite=samesite, <mask> httponly=httponly, <mask> ) <mask> <mask> return <mask> <mask> if not self.should_set_cookie(app, session): <mask> return <mask> </s> set `Vary...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8646edca6f47e2cd57464081b3911218d4734f8d
src/flask/sessions.py
<mask> ) <mask> <mask> return <mask> <mask> # Add a "Vary: Cookie" header if the session was accessed at all. <mask> if session.accessed: <mask> response.vary.add("Cookie") <mask> <mask> if not self.should_set_cookie(app, session): <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8646edca6f47e2cd57464081b3911218d4734f8d
src/flask/sessions.py
@app.route("/clear") def clear(): flask.session.clear() return ""
<mask> @app.route("/setdefault") <mask> def setdefault(): <mask> return flask.session.setdefault("test", "default") <mask> <mask> @app.route("/vary-cookie-header-set") <mask> def vary_cookie_header_set(): <mask> response = flask.Response() <mask> response.vary.add("Cooki...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8646edca6f47e2cd57464081b3911218d4734f8d
tests/test_basic.py
expect("/clear")
<mask> expect("/set") <mask> expect("/get") <mask> expect("/getitem") <mask> expect("/setdefault") <mask> expect("/vary-cookie-header-set") <mask> expect("/vary-header-set", "Accept-Encoding, Accept-Language, Cookie") <mask> expect("/no-vary-header", None) <mask> <mask> <mask> de...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8646edca6f47e2cd57464081b3911218d4734f8d
tests/test_basic.py
<mask> <mask> from . import json <mask> from .globals import _app_ctx_stack <mask> <mask> _missing = object() <mask> <mask> <mask> class JSONMixin(object): <mask> """Mixin for both request and response classes to provide JSON parsing <mask> capabilities. <mask> </s> Remove _missing sentinel and...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
"""Common mixin for both request and response objects to provide JSON parsing capabilities.
<mask> _missing = object() <mask> <mask> <mask> class JSONMixin(object): <mask> """Mixin for both request and response classes to provide JSON parsing <mask> capabilities. <mask> <mask> .. versionadded:: 0.12 <mask> """ <mask> <mask> @property </s> Remove _missing sentinel and update...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
"""Indicates if this request/response is in JSON format or not. By default it is considered to include JSON data if the mimetype is
<mask> """ <mask> <mask> @property <mask> def is_json(self): <mask> """Indicates if this request/response is JSON or not. By default it <mask> is considered to include JSON data if the mimetype is <mask> :mimetype:`application/json` or :mimetype:`application/*+json`. <mask>...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
.. versionadded:: 1.0
<mask> def is_json(self): <mask> """Indicates if this request/response is in JSON format or not. By <mask> default it is considered to include JSON data if the mimetype is <mask> :mimetype:`application/json` or :mimetype:`application/*+json`. <mask> """ <mask> mt = sel...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
"""If this request/response is in JSON format then this property will contain the parsed JSON data. Otherwise it will be ``None``.
<mask> return False <mask> <mask> @property <mask> def json(self): <mask> """If the mimetype is :mimetype:`application/json` this will contain the <mask> parsed JSON data. Otherwise this will be ``None``. <mask> <mask> The :meth:`get_json` method should be used instead...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
warn(DeprecationWarning( 'json is deprecated. Use get_json() instead.'), stacklevel=2)
<mask> <mask> The :meth:`get_json` method should be used instead. <mask> """ <mask> from warnings import warn <mask> warn(DeprecationWarning('json is deprecated. ' <mask> 'Use get_json() instead.'), stacklevel=2) <mask> return self.get_jso...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
on the object.
<mask> :param force: if set to ``True`` the mimetype is ignored. <mask> :param silent: if set to ``True`` this method will fail silently <mask> and return ``None``. <mask> :param cache: if set to ``True`` the parsed JSON data is remembered <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
try: return getattr(self, '_cached_json') except AttributeError: pass
<mask> and return ``None``. <mask> :param cache: if set to ``True`` the parsed JSON data is remembered <mask> on the request. <mask> """ <mask> rv = getattr(self, '_cached_json', _missing) <mask> if rv is not _missing: <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
# We accept MIME charset header against the specification as certain
<mask> <mask> if not (force or self.is_json): <mask> return None <mask> <mask> # We accept a request charset against the specification as certain <mask> # clients have been using this in the past. For responses, we assume <mask> # that if the response charset was se...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/866118302ef910f2b216e23783c9013d282e7807
flask/wrappers.py
# Add a "Vary: Cookie" header if the session was accessed at all. if session.accessed: response.vary.add("Cookie")
<mask> samesite = self.get_cookie_samesite(app) <mask> httponly = self.get_cookie_httponly(app) <mask> <mask> # If the session is modified to be empty, remove the cookie. <mask> # If the session is empty, return without setting the cookie. <mask> if not session: <mask> ...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8705dd39c4fa563ea0fe0bf84c85da8fcc98b88d
src/flask/sessions.py
response.vary.add("Cookie")
<mask> samesite=samesite, <mask> httponly=httponly, <mask> ) <mask> <mask> return <mask> <mask> if not self.should_set_cookie(app, session): </s> set `Vary: Cookie` header consistently for session </s> remove # Add a "Vary: Co...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8705dd39c4fa563ea0fe0bf84c85da8fcc98b88d
src/flask/sessions.py
<mask> ) <mask> <mask> return <mask> <mask> # Add a "Vary: Cookie" header if the session was accessed at all. <mask> if session.accessed: <mask> response.vary.add("Cookie") <mask> <mask> if not self.should_set_cookie(app, session): <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8705dd39c4fa563ea0fe0bf84c85da8fcc98b88d
src/flask/sessions.py
@app.route("/clear") def clear(): flask.session.clear() return ""
<mask> def setdefault(): <mask> return flask.session.setdefault("test", "default") <mask> <mask> @app.route("/vary-cookie-header-set") <mask> def vary_cookie_header_set(): <mask> response = flask.Response() <mask> response.vary.add("Cookie") </s> set `Vary: Cookie` header co...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/8705dd39c4fa563ea0fe0bf84c85da8fcc98b88d
tests/test_basic.py