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 |
|---|---|---|---|---|
size and complexity but on the other hand also that the complexity of the | <mask> What does Micro Mean?
<mask> ---------------------
<mask>
<mask> The micro in microframework for me means on the one hand being small in
<mask> size, complexity but on the other hand also that the complexity of the
<mask> applications that are written with these frameworks do not exceed a
<mask> certain ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51c9829a9cdfa2bf301431f686d7a404cc7c5083 | docs/foreword.rst |
Welcome to Flask's documentation. This documentation is divided in | <mask> .. image:: _static/logo-full.png
<mask> :alt: The Flask Logo with Subtitle
<mask> :align: right
<mask>
<mask> Welcome to Flask's documentation. This documentation is divided into
<mask> different parts. I would suggest to get started with the
<mask> :ref:`installation` and then heading over to th... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51c9829a9cdfa2bf301431f686d7a404cc7c5083 | docs/index.rst |
lighttpd, on Google's App Engine or whatever you have in mind). | <mask> templates. Now you are maybe asking, what is WSGI? WSGI is a standard
<mask> in Python that is basically responsible for ensuring that your application
<mask> is behaving in a specific way that you can run it on different
<mask> environments (for example on a local development server, on an Apache2, on
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51c9829a9cdfa2bf301431f686d7a404cc7c5083 | docs/installation.rst |
return "GET" | <mask>
<mask> class AsyncMethodView(MethodView):
<mask> async def get(self):
<mask> await asyncio.sleep(0)
<mask> return 'GET'
<mask>
<mask> async def post(self):
<mask> await asyncio.sleep(0)
<mask> return 'POST'
<mask>
</s> [pre-commit.ci] auto fixes from pre-comm... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5205cd4ea979f6c322e4e6a256a72e7808592818 | tests/test_async.py |
return "POST" | <mask> return 'GET'
<mask>
<mask> async def post(self):
<mask> await asyncio.sleep(0)
<mask> return 'POST'
<mask>
<mask>
<mask> @pytest.fixture(name="async_app")
<mask> def _async_app():
<mask> app = Flask(__name__)
</s> [pre-commit.ci] auto fixes from pre-commit.com hooks
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5205cd4ea979f6c322e4e6a256a72e7808592818 | tests/test_async.py |
app.add_url_rule("/view", view_func=AsyncView.as_view("view"))
app.add_url_rule("/methodview", view_func=AsyncMethodView.as_view("methodview")) | <mask> raise BlueprintError()
<mask>
<mask> app.register_blueprint(blueprint, url_prefix="/bp")
<mask>
<mask> app.add_url_rule('/view', view_func=AsyncView.as_view('view'))
<mask> app.add_url_rule('/methodview', view_func=AsyncMethodView.as_view('methodview'))
<mask>
<mask> return app... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5205cd4ea979f6c322e4e6a256a72e7808592818 | tests/test_async.py |
import six | <mask> # depend anyways.
<mask> from itsdangerous import simplejson as _json
<mask>
<mask>
<mask> # figure out if simplejson escapes slashes. This behavior was changed
<mask> # from one version to another without reason.
</s> python-modernize automated changes: fix_unicode (but without six.u()) </s> remove ... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/json.py |
return six.text_type(o.__html__()) | <mask> return http_date(o)
<mask> if isinstance(o, uuid.UUID):
<mask> return str(o)
<mask> if hasattr(o, '__html__'):
<mask> return unicode(o.__html__())
<mask> return _json.JSONEncoder.default(self, o)
<mask>
<mask>
<mask> class JSONDecoder(_json.J... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/json.py |
return {' m': six.text_type(value.__html__())} | <mask> return {' t': [_tag(x) for x in value]}
<mask> elif isinstance(value, uuid.UUID):
<mask> return {' u': value.hex}
<mask> elif callable(getattr(value, '__html__', None)):
<mask> return {' m': unicode(value.__html__())}
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/sessions.py |
return six.text_type(value) | <mask> elif isinstance(value, dict):
<mask> return dict((k, _tag(v)) for k, v in six.iteritems(value))
<mask> elif isinstance(value, str):
<mask> try:
<mask> return unicode(value)
<mask> except UnicodeError:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/sessions.py |
import six | <mask> from flask.testsuite import FlaskTestCase, emits_module_deprecation_warning
<mask> from werkzeug.exceptions import BadRequest, NotFound
<mask> from werkzeug.http import parse_date
<mask> from werkzeug.routing import BuildError
<mask>
<mask>
<mask> class BasicFunctionalityTestCase(FlaskTestCase):
<mask>... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/basic.py |
return six.text_type(flask.session.permanent) | <mask> return ''
<mask>
<mask> @app.route('/test')
<mask> def test():
<mask> return unicode(flask.session.permanent)
<mask>
<mask> client = app.test_client()
<mask> rv = client.get('/')
<mask> self.assert_('set-cookie' in rv.headers)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/basic.py |
import six | <mask> from werkzeug.exceptions import NotFound
<mask> from werkzeug.http import parse_cache_control_header
<mask> from jinja2 import TemplateNotFound
<mask>
<mask>
<mask> # import moduleapp here because it uses deprecated features and we don't
<mask> # want to see the warnings
<mask> warnings.simplefilter('i... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/blueprints.py |
return six.text_type(bar) | <mask> return '%s/%d' % (bar, baz)
<mask>
<mask> @bp.route('/bar')
<mask> def bar(bar):
<mask> return unicode(bar)
<mask>
<mask> app = flask.Flask(__name__)
<mask> app.register_blueprint(bp, url_prefix='/1', url_defaults={'bar': 23})
<mask> app.... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/blueprints.py |
return six.text_type(flask.request.json) | <mask> def test_json_bad_requests(self):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/json', methods=['POST'])
<mask> def return_json():
<mask> return unicode(flask.request.json)
<mask> c = app.test_client()
<mask> rv = c.post('/json', data='malfo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/helpers.py |
return six.text_type(flask.request.json) | <mask> def test_json_bad_requests_content_type(self):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/json', methods=['POST'])
<mask> def return_json():
<mask> return unicode(flask.request.json)
<mask> c = app.test_client()
<mask> rv = c.post('/json'... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/helpers.py |
return six.text_type(flask.request.json['a'] + flask.request.json['b']) | <mask> def test_json_attr(self):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/add', methods=['POST'])
<mask> def add():
<mask> return unicode(flask.request.json['a'] + flask.request.json['b'])
<mask> c = app.test_client()
<mask> rv = c.post('/add'... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/helpers.py |
import six | <mask> import flask
<mask> import unittest
<mask> from flask.testsuite import FlaskTestCase
<mask>
<mask>
<mask> class TestToolsTestCase(FlaskTestCase):
<mask>
<mask> def test_environ_defaults_from_config(self):
<mask> app = flask.Flask(__name__)
</s> python-modernize automated changes: fix_uni... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/testing.py |
return six.text_type(flask.session['foo']) | <mask> app.secret_key = 'testing'
<mask>
<mask> @app.route('/')
<mask> def index():
<mask> return unicode(flask.session['foo'])
<mask>
<mask> with app.test_client() as c:
<mask> with c.session_transaction() as sess:
<mask> self.assert_eq... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/522cd0009367d1f775b0e978681426773f51ce14 | flask/testsuite/testing.py |
- main | <mask> name: Tests
<mask> on:
<mask> push:
<mask> branches:
<mask> - master
<mask> - '*.x'
<mask> paths-ignore:
<mask> - 'docs/**'
<mask> - '*.md'
<mask> - '*.rst'
</s> rename default branch in files </s> remove - master
</s> add - main </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | .github/workflows/tests.yaml |
- main | <mask> - '*.md'
<mask> - '*.rst'
<mask> pull_request:
<mask> branches:
<mask> - master
<mask> - '*.x'
<mask> paths-ignore:
<mask> - 'docs/**'
<mask> - '*.md'
<mask> - '*.rst'
</s> rename default branch in files </s> remove - master
</s> add - m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | .github/workflows/tests.yaml |
$ git checkout -b your-branch-name origin/2.0.x | <mask>
<mask> .. code-block:: text
<mask>
<mask> $ git fetch origin
<mask> $ git checkout -b your-branch-name origin/1.1.x
<mask>
<mask> If you're submitting a feature addition or change, branch off of the
<mask> "master" branch.
<mask>
<mask> .. code-block:: text
</s> ren... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | CONTRIBUTING.rst |
"main" branch. | <mask> $ git fetch origin
<mask> $ git checkout -b your-branch-name origin/1.1.x
<mask>
<mask> If you're submitting a feature addition or change, branch off of the
<mask> "master" branch.
<mask>
<mask> .. code-block:: text
<mask>
<mask> $ git fetch origin
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | CONTRIBUTING.rst |
$ git checkout -b your-branch-name origin/main | <mask>
<mask> .. code-block:: text
<mask>
<mask> $ git fetch origin
<mask> $ git checkout -b your-branch-name origin/master
<mask>
<mask> - Using your favorite editor, make your changes,
<mask> `committing as you go`_.
<mask> - Include tests that cover any code changes you make. ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | CONTRIBUTING.rst |
.. _contributing guidelines: https://github.com/pallets/flask/blob/main/CONTRIBUTING.rst | <mask>
<mask> For guidance on setting up a development environment and how to make a
<mask> contribution to Flask, see the `contributing guidelines`_.
<mask>
<mask> .. _contributing guidelines: https://github.com/pallets/flask/blob/master/CONTRIBUTING.rst
<mask>
<mask>
<mask> Donate
<mask> ------
<mask>
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | README.rst |
url = f"{base_url}main/{text}" | <mask> else:
<mask> words = None
<mask>
<mask> if packaging.version.parse(release).is_devrelease:
<mask> url = f"{base_url}master/{text}"
<mask> else:
<mask> url = f"{base_url}{release}/{text}"
<mask>
<mask> if words is None:
<mask> words = url
</s> rename de... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | docs/conf.py |
default Git version is the main branch. :: | <mask> -------
<mask>
<mask> **Be sure to use the same version of the code as the version of the docs
<mask> you're reading.** You probably want the latest tagged version, but the
<mask> default Git version is the master branch. ::
<mask>
<mask> # clone the repository
<mask> $ git clone https://github... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | examples/tutorial/README.rst |
Or if you are using the main branch, install Flask from source before | <mask> Install Flaskr::
<mask>
<mask> $ pip install -e .
<mask>
<mask> Or if you are using the master branch, install Flask from source before
<mask> installing Flaskr::
<mask>
<mask> $ pip install -e ../..
<mask> $ pip install -e .
<mask>
</s> rename default branch in files </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/52adf2ec219a0cb9abcfd116ec104c9a362c602a | examples/tutorial/README.rst |
class _NullSession(SecureCookie):
"""Class used to generate nicer error messages if sessions are not
available. Will still allow read-only access to the empty session
but fail on setting.
"""
def _fail(self, *args, **kwargs):
raise RuntimeError('the session is unavailable because no secret... | <mask>
<mask>
<mask> class _RequestContext(object):
<mask> """The request context contains all request relevant information. It is
<mask> created at the beginning of the request and pushed to the
<mask> `_request_ctx_stack` and removed at the end of it. It will create the
<mask> URL adapter a... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5310fc38227b1907cb541f4a30ea8dfef46c2e19 | flask.py |
if self.session is None:
self.session = _NullSession() | <mask> self.url_adapter = app.url_map.bind_to_environ(environ)
<mask> self.request = app.request_class(environ)
<mask> self.session = app.open_session(self.request)
<mask> self.g = _RequestGlobals()
<mask> self.flashes = None
<mask>
<mask> def __enter__(self):
<mask>... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5310fc38227b1907cb541f4a30ea8dfef46c2e19 | flask.py |
session.save_cookie(response, self.session_cookie_name) | <mask> :class:`~werkzeug.contrib.securecookie.SecureCookie`
<mask> object)
<mask> :param response: an instance of :attr:`response_class`
<mask> """
<mask> if session is not None:
<mask> session.save_cookie(response, self.session_c... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5310fc38227b1907cb541f4a30ea8dfef46c2e19 | flask.py |
if not isinstance(session, _NullSession): | <mask> :return: a new response object or the same, has to be an
<mask> instance of :attr:`response_class`.
<mask> """
<mask> session = _request_ctx_stack.top.session
<mask> if session is not None:
<mask> self.save_session(session, response)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5310fc38227b1907cb541f4a30ea8dfef46c2e19 | flask.py |
def test_missing_session(self):
app = flask.Flask(__name__)
def expect_exception(f, *args, **kwargs):
try:
f(*args, **kwargs)
except RuntimeError, e:
assert e.args and 'session is unavailable' in e.args[0]
else:
asse... | <mask> assert c.post('/set', data={'value': '42'}).data == 'value set'
<mask> assert c.get('/get').data == '42'
<mask>
<mask> def test_request_processing(self):
<mask> app = flask.Flask(__name__)
<mask> evts = []
<mask> @app.before_request
</s> Session falls back to ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5310fc38227b1907cb541f4a30ea8dfef46c2e19 | tests/flask_tests.py |
The name "app" or "wsgi" is imported (as a ".py" file, or package),
automatically detecting an app (``app`` or ``application``) or
factory (``create_app`` or ``make_app``). | <mask> While ``FLASK_APP`` supports a variety of options for specifying your
<mask> application, most use cases should be simple. Here are the typical values:
<mask>
<mask> (nothing)
<mask> The file :file:`wsgi.py` is imported, automatically detecting an app
<mask> (``app``). This provides an easy way to... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/531671c9c5177f24e79a3062e2dc5d0aa60c29af | docs/cli.rst |
The given name is imported, automatically detecting an app (``app``
or ``application``) or factory (``create_app`` or ``make_app``). | <mask> (``app``). This provides an easy way to create an app from a factory with
<mask> extra arguments.
<mask>
<mask> ``FLASK_APP=hello``
<mask> The name is imported, automatically detecting an app (``app``) or factory
<mask> (``create_app``).
<mask>
<mask> ----
<mask>
<mask> ``FLASK_APP``... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/531671c9c5177f24e79a3062e2dc5d0aa60c29af | docs/cli.rst |
$ export FLASK_APP=hello | <mask> .. group-tab:: Bash
<mask>
<mask> .. code-block:: text
<mask>
<mask> $ export FLASK_APP=hello.py
<mask> $ flask run
<mask> * Running on http://127.0.0.1:5000/
<mask>
<mask> .. group-tab:: CMD
<mask>
</s> Improve the wording of using FLASK_APP </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/531671c9c5177f24e79a3062e2dc5d0aa60c29af | docs/quickstart.rst |
> set FLASK_APP=hello | <mask> .. group-tab:: CMD
<mask>
<mask> .. code-block:: text
<mask>
<mask> > set FLASK_APP=hello.py
<mask> > flask run
<mask> * Running on http://127.0.0.1:5000/
<mask>
<mask> .. group-tab:: Powershell
<mask>
</s> Improve the wording of using FLASK_APP </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/531671c9c5177f24e79a3062e2dc5d0aa60c29af | docs/quickstart.rst |
> $env:FLASK_APP = "hello" | <mask> .. group-tab:: Powershell
<mask>
<mask> .. code-block:: text
<mask>
<mask> > $env:FLASK_APP = "hello.py"
<mask> > flask run
<mask> * Running on http://127.0.0.1:5000/
<mask>
<mask> This launches a very simple builtin server, which is good enough for
<mask> testin... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/531671c9c5177f24e79a3062e2dc5d0aa60c29af | docs/quickstart.rst |
.. admonition:: Application Discovery Behavior
As a shortcut, if the file is named ``app.py`` or ``wsgi.py``, you
don't have to set the ``FLASK_APP`` environment variable. See
:doc:`/cli` for more details.
| <mask> * Running on http://127.0.0.1:5000/
<mask>
<mask> This launches a very simple builtin server, which is good enough for
<mask> testing but probably not what you want to use in production. For
<mask> deployment options see :doc:`deploying/index`.
<mask>
</s> Improve the wording of using FLASK_AP... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/531671c9c5177f24e79a3062e2dc5d0aa60c29af | docs/quickstart.rst |
import os
import posixpath | <mask> :copyright: (c) 2010 by Armin Ronacher.
<mask> :license: BSD, see LICENSE for more details.
<mask> """
<mask>
<mask> from threading import Lock
<mask> from datetime import timedelta, datetime
<mask> from itertools import chain
<mask>
</s> phased out shared data middleware in flask for send_fil... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/app.py |
from werkzeug import ImmutableDict, create_environ | <mask> from datetime import timedelta, datetime
<mask> from itertools import chain
<mask>
<mask> from jinja2 import Environment, PackageLoader, FileSystemLoader
<mask> from werkzeug import ImmutableDict, SharedDataMiddleware, create_environ
<mask> from werkzeug.routing import Map, Rule
<mask> from werkzeug.exce... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/app.py |
from werkzeug.exceptions import HTTPException, InternalServerError, NotFound | <mask>
<mask> from jinja2 import Environment, PackageLoader, FileSystemLoader
<mask> from werkzeug import ImmutableDict, SharedDataMiddleware, create_environ
<mask> from werkzeug.routing import Map, Rule
<mask> from werkzeug.exceptions import HTTPException, InternalServerError
<mask>
<mask> from flask.helpers ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/app.py |
_tojson_filter, get_pkg_resources, send_file | <mask> from werkzeug.routing import Map, Rule
<mask> from werkzeug.exceptions import HTTPException, InternalServerError
<mask>
<mask> from flask.helpers import _PackageBoundObject, url_for, get_flashed_messages, \
<mask> _tojson_filter, get_pkg_resources
<mask> from flask.wrappers import Request, Response
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/app.py |
endpoint='static',
view_func=self.send_static_file) | <mask> self.url_map = Map()
<mask>
<mask> if self.static_path is not None:
<mask> self.add_url_rule(self.static_path + '/<filename>',
<mask> build_only=True, endpoint='static')
<mask> if get_pkg_resources() is not None:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/app.py |
def send_static_file(self, filename):
"""Function used internally to send static files from the static
folder to the browser.
.. versionadded:: 0.5
"""
filename = posixpath.normpath(filename)
if filename.startswith('../'):
raise NotFound()
filenam... | <mask> return run_simple(host, port, self, **options)
<mask>
<mask> def test_client(self):
<mask> """Creates a test client for this application. For information
<mask> about unit testing head over to :ref:`testing`.
<mask>
<mask> The test client can be used in a `with` bloc... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/app.py |
if not os.path.isabs(filename):
filename = os.path.join(current_app.root_path, filename) | <mask> else:
<mask> file = filename_or_fp
<mask> filename = getattr(file, 'name', None)
<mask> if filename is not None:
<mask> filename = os.path.join(current_app.root_path, filename)
<mask> if mimetype is None and (filename or attachment_filename):
<mask> mimetype = m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/532347d6adf1da64259f1af91860d5fa27bac9f1 | flask/helpers.py |
"INSERT INTO post (title, body, author_id) VALUES (?, ?, ?)", | <mask> flash(error)
<mask> else:
<mask> db = get_db()
<mask> db.execute(
<mask> "INSERT INTO post (title, body, author_id)" " VALUES (?, ?, ?)",
<mask> (title, body, g.user["id"]),
<mask> )
<mask> db.commit()
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | examples/tutorial/flaskr/blog.py |
"Request finalizing failed with an error while handling an error" | <mask> except Exception:
<mask> if not from_error_handler:
<mask> raise
<mask> self.logger.exception(
<mask> "Request finalizing failed with an " "error while handling an error"
<mask> )
<mask> return response
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/app.py |
message = "Python %(python)s\nFlask %(flask)s\nWerkzeug %(werkzeug)s" | <mask>
<mask> import werkzeug
<mask> from . import __version__
<mask>
<mask> message = "Python %(python)s\n" "Flask %(flask)s\n" "Werkzeug %(werkzeug)s"
<mask> click.echo(
<mask> message
<mask> % {
<mask> "python": platform.python_version(),
<mask> "fl... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/cli.py |
assert rv is self, "Popped wrong request context. (%r instead of %r)" % (
rv,
self,
) | <mask> # Get rid of the app as well if necessary.
<mask> if app_ctx is not None:
<mask> app_ctx.pop(exc)
<mask>
<mask> assert (
<mask> rv is self
<mask> ), "Popped wrong request context. " "(%r instead of %r)" % (rv, self)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/ctx.py |
assert view_func is not None, "expected view func if endpoint is not provided." | <mask> def _endpoint_from_view_func(view_func):
<mask> """Internal helper that returns the default endpoint for a given
<mask> function. This always is the function name.
<mask> """
<mask> assert view_func is not None, "expected view func if endpoint " "is not provided."
<mask> return view_fu... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/helpers.py |
raise TypeError("filename unavailable, required for sending as attachment") | <mask>
<mask> headers = Headers()
<mask> if as_attachment:
<mask> if attachment_filename is None:
<mask> raise TypeError(
<mask> "filename unavailable, required for " "sending as attachment"
<mask> )
<mask>
<mask> if not isinstance(attachment_fi... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/helpers.py |
"Session transactions only make sense with cookies enabled." | <mask> passed through.
<mask> """
<mask> if self.cookie_jar is None:
<mask> raise RuntimeError(
<mask> "Session transactions only make sense " "with cookies enabled."
<mask> )
<mask> app = self.application
<mask> environ_overrides =... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/testing.py |
"Session backend did not open a session. Check the configuration" | <mask> session_interface = app.session_interface
<mask> sess = session_interface.open_session(app, c.request)
<mask> if sess is None:
<mask> raise RuntimeError(
<mask> "Session backend did not open a session. " "Check the configuration"
<mask... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | src/flask/testing.py |
assert ("Make sure to directly send your POST-request to this URL") in str(e) | <mask> with client:
<mask> with pytest.raises(AssertionError) as e:
<mask> client.post("/foo", data={})
<mask> assert "http://localhost/foo/" in str(e)
<mask> assert ("Make sure to directly send " "your POST-request to this URL") in str(e)
<mask>
<mask> rv = clien... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | tests/test_basic.py |
"[Errno 2] Unable to load configuration file (No such file or directory):" | <mask> app = flask.Flask(__name__)
<mask> app.config.from_envvar("FOO_SETTINGS")
<mask> msg = str(e.value)
<mask> assert msg.startswith(
<mask> "[Errno 2] Unable to load configuration " "file (No such file or directory):"
<mask> )
<mask> assert msg.endswith("missing.cfg'")... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | tests/test_config.py |
"[Errno 2] Unable to load configuration file (No such file or directory):" | <mask> with pytest.raises(IOError) as e:
<mask> app.config.from_pyfile("missing.cfg")
<mask> msg = str(e.value)
<mask> assert msg.startswith(
<mask> "[Errno 2] Unable to load configuration " "file (No such file or directory):"
<mask> )
<mask> assert msg.endswith("missing.cfg'"... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | tests/test_config.py |
"[Errno 2] Unable to load configuration file (No such file or directory):" | <mask> with pytest.raises(IOError) as e:
<mask> app.config.from_json("missing.json")
<mask> msg = str(e.value)
<mask> assert msg.startswith(
<mask> "[Errno 2] Unable to load configuration " "file (No such file or directory):"
<mask> )
<mask> assert msg.endswith("missing.json'"... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | tests/test_config.py |
"import flask\napp = flask.Flask(__name__)\n" | <mask> def test_installed_module_paths(
<mask> modules_tmpdir, modules_tmpdir_prefix, purge_module, site_packages, limit_loader
<mask> ):
<mask> site_packages.join("site_app.py").write(
<mask> "import flask\n" "app = flask.Flask(__name__)\n"
<mask> )
<mask> purge_module("site_app")
<mask... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | tests/test_instance_config.py |
rv = flask.render_template_string("Hello {{ config.WORLD_NAME }} {{ foo }}") | <mask> @app.context_processor
<mask> def context_processor():
<mask> return dict(foo=42)
<mask>
<mask> rv = flask.render_template_string("Hello {{ config.WORLD_NAME }} " "{{ foo }}")
<mask> assert rv == "Hello Special World 42"
<mask>
<mask>
<mask> def test_standard_context(app, clie... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/53c893b646252d610e877eb9385e9e250a1ae5e1 | tests/test_templating.py |
`OAuth extension`_ works: there is an `OAuth` object that provides | <mask>
<mask> classes:
<mask> Classes work mostly like initialization functions but can later be
<mask> used to further change the behaviour. For an example look at how the
<mask> `OAuth extension`_ works: ther is an `OAuth` object that provides
<mask> some helper functions like `OAuth.remote_ap... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/extensiondev.rst |
(:ref:`packages`) there are a couple of really nice ways to further improve | <mask> Application Factories
<mask> =====================
<mask>
<mask> If you are already using packages and modules for your application
<mask> (:ref:`packages`) there are couple of really nice ways to further improve
<mask> the experience. A common pattern is creating the application object when
<mask> the ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/appfactories.rst |
Certain things are common enough that the chances are high you will find | <mask>
<mask> Patterns for Flask
<mask> ==================
<mask>
<mask> Certain things are common enough that the changes are high you will find
<mask> them in most web applications. For example quite a lot of applications
<mask> are using relational databases and user authentication. In that case,
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/index.rst |
chances are they will open a database connection at the beginning of the | <mask>
<mask> Certain things are common enough that the changes are high you will find
<mask> them in most web applications. For example quite a lot of applications
<mask> are using relational databases and user authentication. In that case,
<mask> changes are they will open a database connection at the beginni... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/index.rst |
Here's an example `__init__.py`:: | <mask> decorator on top) have to be imported when in the `__init__.py` file.
<mask> Not the object itself, but the module it is in. Do the importing at
<mask> the *bottom* of the file.
<mask>
<mask> Here an example `__init__.py`::
<mask>
<mask> from flask import Flask
<mask> app = Flask(__na... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/packages.rst |
split the views into modules. First let's look at the typical structure of | <mask> Working with Modules
<mask> --------------------
<mask>
<mask> For larger applications with more than a dozen views it makes sense to
<mask> split the views into modules. First let's look at the typical struture of
<mask> such an application::
<mask>
<mask> /yourapplication
<mask> /yourap... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/packages.rst |
you have already worked with, it just does not support all of the methods, | <mask> `admin.py` file in the view package.
<mask>
<mask> First we have to create a :class:`~flask.Module` object with the name of
<mask> the package. This works very similar to the :class:`~flask.Flask` object
<mask> you have already worked with, it just does not support all of the method,
<mask> but most of t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/packages.rst |
Long story short, here's a nice and concise example:: | <mask> the package. This works very similar to the :class:`~flask.Flask` object
<mask> you have already worked with, it just does not support all of the method,
<mask> but most of them are the same.
<mask>
<mask> Long story short, here a nice and concise example::
<mask>
<mask> from flask import Module
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/packages.rst |
def logout(): | <mask> def login():
<mask> pass
<mask>
<mask> @admin.route('/logout')
<mask> def login():
<mask> pass
<mask>
<mask> Do the same with the `frontend.py` and then make sure to register the
<mask> modules in the application (`__init__.py`) like this::
<mask>
</s> Fix some typos in ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/540eca16f8a5963a74298f3630523fd9ad49187a | docs/patterns/packages.rst |
'Detected multiple Flask applications in module "{module}". Use '
'"FLASK_APP={module}:name" to specify the correct '
'one.'.format(module=module.__name__) | <mask> if len(matches) == 1:
<mask> return matches[0]
<mask> elif len(matches) > 1:
<mask> raise NoAppException(
<mask> 'Auto-detected multiple Flask applications in module "{module}".'
<mask> ' Use "FLASK_APP={module}:name" to specify the correct'
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
app = call_factory(script_info, app_factory)
| <mask> app_factory = getattr(module, attr_name, None)
<mask>
<mask> if inspect.isfunction(app_factory):
<mask> try:
<mask> app = call_factory(app_factory, script_info)
<mask> if isinstance(app, Flask):
<mask> return app
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
'Detected factory "{factory}" in module "{module}", but '
'could not call it without arguments. Use '
'"FLASK_APP=\'{module}:{factory}(args)\'" to specify '
'arguments.'.format(
factory=attr_name, module=module.__nam... | <mask> if isinstance(app, Flask):
<mask> return app
<mask> except TypeError:
<mask> raise NoAppException(
<mask> 'Auto-detected "{function}()" in module "{module}", but '
<mask> 'could not call it without speci... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
'Failed to find Flask application or factory in module "{module}". '
'Use "FLASK_APP={module}:name to specify one.'.format(
module=module.__name__
) | <mask> )
<mask> )
<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 WSGI '
<mask> 'middleware.'.format(module=module.__name... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
def call_factory(script_info, app_factory, arguments=()): | <mask> 'middleware.'.format(module=module.__name__)
<mask> )
<mask>
<mask>
<mask> def call_factory(app_factory, script_info, arguments=()):
<mask> """Takes an app factory, a ``script_info` object and optionally a tuple
<mask> of arguments. Checks for the existence of a script_info argument... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
def find_app_by_string(script_info, module, app_name):
"""Checks if the given string is a variable name or a function. If it is a
function, it checks for specified arguments and whether it takes a
``script_info`` argument and calls the function with the appropriate
arguments.
"""
from flask impo... | <mask> return app_factory(script_info)
<mask> return app_factory()
<mask>
<mask>
<mask> def find_app_by_string(string, script_info, module):
<mask> """Checks if the given string is a variable name or a function. If it is
<mask> a function, it checks for specified arguments and whether it ta... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
app = call_factory(script_info, attr, args) | <mask> match = re.match(function_regex, string)
<mask> if match:
<mask> name, args = match.groups()
<mask> try:
<mask> if args is not None:
<mask> args = args.rstrip(' ,')
<mask> if args:
<mask> args = ast.literal_eval(
<ma... | [
"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",
"ke... | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
raise NoAppException(
'{e}\nThe factory "{app_name}" in module "{module}" could not '
'be called with the specified arguments.'.format(
e=e, app_name=app_name, module=module.__name__
)
) | <mask> else:
<mask> raise NoAppException('Failed to find application in module '
<mask> '"{name}"'.format(name=module))
<mask> except TypeError as e:
<mask> new_error = NoAppException(
<mask> '{e}\nThe app factory "... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
app = attr
if isinstance(app, Flask):
return app
raise NoAppException(
'A valid Flask application was not obtained from '
'"{module}:{app_name}".'.format(
module=module.__name__, app_name=app_name
)
) | <mask> ' well as not using keyword arguments or'
<mask> ' non-literals?'.format(e=e, factory=string, module=module))
<mask> reraise(NoAppException, new_error, sys.exc_info()[2])
<mask> else:
<mask> raise NoAppException(
<mask> 'The provided strin... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
<mask> return '.'.join(module_name[::-1])
<mask>
<mask>
<mask> def locate_app(script_info, module_name, app_name, raise_if_not_found=True):
<mask> """Attempts to locate the application."""
<mask> __traceback_hide__ = True
<mask>
<mask> try:
<mask> __import__(module_name)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py | |
return find_app_by_string(script_info, module, app_name) | <mask>
<mask> if app_name is None:
<mask> return find_best_app(script_info, module)
<mask> else:
<mask> return find_app_by_string(app_name, script_info, module)
<mask>
<mask>
<mask> def get_version(ctx, param, value):
<mask> if not value or ctx.resilient_parsing:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
app = call_factory(self, self.create_app) | <mask>
<mask> app = None
<mask>
<mask> if self.create_app is not None:
<mask> app = call_factory(self.create_app, self)
<mask> else:
<mask> if self.app_import_path:
<mask> path, name = (self.app_import_path.split(':', 1) + [None])[:2]
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | flask/cli.py |
def no_app():
pass | <mask>
<mask>
<mask> def create_app3(foo, script_info):
<mask> return Flask('_'.join(['app3', foo, script_info.data['test']]))
</s> rewrite cli errors
consistent order for arguments to load functions
refactor find_app_by_string to flow better
more cli loader tests </s> remove return find_app_by_strin... | [
"keep",
"keep",
"keep",
"add"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | tests/test_apps/cliapp/factory.py |
# strip whitespace
('cliapp.factory', ' create_app () ', 'app'), | <mask> # takes script_info
<mask> ('cliapp.factory', 'create_app3("foo")', 'app3_foo_spam'),
<mask> ))
<mask> def test_locate_app(test_apps, iname, aname, result):
<mask> info = ScriptInfo()
<mask> info.data['test'] = 'spam'
<mask> assert locate_app(info, iname, aname).name == result
<mask> ... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | tests/test_cli.py |
# invalid identifier
('cliapp.factory', 'create_app('),
# no app returned
('cliapp.factory', 'no_app'), | <mask> ('cliapp.app', 'notanapp'),
<mask> # not enough arguments
<mask> ('cliapp.factory', 'create_app2("foo")'),
<mask> # nested import error
<mask> ('cliapp.importerrorapp', None),
<mask> # not a Python file
<mask> ('cliapp.message.txt', None),
<mask> ))
<mask> def test_locate_app... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | tests/test_cli.py |
<mask> # nested import error
<mask> ('cliapp.importerrorapp', None),
<mask> # not a Python file
<mask> ('cliapp.message.txt', None),
<mask> # space before arg list
<mask> ('cliapp.factory', 'create_app ()'),
<mask> ))
<mask> def test_locate_app_raises(test_apps, iname, aname):
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5436dddf64f0103088c4ca212f16efa40c88766a | tests/test_cli.py | |
base ``HTTPException``. This makes error handler behavior more | <mask> passed an instance of ``InternalServerError``. If they are invoked
<mask> due to an unhandled exception, that original exception is now
<mask> available as ``e.original_exception`` rather than being passed
<mask> directly to the handler. The same is true if the handler is for the
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54519ef028660da63c3b2bab51c1f18e7b7c9fa2 | CHANGES.rst |
<mask> raises the exception. However, the blueprint cannot handle 404 routing errors
<mask> because the 404 occurs at the routing level before the blueprint can be
<mask> determined.
<mask>
<mask> .. versionchanged:: 0.11
<mask>
<mask> Handlers are prioritized by specificity of the exception classes they ar... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54519ef028660da63c3b2bab51c1f18e7b7c9fa2 | docs/errorhandling.rst | |
Generic Exception Handlers
``````````````````````````
It is possible to register error handlers for very generic base classes
such as ``HTTPException`` or even ``Exception``. However, be aware that
these will catch more than you might expect.
An error handler for ``HTTPException`` might be useful for turning
the defa... | <mask> determined.
<mask>
<mask> .. versionchanged:: 0.11
<mask>
<mask> Handlers are prioritized by specificity of the exception classes they are
<mask> registered for instead of the order they are registered in.
<mask>
<mask> Logging
<mask> -------
<mask>
<mask> See :ref:`logging` for information ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54519ef028660da63c3b2bab51c1f18e7b7c9fa2 | docs/errorhandling.rst |
always have an ``original_exception`` attribute. Use | <mask> unhandled exception is available as ``e.original_exception``.
<mask>
<mask> .. note::
<mask> Prior to Werkzeug 1.0.0, ``InternalServerError`` will not
<mask> always have a ``original_exception`` attribute. Use
<mask> ``getattr(e, "original_exception", No... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54519ef028660da63c3b2bab51c1f18e7b7c9fa2 | src/flask/app.py |
data and to then invoke that function and pass it to a response object:: | <mask> -----------
<mask>
<mask> This is a basic view function that generates a lot of CSV data on the fly.
<mask> The trick is to have an inner function that uses a generator to generate
<mask> data and to then invoke that function and pass it to a response object
<mask> that has the ``direct_passthrough`` flag... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54875e93173f96d44a73431a4929059c55aed797 | docs/patterns/streaming.rst |
return Response(generate(), mimetype='text/csv') | <mask> def generate_large_csv():
<mask> def generate():
<mask> for row in iter_all_rows():
<mask> yield ','.join(row) + '\n'
<mask> return Response(generate(), direct_passthrough=True,
<mask> mimetype='text/csv')
<mask>
<mask> Each ``yield... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54875e93173f96d44a73431a4929059c55aed797 | docs/patterns/streaming.rst |
return Response(stream_template('the_template.html', rows=rows)) | <mask>
<mask> @app.route('/my-large-page.html')
<mask> def render_large_template():
<mask> rows = iter_all_rows()
<mask> return Response(stream_template('the_template.html', rows=rows),
<mask> direct_passthrough=True)
<mask>
<mask> The trick here is to get the t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/54875e93173f96d44a73431a4929059c55aed797 | docs/patterns/streaming.rst |
#: To register a view function, use the :meth:`route` decorator. | <mask>
<mask> #: A dictionary of all view functions registered. The keys will
<mask> #: be function names which are also used to generate URLs and
<mask> #: the values are the function objects themselves.
<mask> #: to register a view function, use the :meth:`route` decorator.
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/app.py |
#: to populate the template context. The key of the dictionary is the | <mask> #: :meth:`before_request` decorator.
<mask> self.after_request_funcs = {}
<mask>
<mask> #: A dictionary with list of functions that are called without argument
<mask> #: to populate the template context. They key of the dictionary is the
<mask> #: name of the modul... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/app.py |
Here are some examples: | <mask> def url_for(endpoint, **values):
<mask> """Generates a URL to the given endpoint with the method provided.
<mask> The endpoint is relative to the active module if modules are in use.
<mask>
<mask> Here some examples:
<mask>
<mask> ==================== ======================= ============... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/helpers.py |
Here's an example structure for a larger application:: | <mask> modules can share the same import names, but in that case a `name` has
<mask> to be provided to keep them apart. If different import names are used,
<mask> the rightmost part of the import name is used as name.
<mask>
<mask> Here an example structure for a larger appliation::
<mask>
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/module.py |
And here's an example view module (`myapplication/views/admin.py`):: | <mask> app = Flask(__name__)
<mask> app.register_module(admin, url_prefix='/admin')
<mask> app.register_module(frontend)
<mask>
<mask> And here an example view module (`myapplication/views/admin.py`)::
<mask>
<mask> from flask import Module
<mask>
<mask> admin = M... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/module.py |
"""The request object used by default in Flask. Remembers the | <mask> from .globals import _request_ctx_stack
<mask>
<mask>
<mask> class Request(RequestBase):
<mask> """The request object used by default in flask. Remembers the
<mask> matched endpoint and view arguments.
<mask>
<mask> It is what ends up as :class:`~flask.request`. If you want to replace
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/wrappers.py |
"""The response object that is used by default in Flask. Works like the
response object from Werkzeug but is set to have an HTML mimetype by | <mask> return json.loads(self.data)
<mask>
<mask>
<mask> class Response(ResponseBase):
<mask> """The response object that is used by default in flask. Works like the
<mask> response object from Werkzeug but is set to have a HTML mimetype by
<mask> default. Quite often you don't have t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/549af6229039e7fed7bcb2079737e45c27af998e | flask/wrappers.py |
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.7
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: check-byte-order-marker
- id: trailing-whitespace
- id: end-of-file-fixer | <mask> - repo: https://github.com/python/black
<mask> rev: 19.3b0
<mask> hooks:
<mask> - id: black
</s> add pre-commit config for flake8 </s> remove
Flask will automatically detect the factory (``create_app`` or ``make_app``)
</s> add Flask will automatically detect the factory (``create_app... | [
"keep",
"keep",
"keep",
"add"
] | https://github.com/pallets/flask/commit/549fed29ea0b6f0f3cc3731a310f4de3631a759e | .pre-commit-config.yaml |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.