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 |
|---|---|---|---|---|
Sometimes when building a Flask application, you might want to raise a
:exc:`~werkzeug.exceptions.HTTPException` to signal to the user that
something is wrong with the request. Fortunately, Flask comes with a handy
:func:`~flask.abort` function that aborts a request with a HTTP error from
werkzeug as desired. It will a... | <mask> return render_template("500_unhandled.html", e=original), 500
<mask>
<mask>
<mask>
<mask> Registering Custom Exceptions
<mask> -----------------------------
<mask>
<mask> You can create your own custom exceptions by subclassing
<mask> :exc:`werkzeug.exceptions.HTTPException`. As shown above,... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
Depending on the error code it is less or more likely for the user to
actually see such an error. | <mask>
<mask> Registering Custom Exceptions
<mask> -----------------------------
<mask>
<mask> You can create your own custom exceptions by subclassing
<mask> :exc:`werkzeug.exceptions.HTTPException`. As shown above, integer HTTP codes
<mask> are interchangable when registering handlers. (``BadRequest.code == ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
Consider the code below, we might have a user profile route, and if the user
fails to pass a username we can raise a "400 Bad Request". If the user passes a
username and we can't find it, we raise a "404 Not Found". | <mask> You can create your own custom exceptions by subclassing
<mask> :exc:`werkzeug.exceptions.HTTPException`. As shown above, integer HTTP codes
<mask> are interchangable when registering handlers. (``BadRequest.code == 400``)
<mask>
<mask> Non-standard HTTP codes cannot be registered by code because they are ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
from flask import abort, render_template, request | <mask> register and raise that exception class:
<mask>
<mask> .. code-block:: python
<mask>
<mask> class InsufficientStorage(werkzeug.exceptions.HTTPException):
<mask> code = 507
<mask> description = 'Not enough storage space.'
<mask>
<mask> def handle_507(e):
<mask> return ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
# a username needs to be supplied in the query args
# a successful request would be like /profile?username=jack
@app.route("/profile")
def user_profile():
username = request.arg.get("username")
# if a username isn't supplied in the request, return a 400 bad request
if username is... | <mask> class InsufficientStorage(werkzeug.exceptions.HTTPException):
<mask> code = 507
<mask> description = 'Not enough storage space.'
<mask>
<mask> def handle_507(e):
<mask> return 'Not enough storage space!', 507
<mask>
<mask> app.register_error_handler(InsufficientStora... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
user = get_user(username=username)
# if a user can't be found by their username, return 404 not found
if user is None:
abort(404) | <mask>
<mask> def handle_507(e):
<mask> return 'Not enough storage space!', 507
<mask>
<mask> app.register_error_handler(InsufficientStorage, handle_507)
<mask>
<mask> # during an request
<mask> raise InsufficientStorage()
<mask>
<mask> Handlers can be registered for any exception ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
return render_template("profile.html", user=user) | <mask> return 'Not enough storage space!', 507
<mask>
<mask> app.register_error_handler(InsufficientStorage, handle_507)
<mask>
<mask> # during an request
<mask> raise InsufficientStorage()
<mask>
<mask> Handlers can be registered for any exception class that inherits from Exception.
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
Here is another example implementation for a "404 Page Not Found" exception:: | <mask>
<mask> # during an request
<mask> raise InsufficientStorage()
<mask>
<mask> Handlers can be registered for any exception class that inherits from Exception.
<mask>
<mask>
<mask> Unhandled Exceptions
<mask> --------------------
<mask>
</s> more changes to consolidated error handling docs <... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
from flask import render_template | <mask>
<mask> Here is another example implementation for a "404 Page Not Found" exception::
<mask>
<mask>
<mask> @app.errorhandler(404)
<mask> def page_not_found(e):
<mask> # note that we set the 404 status explicitly
</s> more changes to consolidated error handling docs </s> remove Handlers ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
@app.errorhandler(404)
def page_not_found(e):
# note that we set the 404 status explicitly
return render_template('404.html'), 404 | <mask>
<mask> Handlers can be registered for any exception class that inherits from Exception.
<mask>
<mask>
<mask> Unhandled Exceptions
<mask> --------------------
<mask>
<mask> If an exception is raised in the code while Flask is handling a request and
<mask> there is no error handler registered for that... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
When using :doc:`/patterns/appfactories`:: | <mask>
<mask> Unhandled Exceptions
<mask> --------------------
<mask>
<mask> If an exception is raised in the code while Flask is handling a request and
<mask> there is no error handler registered for that exception, a "500 Internal Server
<mask> Error" will be returned instead. See :meth:`flask.Flask.handle_e... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
from flask import Flask, render_template
def page_not_found(e):
return render_template('404.html'), 404
def create_app(config_filename):
app = Flask(__name__)
app.register_error_handler(404, page_not_found)
return app
An example template might be this:
.. sourcecode:: html+... | <mask> there is no error handler registered for that exception, a "500 Internal Server
<mask> Error" will be returned instead. See :meth:`flask.Flask.handle_exception` for
<mask> information about this behavior.
<mask>
<mask> Custom error pages
<mask> ------------------
<mask>
<mask> The above examples wouldn... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
When using :doc:`/patterns/appfactories`: | <mask> # note that we set the 500 status explicitly
<mask> return render_template('500.html'), 500
<mask>
<mask>
<mask> When using the :doc:`/patterns/appfactories`:
<mask>
<mask> .. code-block:: python
<mask>
<mask>
<mask> from flask import Flask, render_template
</s> more changes t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
Blueprint Error Handling
```````````````````````` | <mask>
<mask> # or with register_error_handler
<mask> blog.register_error_handler(500, internal_server_error)
<mask>
<mask>
<mask> In blueprints, error handlers will work as expected. However, there is a caveat
<mask> concerning handlers for 404 and 405 exceptions. These error handlers are only
<mas... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
In blueprints, error handlers will work as expected. However, there is a caveat
concerning handlers for 404 and 405 exceptions. These error handlers are only | <mask> # or with register_error_handler
<mask> blog.register_error_handler(500, internal_server_error)
<mask>
<mask>
<mask>
<mask> In blueprints errorhandlers will simply work as expected; however, there is a caveat
<mask> concerning handlers for 404 and 405 exceptions. These errorhandlers are only
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
access.
This is because the blueprint does not "own" a certain URL space, so | <mask> In blueprints errorhandlers will simply work as expected; however, there is a caveat
<mask> concerning handlers for 404 and 405 exceptions. These errorhandlers are only
<mask> invoked from an appropriate ``raise`` statement or a call to ``abort`` in another
<mask> of the blueprint's view functions; they are... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
should run if given an invalid URL. If you would like to execute different | <mask> invoked from an appropriate ``raise`` statement or a call to ``abort`` in another
<mask> of the blueprint's view functions; they are not invoked by, e.g., an invalid URL
<mask> access. This is because the blueprint does not "own" a certain URL space, so
<mask> the application instance has no way of knowing ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
For more information on Blueprint Error Handling see :ref:`my-blueprint-error-label`. | <mask> return render_template("405.html"), 405
<mask>
<mask>
<mask>
<mask> More information on error handling with blueprint can be found in
<mask> :doc:`/blueprints`.
<mask>
<mask>
<mask> Returning API errors as JSON
<mask> ````````````````````````````
<mask>
<mask> When building APIs in ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
When building APIs in Flask, some developers realise that the built-in | <mask>
<mask> Returning API errors as JSON
<mask> ````````````````````````````
<mask>
<mask> When building APIs in Flask, some developers realise that the builtin
<mask> exceptions are not expressive enough for APIs and that the content type of
<mask> :mimetype:`text/html` they are emitting is not very useful ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
with a ``description`` parameter. The error handler will | <mask> :mimetype:`text/html` they are emitting is not very useful for API consumers.
<mask>
<mask> Using the same techniques as above and :func:`~flask.json.jsonify` we can return JSON
<mask> responses to API errors. :func:`~flask.abort` is called
<mask> with a ``description`` parameter. The errorhandler will
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
We can also create custom exception classes. For instance, we can
introduce a new custom exception for an API that can take a proper human readable message, | <mask> abort(404, description="Resource not found")
<mask>
<mask> return jsonify(resource)
<mask>
<mask>
<mask>
<mask> We can also create custom exception classes; for instance, for an API we can
<mask> introduce a new custom exception that can take a proper human readable message,
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
A view can now raise that exception with an error message. Additionally | <mask>
<mask> return jsonify(user.to_dict())
<mask>
<mask>
<mask> A view can now raise that exception with an error message. Additionally
<mask> some extra payload can be provided as a dictionary through the `payload`
<mask> parameter.
<mask>
<mask>
<mask> Generic Exception Handlers
</s> more c... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
Logging
------- | <mask> A view can now raise that exception with an error message. Additionally
<mask> some extra payload can be provided as a dictionary through the `payload`
<mask> parameter.
<mask>
<mask>
<mask> See :doc:`/logging` for information on how to log exceptions, such as by
<mask> emailing them to admins.
<mask> ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
See :doc:`/logging` for information on how to log exceptions, such as by
emailing them to admins. | <mask> some extra payload can be provided as a dictionary through the `payload`
<mask> parameter.
<mask>
<mask>
<mask> Generic Exception Handlers
<mask> ``````````````````````````
<mask>
<mask> It is possible to register error handlers for very generic base classes
<mask> such as ``HTTPException`` or even `... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
============================ | <mask>
<mask>
<mask>
<mask> Debugging Application Errors
<mask> ````````````````````````````
<mask>
<mask> For production applications, configure your application with logging and
<mask> notifications as described in :doc:`/logging`. This section provides
<mask> pointers when debugging deployment configura... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst |
<mask> notifications as described in :doc:`/logging`. This section provides
<mask> pointers when debugging deployment configuration and digging deeper with a
<mask> full-featured Python debugger.
<mask>
<mask> Logging
<mask> -------
<mask>
<mask> See :doc:`/logging` for information on how to log exceptions, s... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst | |
<mask>
<mask> use_debugger = app.debug and not(app.config.get('DEBUG_WITH_APTANA'))
<mask> app.run(use_debugger=use_debugger, debug=app.debug,
<mask> use_reloader=use_debugger, host='0.0.0.0')
<mask>
<mask>
<mask> .. _error-logging-tools:
<mask>
<mask>
<mask> Error Logging To... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/pallets/flask/commit/569c88d72102e502d71c07193182adb1769ee936 | docs/errorhandling.rst | |
def get_namespace(self, namespace, lowercase=True, trim_namespace=True): | <mask> if key.isupper():
<mask> self[key] = value
<mask> return True
<mask>
<mask> def get_namespace(self, namespace, lowercase=True):
<mask> """Returns a dictionary containing a subset of configuration options
<mask> that match the specified names... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56a7e8361d978c9ae2981167f3b4d959f2cf21e2 | flask/config.py |
:param trim_namespace: a flag indicating if the keys of the resulting
dictionary should not include the namespace | <mask> :param lowercase: a flag indicating if the keys of the resulting
<mask> dictionary should be lowercase
<mask>
<mask> .. versionadded:: 1.0
<mask> """
<mask> rv = {}
<mask> for k, v in iteritems(self):
<mask> if not k.startswit... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56a7e8361d978c9ae2981167f3b4d959f2cf21e2 | flask/config.py |
if trim_namespace:
key = k[len(namespace):] | <mask> rv = {}
<mask> for k, v in iteritems(self):
<mask> if not k.startswith(namespace):
<mask> continue
<mask> key = k[len(namespace):]
<mask> if lowercase:
<mask> key = key.lower()
<mask> rv[key] = v
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56a7e8361d978c9ae2981167f3b4d959f2cf21e2 | flask/config.py |
"""Adds an entry to sys.path_info if it's not already there. This does
not append it but moves it to the front so that we can be sure it
is loaded.
""" | <mask> from werkzeug.utils import import_string, find_modules
<mask>
<mask>
<mask> def add_to_path(path):
<mask> """Adds an entry to sys.path_info if it's not already there."""
<mask> if not os.path.isdir(path):
<mask> raise RuntimeError('Tried to add nonexisting path')
<mask>
<mask> def... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56afafae67ff0db8b9994a4c59d978b56327e886 | flask/testsuite/__init__.py |
sys.path[:] = [x for x in sys.path if not _samefile(path, x)]
sys.path.insert(0, path) | <mask> try:
<mask> return os.path.samefile(x, y)
<mask> except (IOError, OSError):
<mask> return False
<mask> for entry in sys.path:
<mask> try:
<mask> if os.path.samefile(path, entry):
<mask> return
<mask> except (OSError,... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56afafae67ff0db8b9994a4c59d978b56327e886 | flask/testsuite/__init__.py |
# we clear this out for various reasons. The most important one is
# that a real flaskext could be in there which would disable our
# fake package. Secondly we want to make sure that the flaskext
# import hook does not break on reloading. | <mask>
<mask> class ExtImportHookTestCase(FlaskTestCase):
<mask>
<mask> def setup(self):
<mask> for entry, value in sys.modules.items():
<mask> if (entry.startswith('flask.ext.') or
<mask> entry.startswith('flask_') or
<mask> entry.startswith('flaskext.'... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56afafae67ff0db8b9994a4c59d978b56327e886 | flask/testsuite/ext.py |
entry.startswith('flaskext.') or
entry == 'flaskext') and value is not None: | <mask> def setup(self):
<mask> for entry, value in sys.modules.items():
<mask> if (entry.startswith('flask.ext.') or
<mask> entry.startswith('flask_') or
<mask> entry.startswith('flaskext.')) and value is not None:
<mask> sys.modules.pop(entr... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56afafae67ff0db8b9994a4c59d978b56327e886 | flask/testsuite/ext.py |
<mask>
<mask> .. code-block:: python
<mask>
<mask> from flask import Flask
<mask> from markupsafe import escape
<mask>
<mask> app = Flask(__name__)
<mask>
<mask> @app.route("/")
<mask> def hello_world():
</s> Move HTML escaping example back to Variable Rules.
Demonstration of markups... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst | |
return "<p>Hello, World!</p>" | <mask> app = Flask(__name__)
<mask>
<mask> @app.route("/")
<mask> def hello_world():
<mask> return f"<p>Hello, {escape(name)}!</p>"
<mask>
<mask> So what did that code do?
<mask>
<mask> 1. First we imported the :class:`~flask.Flask` class. An instance of
<mask> this class will be o... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst |
<mask> 4. The function returns the message we want to display in the user's
<mask> browser. The default content type is HTML, so HTML in the string
<mask> will be rendered by the browser.
<mask>
<mask> .. note:: HTML escaping
<mask>
<mask> When returning HTML (the default response type in Flask), ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst | |
return f'User {escape(username)}' | <mask>
<mask> @app.route('/user/<username>')
<mask> def show_user_profile(username):
<mask> # show the user profile for that user
<mask> return f'User {username}'
<mask>
<mask> @app.route('/post/<int:post_id>')
<mask> def show_post(post_id):
<mask> # show the post with... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst |
return f'Post {escape(post_id)}' | <mask>
<mask> @app.route('/post/<int:post_id>')
<mask> def show_post(post_id):
<mask> # show the post with the given id, the id is an integer
<mask> return f'Post {post_id}'
<mask>
<mask> @app.route('/path/<path:subpath>')
<mask> def show_subpath(subpath):
<mask> # sho... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst |
return f'Subpath {escape(subpath)}' | <mask>
<mask> @app.route('/path/<path:subpath>')
<mask> def show_subpath(subpath):
<mask> # show the subpath after /path/
<mask> return f'Subpath {subpath}'
<mask>
<mask> Converter types:
<mask>
<mask> ========== ==========================================
<mask> ``string`` (default)... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst |
.. note:: HTML escaping
When returning HTML (the default response type in Flask), any user
input rendered in the output must be escaped to protect from
injection attacks. HTML templates in Jinja, introduced later, will
do this automatically. :func:`~markupsafe.escape`, shown above, can
be used manu... | <mask> ``path`` like ``string`` but also accepts slashes
<mask> ``uuid`` accepts UUID strings
<mask> ========== ==========================================
<mask>
<mask> Unique URLs / Redirection Behavior
<mask> ``````````````````````````````````
<mask>
<mask> The following two rules differ in their use of... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/56e75eace520a78cbee07570706519b0680b7d29 | docs/quickstart.rst |
from markupsafe import escape
| <mask> as a keyword argument. Optionally, you can use a converter to specify the type
<mask> of the argument like ``<converter:variable_name>``. ::
<mask>
<mask> @app.route('/user/<username>')
<mask> def show_user_profile(username):
<mask> # show the user profile for that user
<mask> ret... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/571e92b317a8ccd86ea3a5eb3231a78529f48baa | docs/quickstart.rst |
from flask import Flask, url_for
from markupsafe import escape | <mask> Python shell. See :ref:`context-locals`.
<mask>
<mask> .. code-block:: python
<mask>
<mask> from flask import Flask, escape, url_for
<mask>
<mask> app = Flask(__name__)
<mask>
<mask> @app.route('/')
<mask> def index():
</s> add import for escape in quickstart
import escape from ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/571e92b317a8ccd86ea3a5eb3231a78529f48baa | docs/quickstart.rst |
Here is a basic introduction to how the :class:`~markupsafe.Markup` class works:: | <mask> markup to HTML) you can mark it as safe by using the
<mask> :class:`~jinja2.Markup` class or by using the ``|safe`` filter in the
<mask> template. Head over to the Jinja 2 documentation for more examples.
<mask>
<mask> Here is a basic introduction to how the :class:`~jinja2.Markup` class works::
<mask>
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/571e92b317a8ccd86ea3a5eb3231a78529f48baa | docs/quickstart.rst |
>>> from markupsafe import Markup | <mask> template. Head over to the Jinja 2 documentation for more examples.
<mask>
<mask> Here is a basic introduction to how the :class:`~jinja2.Markup` class works::
<mask>
<mask> >>> from flask import Markup
<mask> >>> Markup('<strong>Hello %s!</strong>') % '<blink>hacker</blink>'
<mask> Markup(... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/571e92b317a8ccd86ea3a5eb3231a78529f48baa | docs/quickstart.rst |
from flask import Flask, session, redirect, url_for, request
from markupsafe import escape | <mask>
<mask> In order to use sessions you have to set a secret key. Here is how
<mask> sessions work::
<mask>
<mask> from flask import Flask, session, redirect, url_for, escape, request
<mask>
<mask> app = Flask(__name__)
<mask>
<mask> # Set the secret key to some random bytes. Keep this real... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/571e92b317a8ccd86ea3a5eb3231a78529f48baa | docs/quickstart.rst |
.PHONY: clean-pyc ext-test test test-with-mem upload-docs docs audit | <mask> .PHONY: clean-pyc ext-test test upload-docs docs audit
<mask>
<mask> all: clean-pyc test
<mask>
<mask> test:
<mask> python run-tests.py
</s> Disabled memory tests by default </s> remove suite.addTest(unittest.makeSuite(MemoryTestCase))
</s> add if os.environ.get('RUN_FLASK_MEMORY_TESTS') == '1... | [
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/574a97cd701df65ef1b4aff3f3e0549d69ce5419 | Makefile |
test-with-mem:
RUN_FLASK_MEMORY_TESTS=1 python run-tests.py
| <mask> test:
<mask> python run-tests.py
<mask>
<mask> audit:
<mask> python setup.py audit
<mask>
<mask> release:
</s> Disabled memory tests by default </s> remove .PHONY: clean-pyc ext-test test upload-docs docs audit
</s> add .PHONY: clean-pyc ext-test test test-with-mem upload-docs docs audit </s> remove... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/574a97cd701df65ef1b4aff3f3e0549d69ce5419 | Makefile |
import os | <mask>
<mask> from __future__ import with_statement
<mask>
<mask> import gc
<mask> import sys
<mask> import flask
<mask> import threading
<mask> import unittest
<mask> from werkzeug.exceptions import NotFound
</s> Disabled memory tests by default </s> remove from werkzeug.test import run_wsgi_app, create_en... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/574a97cd701df65ef1b4aff3f3e0549d69ce5419 | flask/testsuite/regression.py |
<mask> import sys
<mask> import flask
<mask> import threading
<mask> import unittest
<mask> from werkzeug.test import run_wsgi_app, create_environ
<mask> from werkzeug.exceptions import NotFound
<mask> from flask.testsuite import FlaskTestCase
<mask>
<mask>
<mask> _gc_lock = threading.Lock()
</s> Disabled ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/574a97cd701df65ef1b4aff3f3e0549d69ce5419 | flask/testsuite/regression.py | |
if os.environ.get('RUN_FLASK_MEMORY_TESTS') == '1':
suite.addTest(unittest.makeSuite(MemoryTestCase)) | <mask>
<mask>
<mask> def suite():
<mask> suite = unittest.TestSuite()
<mask> suite.addTest(unittest.makeSuite(MemoryTestCase))
<mask> suite.addTest(unittest.makeSuite(ExceptionTestCase))
<mask> return suite
</s> Disabled memory tests by default </s> remove from werkzeug.test import run_wsgi_ap... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/574a97cd701df65ef1b4aff3f3e0549d69ce5419 | flask/testsuite/regression.py |
return f'User {username}' | <mask>
<mask> @app.route('/user/<username>')
<mask> def show_user_profile(username):
<mask> # show the user profile for that user
<mask> return f'User {escape(username)}'
<mask>
<mask> @app.route('/post/<int:post_id>')
<mask> def show_post(post_id):
<mask> # show the p... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/57f9623b0835cbae06b25d7329cda480539049c3 | docs/quickstart.rst |
return f'Post {post_id}' | <mask>
<mask> @app.route('/post/<int:post_id>')
<mask> def show_post(post_id):
<mask> # show the post with the given id, the id is an integer
<mask> return f'Post {escape(post_id)}'
<mask>
<mask> @app.route('/path/<path:subpath>')
<mask> def show_subpath(subpath):
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/57f9623b0835cbae06b25d7329cda480539049c3 | docs/quickstart.rst |
return f'Subpath {subpath}' | <mask>
<mask> @app.route('/path/<path:subpath>')
<mask> def show_subpath(subpath):
<mask> # show the subpath after /path/
<mask> return f'Subpath {escape(subpath)}'
<mask>
<mask> Converter types:
<mask>
<mask> ========== ==========================================
<mask> ``string`` (... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/57f9623b0835cbae06b25d7329cda480539049c3 | docs/quickstart.rst |
<mask> ``path`` like ``string`` but also accepts slashes
<mask> ``uuid`` accepts UUID strings
<mask> ========== ==========================================
<mask>
<mask> .. note:: HTML escaping
<mask>
<mask> When returning HTML (the default response type in Flask), any user
<mask> input rendered in... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/57f9623b0835cbae06b25d7329cda480539049c3 | docs/quickstart.rst | |
manually change hard-coded URLs. | <mask> :func:`~flask.url_for` instead of hard-coding them into your templates?
<mask>
<mask> 1. Reversing is often more descriptive than hard-coding the URLs.
<mask> 2. You can change your URLs in one go instead of needing to remember to
<mask> manually change hard-coded URLs.
<mask> 3. URL building handles ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5830388ee2e70ab9cfcc06728a80c5459bf3723a | docs/quickstart.rst |
transparently. | <mask> 1. Reversing is often more descriptive than hard-coding the URLs.
<mask> 2. You can change your URLs in one go instead of needing to remember to
<mask> manually change hard-coded URLs.
<mask> 3. URL building handles escaping of special characters and Unicode data
<mask> transparently.
<mask> 4. The... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5830388ee2e70ab9cfcc06728a80c5459bf3723a | docs/quickstart.rst |
``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly
handles that for you. | <mask> transparently.
<mask> 4. The generated paths are always absolute, avoiding unexpected behavior
<mask> of relative paths in browsers.
<mask> 5. If your application is placed outside the URL root, for example, in
<mask> ``/myapplication`` instead of ``/``, :func:`~flask.url_for` properly
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5830388ee2e70ab9cfcc06728a80c5459bf3723a | docs/quickstart.rst |
Version 0.10.1
--------------
Pending bugfix release.
| <mask>
<mask> Here you can see the full list of changes between each Flask release.
<mask>
<mask> Version 0.10
<mask> ------------
<mask>
<mask> Released on June 13nd 2013, codename Limoncello.
<mask>
</s> Started 0.10 maintenance branch for a bugfix release </s> remove __version__ = '0.10'
</s> add __ver... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5886925ff34db3d9e913a4bc44891876a7fe65d5 | CHANGES |
__version__ = '0.10.1-dev' | <mask> :copyright: (c) 2011 by Armin Ronacher.
<mask> :license: BSD, see LICENSE for more details.
<mask> """
<mask>
<mask> __version__ = '0.10'
<mask>
<mask> # utilities we import from Werkzeug and Jinja2 that are unused
<mask> # in the module but are exported as public interface.
<mask> from werkze... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5886925ff34db3d9e913a4bc44891876a7fe65d5 | flask/__init__.py |
version='0.10.1-dev', | <mask> print("No problems found in sourcecode.")
<mask>
<mask> setup(
<mask> name='Flask',
<mask> version='0.10',
<mask> url='http://github.com/mitsuhiko/flask/',
<mask> license='BSD',
<mask> author='Armin Ronacher',
<mask> author_email='armin.ronacher@active-4.com',
<mask... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5886925ff34db3d9e913a4bc44891876a7fe65d5 | setup.py |
SECRET_KEY='192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' | <mask> method::
<mask>
<mask> app.config.update(
<mask> TESTING=True,
<mask> SECRET_KEY=b'_5#y2L"F4Q8z\n\xec]/'
<mask> )
<mask>
<mask>
<mask> Environment and Debug Features
<mask> ------------------------------
</s> use secrets instead of os.urandom </s> remove $ python -c ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/config.rst |
$ python -c 'import secrets; print(secrets.token_hex()))'
'192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' | <mask> and can be used for any other security related needs by extensions or your
<mask> application. It should be a long random ``bytes`` or ``str``. For
<mask> example, copy the output of this to your config::
<mask>
<mask> $ python -c 'import os; print(os.urandom(16))'
<mask> b'_5#... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/config.rst |
SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' | <mask>
<mask> Here is an example of a configuration file::
<mask>
<mask> # Example configuration
<mask> SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/'
<mask>
<mask> Make sure to load the configuration very early on, so that extensions have
<mask> the ability to access the configuration when starting up. There... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/config.rst |
$ python -c 'import secrets; print(secrets.token_hex())'
'192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' | <mask> ways to generate pretty random data based on a cryptographic random
<mask> generator. Use the following command to quickly generate a value for
<mask> :attr:`Flask.secret_key` (or :data:`SECRET_KEY`)::
<mask>
<mask> $ python -c 'import os; print(os.urandom(16))'
<mask> b'_5#y2L... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/quickstart.rst |
$ python -c 'import secrets; print(secrets.token_hex())' | <mask> You can use the following command to output a random secret key:
<mask>
<mask> .. code-block:: none
<mask>
<mask> $ python -c 'import os; print(os.urandom(16))'
<mask>
<mask> b'_5#y2L"F4Q8z\n\xec]/'
<mask>
<mask> Create the ``config.py`` file in the instance folder, which the factory
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/tutorial/deploy.rst |
'192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' | <mask> .. code-block:: none
<mask>
<mask> $ python -c 'import os; print(os.urandom(16))'
<mask>
<mask> b'_5#y2L"F4Q8z\n\xec]/'
<mask>
<mask> Create the ``config.py`` file in the instance folder, which the factory
<mask> will read from if it exists. Copy the generated value into it.
<mask>
<mask> .... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/tutorial/deploy.rst |
SECRET_KEY = '192b9bdd22ab9ed4d12e236c78afcb9a393ec15f71bbf5dc987d54727823bcbf' | <mask>
<mask> .. code-block:: python
<mask> :caption: ``venv/var/flaskr-instance/config.py``
<mask>
<mask> SECRET_KEY = b'_5#y2L"F4Q8z\n\xec]/'
<mask>
<mask> You can also set any other necessary configuration here, although
<mask> ``SECRET_KEY`` is the only one needed for Flaskr.
<mask>
<mask>
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58a08a1d7326b9ef744c0f41b9e8c5505dd3d924 | docs/tutorial/deploy.rst |
- Added support for byte strings back to the session system. This broke
compatibility with the common case of people putting binary data for
token verification into the session. | <mask> - Fixed an issue where ``|tojson`` was not quoting single quotes which
<mask> made the filter not work properly in HTML attributes. Now it's
<mask> possible to use that filter in single quoted attributes. This should
<mask> make using that filter with angular.js easier.
<mask>
<mask> Version 0.10
... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58ad83f37c8f643d6b573ebbedf03a1fc3677c51 | CHANGES |
from base64 import b64encode, b64decode | <mask>
<mask> import uuid
<mask> import hashlib
<mask> from datetime import datetime
<mask> from werkzeug.http import http_date, parse_date
<mask> from werkzeug.datastructures import CallbackDict
<mask> from . import Markup, json
<mask> from ._compat import iteritems, text_type
</s> Added support for bytes in... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58ad83f37c8f643d6b573ebbedf03a1fc3677c51 | flask/sessions.py |
elif isinstance(value, bytes):
return {' b': b64encode(value).decode('ascii')} | <mask> elif isinstance(value, uuid.UUID):
<mask> return {' u': value.hex}
<mask> elif callable(getattr(value, '__html__', None)):
<mask> return {' m': text_type(value.__html__())}
<mask> elif isinstance(value, list):
<mask> return... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58ad83f37c8f643d6b573ebbedf03a1fc3677c51 | flask/sessions.py |
elif the_key == ' b':
return b64decode(the_value) | <mask> elif the_key == ' u':
<mask> return uuid.UUID(the_value)
<mask> elif the_key == ' m':
<mask> return Markup(the_value)
<mask> elif the_key == ' d':
<mask> return parse_date(the_value)
<mask> return obj
<mask> ... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58ad83f37c8f643d6b573ebbedf03a1fc3677c51 | flask/sessions.py |
flask.session['b'] = b'\xff' | <mask> flask.session['u'] = the_uuid
<mask> flask.session['dt'] = now
<mask> flask.session['t'] = (1, 2, 3)
<mask> return response
<mask>
<mask> @app.route('/')
</s> Added support for bytes in sessions back | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58ad83f37c8f643d6b573ebbedf03a1fc3677c51 | flask/testsuite/basic.py |
self.assert_equal(rv['b'], b'\xff')
self.assert_equal(type(rv['b']), bytes) | <mask> self.assert_equal(rv['dt'], now)
<mask> self.assert_equal(rv['u'], the_uuid)
<mask> self.assert_equal(rv['t'], (1, 2, 3))
<mask>
<mask> def test_flashes(self):
<mask> app = flask.Flask(__name__)
</s> Added support for bytes in sessions back | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58ad83f37c8f643d6b573ebbedf03a1fc3677c51 | flask/testsuite/basic.py |
- Clearer error message when ``render_template`` and
``render_template_string`` are used outside an application context.
:pr:`4693` | <mask> commands. :pr:`4606`
<mask> - Relax type annotation for ``after_request`` functions. :issue:`4600`
<mask> - ``instance_path`` for namespace packages uses the path closest to
<mask> the imported submodule. :issue:`4600`
<mask>
<mask>
<mask> Version 2.1.2
<mask> -------------
</s> error for ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58f3536a8f5dfc18e559c518ae38cba52bec90a9 | CHANGES.rst |
if ctx is None:
raise RuntimeError(
"This function can only be used when an application context is active."
)
| <mask> :param context: the variables that should be available in the
<mask> context of the template.
<mask> """
<mask> ctx = _app_ctx_stack.top
<mask> ctx.app.update_template_context(context)
<mask> return _render(
<mask> ctx.app.jinja_env.get_or_select_template(te... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58f3536a8f5dfc18e559c518ae38cba52bec90a9 | src/flask/templating.py |
if ctx is None:
raise RuntimeError(
"This function can only be used when an application context is active."
)
| <mask> """
<mask> ctx = _app_ctx_stack.top
<mask> ctx.app.update_template_context(context)
<mask> return _render(ctx.app.jinja_env.from_string(source), context, ctx.app)
</s> error for render_template outside app context | [
"keep",
"add",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/58f3536a8f5dfc18e559c518ae38cba52bec90a9 | src/flask/templating.py |
yourapplication.py | <mask> module. That is quite simple. Imagine a small application looks like
<mask> this::
<mask>
<mask> /yourapplication
<mask> /yourapplication.py
<mask> /static
<mask> /style.css
<mask> /templates
<mask> layout.html
<mask> index.html
</s> A... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59104db2f2f0a507aea2625230e446361e2fc174 | docs/patterns/packages.rst |
style.css | <mask>
<mask> /yourapplication
<mask> /yourapplication.py
<mask> /static
<mask> /style.css
<mask> /templates
<mask> layout.html
<mask> index.html
<mask> login.html
<mask> ...
</s> Address #1980 (#2021)
* Distinguish bet... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59104db2f2f0a507aea2625230e446361e2fc174 | docs/patterns/packages.rst |
__init__.py | <mask> You should then end up with something like that::
<mask>
<mask> /yourapplication
<mask> /yourapplication
<mask> /__init__.py
<mask> /static
<mask> /style.css
<mask> /templates
<mask> layout.html
<mask> inde... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59104db2f2f0a507aea2625230e446361e2fc174 | docs/patterns/packages.rst |
style.css | <mask> /yourapplication
<mask> /yourapplication
<mask> /__init__.py
<mask> /static
<mask> /style.css
<mask> /templates
<mask> layout.html
<mask> index.html
<mask> login.html
<mask> .... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59104db2f2f0a507aea2625230e446361e2fc174 | docs/patterns/packages.rst |
a big problem, just add a new file called :file:`setup.py` next to the inner | <mask>
<mask> But how do you run your application now? The naive ``python
<mask> yourapplication/__init__.py`` will not work. Let's just say that Python
<mask> does not want modules in packages to be the startup file. But that is not
<mask> a big problem, just add a new file called :file:`runserver.py` next to... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59104db2f2f0a507aea2625230e446361e2fc174 | docs/patterns/packages.rst |
def client(): | <mask> from minitwit import minitwit
<mask>
<mask>
<mask> @pytest.fixture
<mask> def client(request):
<mask> db_fd, minitwit.app.config['DATABASE'] = tempfile.mkstemp()
<mask> client = minitwit.app.test_client()
<mask> with minitwit.app.app_context():
<mask> minitwit.init_db()
<mask>
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | examples/minitwit/tests/test_minitwit.py |
yield client
os.close(db_fd)
os.unlink(minitwit.app.config['DATABASE']) | <mask> client = minitwit.app.test_client()
<mask> with minitwit.app.app_context():
<mask> minitwit.init_db()
<mask>
<mask> def teardown():
<mask> """Get rid of the database again after each test."""
<mask> os.close(db_fd)
<mask> os.unlink(minitwit.app.config['DATABAS... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | examples/minitwit/tests/test_minitwit.py |
def leak_detector():
yield
# make sure we're not leaking a request context since we are
# testing flask internally in debug mode in a few cases
leaks = []
while flask._request_ctx_stack.top is not None:
leaks.append(flask._request_ctx_stack.pop())
assert leaks == [] | <mask> os.path.dirname(__file__), 'test_apps'))
<mask> )
<mask>
<mask> @pytest.fixture(autouse=True)
<mask> def leak_detector(request):
<mask> def ensure_clean_request_context():
<mask> # make sure we're not leaking a request context since we are
<mask> # testing flask inter... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/conftest.py |
def disable_extwarnings(recwarn): | <mask> from flask._compat import PY2
<mask>
<mask>
<mask> @pytest.fixture(autouse=True)
<mask> def disable_extwarnings(request, recwarn):
<mask> from flask.exthook import ExtDeprecationWarning
<mask>
<mask> def inner():
<mask> assert set(w.category for w in recwarn.list) \
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/test_ext.py |
yield | <mask> @pytest.fixture(autouse=True)
<mask> def disable_extwarnings(request, recwarn):
<mask> from flask.exthook import ExtDeprecationWarning
<mask>
<mask> def inner():
<mask> assert set(w.category for w in recwarn.list) \
<mask> <= set([ExtDeprecationWarning])
<mask> recwar... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/test_ext.py |
assert set(w.category for w in recwarn.list) \
<= set([ExtDeprecationWarning])
recwarn.clear() | <mask> assert set(w.category for w in recwarn.list) \
<mask> <= set([ExtDeprecationWarning])
<mask> recwarn.clear()
<mask>
<mask> request.addfinalizer(inner)
<mask>
<mask>
<mask> @pytest.fixture(autouse=True)
<mask> def importhook_setup(monkeypatch, request):
<mask> # we... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/test_ext.py |
def importhook_setup(monkeypatch): | <mask> request.addfinalizer(inner)
<mask>
<mask>
<mask> @pytest.fixture(autouse=True)
<mask> def importhook_setup(monkeypatch, request):
<mask> # we clear this out for various reasons. The most important one is
<mask> # that a real flaskext could be in there which would disable our
<mask> # f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/test_ext.py |
yield | <mask> cls.__name__ == 'ExtensionImporter':
<mask> import_hooks += 1
<mask> assert import_hooks == 1
<mask>
<mask> def teardown():
<mask> from flask import ext
<mask> for key in ext.__dict__:
<mask> assert '.' not in key
<mask>
<mask> request.ad... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/test_ext.py |
from flask import ext
for key in ext.__dict__:
assert '.' not in key | <mask> from flask import ext
<mask> for key in ext.__dict__:
<mask> assert '.' not in key
<mask>
<mask> request.addfinalizer(teardown)
<mask>
<mask>
<mask> @pytest.fixture
<mask> def newext_simple(modules_tmpdir):
<mask> x = modules_tmpdir.join('flask_newext_simple.py')
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5963cb5a5172bce3a1ff7b0f8c64230f043c9cfd | tests/test_ext.py |
from .helpers import get_debug_flag, get_env, get_load_dotenv | <mask>
<mask> from . import __version__
<mask> from ._compat import getargspec, iteritems, reraise, text_type
<mask> from .globals import current_app
<mask> from .helpers import get_debug_flag, get_env
<mask>
<mask> try:
<mask> import dotenv
<mask> except ImportError:
<mask> dotenv = None
</s> rena... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5965cb7e1cfcaa329d811d133af373deb8090ec3 | flask/cli.py |
if get_load_dotenv(self.load_dotenv): | <mask> # call into a no-op. This is necessary to avoid ugly errors when the
<mask> # script that is loaded here also attempts to start a server.
<mask> os.environ['FLASK_RUN_FROM_CLI'] = 'true'
<mask>
<mask> val = os.environ.get('FLASK_DONT_LOAD_ENV')
<mask> load_dotenv = ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5965cb7e1cfcaa329d811d133af373deb8090ec3 | flask/cli.py |
' Do "pip install python-dotenv" to use them.', | <mask> if dotenv is None:
<mask> if path or os.path.exists('.env') or os.path.exists('.flaskenv'):
<mask> click.secho(
<mask> ' * Tip: There are .env files present.'
<mask> ' Do "pip install python-dotenv" to use them',
<mask> fg='yellow')
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5965cb7e1cfcaa329d811d133af373deb8090ec3 | flask/cli.py |
def get_load_dotenv(default=True):
"""Get whether the user has disabled loading dotenv files by setting
:envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load the
files.
:param default: What to return if the env var isn't set.
"""
val = os.environ.get('FLASK_SKIP_DOTENV')
if not val:
... | <mask>
<mask> return val.lower() not in ('0', 'false', 'no')
<mask>
<mask>
<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> """
</s> rename to FLASK_SKIP_DOTENV, ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5965cb7e1cfcaa329d811d133af373deb8090ec3 | flask/helpers.py |
@need_dotenv
def test_disable_dotenv_from_env(monkeypatch, runner):
monkeypatch.chdir(test_path)
monkeypatch.setitem(os.environ, 'FLASK_SKIP_DOTENV', '1')
runner.invoke(FlaskGroup())
assert 'FOO' not in os.environ
| <mask> assert 'FOO' not in os.environ
<mask>
<mask>
<mask> def test_run_cert_path():
<mask> # no key
<mask> with pytest.raises(click.BadParameter):
<mask> run_command.make_context('run', ['--cert', __file__])
<mask>
<mask> # no cert
</s> rename to FLASK_SKIP_DOTENV, add docs, test <... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/5965cb7e1cfcaa329d811d133af373deb8090ec3 | tests/test_cli.py |
See :doc:`/errorhandling`. | <mask> return jsonify_error(ex)
<mask> else:
<mask> return ex
<mask>
<mask> More information on error handling see :doc:`/patterns/errorpages`.
</s> consolidate error handling docs
Remove apierrors.rst and errorpages.rst from patterns and integrate the
content into errorhandling.... | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/pallets/flask/commit/59b0b85835fa925e67f9a3f5173f7d6b6e67a411 | docs/blueprints.rst |
Handling Application Errors
=========================== | <mask> Application Errors
<mask> ==================
<mask>
<mask> .. versionadded:: 0.3
<mask>
<mask> Applications fail, servers fail. Sooner or later you will see an exception
<mask> in production. Even if your code is 100% correct, you will still see
</s> consolidate error handling docs
Remove apierrors.... | [
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59b0b85835fa925e67f9a3f5173f7d6b6e67a411 | docs/errorhandling.rst |
production mode, and an exception is raised Flask will display a very simple
page for you and log the exception to the :attr:`~flask.Flask.logger`. | <mask> - network connection of the server to another system failed
<mask>
<mask> And that's just a small sample of issues you could be facing. So how do we
<mask> deal with that sort of problem? By default if your application runs in
<mask> production mode, Flask will display a very simple page for you and lo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59b0b85835fa925e67f9a3f5173f7d6b6e67a411 | docs/errorhandling.rst |
with errors including custom exceptions and 3rd party tools.
.. _common-error-codes:
Common Error Codes
``````````````````
The following error codes are some that are often displayed to the user,
even if the application behaves correctly:
*400 Bad Request*
When the server will not process the request due to so... | <mask> production mode, Flask will display a very simple page for you and log the
<mask> exception to the :attr:`~flask.Flask.logger`.
<mask>
<mask> But there is more you can do, and we will cover some better setups to deal
<mask> with errors.
<mask>
<mask> Error Logging Tools
<mask> -------------------
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/59b0b85835fa925e67f9a3f5173f7d6b6e67a411 | docs/errorhandling.rst |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.