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 |
|---|---|---|---|---|
options['auto_reload'] = self.templates_auto_reload
| <mask> options = dict(self.jinja_options)
<mask> if 'autoescape' not in options:
<mask> options['autoescape'] = self.select_jinja_autoescape
<mask> if 'auto_reload' not in options:
<mask> if self.config['TEMPLATES_AUTO_RELOAD'] is not None:
<mask> op... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/4fc48200a58907ffdf136961b84ef7d19192e6ef | flask/app.py |
def _reconfigure_for_run_debug(self, debug):
"""The ``run`` commands will set the application's debug flag. Some
application configuration may already be calculated based on the
previous debug value. This method will recalculate affected values.
Called by the :func:`flask.cli.run` c... | <mask> for processor in self.shell_context_processors:
<mask> rv.update(processor())
<mask> return rv
<mask>
<mask> def run(self, host=None, port=None, debug=None, **options):
<mask> """Runs the application on a local development server.
<mask>
<mask> Do not use... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/4fc48200a58907ffdf136961b84ef7d19192e6ef | flask/app.py |
if debug is not None:
self._reconfigure_for_run_debug(bool(debug))
| <mask> from .debughelpers import explain_ignored_app_run
<mask> explain_ignored_app_run()
<mask> return
<mask>
<mask> from werkzeug.serving import run_simple
<mask> _host = '127.0.0.1'
<mask> _port = 5000
<mask> server_name = self.config.get("... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/4fc48200a58907ffdf136961b84ef7d19192e6ef | flask/app.py |
<mask> if server_name:
<mask> sn_host, _, sn_port = server_name.partition(':')
<mask> host = host or sn_host or _host
<mask> port = int(port or sn_port or _port)
<mask> if debug is not None:
<mask> self.debug = bool(debug)
<mask> options.setdefault(... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/4fc48200a58907ffdf136961b84ef7d19192e6ef | flask/app.py | |
from werkzeug.serving import run_simple
| <mask> if debug is not None:
<mask> self.debug = bool(debug)
<mask> options.setdefault('use_reloader', self.debug)
<mask> options.setdefault('use_debugger', self.debug)
<mask> if debug:
<mask> self.jinja_env.auto_reload = True
<mask> try:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/4fc48200a58907ffdf136961b84ef7d19192e6ef | flask/app.py |
rv._reconfigure_for_run_debug(debug)
| <mask> 'http://flask.pocoo.org/docs/latest/quickstart/')
<mask> rv = locate_app(self, self.app_import_path)
<mask> debug = get_debug_flag()
<mask> if debug is not None:
<mask> rv.debug = debug
<mask> self._loaded_app = rv
<mask> return r... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/4fc48200a58907ffdf136961b84ef7d19192e6ef | flask/cli.py |
#: Blueprint local JSON decoder class to use.
# Set to None to use the :class:`~flask.app.Flask.json_encoder`.
json_encoder = None
#: Blueprint local JSON decoder class to use.
# Set to None to use the :class:`~flask.app.Flask.json_decoder`.
json_decoder = None
| <mask> _got_registered_once = False
<mask>
<mask> def __init__(self, name, import_name, static_folder=None,
<mask> static_url_path=None, template_folder=None,
<mask> url_prefix=None, subdomain=None, url_defaults=None,
<mask> root_path=None):
<mask> ... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501b8590dd8b262c93d52c92ab4b743af1f5d317 | flask/blueprints.py |
bp = current_app.blueprints.get(request.blueprint, None)
kwargs.setdefault('cls', bp.json_encoder if bp else current_app.json_encoder) | <mask>
<mask> def _dump_arg_defaults(kwargs):
<mask> """Inject default arguments for dump functions."""
<mask> if current_app:
<mask> kwargs.setdefault('cls', current_app.json_encoder)
<mask> if not current_app.config['JSON_AS_ASCII']:
<mask> kwargs.setdefault('ensure_ascii',... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501b8590dd8b262c93d52c92ab4b743af1f5d317 | flask/json.py |
bp = current_app.blueprints.get(request.blueprint, None)
kwargs.setdefault('cls', bp.json_decoder if bp else current_app.json_decoder) | <mask>
<mask> def _load_arg_defaults(kwargs):
<mask> """Inject default arguments for load functions."""
<mask> if current_app:
<mask> kwargs.setdefault('cls', current_app.json_decoder)
<mask> else:
<mask> kwargs.setdefault('cls', JSONDecoder)
<mask>
<mask>
<mask> def dumps(obj, ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501b8590dd8b262c93d52c92ab4b743af1f5d317 | flask/json.py |
with app.test_request_context(): | <mask> def test_json_as_unicode(self):
<mask> app = flask.Flask(__name__)
<mask>
<mask> app.config['JSON_AS_ASCII'] = True
<mask> with app.app_context():
<mask> rv = flask.json.dumps(u'\N{SNOWMAN}')
<mask> assert rv == '"\\u2603"'
<mask>
<mask> app.... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501b8590dd8b262c93d52c92ab4b743af1f5d317 | tests/test_helpers.py |
with app.test_request_context(): | <mask> rv = flask.json.dumps(u'\N{SNOWMAN}')
<mask> assert rv == '"\\u2603"'
<mask>
<mask> app.config['JSON_AS_ASCII'] = False
<mask> with app.app_context():
<mask> rv = flask.json.dumps(u'\N{SNOWMAN}')
<mask> assert rv == u'"\u2603"'
<mask>
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501b8590dd8b262c93d52c92ab4b743af1f5d317 | tests/test_helpers.py |
#: A dictionary with lists of functions that will be called at the
#: beginning of each request. The key of the dictionary is the name of
#: the blueprint this function is active for, or ``None`` for all
#: requests. To register a function, use the :meth:`before_request`
#: decor... | <mask> #:
<mask> #: .. versionadded:: 0.9
<mask> self.url_build_error_handlers = []
<mask>
<mask> #: A dictionary with lists of functions that should be called at the
<mask> #: beginning of the request. The key of the dictionary is the name of
<mask> #: the bluep... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
#: A list of functions that will be called at the beginning of the
#: first request to this instance. To register a function, use the
#: :meth:`before_first_request` decorator. | <mask> #: getting hold of the currently logged in user. To register a
<mask> #: function here, use the :meth:`before_request` decorator.
<mask> self.before_request_funcs = {}
<mask>
<mask> #: A lists of functions that should be called at the beginning of the
<mask> #: fir... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
#: A dictionary with lists of functions that are called before the
#: :attr:`before_request_funcs` functions. The key of the dictionary is
#: the name of the blueprint this function is active for, or ``None``
#: for all requests. To register a function, use
#: :meth:`url_value_pr... | <mask> #:
<mask> #: .. versionadded:: 0.9
<mask> self.teardown_appcontext_funcs = []
<mask>
<mask> #: A dictionary with lists of functions that can be used as URL
<mask> #: value processor functions. Whenever a URL is built these functions
<mask> #: are called to... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
For example, this can be used to open a database connection, or to load
the logged in user from the session. | <mask> @setupmethod
<mask> def before_request(self, f):
<mask> """Registers a function to run before each request.
<mask>
<mask> The function will be called without any arguments. If it returns a
<mask> non-None value, the value is handled as if it was the return value from
<mask... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
The function will be called without any arguments. If it returns a
non-None value, the value is handled as if it was the return value from
the view, and further request handling is stopped. | <mask> @setupmethod
<mask> def before_request(self, f):
<mask> """Registers a function to run before each request.
<mask>
<mask> The function will be called without any arguments.
<mask> If the function returns a non-None value, it's handled as
<mask> if it was the return... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
"""Register a URL value preprocessor function for all view
functions in the application. These functions will be called before the
:meth:`before_request` functions.
The function can modify the values captured from the matched url before
they are passed to the view. For e... | <mask> return f
<mask>
<mask> @setupmethod
<mask> def url_value_preprocessor(self, f):
<mask> """Registers a function as URL value preprocessor for all view
<mask> functions of the application. It's called before the view functions
<mask> are called and can modify the ur... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
"""Called before the request is dispatched. Calls
:attr:`url_value_preprocessors` registered with the app and the
current blueprint (if any). Then calls :attr:`before_request_funcs`
registered with the app and the blueprint.
If any :meth:`before_request` handler returns ... | <mask> reraise(exc_type, exc_value, tb)
<mask> raise error
<mask>
<mask> def preprocess_request(self):
<mask> """Called before the request dispatching.
<mask>
<mask> Triggers two set of hook functions that should be invoked prior to request dispatching:
<mask> :... | [
"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/501f0431259a30569a5e62bcce68d102fc3ef993 | flask/app.py |
- Allow custom CLIs using ``FlaskGroup`` to set the debug flag without
it always being overwritten based on environment variables. (`#2765`_) | <mask> (ISO-8859-1). This fixes compatibility with Gunicorn, which is
<mask> stricter about header encodings than PEP 3333. (`#2766`_)
<mask>
<mask> .. _#2766: https://github.com/pallets/flask/issues/2766
<mask> .. _#2765: https://github.com/pallets/flask/pull/2765
<mask>
<mask>
</s> Add option to no... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | CHANGES.rst |
.. _#2765: https://github.com/pallets/flask/pull/2765 | <mask> - Allow custom CLIs using ``FlaskGroup`` to set the debug flag without
<mask> it always being overwritten based on environment variables. (`#2765`_)
<mask>
<mask> .. _#2766: https://github.com/pallets/flask/issues/2766
<mask>
<mask>
<mask> Version 1.0.2
<mask> -------------
<mask>
<mask> Rele... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | CHANGES.rst |
def __init__(self, app_import_path=None, create_app=None,
set_debug_flag=True): | <mask> :class:`FlaskGroup` but you can also manually create it and pass it
<mask> onwards as click object.
<mask> """
<mask>
<mask> def __init__(self, app_import_path=None, create_app=None):
<mask> #: Optionally the import path for the Flask application.
<mask> self.app_import_pa... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
self.set_debug_flag = set_debug_flag | <mask> #: this script info.
<mask> self.data = {}
<mask> self._loaded_app = None
<mask>
<mask> def load_app(self):
<mask> """Loads the Flask app (if not yet loaded) and returns it. Calling
<mask> this multiple times will just result in the already loaded app to
<mas... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
if self.set_debug_flag:
# Update the app's debug flag through the descriptor so that
# other values repopulate as well.
app.debug = get_debug_flag() | <mask> 'the "FLASK_APP" environment variable, and a "wsgi.py" or '
<mask> '"app.py" module was not found in the current directory.'
<mask> )
<mask>
<mask> debug = get_debug_flag()
<mask>
<mask> # Update the app's debug flag through the descriptor so t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
:param set_debug_flag: Set the app's debug flag based on the active
environment | <mask> :param load_dotenv: Load the nearest :file:`.env` and :file:`.flaskenv`
<mask> files to set environment variables. Will also change the working
<mask> directory to the directory containing the first file found.
<mask>
<mask> .. versionchanged:: 1.0
<mask> If installed, pyth... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
add_version_option=True, load_dotenv=True,
set_debug_flag=True, **extra): | <mask> from :file:`.env` and :file:`.flaskenv` files.
<mask> """
<mask>
<mask> def __init__(self, add_default_commands=True, create_app=None,
<mask> add_version_option=True, load_dotenv=True, **extra):
<mask> params = list(extra.pop('params', None) or ())
<mask>
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
self.set_debug_flag = set_debug_flag | <mask> AppGroup.__init__(self, params=params, **extra)
<mask> self.create_app = create_app
<mask> self.load_dotenv = load_dotenv
<mask>
<mask> if add_default_commands:
<mask> self.add_command(run_command)
<mask> self.add_command(shell_command)
<mask> ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
obj = ScriptInfo(create_app=self.create_app,
set_debug_flag=self.set_debug_flag) | <mask>
<mask> obj = kwargs.get('obj')
<mask>
<mask> if obj is None:
<mask> obj = ScriptInfo(create_app=self.create_app)
<mask>
<mask> kwargs['obj'] = obj
<mask> kwargs.setdefault('auto_envvar_prefix', 'FLASK')
<mask> return super(FlaskGroup, self).main(*ar... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50227f0954e06853bbadf93d1c62dd03429b6711 | flask/cli.py |
assert b'You were logged in' in rv.data | <mask> invalid credentials. Add this new test to the class::
<mask>
<mask> def test_login_logout(self):
<mask> rv = self.login('admin', 'default')
<mask> assert 'You were logged in' in rv.data
<mask> rv = self.logout()
<mask> assert 'You were logged out' in rv.data
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5044f3d6101e5915963a497779b6ad1166a7a388 | docs/testing.rst |
assert b'You were logged out' in rv.data | <mask> def test_login_logout(self):
<mask> rv = self.login('admin', 'default')
<mask> assert 'You were logged in' in rv.data
<mask> rv = self.logout()
<mask> assert 'You were logged out' in rv.data
<mask> rv = self.login('adminx', 'default')
<mask> assert 'Invalid use... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5044f3d6101e5915963a497779b6ad1166a7a388 | docs/testing.rst |
assert b'Invalid username' in rv.data | <mask> assert 'You were logged in' in rv.data
<mask> rv = self.logout()
<mask> assert 'You were logged out' in rv.data
<mask> rv = self.login('adminx', 'default')
<mask> assert 'Invalid username' in rv.data
<mask> rv = self.login('admin', 'defaultx')
<mask> assert... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5044f3d6101e5915963a497779b6ad1166a7a388 | docs/testing.rst |
assert b'Invalid password' in rv.data | <mask> assert 'You were logged out' in rv.data
<mask> rv = self.login('adminx', 'default')
<mask> assert 'Invalid username' in rv.data
<mask> rv = self.login('admin', 'defaultx')
<mask> assert 'Invalid password' in rv.data
<mask>
<mask> Test Adding Messages
<mask> -----------... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5044f3d6101e5915963a497779b6ad1166a7a388 | docs/testing.rst |
assert b'No entries here so far' not in rv.data
assert b'<Hello>' in rv.data
assert b'<strong>HTML</strong> allowed here' in rv.data | <mask> rv = self.app.post('/add', data=dict(
<mask> title='<Hello>',
<mask> text='<strong>HTML</strong> allowed here'
<mask> ), follow_redirects=True)
<mask> assert 'No entries here so far' not in rv.data
<mask> assert '<Hello>' in rv.data
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5044f3d6101e5915963a497779b6ad1166a7a388 | docs/testing.rst |
become pretty paranoid. If an application has automated tests, you can
safely change things, and you will instantly know if your change broke | <mask>
<mask> Not sure where that is coming from, and it's not entirely correct, but
<mask> also not that far from the truth. Untested applications make it hard to
<mask> improve existing code and developers of untested applications tend to
<mask> become pretty paranoid. If an application however has automated ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/505c530c9a4c8f1b6b063bcb481a4fdcf3897709 | docs/testing.rst |
requests to the application, and the client will also keep track of cookies | <mask> each individual test function. To delete the database after the test, we
<mask> close the file and remove it from the filesystem in the
<mask> :meth:`~unittest.TestCase.tearDown` method. What the test client does is
<mask> give us a simple interface to the application. We can trigger test
<mask> requests... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/505c530c9a4c8f1b6b063bcb481a4fdcf3897709 | docs/testing.rst |
the administrative user, so we need a way to log our test client in to the | <mask> Logging In and Out
<mask> ------------------
<mask>
<mask> The majority of the functionality of our application is only available for
<mask> the administration user. So we need a way to log our test client in to the
<mask> application and out of it again. For that we fire some requests to the
<mask> lo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/505c530c9a4c8f1b6b063bcb481a4fdcf3897709 | docs/testing.rst |
Besides using the test client we used above, there is also the | <mask>
<mask> Other Testing Tricks
<mask> --------------------
<mask>
<mask> Besides using the test client we used above there is also the
<mask> :meth:`~flask.Flask.test_request_context` method that in combination with
<mask> the `with` statement can be used to activate a request context
<mask> temporarily. ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/505c530c9a4c8f1b6b063bcb481a4fdcf3897709 | docs/testing.rst |
functions. Here's a full example that showcases this:: | <mask> :meth:`~flask.Flask.test_request_context` method that in combination with
<mask> the `with` statement can be used to activate a request context
<mask> temporarily. With that you can access the :class:`~flask.request`,
<mask> :class:`~flask.g` and :class:`~flask.session` objects like in view
<mask> function... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/505c530c9a4c8f1b6b063bcb481a4fdcf3897709 | docs/testing.rst |
- Georg Brandl
- Justin Quick
- Kenneth Reitz
- Marian Sigler
- Ron DuPlain
- Sebastien Estienne
- Simon Sapin
- Stephane Wirtel
- Zhao Xiaohong | <mask>
<mask> - Chris Edgemon
<mask> - Chris Grindstaff
<mask> - Florent Xicluna
</s> Updated AUTHORS file and added missing versionadded | [
"keep",
"keep",
"keep",
"add"
] | https://github.com/pallets/flask/commit/50bca8c2d34b4b31ffcc98f6ced44b18de3c78b0 | AUTHORS |
- added the ability to register application wide error handlers
from modules.
| <mask> Release date to be announced, codename to be selected.
<mask>
<mask> Version 0.3.1
<mask> -------------
<mask>
<mask> Bugfix release, released May 28th
<mask>
</s> Updated AUTHORS file and added missing versionadded | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50bca8c2d34b4b31ffcc98f6ced44b18de3c78b0 | CHANGES |
.. versionadded:: 0.4 | <mask>
<mask> def app_errorhandler(self, code):
<mask> """Like :meth:`Flask.errorhandler` but for a module. This
<mask> handler is used for all requests, even if outside of the module.
<mask> """
<mask> def decorator(f):
<mask> self._record(lambda s: s.app.errorh... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50bca8c2d34b4b31ffcc98f6ced44b18de3c78b0 | flask.py |
Let's continue building our code in the ``flaskr.py`` file.
(Scroll to the end of the page for more about project layout.)
| <mask>
<mask> Step 4: Database Connections
<mask> ----------------------------
<mask>
<mask> You currently have a function for establishing a database connection with
<mask> `connect_db`, but by itself, it is not particularly useful. Creating and
<mask> closing database connections all the time is very ineffi... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/dbcon.rst |
Such a schema could be created by piping the ``schema.sql`` file into the
``sqlite3`` command as follows:: | <mask> systems need a schema that tells them how to store that information.
<mask> Before starting the server for the first time, it's important to create
<mask> that schema.
<mask>
<mask> Such a schema can be created by piping the ``schema.sql`` file into the
<mask> `sqlite3` command as follows::
<mask>
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/dbinit.rst |
However, the downside of this is that it requires the ``sqlite3`` command
to be installed, which is not necessarily the case on every system. This
also requires that you provide the path to the database, which can introduce
errors. | <mask> `sqlite3` command as follows::
<mask>
<mask> sqlite3 /tmp/flaskr.db < schema.sql
<mask>
<mask> The downside of this is that it requires the ``sqlite3`` command to be
<mask> installed, which is not necessarily the case on every system. This also
<mask> requires that you provide the path to the datab... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/dbinit.rst |
Instead of the ``sqlite3`` command above, it's a good idea to add a function
to our application that initializes the database for you. To do this, you
can create a function and hook it into a :command:`flask` command that
initializes the database.
Take a look at the code segment below. A good place to add this functio... | <mask> requires that you provide the path to the database, which can introduce
<mask> errors. It's a good idea to add a function that initializes the database
<mask> for you, to the application.
<mask>
<mask> To do this, you can create a function and hook it into a :command:`flask`
<mask> command that initializ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/dbinit.rst |
Now, in a terminal, from the application root directory :file:`flaskr/` it is
possible to create a database with the :command:`flask` script:: | <mask> On that cursor, there is a method to execute a complete script. Finally, you
<mask> only have to commit the changes. SQLite3 and other transactional
<mask> databases will not commit unless you explicitly tell it to.
<mask>
<mask> Now, it is possible to create a database with the :command:`flask` script::... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/dbinit.rst |
It is recommended to install your Flask application within a virtualenv. Please
read the :ref:`installation` section to set up your environment.
Now that you have installed Flask, you will need to create the folders required
for this tutorial. Your directory structure will look like this:: | <mask>
<mask> Step 0: Creating The Folders
<mask> ============================
<mask>
<mask> Before getting started, you will need to create the folders needed for this
<mask> application::
<mask>
<mask> /flaskr
<mask> /flaskr
<mask> /static
<mask> /templates
</s> Mino... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/folders.rst |
how to run ``flaskr`` later on in this tutorial.
For now go ahead and create the applications directory structure. In the next
few steps you will be creating the database schema as well as the main module. | <mask> /templates
<mask>
<mask> The application will be installed and run as Python package. This is the
<mask> recommended way to install and run Flask applications. You will see exactly
<mask> how to run ``flaskr`` later on in this tutorial. For now go ahead and create
<mask> the applications di... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/folders.rst |
Learn by example to develop an application with Python and Flask.
In this tutorial, we will create a simple blogging application. It only
supports one user, only allows text entries, and has no feeds or comments.
While very simple, this example still features everything you need to get
started. In addition to Flask, ... | <mask>
<mask> Tutorial
<mask> ========
<mask>
<mask> You want to develop an application with Python and Flask? Here you have
<mask> the chance to learn by example. In this tutorial, we will create a simple
<mask> microblogging application. It only supports one user that can create
<mask> text-only entries ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/index.rst |
.. _example source: https://github.com/pallets/flask/tree/master/examples/flaskr/ | <mask>
<mask> If you want the full source code in advance or for comparison, check out
<mask> the `example source`_.
<mask>
<mask> .. _example source:
<mask> https://github.com/pallets/flask/tree/master/examples/flaskr/
<mask>
<mask> .. toctree::
<mask> :maxdepth: 2
<mask>
<mask> introduction
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/index.rst |
following the `Python Packaging Guide`_. Presently this involves
creating two new files; :file:`setup.py` and :file:`MANIFEST.in` in the
projects root directory. You also need to add an :file:`__init__.py`
file to make the :file:`flaskr/flaskr` directory a package. After these | <mask> tutorial you will see exactly how to extend the ``flask`` command line
<mask> interface (CLI).
<mask>
<mask> A useful pattern to manage a Flask application is to install your app
<mask> following the `Python Packaging Guide`_. Presently this involves
<mask> creating two new files; :file:`setup.py` and :... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
Create the ``setup.py`` file for ``flaskr`` with the following content:: | <mask> schema.sql
<mask> setup.py
<mask> MANIFEST.in
<mask>
<mask> The content of the ``setup.py`` file for ``flaskr`` is:
<mask>
<mask> .. sourcecode:: python
<mask>
<mask> from setuptools import setup
<mask>
<mask> setup(
<mask> name='flaskr',
</s> Minor ed... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
as well as the schema.
Create the :file:`MANIFEST.in` and add the following lines:: | <mask>
<mask> When using setuptools, it is also necessary to specify any special files
<mask> that should be included in your package (in the :file:`MANIFEST.in`).
<mask> In this case, the static and templates directories need to be included,
<mask> as well as the schema. Create the :file:`MANIFEST.in` and add th... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
Next, to simplify locating the application, create the file,
:file:`flaskr/__init__.py` containing only the following import statement:: | <mask> graft flaskr/templates
<mask> graft flaskr/static
<mask> include flaskr/schema.sql
<mask>
<mask> To simplify locating the application, add the following import statement
<mask> into this file, :file:`flaskr/__init__.py`:
<mask>
<mask> .. sourcecode:: python
<mask>
<mask> from .flask... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
This import statement brings the application instance into the top-level
of the application package. When it is time to run the application, the
Flask development server needs the location of the app instance. This
import statement simplifies the location process. Without the above
import statement, the export state... | <mask> .. sourcecode:: python
<mask>
<mask> from .flaskr import app
<mask>
<mask> This import statement brings the application instance into the top-level
<mask> of the application package. When it is time to run the application, the
<mask> Flask development server needs the location of the app instance... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
With that said, from the ``flaskr/`` directory, go ahead and install the
application with:: | <mask> ``export FLASK_APP=flaskr.flaskr``.
<mask>
<mask> At this point you should be able to install the application. As usual, it
<mask> is recommended to install your Flask application within a `virtualenv`_.
<mask> With that said, go ahead and install the application with::
<mask>
<mask> pip install --... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
The above installation command assumes that it is run within the projects
root directory, ``flaskr/``. The ``editable`` flag allows editing
source code without having to reinstall the Flask app each time you make
changes. The flaskr app is now installed in your virtualenv (see output | <mask> With that said, go ahead and install the application with::
<mask>
<mask> pip install --editable .
<mask>
<mask> The above installation command assumes that it is run within the projects
<mask> root directory, `flaskr/`. The `editable` flag allows editing
<mask> source code without having to rein... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
Do this on Mac or Linux with the following commands in ``flaskr/``:: | <mask> changes. The flaskr app is now installed in your virtualenv (see output
<mask> of ``pip freeze``).
<mask>
<mask> With that out of the way, you should be able to start up the application.
<mask> Do this with the following commands::
<mask>
<mask> export FLASK_APP=flaskr
<mask> export FLASK_DEB... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
(In case you are on Windows you need to use ``set`` instead of ``export``). | <mask> export FLASK_APP=flaskr
<mask> export FLASK_DEBUG=true
<mask> flask run
<mask>
<mask> (In case you are on Windows you need to use `set` instead of `export`).
<mask> The :envvar:`FLASK_DEBUG` flag enables or disables the interactive debugger.
<mask> *Never leave debug mode activated in a produ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
the address at which you can access it in a browser. | <mask> *Never leave debug mode activated in a production system*, because it will
<mask> allow users to execute code on the server!
<mask>
<mask> You will see a message telling you that server has started along with
<mask> the address at which you can access it.
<mask>
<mask> When you head over to the server i... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/packaging.rst |
Next, we will create the application module, :file:`flaskr.py`. Just like the
:file:`schema.sql` file you created in the previous step, this file should be
placed inside of the :file:`flaskr/flaskr` folder.
For this tutorial, all the Python code we use will be put into this file
(except for one line in ``__init__.py`... | <mask>
<mask> Step 2: Application Setup Code
<mask> ==============================
<mask>
<mask> Now that the schema is in place, you can create the application module,
<mask> :file:`flaskr.py`. This file should be placed inside of the
<mask> :file:`flaskr/flaskr` folder. The first several lines of code in t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
<mask> import the values from there.
<mask>
<mask> Here are the import statements (in :file:`flaskr.py`)::
<mask>
<mask> # all the imports
<mask> import os
<mask> import sqlite3
<mask> from flask import Flask, request, session, g, redirect, url_for, abort, \
<mask> render_template, f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst | |
<mask>
<mask> # all the imports
<mask> import os
<mask> import sqlite3
<mask> from flask import Flask, request, session, g, redirect, url_for, abort, \
<mask> render_template, flash
<mask>
<mask> The next couple lines will create the actual application instance and
<mask> initialize ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst | |
from flask import (Flask, request, session, g, redirect, url_for, abort,
render_template, flash) | <mask> import sqlite3
<mask> from flask import Flask, request, session, g, redirect, url_for, abort, \
<mask> render_template, flash
<mask>
<mask> The next couple lines will create the actual application instance and
<mask> initialize it with the config from the same file in :file:`flaskr.py`:
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
The next couple lines will create the actual application instance and
initialize it with the config from the same file in :file:`flaskr.py`:: | <mask>
<mask> The next couple lines will create the actual application instance and
<mask> initialize it with the config from the same file in :file:`flaskr.py`:
<mask>
<mask> .. sourcecode:: python
<mask>
<mask> app = Flask(__name__) # create the application instance :)
<mask> app.config.from_object... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
In the above code, the :class:`~flask.Config` object works similarly to a
dictionary, so it can be updated with new values. | <mask> PASSWORD='default'
<mask> ))
<mask> app.config.from_envvar('FLASKR_SETTINGS', silent=True)
<mask>
<mask> The :class:`~flask.Config` object works similarly to a dictionary, so it can be
<mask> updated with new values.
<mask>
<mask> .. admonition:: Database Path
<mask>
<mask> Opera... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
configuration setups. :meth:`~flask.Config.from_envvar` can help achieve
this. :: | <mask>
<mask> Usually, it is a good idea to load a separate, environment-specific
<mask> configuration file. Flask allows you to import multiple configurations and it
<mask> will use the setting defined in the last import. This enables robust
<mask> configuration setups. :meth:`~flask.Config.from_envvar` can h... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
If you want to do this (not required for this tutorial) simply define the
environment variable :envvar:`FLASKR_SETTINGS` that points to a config file
to be loaded. The silent switch just tells Flask to not complain if no such
environment key is set. | <mask> .. sourcecode:: python
<mask>
<mask> app.config.from_envvar('FLASKR_SETTINGS', silent=True)
<mask>
<mask> Simply define the environment variable :envvar:`FLASKR_SETTINGS` that points to
<mask> a config file to be loaded. The silent switch just tells Flask to not complain
<mask> if no such environmen... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
Lastly, add a method that allows for easy connections to the specified
database. :: | <mask>
<mask> The ``SECRET_KEY`` is needed to keep the client-side sessions secure.
<mask> Choose that key wisely and as hard to guess and complex as possible.
<mask>
<mask> Lastly, you will add a method that allows for easy connections to the
<mask> specified database. This can be used to open a connection on... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
This can be used to open a connection on request and also from the
interactive Python shell or a script. This will come in handy later.
You can create a simple database connection through SQLite and then tell
it to use the :class:`sqlite3.Row` object to represent rows. This allows
the rows to be treated as if they wer... | <mask> rv.row_factory = sqlite3.Row
<mask> return rv
<mask>
<mask> In the next section you will see how to run the application.
<mask>
<mask> Continue with :ref:`tutorial-packaging`.
</s> Minor edits to tutorial for clarity. (#2330) </s> remove how to run ``flaskr`` later on in this tutorial. ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/setup.rst |
Create the follwing three HTML files and place them in the
:file:`templates` folder: | <mask>
<mask> We are also using template inheritance which makes it possible to reuse
<mask> the layout of the website in all pages.
<mask>
<mask> Put the following templates into the :file:`templates` folder:
<mask>
<mask> .. _Jinja2: http://jinja.pocoo.org/docs/templates
<mask>
<mask> layout.html
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/templates.rst |
view functions. You will need four of them; Show Entries, Add New Entry,
Login and Logout. Add the following code snipets to :file:`flaskr.py`. | <mask> Step 6: The View Functions
<mask> ==========================
<mask>
<mask> Now that the database connections are working, you can start writing the
<mask> view functions. You will need four of them:
<mask>
<mask> Show Entries
<mask> ------------
<mask>
<mask> This view shows all the entries stored ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/50c6df709800ac7504b71209564c8ce5b746d2b8 | docs/tutorial/views.rst |
<mask> if not username:
<mask> error = 'Username is required.'
<mask> elif not password:
<mask> error = 'Password is required.'
<mask> elif db.execute(
<mask> 'SELECT id FROM user WHERE username = ?', (username,)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | docs/tutorial/views.rst | |
try:
db.execute(
"INSERT INTO user (username, password) VALUES (?, ?)",
(username, generate_password_hash(password)),
)
db.commit()
except db.IntegrityError:
er... | <mask> ).fetchone() is not None:
<mask> error = f"User {username} is already registered."
<mask>
<mask> if error is None:
<mask> db.execute(
<mask> 'INSERT INTO user (username, password) VALUES (?, ?)',
<mask> (usern... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | docs/tutorial/views.rst |
#. If validation succeeds, insert the new user data into the database. | <mask> input their ``username`` and ``password``.
<mask>
<mask> #. Validate that ``username`` and ``password`` are not empty.
<mask>
<mask> #. Validate that ``username`` is not already registered by querying the
<mask> database and checking if a result is returned.
<mask> :meth:`db.execute <sqlit... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | docs/tutorial/views.rst |
- :meth:`db.execute <sqlite3.Connection.execute>` takes a SQL
query with ``?`` placeholders for any user input, and a tuple of
values to replace the placeholders with. The database library
will take care of escaping the values so you are not vulnerable
to a *SQL injection attack*. | <mask> to replace the placeholders with. The database library will take
<mask> care of escaping the values so you are not vulnerable to a
<mask> *SQL injection attack*.
<mask>
<mask> :meth:`~sqlite3.Cursor.fetchone` returns one row from the query.
<mask> If the query returned no results, it r... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | docs/tutorial/views.rst |
- For security, passwords should never be stored in the database
directly. Instead,
:func:`~werkzeug.security.generate_password_hash` is used to
securely hash the password, and that hash is stored. Since this
query modifies data,
:meth:`db.commit() <sqlite3.Connection.commi... | <mask> If the query returned no results, it returns ``None``. Later,
<mask> :meth:`~sqlite3.Cursor.fetchall` is used, which returns a list of
<mask> all results.
<mask>
<mask> #. If validation succeeds, insert the new user data into the database.
<mask> For security, passwords should never be st... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | docs/tutorial/views.rst |
:meth:`~sqlite3.Cursor.fetchone` returns one row from the query.
If the query returned no results, it returns ``None``. Later,
:meth:`~sqlite3.Cursor.fetchall` will be used, which returns a list
of all results.
| <mask> There are a few differences from the ``register`` view:
<mask>
<mask> #. The user is queried first and stored in a variable for later use.
<mask>
<mask> #. :func:`~werkzeug.security.check_password_hash` hashes the submitted
<mask> password in the same way as the stored hash and securely compares
<... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | docs/tutorial/views.rst |
<mask> if not username:
<mask> error = "Username is required."
<mask> elif not password:
<mask> error = "Password is required."
<mask> elif (
<mask> db.execute("SELECT id FROM user WHERE username = ?", (username,)).fetchone()
<mask> is not N... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | examples/tutorial/flaskr/auth.py | |
try:
db.execute(
"INSERT INTO user (username, password) VALUES (?, ?)",
(username, generate_password_hash(password)),
)
db.commit()
except db.IntegrityError:
# The username was already taken, ... | <mask> ):
<mask> error = f"User {username} is already registered."
<mask>
<mask> if error is None:
<mask> # the name is available, store it in the database and go to
<mask> # the login page
<mask> db.execute(
<mask> "INSERT INTO us... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51196575479e34c3ea43612e1eb770db3aa5d114 | examples/tutorial/flaskr/auth.py |
<mask> or upgrade your key incorrectly.
<mask>
<mask> - https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning
<mask>
<mask> Copy/Paste Security Issues
<mask> ~~~~~~~~~~~~~~~~~~~~~~~~~~
<mask>
<mask> If your website allows users to upload their own code, hidden characters
<mask> such as the... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51686f5ab44fce6bc487545f621e199d726b6f50 | docs/security.rst | |
Copy/Paste to Terminal
----------------------
Hidden characters such as the backspace character (``\b``, ``^H``) can
cause text to render differently in HTML than how it is interpreted if
`pasted into a terminal <https://security.stackexchange.com/q/39118>`__. | <mask>
<mask> Copy/Paste Security Issues
<mask> ~~~~~~~~~~~~~~~~~~~~~~~~~~
<mask>
<mask> If your website allows users to upload their own code, hidden characters
<mask> such as the backspace character (``\b``, ``^H``) can cause the code to
<mask> have a different meaning when copy and pasted into terminals.
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51686f5ab44fce6bc487545f621e199d726b6f50 | docs/security.rst |
``import yosemite`` in HTML, but the backspaces are applied when pasted
into a terminal, and it becomes ``import os``. | <mask> such as the backspace character (``\b``, ``^H``) can cause the code to
<mask> have a different meaning when copy and pasted into terminals.
<mask>
<mask> For example, ``import y\bose\bm\bi\bt\be\b`` renders as
<mask> ``import yosemite`` but becomes ``import os`` when pasted in a terminal.
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51686f5ab44fce6bc487545f621e199d726b6f50 | docs/security.rst |
If you expect users to copy and paste untrusted code from your site,
such as from comments posted by users on a technical blog, consider
applying extra filtering, such as replacing all ``\b`` characters. | <mask>
<mask> For example, ``import y\bose\bm\bi\bt\be\b`` renders as
<mask> ``import yosemite`` but becomes ``import os`` when pasted in a terminal.
<mask>
<mask> Consider applying extra filtering, such as replacing all ``\b``
<mask> characters.
<mask>
<mask> .. code-block:: python
<mask>
<mask> body... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51686f5ab44fce6bc487545f621e199d726b6f50 | docs/security.rst |
Most modern terminals will warn about and remove hidden characters when
pasting, so this isn't strictly necessary. It's also possible to craft
dangerous commands in other ways that aren't possible to filter.
Depending on your site's use case, it may be good to show a warning
about copying code in general. | <mask> .. code-block:: python
<mask>
<mask> body = body.replace("\b", "")
<mask>
<mask> - https://security.stackexchange.com/q/39118
</s> expand section on copy/paste security </s> remove Consider applying extra filtering, such as replacing all ``\b``
characters.
</s> add If you expect users to copy and pa... | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/pallets/flask/commit/51686f5ab44fce6bc487545f621e199d726b6f50 | docs/security.rst |
#: The name of the package or module. Do not change this once | <mask>
<mask> class _PackageBoundObject(object):
<mask>
<mask> def __init__(self, import_name):
<mask> #: the name of the package or module. Do not change this once
<mask> #: it was set by the constructor.
<mask> self.import_name = import_name
<mask>
<mask> #: where is t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: Where is the app root located? | <mask> #: the name of the package or module. Do not change this once
<mask> #: it was set by the constructor.
<mask> self.import_name = import_name
<mask>
<mask> #: where is the app root located?
<mask> self.root_path = _get_package_path(self.import_name)
<mask>
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The class that is used for request objects. See :class:`~flask.Request` | <mask> from flask import Flask
<mask> app = Flask(__name__)
<mask> """
<mask>
<mask> #: the class that is used for request objects. See :class:`~flask.Request`
<mask> #: for more information.
<mask> request_class = Request
<mask>
<mask> #: the class that is used for respo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The class that is used for response objects. See | <mask> #: the class that is used for request objects. See :class:`~flask.Request`
<mask> #: for more information.
<mask> request_class = Request
<mask>
<mask> #: the class that is used for response objects. See
<mask> #: :class:`~flask.Response` for more information.
<mask> response_cl... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: Path for the static files. If you don't want to use static files | <mask> #: the class that is used for response objects. See
<mask> #: :class:`~flask.Response` for more information.
<mask> response_class = Response
<mask>
<mask> #: path for the static files. If you don't want to use static files
<mask> #: you can set this value to `None` in which case no ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The debug flag. Set this to `True` to enable debugging of the | <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> #: the debug flag. Set this to `True` to enable debugging of the
<mask> #: application. In d... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: If a secret key is set, cryptographic components can use this to | <mask> #: This attribute can also be configured from the config with the `DEBUG`
<mask> #: configuration key. Defaults to `False`.
<mask> debug = ConfigAttribute('DEBUG')
<mask>
<mask> #: if a secret key is set, cryptographic components can use this to
<mask> #: sign cookies and other things... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The secure cookie uses this for the name of the session cookie. | <mask> #: This attribute can also be configured from the config with the
<mask> #: `SECRET_KEY` configuration key. Defaults to `None`.
<mask> secret_key = ConfigAttribute('SECRET_KEY')
<mask>
<mask> #: The secure cookie uses this for the name of the session cookie
<mask> #:
<mask> #: Th... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The name of the logger to use. By default the logger name is the | <mask> #: This attribute can also be configured from the config with the
<mask> #: `USE_X_SENDFILE` configuration key. Defaults to `False`.
<mask> use_x_sendfile = ConfigAttribute('USE_X_SENDFILE')
<mask>
<mask> #: the name of the logger to use. By default the logger name is the
<mask> #: p... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The logging format used for the debug logger. This is only used when | <mask> #:
<mask> #: .. versionadded:: 0.4
<mask> logger_name = ConfigAttribute('LOGGER_NAME')
<mask>
<mask> #: the logging format used for the debug logger. This is only used when
<mask> #: the application is in debug mode, otherwise the attached logging
<mask> #: handler does the forma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: Options that are passed directly to the Jinja2 environment. | <mask> '%(message)s\n' +
<mask> '-' * 80
<mask> )
<mask>
<mask> #: options that are passed directly to the Jinja2 environment
<mask> jinja_options = ImmutableDict(
<mask> autoescape=True,
<mask> extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']
<mask> )
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: Default configuration parameters. | <mask> autoescape=True,
<mask> extensions=['jinja2.ext.autoescape', 'jinja2.ext.with_']
<mask> )
<mask>
<mask> #: default configuration parameters
<mask> default_config = ImmutableDict({
<mask> 'DEBUG': False,
<mask> 'SECRET_KEY': ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The configuration dictionary as :class:`Config`. This behaves | <mask>
<mask> def __init__(self, import_name):
<mask> _PackageBoundObject.__init__(self, import_name)
<mask>
<mask> #: the configuration dictionary as :class:`Config`. This behaves
<mask> #: exactly like a regular dictionary but supports additional methods
<mask> #: to load... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: Prepare the deferred setup of the logger. | <mask> #: exactly like a regular dictionary but supports additional methods
<mask> #: to load a config from files.
<mask> self.config = Config(self.root_path, self.default_config)
<mask>
<mask> #: prepare the deferred setup of the logger
<mask> self._logger = None
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: A dictionary of all view functions registered. The keys will | <mask> #: prepare the deferred setup of the logger
<mask> self._logger = None
<mask> self.logger_name = self.import_name
<mask>
<mask> #: a dictionary of all view functions registered. The keys will
<mask> #: be function names which are also used to generate URLs and
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
#: The Jinja2 environment. It is created from the | <mask> self.wsgi_app = SharedDataMiddleware(self.wsgi_app, {
<mask> self.static_path: target
<mask> })
<mask>
<mask> #: the Jinja2 environment. It is created from the
<mask> #: :attr:`jinja_options` and the loader that is returned
<mask> #: by the... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/51a5add86d0fa9889b69d51d45d06a2ac4c5df9f | flask.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.