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 |
|---|---|---|---|---|
<mask> import sys
<mask> import flask
<mask> import unittest
<mask> import tempfile
<mask> import warnings
<mask> from datetime import datetime
<mask> from werkzeug import parse_date
<mask>
<mask>
<mask> example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')
</s> Fix typo, remove useless ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py | |
assert not rv.data # head truncates | <mask> assert rv.status_code == 405
<mask> assert sorted(rv.allow) == ['GET', 'HEAD']
<mask> rv = c.head('/')
<mask> assert rv.status_code == 200
<mask> assert not rv.data # head truncates
<mask> assert c.post('/more').data == 'POST'
<mask> assert c.get('/m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
assert not rv.data # head truncates | <mask> assert rv.status_code == 405
<mask> assert sorted(rv.allow) == ['GET', 'HEAD']
<mask> rv = c.head('/')
<mask> assert rv.status_code == 200
<mask> assert not rv.data # head truncates
<mask> assert c.post('/more').data == 'POST'
<mask> assert c.get('/m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
1 // 0 | <mask> def index():
<mask> flask.abort(404)
<mask> @app.route('/error')
<mask> def error():
<mask> 1/0
<mask> c = app.test_client()
<mask> rv = c.get('/')
<mask> assert rv.status_code == 404
<mask> assert rv.data == 'not found'
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
base_to_url = super(ListConverter, self).to_url
return ','.join(base_to_url(x) for x in value) | <mask> class ListConverter(BaseConverter):
<mask> def to_python(self, value):
<mask> return value.split(',')
<mask> def to_url(self, value):
<mask> return ','.join(super(ListConverter, self).to_url(x) for x in value)
<mask> app = flask.Flask(... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
render = flask.render_template_string | <mask> def test_template_escaping(self):
<mask> app = flask.Flask(__name__)
<mask> with app.test_request_context():
<mask> rv = render('{{ "</script>"|tojson|safe }}')
<mask> assert rv == '"<\\/script>"'
<mask> rv = render('{{ "<\0/script>"|tojson|safe }}')
... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
rv = render('{{ "</script>"|tojson|safe }}') | <mask>
<mask> def test_template_escaping(self):
<mask> app = flask.Flask(__name__)
<mask> with app.test_request_context():
<mask> rv = flask.render_template_string('{{ "</script>"|tojson|safe }}')
<mask> assert rv == '"<\\/script>"'
<mask> rv = flask.rende... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
rv = render('{{ "<\0/script>"|tojson|safe }}') | <mask> app = flask.Flask(__name__)
<mask> with app.test_request_context():
<mask> rv = flask.render_template_string('{{ "</script>"|tojson|safe }}')
<mask> assert rv == '"<\\/script>"'
<mask> rv = flask.render_template_string('{{ "<\0/script>"|tojson|safe }}')
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/67fc46526234653b0a519e9f1e8a05a2c40c80f8 | tests/flask_tests.py |
automatically remove database sessions at the end of the request or
when the application shuts down:: | <mask> already with the :class:`~sqlalchemy.orm.scoped_session`.
<mask>
<mask> To use SQLAlchemy in a declarative way with your application, you just
<mask> have to put the following code into your application module. Flask will
<mask> automatically remove database sessions at the end of the request for you::
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/681cb8f366d8253360805ba58321871bfe3fc959 | docs/patterns/sqlalchemy.rst |
@app.teardown_appcontext | <mask> automatically remove database sessions at the end of the request for you::
<mask>
<mask> from yourapplication.database import db_session
<mask>
<mask> @app.teardown_request
<mask> def shutdown_session(exception=None):
<mask> db_session.remove()
<mask>
<mask> Here is an example mod... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/681cb8f366d8253360805ba58321871bfe3fc959 | docs/patterns/sqlalchemy.rst |
each request or application context shutdown. Put this into your
application module:: | <mask> def init_db():
<mask> metadata.create_all(bind=engine)
<mask>
<mask> As for the declarative approach you need to close the session after
<mask> each request. Put this into your application module::
<mask>
<mask> from yourapplication.database import db_session
<mask>
<mask> @app.t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/681cb8f366d8253360805ba58321871bfe3fc959 | docs/patterns/sqlalchemy.rst |
@app.teardown_appcontext | <mask> each request. Put this into your application module::
<mask>
<mask> from yourapplication.database import db_session
<mask>
<mask> @app.teardown_request
<mask> def shutdown_session(exception=None):
<mask> db_session.remove()
<mask>
<mask> Here is an example table and model (put th... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/681cb8f366d8253360805ba58321871bfe3fc959 | docs/patterns/sqlalchemy.rst |
class ConfigAttribute(object):
"""Makes an attribute forward to the config"""
def __init__(self, name):
self.__name__ = name
def __get__(self, obj, type=None):
if obj is None:
return self
return obj.config[self.__name__]
def __set__(self, obj, value):
obj.c... | <mask>
<mask>
<mask> class Flask(_PackageBoundObject):
<mask> """The flask object implements a WSGI application and acts as the central
<mask> object. It is passed the name of the module or package of the
<mask> application. Once it is created it will act as a central registry for
<mask> the ... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
#: the debug flag. Set this to `True` to enable debugging of the
#: application. In debug mode the debugger will kick in when an unhandled
#: exception ocurrs and the integrated server will automatically reload
#: the application if changes in the code are detected.
debug = ConfigAttribute('debug'... | <mask> #: you can set this value to `None` in which case no URL rule is added
<mask> #: and the development server will no longer serve any static files.
<mask> static_path = '/static'
<mask>
<mask> #: if a secret key is set, cryptographic components can use this to
<mask> #: sign cookies and... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
secret_key = ConfigAttribute('secret_key') | <mask>
<mask> #: if a secret key is set, cryptographic components can use this to
<mask> #: sign cookies and other things. Set this to a complex random value
<mask> #: when you want to use the secure cookie for instance.
<mask> secret_key = None
<mask>
<mask> #: The secure cookie uses this... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
session_cookie_name = ConfigAttribute('session.cookie_name') | <mask> #: when you want to use the secure cookie for instance.
<mask> secret_key = None
<mask>
<mask> #: The secure cookie uses this for the name of the session cookie
<mask> session_cookie_name = 'session'
<mask>
<mask> #: A :class:`~datetime.timedelta` which is used to set the expiration
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
permanent_session_lifetime = ConfigAttribute('session.permanent_lifetime') | <mask>
<mask> #: A :class:`~datetime.timedelta` which is used to set the expiration
<mask> #: date of a permanent session. The default is 31 days which makes a
<mask> #: permanent session survive for roughly one month.
<mask> permanent_session_lifetime = timedelta(days=31)
<mask>
<mask> #:... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
use_x_sendfile = ConfigAttribute('use_x_sendfile') | <mask> #: mind that the server has to support this. This only affects files
<mask> #: sent with the :func:`send_file` method.
<mask> #:
<mask> #: .. versionadded:: 0.2
<mask> use_x_sendfile = False
<mask>
<mask> #: the logging format used for the debug logger. This is only used when
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
#: default configuration parameters
default_config = ImmutableDict({
'debug': False,
'secret_key': None,
'session.cookie_name': 'session',
'session.permanent_lifetime': timedelta(days=31),
... | <mask> autoescape=True,
<mask> extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']
<mask> )
<mask>
<mask> def __init__(self, import_name):
<mask> _PackageBoundObject.__init__(self, import_name)
<mask>
<mask> #: the debug flag. Set this to `True` to enable debuggin... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
#: the configuration dictionary
self.config = self.default_config.copy()
if config:
self.config.update(config) | <mask>
<mask> def __init__(self, import_name):
<mask> _PackageBoundObject.__init__(self, import_name)
<mask>
<mask> #: the debug flag. Set this to `True` to enable debugging of
<mask> #: the application. In debug mode the debugger will kick in
<mask> #: when an unhandled e... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68278fd78e15e3ef6a591f3f2b6cc700d1e4d6dd | flask.py |
from werkzeug.routing import Map, Rule, RequestRedirect | <mask> from itertools import chain
<mask> from functools import update_wrapper
<mask>
<mask> from werkzeug.datastructures import ImmutableDict
<mask> from werkzeug.routing import Map, Rule
<mask> from werkzeug.exceptions import HTTPException, InternalServerError, \
<mask> MethodNotAllowed, BadRequest
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68473291344629dff3955fdc07776f2fca7b9b69 | flask/app.py |
def raise_routing_exception(self, request):
"""Exceptions that are recording during routing are reraised with
this method. During debug we are not reraising redirect requests
for non ``GET``, ``HEAD``, or ``OPTIONS`` requests and we're raising
a different error instead to help debug... | <mask> return InternalServerError()
<mask> return handler(e)
<mask>
<mask> def dispatch_request(self):
<mask> """Does the request dispatching. Matches the URL and returns the
<mask> return value of the view or error handler. This does not have to
<mask> be a res... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68473291344629dff3955fdc07776f2fca7b9b69 | flask/app.py |
self.raise_routing_exception(req) | <mask> moved to the new :meth:`full_dispatch_request`.
<mask> """
<mask> req = _request_ctx_stack.top.request
<mask> if req.routing_exception is not None:
<mask> raise req.routing_exception
<mask> rule = req.url_rule
<mask> # if we provide automatic ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/68473291344629dff3955fdc07776f2fca7b9b69 | flask/app.py |
combining existing libraries - there is not a lot of code involved. | <mask>
<mask> Flask is powered by Werkzeug and Jinja2, two libraries that are in use at
<mask> a number of large websites out there and all Flask does is bring those
<mask> two together. Being a microframework Flask does not do much more than
<mask> combinding existing libraries - there is not a lot of code invo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/becomingbig.rst |
subdomain support (e.g.: ``'localhost'``) | <mask> :class:`datetime.timedelta` object.
<mask> ``USE_X_SENDFILE`` enable/disable x-sendfile
<mask> ``LOGGER_NAME`` the name of the logger
<mask> ``SERVER_NAME`` the name of the server. Required for
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/config.rst |
configurations separately to the production server(s). For some | <mask> code at all. If you are working often on different projects you can
<mask> even create your own script for sourcing that activates a virtualenv
<mask> and exports the development configuration for you.
<mask> - Use a tool like `fabric`_ in production to push code and
<mask> configurations... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/config.rst |
`.cgi` into a `cgi-bin` (and use `mod_rewrite` or something similar to | <mask> Server Setup
<mask> ------------
<mask>
<mask> Usually there are two ways to configure the server. Either just copy the
<mask> `.cgi` into a `cgi-bin` (and use `mod_rerwite` or something similar to
<mask> rewrite the URL) or let the server point to the file directly.
<mask>
<mask> In Apache for exampl... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/deploying/cgi.rst |
File "yourapplication.fcgi", line 4, in <module> | <mask> $ su www-data
<mask> $ cd /var/www/yourapplication
<mask> $ python application.fcgi
<mask> Traceback (most recent call last):
<mask> File "yourapplication.fcg", line 4, in <module>
<mask> ImportError: No module named yourapplication
<mask>
<mask> In this case the error seems to... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/deploying/fastcgi.rst |
Troubleshooting
--------------- | <mask> .. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide
<mask> .. _virtual python: http://pypi.python.org/pypi/virtualenv
<mask> .. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/
<mask>
<mask> Toubleshooting
<mask> --------------
<mask>
<mask> If your applica... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/deploying/mod_wsgi.rst |
but you might want to write your own WSGI middleware for specific setups. | <mask> If you deploy your application behind an HTTP proxy you will need to
<mask> rewrite a few headers in order for the application to work. The two
<mask> problematic values in the WSGI environment usually are `REMOTE_ADDR` and
<mask> `HTTP_HOST`. Werkzeug ships a fixer that will solve some common setups,
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/deploying/others.rst |
and the remote address from `X-Forward-For`:: | <mask> `HTTP_HOST`. Werkzeug ships a fixer that will solve some common setups,
<mask> but you might want to write your own WSGI middlware for specific setups.
<mask>
<mask> The most common setup invokes the host being set from `X-Forwarded-Host`
<mask> and the remote address from `X-Forwared-For`::
<mask>
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/deploying/others.rst |
called ``init_helloworld(app[, extra_args])`` that initializes the | <mask> There are two recommended ways for an extension to initialize:
<mask>
<mask> initialization functions:
<mask> If your extension is called `helloworld` you might have a function
<mask> called ``init_helloworld(app[, extra_args])`` that initalizes the
<mask> extension for that application. It c... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/extensiondev.rst |
Furthermore you must not use the names of the authors to promote derivatives | <mask>
<mask> Flask is licensed under a three clause BSD License. It basically means:
<mask> do whatever you want with it as long as the copyright in Flask sticks
<mask> around, the conditions are not modified and the disclaimer is present.
<mask> Furthermore you must not use the names of the authors to promote ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/license.rst |
looking for was deleted for all eternity. | <mask> resources that previously existed and got deleted answer with 410
<mask> instead of 404. If you are not deleting documents permanently from
<mask> the database but just mark them as deleted, do the user a favour and
<mask> use the 410 code instead and display a message that what he was
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/errorpages.rst |
are not able to upload HTML files that would cause XSS problems (see
:ref:`xss`). Also make sure to disallow `.php` files if the server
executes them, but who has PHP installed on his server, right? :) | <mask>
<mask> Why do we limit the extensions that are allowed? You probably don't want
<mask> your users to be able to upload everything there if the server is directly
<mask> sending out the data to the client. That way you can make sure that users
<mask> are not able to upload HTML files that would cause XSS ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/fileuploads.rst |
flash('You were successfully logged in') | <mask> if request.form['username'] != 'admin' or \
<mask> request.form['password'] != 'secret':
<mask> error = 'Invalid credentials'
<mask> else:
<mask> flash('You were sucessfully logged in')
<mask> return redirect(url_for('in... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/flashing.rst |
categories. The loop looks slightly different in that situation then: | <mask> flash(u'Invalid password provided', 'error')
<mask>
<mask> Inside the template you then have to tell the
<mask> :func:`~flask.get_flashed_messages` function to also return the
<mask> categories. The loop looks slighty different in that situation then:
<mask>
<mask> .. sourcecode:: html+jinja
<mask... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/flashing.rst |
to be in a file that is imported upfront to work properly on the first | <mask> url('/', 'views.index')
<mask> url('/user/<username>', 'views.user')
<mask>
<mask> One thing to keep in mind is that before and after request handlers have
<mask> to be in a file that is imported upfront to work propery on the first
<mask> request. The same goes for any kind of remaining decorato... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/lazyloading.rst |
separate between attributes. | <mask> validator for the maximum character length and uses a special MongoKit feature
<mask> called `use_dot_notation`. Per default MongoKit behaves like a python
<mask> dictionary but with `use_dot_notation` set to `True` you can use your
<mask> documents like you use models in nearly any other ORM by using dots ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/mongokit.rst |
the SQL statement with string formatting because this makes it possible | <mask> print the_username, 'has the id', user['user_id']
<mask>
<mask> To pass variable parts to the SQL statement, use a question mark in the
<mask> statement and pass in the arguments as a list. Never directly add them to
<mask> the SQL statement with string formattings because this makes it possible
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/sqlite3.rst |
Notice that this assumes an instantiated `cache` object is available, see | <mask> return rv
<mask> return decorated_function
<mask> return decorator
<mask>
<mask> Notice that this assumes an instanciated `cache` object is available, see
<mask> :ref:`caching-pattern` for more information.
<mask>
<mask>
<mask> Templating Decorator
<mask> --------... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/patterns/viewdecorators.rst |
(e.g.: ``-``, ``~`` etc.) as well on the inner side of parentheses. | <mask> --------------------------
<mask>
<mask> General whitespace rules:
<mask> - No whitespace for unary operators that are not words
<mask> (eg: ``-``, ``~`` etc.) as well on the inner side of parentheses.
<mask> - Whitespace is placed between binary operators.
<mask>
<mask> Good::
<mask>
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/styleguide.rst |
laid out differently. If it's just one line, the closing triple | <mask>
<mask> Docstring conventions:
<mask> All docstrings are formatted with reStructuredText as understood by
<mask> Sphinx. Depending on the number of lines in the docstring, they are
<mask> layed out differently. If it's just one line, the closing triple
<mask> quote is on the same line as the open... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/styleguide.rst |
that it spans three lines. In this case the closing triple quote | <mask>
<mask>
<mask> def bar():
<mask> """This is a longer docstring with so much information in there
<mask> that it spans three lines. In this case the closing tripple quote
<mask> is on its own line.
<mask> """
<mask>
<mask> Module header:
<mask> The module header ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/styleguide.rst |
Whenever you do this, please be very cautious about the variables you are | <mask> <p>autoescaping is disabled here
<mask> <p>{{ will_not_be_escaped }}
<mask> {% endautoescape %}
<mask>
<mask> Whenever you do this, please be very cautious about the varibles you are
<mask> using in this block.
<mask>
<mask> Registering Filters
<mask> -------------------
<mask>
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/templating.rst |
Want your server to be publicly available? Check out the | <mask> focus on that a little later. First we should get the database working.
<mask>
<mask> .. admonition:: Externally Visible Server
<mask>
<mask> Want your server to be publically available? Check out the
<mask> :ref:`externally visible server <public-server>` section for more
<mask> information.... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/tutorial/setup.rst |
depend on the order of execution of post-request functions, be sure to | <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 and
<mask> how other systems handle request pre- and postprocessing. If you
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6875a057ec97fb17927b951cd1e5baeef2cf81d8 | docs/upgrading.rst |
- Support async views, error handlers, before and after request, and
teardown functions. :pr:`3412` | <mask> - Use Jinja's implementation of the ``|tojson`` filter. :issue:`3881`
<mask> - Add route decorators for common HTTP methods. For example,
<mask> ``@app.post("/login")`` is a shortcut for
<mask> ``@app.route("/login", methods=["POST"])``. :pr:`3907`
<mask>
<mask>
<mask> Version 1.1.2
<mask> ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | CHANGES.rst |
Async-await and ASGI support
----------------------------
Flask supports ``async`` coroutines for view functions, and certain
others by executing the coroutine on a seperate thread instead of
utilising an event loop on the main thread as an async first (ASGI)
frameworks would. This is necessary for Flask to remain bac... | <mask> Also see the :doc:`/becomingbig` section of the documentation for some
<mask> inspiration for larger applications based on Flask.
<mask>
<mask>
<mask> What Flask is, What Flask is Not
<mask> --------------------------------
<mask>
<mask> Flask will never have a database layer. It will not have a form... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | docs/design.rst |
async_await | <mask> shell
<mask> patterns/index
<mask> deploying/index
<mask> becomingbig
<mask>
<mask>
<mask> API Reference
<mask> -------------
<mask>
<mask> If you are looking for information on a specific function, class or
</s> Add `async` support
This allows for async functions to be passed to the F... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | docs/index.rst |
asgiref | <mask> pytest
<mask> blinker
<mask> greenlet
<mask> python-dotenv
</s> Add `async` support
This allows for async functions to be passed to the Flask class
instance, for example as a view function,
@app.route("/")
async def index():
return "Async hello"
this comes with a cost though of poorer per... | [
"add",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | requirements/tests.in |
asgiref==3.2.10
# via -r requirements/tests.in | <mask> #
<mask> # pip-compile requirements/tests.in
<mask> #
<mask> attrs==20.3.0
<mask> # via pytest
<mask> blinker==1.4
<mask> # via -r requirements/tests.in
<mask> greenlet==1.0.0
</s> Add `async` support
This allows for async functions to be passed to the Flask class
instance, for example as a ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | requirements/tests.txt |
extras_require={
"async": ["asgiref>=3.2"],
"dotenv": ["python-dotenv"],
}, | <mask> "Jinja2>=2.10.1",
<mask> "itsdangerous>=0.24",
<mask> "click>=5.1",
<mask> ],
<mask> extras_require={"dotenv": ["python-dotenv"]},
<mask> )
</s> Add `async` support
This allows for async functions to be passed to the Flask class
instance, for example as a view function,
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | setup.py |
self.view_functions[endpoint] = self.ensure_sync(view_func) | <mask> raise AssertionError(
<mask> "View function mapping is overwriting an existing"
<mask> f" endpoint function: {endpoint}"
<mask> )
<mask> self.view_functions[endpoint] = view_func
<mask>
<mask> @setupmethod
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | src/flask/app.py |
self.before_first_request_funcs.append(self.ensure_sync(f)) | <mask> value is ignored.
<mask>
<mask> .. versionadded:: 0.8
<mask> """
<mask> self.before_first_request_funcs.append(f)
<mask> return f
<mask>
<mask> @setupmethod
<mask> def teardown_appcontext(self, f):
<mask> """Registers a function to be called whe... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | src/flask/app.py |
self.teardown_appcontext_funcs.append(self.ensure_sync(f)) | <mask> The return values of teardown functions are ignored.
<mask>
<mask> .. versionadded:: 0.9
<mask> """
<mask> self.teardown_appcontext_funcs.append(f)
<mask> return f
<mask>
<mask> @setupmethod
<mask> def shell_context_processor(self, f):
<mask> ""... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | src/flask/app.py |
from functools import wraps | <mask> import socket
<mask> import warnings
<mask> from functools import update_wrapper
<mask> from threading import RLock
<mask>
<mask> import werkzeug.utils
<mask> from werkzeug.exceptions import NotFound
<mask> from werkzeug.routing import BuildError
</s> Add `async` support
This allows for async function... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6979265fa643ed982d062f38d386c37bbbef0d9b | src/flask/helpers.py |
<mask> import os
<mask> import sys
<mask> from threading import Lock
<mask> from datetime import timedelta
<mask> from itertools import chain
<mask> from functools import update_wrapper
<mask>
<mask> from werkzeug.datastructures import ImmutableDict
<mask> from werkzeug.routing import Map, Rule, RequestRedire... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py | |
from itertools import chain
from threading import Lock | <mask> from datetime import timedelta
<mask> from functools import update_wrapper
<mask>
<mask> from werkzeug.datastructures import ImmutableDict, Headers
<mask> from werkzeug.exceptions import BadRequest, HTTPException, \
<mask> InternalServerError, MethodNotAllowed, default_exceptions
<mask> from werkzeug... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
from werkzeug.datastructures import ImmutableDict, Headers
from werkzeug.exceptions import BadRequest, HTTPException, \
InternalServerError, MethodNotAllowed, default_exceptions
from werkzeug.routing import BuildError, Map, RequestRedirect, Rule
from . import cli, json
from ._compat import integer_types, reraise, ... | <mask> from datetime import timedelta
<mask> from itertools import chain
<mask> from functools import update_wrapper
<mask>
<mask> from werkzeug.datastructures import ImmutableDict
<mask> from werkzeug.routing import Map, Rule, RequestRedirect, BuildError
<mask> from werkzeug.exceptions import HTTPException, In... | [
"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/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
from .signals import appcontext_tearing_down, got_request_exception, \
request_finished, request_started, request_tearing_down | <mask> from .helpers import _PackageBoundObject, \
<mask> _endpoint_from_view_func, find_package, get_debug_flag, \
<mask> get_flashed_messages, locked_cached_property, url_for
<mask> from .sessions import SecureCookieSessionInterface
<mask> from .templating import DispatchingJinjaLoader, Environment, \
<... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
_default_template_ctx_processor
from .wrappers import Request, Response | <mask> from .ctx import RequestContext, AppContext, _AppCtxGlobals
<mask> from .globals import _request_ctx_stack, request, session, g
<mask> from .sessions import SecureCookieSessionInterface
<mask> from .templating import DispatchingJinjaLoader, Environment, \
<mask> _default_template_ctx_processor
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
"""Convert the return value from a view function to an instance of
:attr:`response_class`.
:param rv: the return value from the view function. The view function
must return a response. Returning ``None``, or the view ending
without returning, is not allowed. The followin... | <mask> """
<mask> return False
<mask>
<mask> def make_response(self, rv):
<mask> """Converts the return value from a view function to a real
<mask> response object that is an instance of :attr:`response_class`.
<mask>
<mask> The following types are allowed for `rv`:... | [
"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/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
<mask> .. versionchanged:: 0.9
<mask> Previously a tuple was interpreted as the arguments for the
<mask> response object.
<mask> """
<mask> status_or_headers = headers = None
<mask> if isinstance(rv, tuple):
<mask> rv, status_or_headers, headers =... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py | |
status = headers = None
# unpack tuple returns
if isinstance(rv, (tuple, list)):
len_rv = len(rv) | <mask> status_or_headers = headers = None
<mask> if isinstance(rv, tuple):
<mask> rv, status_or_headers, headers = rv + (None,) * (3 - len(rv))
<mask>
<mask> if rv is None:
<mask> raise ValueError('View function did not return a response')
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
# a 3-tuple is unpacked directly
if len_rv == 3:
rv, status, headers = rv
# decide if a 2-tuple has status or headers
elif len_rv == 2:
if isinstance(rv[1], (Headers, dict, tuple, list)):
rv, headers = rv
... | <mask>
<mask> if rv is None:
<mask> raise ValueError('View function did not return a response')
<mask>
<mask> if isinstance(status_or_headers, (dict, list)):
<mask> headers, status_or_headers = status_or_headers, None
<mask>
<mask> if not isinstance(rv, self.re... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
# the body must not be None
if rv is None:
raise TypeError(
'The view function did not return a valid response. The'
' function either returned None or ended without a return'
' statement.'
)
# make sure the body is an inst... | <mask> ' (body, status), or (body, headers).'
<mask> )
<mask>
<mask> if not isinstance(rv, self.response_class):
<mask> if isinstance(rv, (text_type, bytes, bytearray)):
<mask> # let the response class set the status and headers instead of
... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
<mask> if isinstance(status_or_headers, (dict, list)):
<mask> headers, status_or_headers = status_or_headers, None
<mask>
<mask> if not isinstance(rv, self.response_class):
<mask> # When we create a response object directly, we let the constructor
<mask> # set ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py | |
# let the response class set the status and headers instead of
# waiting to do it manually, so that the class can handle any
# special logic
rv = self.response_class(rv, status=status, headers=headers)
status = headers = None | <mask> # set the headers and status. We do this because there can be
<mask> # some extra logic involved when creating these objects with
<mask> # specific values (like default content type selection).
<mask> if isinstance(rv, (text_type, bytes, bytearray)):
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
# evaluate a WSGI callable, or coerce a different response
# class to the correct type
try:
rv = self.response_class.force_type(rv, request.environ)
except TypeError as e:
new_error = TypeError(
... | <mask> rv = self.response_class(rv, headers=headers,
<mask> status=status_or_headers)
<mask> headers = status_or_headers = None
<mask> else:
<mask> rv = self.response_class.force_type(rv, request.environ)
<mask>
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
rv.status_code = status
# extend existing headers with provided headers | <mask> if status_or_headers is not None:
<mask> if isinstance(status_or_headers, string_types):
<mask> rv.status = status_or_headers
<mask> else:
<mask> rv.status_code = status_or_headers
<mask> if headers:
<mask> rv.headers.exte... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | flask/app.py |
@app.route('/text_headers')
def from_text_headers(): | <mask> 'X-Foo': 'Testing',
<mask> 'Content-Type': 'text/plain; charset=utf-8'
<mask> }
<mask>
<mask> @app.route('/two_args')
<mask> def from_two_args_tuple():
<mask> return 'Hello', {
<mask> 'X-Foo': 'Test',
<mask> 'Content-Type': 'text/p... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | tests/test_basic.py |
@app.route('/text_status')
def from_text_status(): | <mask> 'X-Foo': 'Test',
<mask> 'Content-Type': 'text/plain; charset=utf-8'
<mask> }
<mask>
<mask> @app.route('/args_status')
<mask> def from_status_tuple():
<mask> return 'Hi, status!', 400
<mask>
<mask> @app.route('/args_header')
<mask> def from_respo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | tests/test_basic.py |
@app.route('/response_headers')
def from_response_headers():
return flask.Response('Hello world', 404, {'X-Foo': 'Baz'}), { | <mask> @app.route('/args_status')
<mask> def from_status_tuple():
<mask> return 'Hi, status!', 400
<mask>
<mask> @app.route('/args_header')
<mask> def from_response_instance_status_tuple():
<mask> return flask.Response('Hello world', 404), {
<mask> "X-Foo": "Bar",
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/697f7b9365304c45216e6c8dd307d931ea1506d0 | tests/test_basic.py |
rv = c.get('/text_headers')
assert rv.data == b'Hello'
assert rv.headers['X-Foo'] == 'Test'
assert rv.status_code == 200
assert rv.mimetype == 'text/plain'
rv = c.get('/text_status')
assert rv.data == b'Hi, status!'
assert rv.status_code == 400
assert rv.mimetype == 'text/html'
... | <mask> assert rv.data == b'Meh'
<mask> assert rv.headers['X-Foo'] == 'Testing'
<mask> assert rv.status_code == 400
<mask> assert rv.mimetype == 'text/plain'
<mask> rv2 = c.get('/two_args')
<mask> assert rv2.data == b'Hello'
<mask> assert rv2.headers['X-Foo'] == 'Test'
<mask> asse... | [
"keep",
"keep",
"keep",
"keep",
"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/697f7b9365304c45216e6c8dd307d931ea1506d0 | tests/test_basic.py |
<mask> # Providing host_matching=True without static_host but with static_folder=None should not error.
<mask> flask.Flask(__name__, host_matching=True, static_folder=None)
<mask>
<mask>
<mask> def test_none_response():
<mask> app = flask.Flask(__name__)
<mask> app.testing = True
<mask>
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"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/697f7b9365304c45216e6c8dd307d931ea1506d0 | tests/test_basic.py | |
- ``flask.url_for`` will call ``app.url_for``. :issue:`4568` | <mask> previously global behaviors.
<mask>
<mask> - ``flask.abort`` will call ``app.aborter``.
<mask> ``Flask.aborter_class`` and ``Flask.make_aborter`` can be used
<mask> to customize this aborter. :issue:`4567`
<mask> - ``flask.redirect`` will call ``app.redirect``. :issue:`4569... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/69e2300608497bba103fd05735c878c0d642dd68 | CHANGES.rst |
<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 url_for
<mask> from .json import jsonify
<mask> from .logging import create_logger
<mask> from .scaffold... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/69e2300608497bba103fd05735c878c0d642dd68 | src/flask/app.py | |
#: Moved from ``flask.abort``, which calls this object. | <mask> #: :meth:`make_aborter`. This is called by :func:`flask.abort`
<mask> #: to raise HTTP errors, and can be called directly as well.
<mask> #:
<mask> #: .. versionadded:: 2.2
<mask> self.aborter = self.make_aborter()
<mask>
<mask> #: A list of functions that ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/69e2300608497bba103fd05735c878c0d642dd68 | src/flask/app.py |
url_for=self.url_for, | <mask> options["auto_reload"] = self.templates_auto_reload
<mask>
<mask> rv = self.jinja_environment(self, **options)
<mask> rv.globals.update(
<mask> url_for=url_for,
<mask> get_flashed_messages=get_flashed_messages,
<mask> config=self.config,
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/69e2300608497bba103fd05735c878c0d642dd68 | src/flask/app.py |
Logging Application Errors
========================== | <mask> .. _application-errors:
<mask>
<mask> Handling Application Errors
<mask> ===========================
<mask>
<mask> .. versionadded:: 0.3
<mask>
<mask> Applications fail, servers fail. Sooner or later you will see an exception
<mask> in production. Even if your code is 100% correct, you will still s... | [
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/69e7a0a2a0391ed1bdd102deffbd98137790f959 | docs/errorhandling.rst |
.. _debug-mode:
| <mask>
<mask> This tells your operating system to listen on all public IPs.
<mask>
<mask>
<mask> Debug Mode
<mask> ----------
<mask>
<mask> The :meth:`~flask.Flask.run` method is nice to start a local
<mask> development server, but you would have to restart it manually after each
<mask> change to your ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/69e7a0a2a0391ed1bdd102deffbd98137790f959 | docs/quickstart.rst |
Have another debugger in mind? See :ref:`working-with-debuggers`. | <mask> :align: center
<mask> :class: screenshot
<mask> :alt: screenshot of debugger in action
<mask>
<mask> .. admonition:: Working With Other Debuggers
<mask>
<mask> Debuggers interfere with each other.
<mask> That said, you may still wish to use the debugger in a tool of your choice.
<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/69e7a0a2a0391ed1bdd102deffbd98137790f959 | docs/quickstart.rst |
) from None | <mask> from asgiref.sync import async_to_sync as asgiref_async_to_sync
<mask> except ImportError:
<mask> raise RuntimeError(
<mask> "Install Flask with the 'async' extra in order to use async views."
<mask> )
<mask>
<mask> # Check that Werkzeug... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/app.py |
).with_traceback(sys.exc_info()[2]) from None | <mask> f"{e}\nThe view function did not return a valid"
<mask> " response. The return type must be a string,"
<mask> " dict, tuple, Response instance, or WSGI"
<mask> f" callable, but it was a {type(rv).__name__}."
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/app.py |
except TypeError as e: | <mask> app = call_factory(script_info, app_factory)
<mask>
<mask> if isinstance(app, Flask):
<mask> return app
<mask> except TypeError:
<mask> if not _called_with_wrong_args(app_factory):
<mask> raise
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
) from e | <mask> f"Detected factory {attr_name!r} in module {module.__name__!r},"
<mask> " but could not call it without arguments. Use"
<mask> f" \"FLASK_APP='{module.__name__}:{attr_name}(args)'\""
<mask> " to specify arguments."
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
) from None | <mask> expr = ast.parse(app_name.strip(), mode="eval").body
<mask> except SyntaxError:
<mask> raise NoAppException(
<mask> f"Failed to parse {app_name!r} as an attribute name or function call."
<mask> )
<mask>
<mask> if isinstance(expr, ast.Name):
<mask> name... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
) from None | <mask> # literal_eval gives cryptic error messages, show a generic
<mask> # message with the full expression instead.
<mask> raise NoAppException(
<mask> f"Failed to parse arguments as literal values: {app_name!r}."
<mask> )
<mask> else:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
except AttributeError as e: | <mask> )
<mask>
<mask> try:
<mask> attr = getattr(module, name)
<mask> except AttributeError:
<mask> raise NoAppException(
<mask> f"Failed to find attribute {name!r} in {module.__name__!r}."
<mask> )
<mask>
<mask> # If the attribute is a function, call... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
) from e | <mask> attr = getattr(module, name)
<mask> except AttributeError:
<mask> raise NoAppException(
<mask> f"Failed to find attribute {name!r} in {module.__name__!r}."
<mask> )
<mask>
<mask> # If the attribute is a function, call it with any args and kwargs
<mask> # t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
except TypeError as e: | <mask> # to get the real application.
<mask> if inspect.isfunction(attr):
<mask> try:
<mask> app = call_factory(script_info, attr, args, kwargs)
<mask> except TypeError:
<mask> if not _called_with_wrong_args(attr):
<mask> raise
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
) from e | <mask> raise NoAppException(
<mask> f"The factory {app_name!r} in module"
<mask> f" {module.__name__!r} could not be called with the"
<mask> " specified arguments."
<mask> )
<mask> else:
<mask> app = attr
<mask>
<mask> if ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
except ImportError as e: | <mask> __traceback_hide__ = True # noqa: F841
<mask>
<mask> try:
<mask> __import__(module_name)
<mask> except ImportError:
<mask> # Reraise the ImportError if it occurred within the imported module.
<mask> # Determine this by checking whether the trace has a depth > 1.
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4bf9eec13e035cf10ecc16e462049b4c967e41 | src/flask/cli.py |
- Enhance typing of ``app.errorhandler`` decorator. :issue:`4095` | <mask> decorators to accept functions with no arguments. :issue:`4098`
<mask> - Support View and MethodView instances with async handlers. :issue:`4112`
<mask>
<mask>
<mask> Version 2.0.1
<mask> -------------
</s> improve typing for `app.errorhandler` decorator </s> remove t.Dict[t.Optional[i... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4e7e948d7e5bd5b2b76c1b7f1a0392644bee1e | CHANGES.rst |
<mask> from .templating import Environment
<mask> from .typing import AfterRequestCallable
<mask> from .typing import BeforeFirstRequestCallable
<mask> from .typing import BeforeRequestCallable
<mask> from .typing import ErrorHandlerCallable
<mask> from .typing import ResponseReturnValue
<mask> from .typing impo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4e7e948d7e5bd5b2b76c1b7f1a0392644bee1e | src/flask/app.py | |
from .typing import ErrorHandlerCallable | <mask> from .blueprints import Blueprint
<mask> from .testing import FlaskClient
<mask> from .testing import FlaskCliRunner
<mask>
<mask> if sys.version_info >= (3, 8):
<mask> iscoroutinefunction = inspect.iscoroutinefunction
<mask> else:
<mask>
</s> improve typing for `app.errorhandler` deco... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4e7e948d7e5bd5b2b76c1b7f1a0392644bee1e | src/flask/app.py |
def _find_error_handler(
self, e: Exception
) -> t.Optional["ErrorHandlerCallable[Exception]"]: | <mask> """
<mask> self.shell_context_processors.append(f)
<mask> return f
<mask>
<mask> def _find_error_handler(self, e: Exception) -> t.Optional[ErrorHandlerCallable]:
<mask> """Return a registered error handler for an exception in this order:
<mask> blueprint handle... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4e7e948d7e5bd5b2b76c1b7f1a0392644bee1e | src/flask/app.py |
<mask> from .scaffold import Scaffold
<mask> from .typing import AfterRequestCallable
<mask> from .typing import BeforeFirstRequestCallable
<mask> from .typing import BeforeRequestCallable
<mask> from .typing import ErrorHandlerCallable
<mask> from .typing import TeardownCallable
<mask> from .typing import Templ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4e7e948d7e5bd5b2b76c1b7f1a0392644bee1e | src/flask/blueprints.py | |
from .typing import ErrorHandlerCallable | <mask>
<mask> if t.TYPE_CHECKING:
<mask> from .app import Flask
<mask>
<mask> DeferredSetupFunction = t.Callable[["BlueprintSetupState"], t.Callable]
<mask>
<mask>
</s> improve typing for `app.errorhandler` decorator </s> remove from .typing import ErrorHandlerCallable
</s> add from .typing import Gene... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/6a4e7e948d7e5bd5b2b76c1b7f1a0392644bee1e | src/flask/blueprints.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.