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 |
|---|---|---|---|---|
should be correct, but actually is not. For example you may have some client-side
code that sends an HTTP request to the server but it's obviously
malformed. This might be caused by a user tampering with the data, or the
client code failing. Most of the time it's okay to reply with ``400 Bad | <mask>
<mask> .. versionadded:: 0.3
<mask>
<mask> Sometimes you might be in a situation where you deal with data that
<mask> should be correct, but actually is not. For example you may have some client
<mask> side code that sends an HTTP request to the server but it's obviously
<mask> malformed. This might b... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ccca13bbdfcbab126722c050dc4ea3d8fa56dc3 | docs/quickstart.rst |
endpoint = view_args = None | <mask> the request object used you can subclass this and set
<mask> :attr:`~flask.Flask.request_class` to your subclass.
<mask> """
<mask>
<mask> def __init__(self, environ):
<mask> RequestBase.__init__(self, environ)
<mask> self.endpoint = None
<mask> self.view_args = N... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7cf5a9bf6e34fc57f82e560f01c408fbe603e9d4 | flask.py |
session['_flashes'] = session.get('_flashes', ()) + (message,) | <mask> the template has to call :func:`get_flashed_messages`.
<mask>
<mask> :param message: the message to be flashed.
<mask> """
<mask> session['_flashes'] = (session.get('_flashes', [])) + [message]
<mask>
<mask>
<mask> def get_flashed_messages():
<mask> """Pulls all flashed messages f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7cf5a9bf6e34fc57f82e560f01c408fbe603e9d4 | flask.py |
_request_ctx_stack.top.flashes = flashes = session.pop('_flashes', ()) | <mask> the same messages.
<mask> """
<mask> flashes = _request_ctx_stack.top.flashes
<mask> if flashes is None:
<mask> _request_ctx_stack.top.flashes = flashes = \
<mask> session.pop('_flashes', [])
<mask> return flashes
<mask>
<mask>
<mask> def jsonify(*args, **kwarg... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7cf5a9bf6e34fc57f82e560f01c408fbe603e9d4 | flask.py |
from collections import Mapping, deque | <mask> from threading import Lock
<mask> from datetime import timedelta
<mask> from itertools import chain
<mask> from functools import update_wrapper
<mask> from collections import Mapping
<mask>
<mask> from werkzeug.datastructures import ImmutableDict
<mask> from werkzeug.routing import Map, Rule, RequestRed... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7d506f2408520ecb21025f93d9ece00431004501 | flask/app.py |
return
queue = deque(exc_class.__mro__)
# Protect from geniuses who might create circular references in
# __mro__
done = set()
while True:
cls = queue.popleft()
if cls in done:
continue
... | <mask> exc_class, code = self._get_exc_class_and_code(type(e))
<mask>
<mask> def find_superclass(handler_map):
<mask> if not handler_map:
<mask> return None
<mask> for superclass in exc_class.__mro__:
<mask> if superclass is BaseExc... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7d506f2408520ecb21025f93d9ece00431004501 | flask/app.py |
# cache for next time exc_class is raised
handler_map[exc_class] = handler | <mask> if superclass is BaseException:
<mask> return None
<mask> handler = handler_map.get(superclass)
<mask> if handler is not None:
<mask> handler_map[exc_class] = handler # cache for next time exc_class is raised
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7d506f2408520ecb21025f93d9ece00431004501 | flask/app.py |
queue.extend(cls.__mro__)
| <mask> handler = handler_map.get(superclass)
<mask> if handler is not None:
<mask> handler_map[exc_class] = handler # cache for next time exc_class is raised
<mask> return handler
<mask> return None
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7d506f2408520ecb21025f93d9ece00431004501 | flask/app.py |
handler = find_handler(self.error_handler_spec
.get(request.blueprint, {})
.get(code)) | <mask> return handler
<mask> return None
<mask>
<mask> # try blueprint handlers
<mask> handler = find_superclass(self.error_handler_spec.get(request.blueprint, {}).get(code))
<mask>
<mask> if handler is not None:
<mask> return... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7d506f2408520ecb21025f93d9ece00431004501 | flask/app.py |
return find_handler(self.error_handler_spec[None].get(code)) | <mask> if handler is not None:
<mask> return handler
<mask>
<mask> # fall back to app handlers
<mask> return find_superclass(self.error_handler_spec[None].get(code))
<mask>
<mask> def handle_http_exception(self, e):
<mask> """Handles an HTTP exception. ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7d506f2408520ecb21025f93d9ece00431004501 | flask/app.py |
Installing FastCGI applications on nginx is a bit different because by default
no FastCGI parameters are forwarded. | <mask>
<mask> Configuring nginx
<mask> -----------------
<mask>
<mask> Installing FastCGI applications on nginx is a bit tricky because by default
<mask> some FastCGI parameters are not properly forwarded.
<mask>
<mask> A basic FastCGI configuration for nginx looks like this::
<mask>
<mask> location /... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7dae84f0027945bac29b45b63fdc0f795a5a813a | docs/deploying/fastcgi.rst |
A basic flask FastCGI configuration for nginx looks like this:: | <mask>
<mask> Installing FastCGI applications on nginx is a bit tricky because by default
<mask> some FastCGI parameters are not properly forwarded.
<mask>
<mask> A basic FastCGI configuration for nginx looks like this::
<mask>
<mask> location /yourapplication/ {
<mask> include fastcgi_params;
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7dae84f0027945bac29b45b63fdc0f795a5a813a | docs/deploying/fastcgi.rst |
location = /yourapplication { rewrite ^ /yourapplication/ last; }
location /yourapplication { try_files $uri @yourapplication; }
location @yourapplication { | <mask> some FastCGI parameters are not properly forwarded.
<mask>
<mask> A basic FastCGI configuration for nginx looks like this::
<mask>
<mask> location /yourapplication/ {
<mask> include fastcgi_params;
<mask> if ($uri ~ ^/yourapplication/(.*)?) {
<mask> set $path_url $1;
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7dae84f0027945bac29b45b63fdc0f795a5a813a | docs/deploying/fastcgi.rst |
fastcgi_split_path_info ^(/yourapplication)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name; | <mask> A basic FastCGI configuration for nginx looks like this::
<mask>
<mask> location /yourapplication/ {
<mask> include fastcgi_params;
<mask> if ($uri ~ ^/yourapplication/(.*)?) {
<mask> set $path_url $1;
<mask> }
<mask> fastcgi_param PATH_INFO $path_url;
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7dae84f0027945bac29b45b63fdc0f795a5a813a | docs/deploying/fastcgi.rst |
to have it in the URL root it's a bit simpler because you don't have to figure | <mask> fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
<mask> }
<mask>
<mask> This configuration binds the application to `/yourapplication`. If you want
<mask> to have it in the URL root it's a bit easier because you don't have to figure
<mask> out how to calculate `PATH_INFO` and `SCRIPT_NAME`::... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7dae84f0027945bac29b45b63fdc0f795a5a813a | docs/deploying/fastcgi.rst |
location / { try_files $uri @yourapplication; }
location @yourapplication { | <mask> This configuration binds the application to `/yourapplication`. If you want
<mask> to have it in the URL root it's a bit easier because you don't have to figure
<mask> out how to calculate `PATH_INFO` and `SCRIPT_NAME`::
<mask>
<mask> location /yourapplication/ {
<mask> include fastcgi_params... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7dae84f0027945bac29b45b63fdc0f795a5a813a | docs/deploying/fastcgi.rst |
flaskr.app.config['TESTING'] = True | <mask>
<mask> def setUp(self):
<mask> self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
<mask> self.app = flaskr.app.test_client()
<mask> flaskr.init_db()
<mask>
<mask> def tearDown(self):
<mask> os.close(self.db_fd)
</s> Mention th... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e55b5084ddbaeeadd8358b216f36e7706c79199 | docs/testing.rst |
:meth:`~unittest.TestCase.tearDown` method. Additionally during setup the
``TESTING`` config flag is activated. What it does is disabling the error
catching during request handling so that you get better error reports when
performing test requests against the application. | <mask> The code in the :meth:`~unittest.TestCase.setUp` method creates a new test
<mask> client and initializes a new database. This function is called before
<mask> each individual test function is run. To delete the database after the
<mask> test, we close the file and remove it from the filesystem in the
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e55b5084ddbaeeadd8358b216f36e7706c79199 | docs/testing.rst |
flaskr.app.config['TESTING'] = True | <mask>
<mask> def setUp(self):
<mask> """Before each test, set up a blank database"""
<mask> self.db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
<mask> self.app = flaskr.app.test_client()
<mask> flaskr.init_db()
<mask>
<mask> def tearDown(self):
<mask> ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e55b5084ddbaeeadd8358b216f36e7706c79199 | examples/flaskr/flaskr_tests.py |
<mask> packaging==23.0
<mask> # via build
<mask> pyproject-hooks==1.0.0
<mask> # via build
<mask> tomli==2.0.1
<mask> # via build
</s> enforce minimum versions in env </s> remove exceptiongroup==1.1.1
# via pytest
greenlet==2.0.2 ; python_version < "3.11"
# via -r requirements/tests.in
</s> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/build.txt | |
Werkzeug==2.2.2 | <mask> Werkzeug==2.0.0
<mask> Jinja2==3.0.0
<mask> MarkupSafe==2.0.0
<mask> itsdangerous==2.0.0
<mask> click==8.0.0
</s> enforce minimum versions in env </s> remove MarkupSafe==2.0.0
</s> add MarkupSafe==2.1.1 </s> remove markupsafe==2.0.0
</s> add markupsafe==2.1.1 | [
"replace",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests-pallets-min.in |
MarkupSafe==2.1.1 | <mask> Werkzeug==2.0.0
<mask> Jinja2==3.0.0
<mask> MarkupSafe==2.0.0
<mask> itsdangerous==2.0.0
<mask> click==8.0.0
</s> enforce minimum versions in env </s> remove Werkzeug==2.0.0
</s> add Werkzeug==2.2.2 </s> remove markupsafe==2.0.0
</s> add markupsafe==2.1.1 | [
"keep",
"keep",
"replace",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests-pallets-min.in |
# SHA1:f7109e66098c9e4cb68dc5f0d8e14f429ceed12c | <mask> # SHA1:4de7d9e6254a945fd97ec10880dd23b6cd43b70d
<mask> #
<mask> # This file is autogenerated by pip-compile-multi
<mask> # To update, run:
<mask> #
<mask> # pip-compile-multi
</s> enforce minimum versions in env </s> remove werkzeug==2.0.0
</s> add # werkzeug
werkzeug==2.2.2 </s> remove markupsa... | [
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests-pallets-min.txt |
markupsafe==2.1.1 | <mask> itsdangerous==2.0.0
<mask> # via -r requirements/tests-pallets-min.in
<mask> jinja2==3.0.0
<mask> # via -r requirements/tests-pallets-min.in
<mask> markupsafe==2.0.0
<mask> # via
<mask> # -r requirements/tests-pallets-min.in
<mask> # jinja2
<mask> werkzeug==2.0.0
<mask> # vi... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests-pallets-min.txt |
# werkzeug
werkzeug==2.2.2 | <mask> markupsafe==2.0.0
<mask> # via
<mask> # -r requirements/tests-pallets-min.in
<mask> # jinja2
<mask> werkzeug==2.0.0
<mask> # via -r requirements/tests-pallets-min.in
</s> enforce minimum versions in env </s> remove markupsafe==2.0.0
</s> add markupsafe==2.1.1 </s> remove exceptiongrou... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests-pallets-min.txt |
<mask> asgiref==3.6.0
<mask> # via -r requirements/tests.in
<mask> blinker==1.6.1
<mask> # via -r requirements/tests.in
<mask> exceptiongroup==1.1.1
<mask> # via pytest
<mask> greenlet==2.0.2 ; python_version < "3.11"
<mask> # via -r requirements/tests.in
<mask> iniconfig==2.0.0
<mask> # v... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests.txt | |
<mask> pytest==7.3.0
<mask> # via -r requirements/tests.in
<mask> python-dotenv==1.0.0 ; python_version >= "3.8"
<mask> # via -r requirements/tests.in
<mask> tomli==2.0.1
<mask> # via pytest
<mask> typing-extensions==4.5.0
<mask> # via blinker
</s> enforce minimum versions in env </s> remove ex... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/tests.txt | |
<mask> mypy-extensions==1.0.0
<mask> # via mypy
<mask> pycparser==2.21
<mask> # via cffi
<mask> tomli==2.0.1
<mask> # via mypy
<mask> types-contextvars==2.4.7.2
<mask> # via -r requirements/typing.in
<mask> types-dataclasses==0.6.6
<mask> # via -r requirements/typing.in
<mask> types-setup... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | requirements/typing.txt | |
constrain_package_deps = true
use_frozen_constraints = true | <mask> wheel_build_env = .pkg
<mask> envtmpdir = {toxworkdir}/tmp/{envname}
<mask> deps =
<mask> -r requirements/tests.txt
<mask> min: -r requirements/tests-pallets-min.txt
<mask> dev: https://github.com/pallets/werkzeug/archive/refs/heads/main.tar.gz
<mask> dev: https://github.com/pallets/jinja/... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | tox.ini |
constrain_package_deps = true
use_frozen_constraints = true | <mask> package = wheel
<mask> wheel_build_env = .pkg
<mask> deps = -r requirements/typing.txt
<mask> commands = mypy
<mask>
<mask> [testenv:docs]
<mask> package = wheel
</s> enforce minimum versions in env </s> remove tomli==2.0.1
# via mypy
</s> add </s> remove markupsafe==2.0.0
</s> add markupsafe==2.... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | tox.ini |
constrain_package_deps = true
use_frozen_constraints = true | <mask> package = wheel
<mask> wheel_build_env = .pkg
<mask> deps = -r requirements/docs.txt
<mask> commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html
</s> enforce minimum versions in env </s> remove markupsafe==2.0.0
</s> add markupsafe==2.1.1 </s> remove werkzeug==2.0.0
</s> add ... | [
"keep",
"add",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7e6e68aed91c4c36142f6f1d32c0d74ac75e65be | tox.ini |
- Auto-detect 0-argument app factory called ``create_app`` or ``make_app`` from
``FLASK_APP``. (`#2297`_) | <mask> - ``SESSION_COOKIE_DOMAIN`` is set if it is detected through ``SERVER_NAME``.
<mask> (`#2282`_)
<mask>
<mask> .. _#1489: https://github.com/pallets/flask/pull/1489
<mask> .. _#1898: https://github.com/pallets/flask/pull/1898
<mask> .. _#1936: https://github.com/pallets/flask/pull/1936
<mask> .. _#2017:... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ecdbcfa2b2d1c83c8c6561b49303ed5b1042350 | CHANGES |
.. _#2297: https://github.com/pallets/flask/pull/2297 | <mask> .. _#2254: https://github.com/pallets/flask/pull/2254
<mask> .. _#2256: https://github.com/pallets/flask/pull/2256
<mask> .. _#2259: https://github.com/pallets/flask/pull/2259
<mask> .. _#2282: https://github.com/pallets/flask/pull/2282
<mask>
<mask> Version 0.12.2
<mask> --------------
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ecdbcfa2b2d1c83c8c6561b49303ed5b1042350 | CHANGES |
matches = [
v for k, v in iteritems(module.__dict__) if isinstance(v, Flask)
] | <mask> if isinstance(app, Flask):
<mask> return app
<mask>
<mask> # Otherwise find the only object that is a Flask instance.
<mask> matches = [v for k, v in iteritems(module.__dict__)
<mask> if isinstance(v, Flask)]
<mask>
<mask> if len(matches) == 1:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ecdbcfa2b2d1c83c8c6561b49303ed5b1042350 | flask/cli.py |
elif len(matches) > 1:
raise NoAppException(
'Auto-detected multiple Flask applications in module "{module}".'
' Use "FLASK_APP={module}:name" to specify the correct'
' one.'.format(module=module.__name__)
) | <mask> ]
<mask>
<mask> if len(matches) == 1:
<mask> return matches[0]
<mask>
<mask> # Search for app factory callables.
<mask> for attr_name in 'create_app', 'make_app':
<mask> app_factory = getattr(module, attr_name, None)
<mask>
<mask> if callable(app_factory):
</... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ecdbcfa2b2d1c83c8c6561b49303ed5b1042350 | flask/cli.py |
'could not call it without specifying arguments.'.format(
callable=attr_name, module=module.__name__
)
) | <mask> return app
<mask> except TypeError:
<mask> raise NoAppException(
<mask> 'Auto-detected "{callable}()" in module "{module}", but '
<mask> 'could not call it without specifying arguments.'
<mask> .form... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ecdbcfa2b2d1c83c8c6561b49303ed5b1042350 | flask/cli.py |
'Failed to find application in module "{module}". Are you sure '
'it contains a Flask application? Maybe you wrapped it in a WSGI '
'middleware.'.format(module=module.__name__)
) | <mask> .format(callable=attr_name,
<mask> module=module.__name__))
<mask>
<mask> raise NoAppException(
<mask> 'Failed to find application in module "{module}". Are you sure '
<mask> 'it contains a Flask application? Maybe you wrapped it in a W... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ecdbcfa2b2d1c83c8c6561b49303ed5b1042350 | flask/cli.py |
.. autofunction:: safe_join
| <mask>
<mask> .. autofunction:: send_from_directory
<mask>
<mask> .. autofunction:: escape
<mask>
<mask> .. autoclass:: Markup
<mask> :members: escape, unescape, striptags
<mask>
</s> Add safe_join: returns the filename used by send_from_directory.
Signed-off-by: Armin Ronacher <armin.ronacher@active-4... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ed3196e8d1861acd027c409c47e51cce812ba63 | docs/api.rst |
get_template_attribute, make_response, safe_join | <mask> from .app import Flask, Request, Response
<mask> from .config import Config
<mask> from .helpers import url_for, jsonify, json_available, flash, \
<mask> send_file, send_from_directory, get_flashed_messages, \
<mask> get_template_attribute, make_response
<mask> from .globals import current_app, g, ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ed3196e8d1861acd027c409c47e51cce812ba63 | flask/__init__.py |
filename = safe_join(directory, filename) | <mask> download.
<mask> :param options: optional keyword arguments that are directly
<mask> forwarded to :func:`send_file`.
<mask> """
<mask> filename = posixpath.normpath(filename)
<mask> for sep in _os_alt_seps:
<mask> if sep in filename:
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7ed3196e8d1861acd027c409c47e51cce812ba63 | flask/helpers.py |
2. install the app from the root of the project directory
pip install --editable .
3. tell flask about the right application: | <mask> 1. edit the configuration in the minitwit.py file or
<mask> export an MINITWIT_SETTINGS environment variable
<mask> pointing to a configuration file.
<mask>
<mask> 2. tell flask about the right application:
<mask>
<mask> export FLASK_APP=minitwit
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f288371674b420ac2df8ff2313e3b469662ee41 | examples/minitwit/README |
4. fire up a shell and run this: | <mask> 2. tell flask about the right application:
<mask>
<mask> export FLASK_APP=minitwit
<mask>
<mask> 2. fire up a shell and run this:
<mask>
<mask> flask initdb
<mask>
<mask> 3. now you can run minitwit:
<mask>
</s> Update README for minitwit (#2119)
add step 2 to... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f288371674b420ac2df8ff2313e3b469662ee41 | examples/minitwit/README |
5. now you can run minitwit: | <mask> 2. fire up a shell and run this:
<mask>
<mask> flask initdb
<mask>
<mask> 3. now you can run minitwit:
<mask>
<mask> flask run
<mask>
<mask> the application will greet you on
<mask> http://localhost:5000/
</s> Update README for minitwit (#2119)
add ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f288371674b420ac2df8ff2313e3b469662ee41 | examples/minitwit/README |
Extension authors can support async functions by utilising the
:meth:`flask.Flask.ensure_sync` method. For example, if the extension
provides a view function decorator add ``ensure_sync`` before calling
the decorated function,
.. code-block:: python
def extension(func):
@wraps(func)
def wrapper(*a... | <mask> awaitable. Other functions they provide will not be awaitable either and
<mask> will probably be blocking if called within an async view.
<mask>
<mask> Check the changelog of the extension you want to use to see if they've
<mask> implemented async support, or make a feature request or PR to them.
<mask>
... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | docs/async-await.rst |
from .helpers import async_to_sync | <mask> from .globals import g
<mask> from .globals import request
<mask> from .globals import session
<mask> from .helpers import get_debug_flag
<mask> from .helpers import get_env
<mask> from .helpers import get_flashed_messages
<mask> from .helpers import get_load_dotenv
<mask> from .helpers import locked_cac... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
<mask> from .helpers import get_env
<mask> from .helpers import get_flashed_messages
<mask> from .helpers import get_load_dotenv
<mask> from .helpers import locked_cached_property
<mask> from .helpers import run_async
<mask> from .helpers import url_for
<mask> from .json import jsonify
<mask> from .logging impo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py | |
<mask>
<mask> self.url_map.add(rule)
<mask> if view_func is not None:
<mask> old_func = self.view_functions.get(endpoint)
<mask> if getattr(old_func, "_flask_sync_wrapper", False):
<mask> old_func = old_func.__wrapped__ # type: ignore
<mask> i... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py | |
self.view_functions[endpoint] = view_func | <mask> raise AssertionError(
<mask> "View function mapping is overwriting an existing"
<mask> f" endpoint function: {endpoint}"
<mask> )
<mask> self.view_functions[endpoint] = self.ensure_sync(view_func)
<mask>
<mask> @setup... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
self.before_first_request_funcs.append(f) | <mask> value is ignored.
<mask>
<mask> .. versionadded:: 0.8
<mask> """
<mask> self.before_first_request_funcs.append(self.ensure_sync(f))
<mask> return f
<mask>
<mask> @setupmethod
<mask> def teardown_appcontext(self, f: TeardownCallable) -> TeardownCallable:
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
self.teardown_appcontext_funcs.append(f) | <mask> The return values of teardown functions are ignored.
<mask>
<mask> .. versionadded:: 0.9
<mask> """
<mask> self.teardown_appcontext_funcs.append(self.ensure_sync(f))
<mask> return f
<mask>
<mask> @setupmethod
<mask> def shell_context_processor(self, f: t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
return self.ensure_sync(handler)(e) | <mask>
<mask> handler = self._find_error_handler(e)
<mask> if handler is None:
<mask> return e
<mask> return handler(e)
<mask>
<mask> def trap_http_exception(self, e: Exception) -> bool:
<mask> """Checks if an HTTP exception should be trapped or not. By default... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
return self.ensure_sync(handler)(e) | <mask>
<mask> if handler is None:
<mask> raise
<mask>
<mask> return handler(e)
<mask>
<mask> def handle_exception(self, e: Exception) -> Response:
<mask> """Handle an exception that did not have an error handler
<mask> associated with it, or that was raised fr... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
server_error = self.ensure_sync(handler)(server_error) | <mask> server_error = InternalServerError(original_exception=e)
<mask> handler = self._find_error_handler(server_error)
<mask>
<mask> if handler is not None:
<mask> server_error = handler(server_error)
<mask>
<mask> return self.finalize_request(server_error, from_err... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) | <mask> and req.method == "OPTIONS"
<mask> ):
<mask> return self.make_default_options_response()
<mask> # otherwise dispatch to the handler for that endpoint
<mask> return self.view_functions[rule.endpoint](**req.view_args)
<mask>
<mask> def full_dispatch_reque... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
self.ensure_sync(func)() | <mask> with self._before_request_lock:
<mask> if self._got_first_request:
<mask> return
<mask> for func in self.before_first_request_funcs:
<mask> func()
<mask> self._got_first_request = True
<mask>
<mask> def make_default_options_... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
return async_to_sync(func) | <mask>
<mask> .. versionadded:: 2.0
<mask> """
<mask> if iscoroutinefunction(func):
<mask> return run_async(func)
<mask>
<mask> return func
<mask>
<mask> def make_response(self, rv: ResponseReturnValue) -> Response:
<mask> """Convert the return value ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
rv = self.ensure_sync(func)() | <mask> for bp in self._request_blueprints():
<mask> if bp in self.before_request_funcs:
<mask> funcs = chain(funcs, self.before_request_funcs[bp])
<mask> for func in funcs:
<mask> rv = func()
<mask> if rv is not None:
<mask> retu... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
response = self.ensure_sync(handler)(response) | <mask> funcs = chain(funcs, reversed(self.after_request_funcs[bp]))
<mask> if None in self.after_request_funcs:
<mask> funcs = chain(funcs, reversed(self.after_request_funcs[None]))
<mask> for handler in funcs:
<mask> response = handler(response)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
self.ensure_sync(func)(exc) | <mask> for bp in self._request_blueprints():
<mask> if bp in self.teardown_request_funcs:
<mask> funcs = chain(funcs, reversed(self.teardown_request_funcs[bp]))
<mask> for func in funcs:
<mask> func(exc)
<mask> request_tearing_down.send(self, exc=exc... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
self.ensure_sync(func)(exc) | <mask> """
<mask> if exc is _sentinel:
<mask> exc = sys.exc_info()[1]
<mask> for func in reversed(self.teardown_appcontext_funcs):
<mask> func(exc)
<mask> appcontext_tearing_down.send(self, exc=exc)
<mask>
<mask> def app_context(self) -> AppContext:
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/app.py |
def extend(bp_dict, parent_dict): | <mask>
<mask> # Merge blueprint data into parent.
<mask> if first_registration:
<mask>
<mask> def extend(bp_dict, parent_dict, ensure_sync=False):
<mask> for key, values in bp_dict.items():
<mask> key = self.name if key is None else f"{self.name}.... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
<mask> def extend(bp_dict, parent_dict, ensure_sync=False):
<mask> for key, values in bp_dict.items():
<mask> key = self.name if key is None else f"{self.name}.{key}"
<mask>
<mask> if ensure_sync:
<mask> values = [app.ens... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py | |
exc_class: func for exc_class, func in code_values.items() | <mask> value = defaultdict(
<mask> dict,
<mask> {
<mask> code: {
<mask> exc_class: app.ensure_sync(func)
<mask> for exc_class, func in code_values.items()
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
app.view_functions[endpoint] = func | <mask> )
<mask> app.error_handler_spec[key] = value
<mask>
<mask> for endpoint, func in self.view_functions.items():
<mask> app.view_functions[endpoint] = app.ensure_sync(func)
<mask>
<mask> extend(
<mask> self.before_requ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
extend(self.before_request_funcs, app.before_request_funcs)
extend(self.after_request_funcs, app.after_request_funcs) | <mask>
<mask> for endpoint, func in self.view_functions.items():
<mask> app.view_functions[endpoint] = app.ensure_sync(func)
<mask>
<mask> extend(
<mask> self.before_request_funcs, app.before_request_funcs, ensure_sync=True
<mask> )
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
<mask> extend(self.after_request_funcs, app.after_request_funcs, ensure_sync=True)
<mask> extend(
<mask> self.teardown_request_funcs,
<mask> app.teardown_request_funcs,
<mask> ensure_sync=True,
<mask> )
<mask> extend(... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py | |
lambda s: s.app.before_request_funcs.setdefault(None, []).append(f) | <mask> """Like :meth:`Flask.before_request`. Such a function is executed
<mask> before each request, even if outside of a blueprint.
<mask> """
<mask> self.record_once(
<mask> lambda s: s.app.before_request_funcs.setdefault(None, []).append(
<mask> s.ap... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
self.record_once(lambda s: s.app.before_first_request_funcs.append(f)) | <mask> ) -> BeforeRequestCallable:
<mask> """Like :meth:`Flask.before_first_request`. Such a function is
<mask> executed before the first request to the application.
<mask> """
<mask> self.record_once(
<mask> lambda s: s.app.before_first_request_funcs.append(s.app.... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
lambda s: s.app.after_request_funcs.setdefault(None, []).append(f) | <mask> """Like :meth:`Flask.after_request` but for a blueprint. Such a function
<mask> is executed after each request, even if outside of the blueprint.
<mask> """
<mask> self.record_once(
<mask> lambda s: s.app.after_request_funcs.setdefault(None, []).append(
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py |
<mask> self.record_once(
<mask> lambda s: s.app.url_default_functions.setdefault(None, []).append(f)
<mask> )
<mask> return f
<mask>
<mask> def ensure_sync(self, f: t.Callable) -> t.Callable:
<mask> """Ensure the function is synchronous.
<mask>
<mask> O... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/blueprints.py | |
<mask> import typing as t
<mask> import warnings
<mask> from datetime import timedelta
<mask> from functools import update_wrapper
<mask> from functools import wraps
<mask> from threading import RLock
<mask>
<mask> import werkzeug.utils
<mask> from werkzeug.exceptions import NotFound
<mask> from werkzeug.loc... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/helpers.py | |
def async_to_sync(func: t.Callable[..., t.Coroutine]) -> t.Callable[..., t.Any]:
"""Return a sync function that will run the coroutine function *func*.
This can be used as so
result = async_to_async(func)(*args, **kwargs)
""" | <mask>
<mask> return False
<mask>
<mask>
<mask> def run_async(func: t.Callable[..., t.Coroutine]) -> t.Callable[..., t.Any]:
<mask> """Return a sync function that will run the coroutine function *func*."""
<mask> try:
<mask> from asgiref.sync import async_to_sync
<mask> except Import... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/helpers.py |
from asgiref.sync import async_to_sync as asgiref_async_to_sync | <mask>
<mask> def run_async(func: t.Callable[..., t.Coroutine]) -> t.Callable[..., t.Any]:
<mask> """Return a sync function that will run the coroutine function *func*."""
<mask> try:
<mask> from asgiref.sync import async_to_sync
<mask> except ImportError:
<mask> raise RuntimeError(
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/helpers.py |
return asgiref_async_to_sync(func) | <mask> raise RuntimeError(
<mask> "Async cannot be used with this combination of Python & Greenlet versions."
<mask> )
<mask>
<mask> @wraps(func)
<mask> def wrapper(*args: t.Any, **kwargs: t.Any) -> t.Any:
<mask> return async_to_sync(func)(*args, **kwargs)
<mask>
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/helpers.py |
self.view_functions[endpoint] = f | <mask> function.
<mask> """
<mask>
<mask> def decorator(f):
<mask> self.view_functions[endpoint] = self.ensure_sync(f)
<mask> return f
<mask>
<mask> return decorator
<mask>
<mask> @setupmethod
</s> Simplify the async handling code
Firstly `r... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/scaffold.py |
self.before_request_funcs.setdefault(None, []).append(f) | <mask> a non-``None`` value, the value is handled as if it was the
<mask> return value from the view, and further request handling is
<mask> stopped.
<mask> """
<mask> self.before_request_funcs.setdefault(None, []).append(self.ensure_sync(f))
<mask> return f
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/scaffold.py |
self.after_request_funcs.setdefault(None, []).append(f) | <mask> ``after_request`` functions will not be called. Therefore, this
<mask> should not be used for actions that must execute, such as to
<mask> close resources. Use :meth:`teardown_request` for that.
<mask> """
<mask> self.after_request_funcs.setdefault(None, []).append(se... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/scaffold.py |
self.teardown_request_funcs.setdefault(None, []).append(f) | <mask> immediately. Instead it will keep it alive so that the interactive
<mask> debugger can still access it. This behavior can be controlled
<mask> by the ``PRESERVE_CONTEXT_ON_EXCEPTION`` configuration variable.
<mask> """
<mask> self.teardown_request_funcs.set... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/scaffold.py |
self.error_handler_spec[None][code][exc_class] = f | <mask> " code. Use a subclass of HTTPException with that code"
<mask> " instead."
<mask> )
<mask>
<mask> self.error_handler_spec[None][code][exc_class] = self.ensure_sync(f)
<mask>
<mask> @staticmethod
<mask> def _get_exc_class_and_code(
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/scaffold.py |
<mask> return exc_class, exc_class.code
<mask> else:
<mask> return exc_class, None
<mask>
<mask> def ensure_sync(self, func: t.Callable) -> t.Callable:
<mask> raise NotImplementedError()
<mask>
<mask>
<mask> def _endpoint_from_view_func(view_func: t.Callable) -> s... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | src/flask/scaffold.py | |
from flask.helpers import async_to_sync | <mask>
<mask> from flask import Blueprint
<mask> from flask import Flask
<mask> from flask import request
<mask> from flask.helpers import run_async
<mask>
<mask> pytest.importorskip("asgiref")
<mask>
<mask>
<mask> class AppError(Exception):
</s> Simplify the async handling code
Firstly `run_sync` was a... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | tests/test_async.py |
async_to_sync(None) | <mask>
<mask> @pytest.mark.skipif(sys.version_info >= (3, 7), reason="should only raise Python < 3.7")
<mask> def test_async_runtime_error():
<mask> with pytest.raises(RuntimeError):
<mask> run_async(None)
</s> Simplify the async handling code
Firstly `run_sync` was a misleading name as it didn't ru... | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/pallets/flask/commit/7f87f3dd93baf45d5f69f02a2dcf4493dfc4a1be | tests/test_async.py |
$ export MAIL_ENABLED=false | <mask> Environment variables can be set on Linux or OS X with the export command in
<mask> the shell before starting the server::
<mask>
<mask> $ export SECRET_KEY='5f352379324c22463451387a0aec5d2f'
<mask> $ export DEBUG=False
<mask> $ python run-app.py
<mask> * Running on http://127.0.0.1:5000... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst |
<mask> $ export SECRET_KEY='5f352379324c22463451387a0aec5d2f'
<mask> $ export DEBUG=False
<mask> $ python run-app.py
<mask> * Running on http://127.0.0.1:5000/
<mask> * Restarting with reloader...
<mask>
<mask> On Windows systems use the `set` builtin instead::
<mask>
<mask> >set SE... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst | |
On Windows systems use the ``set`` builtin instead:: | <mask> $ python run-app.py
<mask> * Running on http://127.0.0.1:5000/
<mask> * Restarting with reloader...
<mask>
<mask> On Windows systems use the `set` builtin instead::
<mask>
<mask> >set SECRET_KEY='5f352379324c22463451387a0aec5d2f'
<mask> >set DEBUG=False
<mask>
<mask> While this... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst |
<mask>
<mask> On Windows systems use the `set` builtin instead::
<mask>
<mask> >set SECRET_KEY='5f352379324c22463451387a0aec5d2f'
<mask> >set DEBUG=False
<mask>
<mask> While this approach is straightforward to use, it is important to remember that
<mask> environment variables are strings -- they are ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst | |
<mask> into Python types.
<mask>
<mask> Here is an example of a configuration file that uses environment variables::
<mask>
<mask> # Example configuration
<mask> import os
<mask>
<mask> ENVIRONMENT_DEBUG = os.environ.get("DEBUG", default=False)
<mask> if ENVIRONMENT_DEBUG.lower() in ("f", "f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst | |
_mail_enabled = os.environ.get("MAIL_ENABLED", default="true")
MAIL_ENABLED = _mail_enabled.lower() in {"1", "t", "true"}
SECRET_KEY = os.environ.get("SECRET_KEY") | <mask>
<mask> # Example configuration
<mask> import os
<mask>
<mask> ENVIRONMENT_DEBUG = os.environ.get("DEBUG", default=False)
<mask> if ENVIRONMENT_DEBUG.lower() in ("f", "false"):
<mask> ENVIRONMENT_DEBUG = False
<mask>
<mask> DEBUG = ENVIRONMENT_DEBUG
<mask> SECRET_KEY =... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst |
<mask> ENVIRONMENT_DEBUG = os.environ.get("DEBUG", default=False)
<mask> if ENVIRONMENT_DEBUG.lower() in ("f", "false"):
<mask> ENVIRONMENT_DEBUG = False
<mask>
<mask> DEBUG = ENVIRONMENT_DEBUG
<mask> SECRET_KEY = os.environ.get("SECRET_KEY", default=None)
<mask> if not SECRET_KEY:
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst | |
raise ValueError("No SECRET_KEY set for Flask application") | <mask>
<mask> DEBUG = ENVIRONMENT_DEBUG
<mask> SECRET_KEY = os.environ.get("SECRET_KEY", default=None)
<mask> if not SECRET_KEY:
<mask> raise ValueError("No secret key set for Flask application")
<mask>
<mask>
<mask> Notice that any value besides an empty string will be interpreted as a b... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/800c744fe7236175cbf0bbbc1a152899897579df | docs/config.rst |
# Module already imported and has a file attribute. Use that first.
mod = sys.modules.get(import_name)
if mod is not None and hasattr(mod, '__file__'):
return os.path.dirname(os.path.abspath(mod.__file__))
# Next attempt: check the loader. | <mask> Not to be confused with the package path returned by :func:`find_package`.
<mask> """
<mask> loader = pkgutil.get_loader(import_name)
<mask>
<mask> # Loader does not exist or we're referring to an unloaded main module
<mask> # or a main module without path (interactive sessions), go wi... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8071f11328ab2b767608c5c63d0bad72d9408120 | flask/helpers.py |
# Loader does not exist or we're referring to an unloaded main module
# or a main module without path (interactive sessions), go with the
# current working directory. | <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> if loader is None or import_name == '__main__':
<mask> return os.getcwd()
<mask>
<mask> # For .egg, zipimporter do... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8071f11328ab2b767608c5c63d0bad72d9408120 | flask/helpers.py |
<mask> Not to be confused with the package path returned by :func:`find_package`.
<mask> """
<mask> loader = pkgutil.get_loader(import_name)
<mask> if loader is None or import_name == '__main__':
<mask> # import name is not found, or interactive/main module
<mask> return os.getcwd(... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8071f11328ab2b767608c5c63d0bad72d9408120 | flask/helpers.py | |
# Some other loaders might exhibit the same behavior. | <mask> if loader is None or import_name == '__main__':
<mask> return os.getcwd()
<mask>
<mask> # For .egg, zipimporter does not have get_filename until Python 2.7.
<mask> if hasattr(loader, 'get_filename'):
<mask> filepath = loader.get_filename(import_name)
<mask> else:
<mask> ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8071f11328ab2b767608c5c63d0bad72d9408120 | flask/helpers.py |
It's similar to a folder in a file system. If you access ``/projects`` - the URL without | <mask> def about():
<mask> return 'The about page'
<mask>
<mask> The canonical URL for the ``projects`` endpoint has a trailing slash.
<mask> It's similar to a folder in a file system. If you access the URL without
<mask> a trailing slash, Flask redirects you to the canonical URL with the
<mask> tra... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8074cbdc470494a6f20cf08f8831dc4ae388d7f6 | docs/quickstart.rst |
trailing slash - ``/projects/``. | <mask>
<mask> The canonical URL for the ``projects`` endpoint has a trailing slash.
<mask> It's similar to a folder in a file system. If you access the URL without
<mask> a trailing slash, Flask redirects you to the canonical URL with the
<mask> trailing slash.
<mask>
<mask> The canonical URL for the ``about``... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8074cbdc470494a6f20cf08f8831dc4ae388d7f6 | docs/quickstart.rst |
slash. It's similar to the pathname of a file. Accessing ``/about/`` - the URL with a | <mask> a trailing slash, Flask redirects you to the canonical URL with the
<mask> trailing slash.
<mask>
<mask> The canonical URL for the ``about`` endpoint does not have a trailing
<mask> slash. It's similar to the pathname of a file. Accessing the URL with a
<mask> trailing slash produces a 404 "Not Found" err... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8074cbdc470494a6f20cf08f8831dc4ae388d7f6 | docs/quickstart.rst |
cli.show_server_banner(self.env, self.debug, self.name, False) | <mask> options.setdefault('use_reloader', self.debug)
<mask> options.setdefault('use_debugger', self.debug)
<mask> options.setdefault('threaded', True)
<mask>
<mask> cli.show_server_banner(self.env, self.debug, self.name)
<mask>
<mask> from werkzeug.serving import run_si... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/80a9e0edf6208b3c1c9bc28bfb1a5f04b1f59e1d | flask/app.py |
def show_server_banner(env, debug, app_import_path, eager_loading): | <mask>
<mask> return new_dir is not None # at least one file was located and loaded
<mask>
<mask>
<mask> def show_server_banner(env, debug, app_import_path, eager_loading=True):
<mask> """Show extra startup messages the first time the server is run,
<mask> ignoring the reloader.
<mask> """
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/80a9e0edf6208b3c1c9bc28bfb1a5f04b1f59e1d | flask/cli.py |
<mask> if app_import_path is not None:
<mask> message = ' * Serving Flask app "{0}"'.format(app_import_path)
<mask> if not eager_loading:
<mask> message += ' (lazy loading)'
<mask> print(message)
<mask>
<mask> print(' * Environment: {0}'.format(env))
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/80a9e0edf6208b3c1c9bc28bfb1a5f04b1f59e1d | flask/cli.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.