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 |
|---|---|---|---|---|
subdomain_matching=False, | <mask> static_host=None,
<mask> host_matching=False,
<mask> template_folder='templates',
<mask> instance_path=None,
<mask> instance_relative_config=False,
<mask> root_path=None
<mask> ):
</s> Do not enable subdomain matching by default
Updated tests for new su... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | flask/app.py |
self.subdomain_matching = subdomain_matching | <mask>
<mask> self.url_map.host_matching = host_matching
<mask>
<mask> # tracks internally if the application already handled at least one
<mask> # request.
<mask> self._got_first_request = False
</s> Do not enable subdomain matching by default
Updated tests for new subdomain ma... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | flask/app.py |
rv = self.url_map.bind_to_environ(request.environ, | <mask> This can now also be called without a request object when the
<mask> URL adapter is created for the application context.
<mask> """
<mask> if request is not None:
<mask> return self.url_map.bind_to_environ(request.environ,
<mask> server_name... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | flask/app.py |
# If subdomain matching is not enabled (which is the default
# we put back the default subdomain in all cases. This really
# should be the default in Werkzeug but it currently does not
# have that feature.
if not self.subdomain_matching:
rv.su... | <mask> """
<mask> if request is not None:
<mask> rv = self.url_map.bind_to_environ(request.environ,
<mask> server_name=self.config['SERVER_NAME'])
<mask> # We need at the very least the server name to be set for this
<mask> # to work.
<mask> if ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | flask/app.py |
def test_test_app_proper_environ():
app = flask.Flask(__name__, subdomain_matching=True) | <mask> assert repr(flask.g) == '<LocalProxy unbound>'
<mask> assert not flask.g
<mask>
<mask>
<mask> def test_test_app_proper_environ(app, client):
<mask> app.config.update(
<mask> SERVER_NAME='localhost.localdomain:5000'
<mask> )
<mask>
<mask> @app.route('/')
</s> Do not enabl... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
client = app.test_client() | <mask> app.config.update(
<mask> SERVER_NAME='localhost.localdomain:5000'
<mask> )
<mask>
<mask> @app.route('/')
<mask> def index():
<mask> return 'Foo'
</s> Do not enable subdomain matching by default
Updated tests for new subdomain matching
Added a test to validate matching be... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
def test_subdomain_basic_support():
app = flask.Flask(__name__, subdomain_matching=True) | <mask> assert 'foos' not in flask.g
<mask> assert sorted(flask.g) == ['bar', 'foo']
<mask>
<mask>
<mask> def test_subdomain_basic_support(app, client):
<mask> app.config['SERVER_NAME'] = 'localhost.localdomain'
<mask>
<mask> @app.route('/')
<mask> def normal_index():
<mask> retu... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
client = app.test_client() | <mask> app = flask.Flask(__name__, subdomain_matching=True)
<mask> app.config['SERVER_NAME'] = 'localhost.localdomain'
<mask>
<mask> @app.route('/')
<mask> def normal_index():
<mask> return 'normal index'
<mask>
<mask> @app.route('/', subdomain='test')
</s> Do not enable subdomain... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
def test_subdomain_matching():
app = flask.Flask(__name__, subdomain_matching=True)
client = app.test_client() | <mask> rv = client.get('/', 'http://test.localhost.localdomain/')
<mask> assert rv.data == b'test index'
<mask>
<mask>
<mask> def test_subdomain_matching(app, client):
<mask> app.config['SERVER_NAME'] = 'localhost.localdomain'
<mask>
<mask> @app.route('/', subdomain='<user>')
<mask> def ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
def test_subdomain_matching_with_ports():
app = flask.Flask(__name__, subdomain_matching=True) | <mask> rv = client.get('/', 'http://mitsuhiko.localhost.localdomain/')
<mask> assert rv.data == b'index for mitsuhiko'
<mask>
<mask>
<mask> def test_subdomain_matching_with_ports(app, client):
<mask> app.config['SERVER_NAME'] = 'localhost.localdomain:3000'
<mask>
<mask> @app.route('/', subdom... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
client = app.test_client() | <mask> app = flask.Flask(__name__, subdomain_matching=True)
<mask> app.config['SERVER_NAME'] = 'localhost.localdomain:3000'
<mask>
<mask> @app.route('/', subdomain='<user>')
<mask> def index(user):
<mask> return 'index for %s' % user
<mask>
</s> Do not enable subdomain matching by defa... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_basic.py |
def test_blueprint_with_subdomain():
app = flask.Flask(__name__, subdomain_matching=True) | <mask> assert eb.script_root == ''
<mask> assert eb.path == '/'
<mask>
<mask>
<mask> def test_blueprint_with_subdomain(app, client):
<mask> app.config['SERVER_NAME'] = 'example.com:1234'
<mask> app.config['APPLICATION_ROOT'] = '/foo'
<mask>
<mask> bp = flask.Blueprint('company', __name__... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_testing.py |
client = app.test_client() | <mask> app.config['SERVER_NAME'] = 'example.com:1234'
<mask> app.config['APPLICATION_ROOT'] = '/foo'
<mask>
<mask> bp = flask.Blueprint('company', __name__, subdomain='xxx')
<mask>
<mask> @bp.route('/')
</s> Do not enable subdomain matching by default
Updated tests for new subdomain matching
Ad... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_testing.py |
def test_subdomain():
app = flask.Flask(__name__, subdomain_matching=True) | <mask> assert rv.is_json
<mask> assert rv.get_json() == json_data
<mask>
<mask>
<mask> def test_subdomain(app, client):
<mask> app.config['SERVER_NAME'] = 'example.com'
<mask>
<mask> @app.route('/', subdomain='<company_id>')
<mask> def view(company_id):
<mask> return com... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_testing.py |
client = app.test_client() | <mask> def test_subdomain():
<mask> app = flask.Flask(__name__, subdomain_matching=True)
<mask> app.config['SERVER_NAME'] = 'example.com'
<mask>
<mask> @app.route('/', subdomain='<company_id>')
<mask> def view(company_id):
<mask> return company_id
<mask>
</s> Do not enable subdomain m... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cec2010c0564bbd6e1f9cd8881404f70178247f | tests/test_testing.py |
from setuptools import setup, find_packages | <mask> from setuptools import setup
<mask>
<mask> setup(
<mask> name='flaskr',
<mask> packages=['flaskr'],
<mask> include_package_data=True,
</s> Adds in blueprints and an application factory </s> remove packages=['flaskr'],
</s> add packages=find_packages(), </s> remove from flaskr import ... | [
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/setup.py |
packages=find_packages(), | <mask> from setuptools import setup
<mask>
<mask> setup(
<mask> name='flaskr',
<mask> packages=['flaskr'],
<mask> include_package_data=True,
<mask> install_requires=[
<mask> 'flask',
<mask> ],
<mask> setup_requires=[
</s> Adds in blueprints and an application factory </s> rem... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/setup.py |
from flaskr.factory import create_app
from flaskr.blueprints.flaskr import init_db
test_app = create_app() | <mask>
<mask> import os
<mask> import tempfile
<mask> import pytest
<mask> from flaskr import flaskr
<mask>
<mask>
<mask> @pytest.fixture
<mask> def client(request):
<mask> db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
</s> Adds in blueprints and an application factory </s> remove db_f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
db_fd, test_app.config['DATABASE'] = tempfile.mkstemp()
test_app.config['TESTING'] = True
client = test_app.test_client()
with test_app.app_context():
init_db() | <mask>
<mask>
<mask> @pytest.fixture
<mask> def client(request):
<mask> db_fd, flaskr.app.config['DATABASE'] = tempfile.mkstemp()
<mask> flaskr.app.config['TESTING'] = True
<mask> client = flaskr.app.test_client()
<mask> with flaskr.app.app_context():
<mask> flaskr.init_db()
<mask>
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
os.unlink(test_app.config['DATABASE']) | <mask> flaskr.init_db()
<mask>
<mask> def teardown():
<mask> os.close(db_fd)
<mask> os.unlink(flaskr.app.config['DATABASE'])
<mask> request.addfinalizer(teardown)
<mask>
<mask> return client
<mask>
<mask>
</s> Adds in blueprints and an application factory </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
rv = login(client, test_app.config['USERNAME'],
test_app.config['PASSWORD']) | <mask>
<mask>
<mask> def test_login_logout(client):
<mask> """Make sure login and logout works"""
<mask> rv = login(client, flaskr.app.config['USERNAME'],
<mask> flaskr.app.config['PASSWORD'])
<mask> assert b'You were logged in' in rv.data
<mask> rv = logout(client)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
rv = login(client,test_app.config['USERNAME'] + 'x',
test_app.config['PASSWORD']) | <mask> flaskr.app.config['PASSWORD'])
<mask> assert b'You were logged in' in rv.data
<mask> rv = logout(client)
<mask> assert b'You were logged out' in rv.data
<mask> rv = login(client, flaskr.app.config['USERNAME'] + 'x',
<mask> flaskr.app.config['PASSWORD'])
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
rv = login(client, test_app.config['USERNAME'],
test_app.config['PASSWORD'] + 'x') | <mask> assert b'You were logged out' in rv.data
<mask> rv = login(client, flaskr.app.config['USERNAME'] + 'x',
<mask> flaskr.app.config['PASSWORD'])
<mask> assert b'Invalid username' in rv.data
<mask> rv = login(client, flaskr.app.config['USERNAME'],
<mask> flaskr.app... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
login(client, test_app.config['USERNAME'],
test_app.config['PASSWORD']) | <mask>
<mask>
<mask> def test_messages(client):
<mask> """Test that messages work"""
<mask> login(client, flaskr.app.config['USERNAME'],
<mask> flaskr.app.config['PASSWORD'])
<mask> rv = client.post('/add', data=dict(
<mask> title='<Hello>',
<mask> text='<strong>HTML</st... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8cf32bca519723c5d97f123127cdec81dba868f6 | examples/flaskr/tests/test_flaskr.py |
consider an application that's currently connecting to SQLite like the
documentation suggests (:ref:`sqlite3`). So how does the extension | <mask> Initializing Extensions
<mask> -----------------------
<mask>
<mask> Many extensions will need some kind of initialization step. For example,
<mask> consider your application is currently connecting to SQLite like the
<mask> documentation suggests (:ref:`sqlite3`) you will need to provide a few
<mask> f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
we will use the class-based approach because it will provide users with an
object that handles opening and closing database connections. | <mask> some helper functions like `OAuth.remote_app` to create a reference to
<mask> a remote application that uses OAuth.
<mask>
<mask> What to use depends on what you have in mind. For the SQLite 3 extension
<mask> we will use the class-based approach because it will provide users with a
<mask> manage... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
<mask> ------------------
<mask>
<mask> Here's the contents of the `flask_sqlite3.py` for copy/paste::
<mask>
<mask> from __future__ import absolute_import
<mask> import sqlite3
<mask>
<mask> from flask import _request_ctx_stack
<mask>
<mask> class SQLite3(object):
</s> Reword the docs fo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst | |
def __init__(self, app=None):
if app is not None:
self.app = app
self.init_app(self.app)
else:
self.app = None
def init_app(self, app): | <mask> from flask import _request_ctx_stack
<mask>
<mask> class SQLite3(object):
<mask>
<mask> def __init__(self, app):
<mask> self.app = app
<mask> self.app.config.setdefault('SQLITE3_DATABASE', ':memory:')
<mask> self.app.teardown_request(self.teardown_req... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
@property
def connection(self): | <mask> def teardown_request(self, exception):
<mask> ctx = _request_ctx_stack.top
<mask> ctx.sqlite3_db.close()
<mask>
<mask> def get_db(self):
<mask> ctx = _request_ctx_stack.top
<mask> if ctx is not None:
<mask> return ctx.sqlite... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
1. The ``__init__`` method takes an optional app object and, if supplied, will
call ``init_app``.
2. The ``init_app`` method exists so that the ``SQLite3`` object can be
instantiated without requiring an app object. This method supports the
factory pattern for creating applications. The ``init_app`` wil... | <mask> return ctx.sqlite3_db
<mask>
<mask> So here's what these lines of code do:
<mask>
<mask> 1. The ``__future__`` import is necessary to activate absolute imports.
<mask> Otherwise we could not call our module `sqlite3.py` and import the
<mask> top-level `sqlite3` module which actu... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
``_request_ctx_stack.top``. Extensions should use the top context and not the
``g`` object to store things like database connections.
5. Finally, we add a ``connection`` property that simplifies access to the context's | <mask> `teardown_request` handlers.
<mask> 3. Next, we define a `connect` function that opens a database connection.
<mask> 4. Then we set up the request handlers we bound to the app above. Note here
<mask> that we're attaching our database connection to the top request context via
<mask> `_request_... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
db = SQLite3(app) | <mask> from flask_sqlite3 import SQLite3
<mask>
<mask> app = Flask(__name__)
<mask> app.config.from_pyfile('the-config.cfg')
<mask> manager = SQLite3(app)
<mask> db = manager.get_db()
<mask>
<mask> You can then use the database from views like this::
<mask>
<mask> @app.route('/')
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
cur = db.connection.cursor() | <mask> You can then use the database from views like this::
<mask>
<mask> @app.route('/')
<mask> def show_all():
<mask> cur = db.cursor()
<mask> cur.execute(...)
<mask>
<mask> Opening a database connection from outside a view function is simple.
<mask>
<mask> >>> from yourapplicatio... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
Additionally, the ``init_app`` method is used to support the factory pattern
for creating apps:: | <mask> def show_all():
<mask> cur = db.cursor()
<mask> cur.execute(...)
<mask>
<mask> Opening a database connection from outside a view function is simple.
<mask>
<mask> >>> from yourapplication import db
<mask> >>> cur = db.cursor()
<mask> >>> cur.execute(...)
<mask>
<mask> Adding an ... | [
"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/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
db = Sqlite3()
# Then later on.
app = create_app('the-config.cfg')
db.init_app(app) | <mask> def before_request(self):
<mask> ctx = _request_ctx_stack.top
<mask> ctx.sqlite3_db = self.connect()
<mask>
<mask> def teardown_request(self, exception):
<mask> ctx = _request_ctx_stack.top
<mask> ctx.sqlite3_db.close()
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
Keep in mind that supporting this factory pattern for creating apps is required
for approved flask extensions (described below). | <mask> def teardown_request(self, exception):
<mask> ctx = _request_ctx_stack.top
<mask> ctx.sqlite3_db.close()
<mask>
<mask> def get_db(self):
<mask> ctx = _request_ctx_stack.top
<mask> if ctx is not None:
<mask> return ctx.sqlite... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
<mask> ctx = _request_ctx_stack.top
<mask> if ctx is not None:
<mask> return ctx.sqlite3_db
<mask>
<mask> The user could then initialize the extension in one file::
<mask>
<mask> manager = SQLite3()
<mask>
<mask> and bind their app to the extension in another file... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst | |
Using _request_ctx_stack
------------------------ | <mask> return ctx.sqlite3_db
<mask>
<mask> The user could then initialize the extension in one file::
<mask>
<mask> manager = SQLite3()
<mask>
<mask> and bind their app to the extension in another file::
<mask>
<mask> manager.init_app(app)
<mask>
</s> Reword the docs for writing ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
In the example above, before every request, a ``sqlite3_db`` variable is assigned
to ``_request_ctx_stack.top``. In a view function, this variable is accessible
using the ``connection`` property of ``SQLite3``. During the teardown of a
request, the ``sqlite3_db`` connection is closed. By using this pattern, the
*sam... | <mask> The user could then initialize the extension in one file::
<mask>
<mask> manager = SQLite3()
<mask>
<mask> and bind their app to the extension in another file::
<mask>
<mask> manager.init_app(app)
<mask>
<mask> End-Of-Request Behavior
<mask> -----------------------
<mask>
<mask> Due to t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d1546f8e64e093847ad3d5579ad5f9b7c3d0e45 | docs/extensiondev.rst |
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER | <mask>
<mask> app = Flask(__name__)
<mask>
<mask> So first we need a couple of imports. Most should be straightforward, the
<mask> :func:`werkzeug.secure_filename` is explained a little bit later. The
<mask> `UPLOAD_FOLDER` is where we will store the uploaded files and the
<mask> `ALLOWED_EXTENSIONS` is ... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d2daea327c2d0654004c2be9cb2eae074bbb80a | docs/patterns/fileuploads.rst |
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) | <mask> if request.method == 'POST':
<mask> file = request.files['file']
<mask> if file and allowed_file(file.filename):
<mask> filename = secure_filename(file.filename)
<mask> file.save(os.path.join(UPLOAD_FOLDER, filename))
<mask> re... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d2daea327c2d0654004c2be9cb2eae074bbb80a | docs/patterns/fileuploads.rst |
'/uploads': app.config['UPLOAD_FOLDER'] | <mask> from werkzeug import SharedDataMiddleware
<mask> app.add_url_rule('/uploads/<filename>', 'uploaded_file',
<mask> build_only=True)
<mask> app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {
<mask> '/uploads': UPLOAD_FOLDER
<mask> })
<mask>
<mask> If you now r... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d2daea327c2d0654004c2be9cb2eae074bbb80a | docs/patterns/fileuploads.rst |
paths-ignore:
- 'docs/**'
- '*.md'
- '*.rst' | <mask> branches:
<mask> - master
<mask> - '*.x'
<mask> pull_request:
<mask> branches:
<mask> - master
<mask> - '*.x'
</s> use rtd to build docs for prs
skip code tests when only docs change </s> remove - {name: Docs, python: '3.9', os: ubuntu-latest, tox: docs}
</s>... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d9501598ff066706c1300a9f6f5193912f2cb4d | .github/workflows/tests.yaml |
paths-ignore:
- 'docs/**'
- '*.md'
- '*.rst' | <mask> pull_request:
<mask> branches:
<mask> - master
<mask> - '*.x'
<mask> jobs:
<mask> tests:
<mask> name: ${{ matrix.name }}
<mask> runs-on: ${{ matrix.os }}
<mask> strategy:
<mask> fail-fast: false
</s> use rtd to build docs for prs
skip code tests when only docs ch... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d9501598ff066706c1300a9f6f5193912f2cb4d | .github/workflows/tests.yaml |
<mask> - {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38}
<mask> - {name: '3.7', python: '3.7', os: ubuntu-latest, tox: py37}
<mask> - {name: '3.6', python: '3.6', os: ubuntu-latest, tox: py36}
<mask> - {name: 'PyPy', python: pypy3, os: ubuntu-latest, tox: pypy3}
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8d9501598ff066706c1300a9f6f5193912f2cb4d | .github/workflows/tests.yaml | |
def _make_timedelta(value):
if not isinstance(value, timedelta):
return timedelta(seconds=value)
return value
| <mask> # a lock used for logger initialization
<mask> _logger_lock = Lock()
<mask>
<mask>
<mask> def setupmethod(f):
<mask> """Wraps a method so that it performs a check in debug mode if the
<mask> first request was already handled.
<mask> """
</s> Moved the conversion thing into the ConfigAttrib... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/app.py |
#: A :class:`~datetime.timedelta` which is used to set the expiration
#: date of a permanent session. The default is 31 days which makes a
#: permanent session survive for roughly one month.
#:
#: This attribute can also be configured from the config with the
#: `PERMANENT_SESSION_LIFETIME` con... | <mask> session_cookie_name = ConfigAttribute('SESSION_COOKIE_NAME')
<mask>
<mask> #: Enable this if you want to use the X-Sendfile feature. Keep in
<mask> #: mind that the server has to support this. This only affects files
<mask> #: sent with the :func:`send_file` method.
<mask> #:
</s> M... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/app.py |
<mask> if rv is not None:
<mask> return rv
<mask> return self.debug
<mask>
<mask> def _get_permanent_session_lifetime(self):
<mask> """A :class:`~datetime.timedelta` which is used to set the expiration
<mask> date of a permanent session. The default is 31 days wh... | [
"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/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/app.py | |
def __init__(self, name, get_converter=None): | <mask>
<mask> class ConfigAttribute(object):
<mask> """Makes an attribute forward to the config"""
<mask>
<mask> def __init__(self, name):
<mask> self.__name__ = name
<mask>
<mask> def __get__(self, obj, type=None):
<mask> if obj is None:
<mask> return self
</s> Mov... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/config.py |
self.get_converter = get_converter | <mask> def __init__(self, name, get_converter=None):
<mask> self.__name__ = name
<mask>
<mask> def __get__(self, obj, type=None):
<mask> if obj is None:
<mask> return self
<mask> rv = obj.config[self.__name__]
</s> Moved the conversion thing into the ConfigAttribute.... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/config.py |
rv = obj.config[self.__name__]
if self.get_converter is not None:
rv = self.get_converter(rv)
return rv | <mask>
<mask> def __get__(self, obj, type=None):
<mask> if obj is None:
<mask> return self
<mask> return obj.config[self.__name__]
<mask>
<mask> def __set__(self, obj, value):
<mask> obj.config[self.__name__] = value
<mask>
<mask>
</s> Moved the conversion thin... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/config.py |
def test_session_lifetime(self):
app = flask.Flask(__name__)
app.config['PERMANENT_SESSION_LIFETIME'] = 42
self.assert_equal(app.permanent_session_lifetime.total_seconds(), 42)
| <mask> self.assert_(not app.config.from_pyfile('missing.cfg', silent=True))
<mask>
<mask>
<mask> class InstanceTestCase(FlaskTestCase):
<mask>
<mask> def test_explicit_instance_paths(self):
<mask> here = os.path.abspath(os.path.dirname(__file__))
<mask> try:
</s> Moved the conver... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8da8a21b69cc06e58b1b28fa0ecec63b5cf3d9b4 | flask/testsuite/config.py |
explicit unlike URL rules. Also with the move of the views into from
`yourapplication.views.admin` too `yourapplication.apps.admin.views` you
will have to give the module an explit shortname. Why? Because otherwise
all your modules will be internally known as `views` which is obviously
not what you want:: | <mask> If you want to refer to the templates you just have to prefix it with the
<mask> name of the module. So for the admin it would be
<mask> ``render_template('admin/list_items.html')`` and so on. It is not
<mask> possible to refer to templates without the prefixed module name. This is
<mask> explicit unlike... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8ed051d5b5f136397e26dc20845869366afc2cae | docs/patterns/packages.rst |
# in yourapplication/apps/admin/views.py
admin = Module(__name__, 'admin')
The setup code changes slightly because of the imports:: | <mask> ``render_template('admin/list_items.html')`` and so on. It is not
<mask> possible to refer to templates without the prefixed module name. This is
<mask> explicit unlike URL rules.
<mask>
<mask> You also need to explicitly pass the ``url_prefix`` argument when
<mask> registering your modules this way::
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8ed051d5b5f136397e26dc20845869366afc2cae | docs/patterns/packages.rst |
app.register_module(frontend) | <mask>
<mask>
<mask> app = Flask(__name__)
<mask> app.register_module(admin, url_prefix='/admin')
<mask> app.register_module(frontend, url_prefix='/frontend')
<mask>
<mask> This is because Flask cannot infer the prefix from the package names.
<mask>
<mask> .. admonition:: References to Static F... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8ed051d5b5f136397e26dc20845869366afc2cae | docs/patterns/packages.rst |
.. _registering-filters:
| <mask> Whenever you do this, please be very cautious about the variables you are
<mask> using in this block.
<mask>
<mask> Registering Filters
<mask> -------------------
<mask>
<mask> If you want to register your own filters in Jinja2 you have two ways to do
<mask> that. You can either put them by hand into ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8ef2ca99b991f66f0b61975e883325fcf5c13046 | docs/templating.rst |
the template context, for all templates in the app:: | <mask> context processors exist in Flask. Context processors run before the
<mask> template is rendered and have the ability to inject new values into the
<mask> template context. A context processor is a function that returns a
<mask> dictionary. The keys and values of this dictionary are then merged with
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8ef2ca99b991f66f0b61975e883325fcf5c13046 | docs/templating.rst |
You could also build `format_price` as a template filter (see
:ref:`registering-filters`), but this demonstrates how to pass functions in a
context processor. | <mask> `format_price` which can then be used in template::
<mask>
<mask> {{ format_price(0.33) }}
<mask>
<mask> The difference from regular context processor' variables is that functions
<mask> are evaluated upon template rendering compared to variables whose values
<mask> are created during `app` startup ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace"
] | https://github.com/pallets/flask/commit/8ef2ca99b991f66f0b61975e883325fcf5c13046 | docs/templating.rst |
import weakref | <mask> import os
<mask> import sys
<mask> from datetime import timedelta
<mask> from itertools import chain
<mask> from threading import Lock
<mask>
</s> Break reference cycle created by default in Flask instances.
Flask instances with static folders were creating a reference cycle
via their "static" view fun... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8efea0ccbbf0985e0c3c001e5bd90b4912a18f54 | src/flask/app.py |
# Use a weakref to avoid creating a reference cycle between the app
# and the view function (see #3761).
self_ref = weakref.ref(self) | <mask> if self.has_static_folder:
<mask> assert (
<mask> bool(static_host) == host_matching
<mask> ), "Invalid static_host/host_matching combination"
<mask> self.add_url_rule(
<mask> f"{self.static_url_path}/<path:filename>",
<mask> ... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8efea0ccbbf0985e0c3c001e5bd90b4912a18f54 | src/flask/app.py |
view_func=lambda **kw: self_ref().send_static_file(**kw), | <mask> self.add_url_rule(
<mask> f"{self.static_url_path}/<path:filename>",
<mask> endpoint="static",
<mask> host=static_host,
<mask> view_func=self.send_static_file,
<mask> )
<mask>
<mask> # Set the name of the Cli... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8efea0ccbbf0985e0c3c001e5bd90b4912a18f54 | src/flask/app.py |
import weakref | <mask> import re
<mask> import sys
<mask> import time
<mask> import uuid
<mask> from datetime import datetime
<mask> from platform import python_implementation
<mask> from threading import Thread
<mask>
</s> Break reference cycle created by default in Flask instances.
Flask instances with static folders were... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8efea0ccbbf0985e0c3c001e5bd90b4912a18f54 | tests/test_basic.py |
from platform import python_implementation | <mask> import time
<mask> import uuid
<mask> import weakref
<mask> from datetime import datetime
<mask> from threading import Thread
<mask>
<mask> import pytest
<mask> import werkzeug.serving
</s> Break reference cycle created by default in Flask instances.
Flask instances with static folders were creating a... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8efea0ccbbf0985e0c3c001e5bd90b4912a18f54 | tests/test_basic.py |
require_cpython_gc = pytest.mark.skipif(
python_implementation() != "CPython", reason="Requires CPython GC behavior",
)
| <mask> import flask
<mask>
<mask>
<mask> def test_options_work(app, client):
<mask> @app.route("/", methods=["GET", "POST"])
<mask> def index():
<mask> return "Hello World"
<mask>
</s> Break reference cycle created by default in Flask instances.
Flask instances with static folders were crea... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8efea0ccbbf0985e0c3c001e5bd90b4912a18f54 | tests/test_basic.py |
Browsers recognize various response headers in order to control security. We
recommend reviewing each of the headers below for use in your application.
The `Flask-Talisman`_ extension can be used to manage HTTPS and the security
headers for you.
.. _Flask-Talisman: https://github.com/GoogleCloudPlatform/flask-talisman | <mask>
<mask> Security Headers
<mask> ----------------
<mask>
<mask> This section contains a list of HTTP security headers supported by Flask.
<mask> To configure HTTPS and handle the headers listed below we suggest the package `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_.
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | <mask> This section contains a list of HTTP security headers supported by Flask.
<mask> To configure HTTPS and handle the headers listed below we suggest the package `flask-talisman <https://github.com/GoogleCloudPlatform/flask-talisman>`_.
<mask>
<mask> HTTP Strict Transport Security (HSTS)
<mask> -------------... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
Tells the browser to convert all HTTP requests to HTTPS, preventing
man-in-the-middle (MITM) attacks. :: | <mask>
<mask> HTTP Strict Transport Security (HSTS)
<mask> -------------------------------------
<mask>
<mask> Redirects HTTP requests to HTTPS on all URLs, preventing man-in-the-middle (MITM) attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
</s> clean up security header docs... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
response.haders['Strict-Transport-Security'] = 'max-age=31536000; includeSubDomains' | <mask> -------------------------------------
<mask>
<mask> Redirects HTTP requests to HTTPS on all URLs, preventing man-in-the-middle (MITM) attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Strict-Transport-Security: max-age=<expire-time
<mask> Strict-Transport-Se... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security | <mask> Redirects HTTP requests to HTTPS on all URLs, preventing man-in-the-middle (MITM) attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Strict-Transport-Security: max-age=<expire-time
<mask> Strict-Transport-Security: max-age=<expire-time>; includeSubDomains
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
Content Security Policy (CSP)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | <mask> Strict-Transport-Security: max-age=<expire-time
<mask> Strict-Transport-Security: max-age=<expire-time>; includeSubDomains
<mask> Strict-Transport-Security: max-age=<expire-time>; preload
<mask>
<mask> See also `Strict Transport Security <https://developer.mozilla.org/en-US/docs/Web/HTTP/Header... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
Tell the browser where it can load various types of resource from. This header
should be used whenever possible, but requires some work to define the correct
policy for your site. A very strict policy would be:: | <mask> Strict-Transport-Security: max-age=<expire-time>; preload
<mask>
<mask> See also `Strict Transport Security <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>`_.
<mask>
<mask> HTTP Public Key Pinning (HPKP)
<mask> ------------------------------
<mask>
<mask> Thi... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
response.headers['Content-Security-Policy'] = "default-src: 'self'" | <mask>
<mask> HTTP Public Key Pinning (HPKP)
<mask> ------------------------------
<mask>
<mask> This enables your web server to authenticate with a client browser using a specific certificate key to prevent man-in-the-middle (MITM) attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://csp.withgoogle.com/docs/index.html
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy | <mask> ------------------------------
<mask>
<mask> This enables your web server to authenticate with a client browser using a specific certificate key to prevent man-in-the-middle (MITM) attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Public-Key-Pins: pin-sha256="base64... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
X-Content-Type-Options
~~~~~~~~~~~~~~~~~~~~~~ | <mask> This enables your web server to authenticate with a client browser using a specific certificate key to prevent man-in-the-middle (MITM) attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
Forces the browser to honor the response content type instead of trying to
detect it, which can be abused to generate a cross-site scripting (XSS)
attack. :: | <mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; report-uri="reportURI"]
<mask>
<mask> See also `Public Key Pinning <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_.
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
response.headers['X-Content-Type-Options'] = 'nosniff' | <mask> .. sourcecode:: none
<mask>
<mask> Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; report-uri="reportURI"]
<mask>
<mask> See also `Public Key Pinning <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_.
<mask>
<mask> X-Frame-Options (Clickjack... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options | <mask> Public-Key-Pins: pin-sha256="base64=="; max-age=expireTime [; includeSubDomains][; report-uri="reportURI"]
<mask>
<mask> See also `Public Key Pinning <https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning>`_.
<mask>
<mask> X-Frame-Options (Clickjacking Protection)
<mask> --------------... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
X-Frame-Options
~~~~~~~~~~~~~~~ | <mask>
<mask> X-Frame-Options (Clickjacking Protection)
<mask> -----------------------------------------
<mask>
<mask> Prevents the client from clicking page elements outside of the website, avoiding hijacking or UI redress attacks.
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> X-Frame-Options: DE... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
Prevents external sites from embedding your site in an ``iframe``. This
prevents a class of attacks where clicks in the outer frame can be translated
invisibly to clicks on your page's elements. This is also known as
"clickjacking". :: | <mask> -----------------------------------------
<mask>
<mask> Prevents the client from clicking page elements outside of the website, avoiding hijacking or UI redress attacks.
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> X-Frame-Options: DENY
<mask> X-Frame-Options: SAMEORIGIN
<mask> X-Fra... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
response.headers['X-Frame-Options'] = 'SAMEORIGIN' | <mask> X-Frame-Options: DENY
<mask> X-Frame-Options: SAMEORIGIN
<mask> X-Frame-Options: ALLOW-FROM https://example.com/
<mask>
<mask> See also `X-Frame-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>`_.
<mask>
<mask> X-Content-Type-Options
<mask> ----------------... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options | <mask> X-Frame-Options: ALLOW-FROM https://example.com/
<mask>
<mask> See also `X-Frame-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>`_.
<mask>
<mask> X-Content-Type-Options
<mask> ----------------------
<mask>
<mask> This header prevents Cross-site scripting (XSS) b... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
X-XSS-Protection
~~~~~~~~~~~~~~~~ | <mask>
<mask> X-Content-Type-Options
<mask> ----------------------
<mask>
<mask> This header prevents Cross-site scripting (XSS) by blocking requests on clients and forcing them to first read and validate the content-type before reading any of the contents of the request.
<mask>
<mask> .. sourcecode:: none
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
The browser will try to prevent reflected XSS attacks by not loading the page
if the request contains something that looks like JavaScript and the response
contains the same data. :: | <mask> ----------------------
<mask>
<mask> This header prevents Cross-site scripting (XSS) by blocking requests on clients and forcing them to first read and validate the content-type before reading any of the contents of the request.
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> X-Content-Type-Opti... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
response.headers['X-XSS-Protection'] = '1; mode=block' | <mask> .. sourcecode:: none
<mask>
<mask> X-Content-Type-Options: nosniff
<mask>
<mask> See also `X-Content-Type-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_.
<mask>
<mask> Content Security Policy (CSP)
<mask> -----------------------------
<mask>
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection | <mask> X-Content-Type-Options: nosniff
<mask>
<mask> See also `X-Content-Type-Options <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>`_.
<mask>
<mask> Content Security Policy (CSP)
<mask> -----------------------------
<mask>
<mask> Enhances security and prevents common ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
Set-Cookie options
~~~~~~~~~~~~~~~~~~ | <mask>
<mask> Content Security Policy (CSP)
<mask> -----------------------------
<mask>
<mask> Enhances security and prevents common web vulnerabilities such as cross-site scripting (XSS) and man-in-the-middle (MITM) related attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
</... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
These options can be added to a ``Set-Cookie`` header to improve their
security. Flask has configuration options to set these on the session cookie.
They can be set on other cookies too. | <mask> -----------------------------
<mask>
<mask> Enhances security and prevents common web vulnerabilities such as cross-site scripting (XSS) and man-in-the-middle (MITM) related attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Content-Security-Policy: default-src ht... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- ``Secure`` limits cookies to HTTPS traffic only.
- ``HttpOnly`` protects the contents of cookies from being read with
JavaScript.
- ``SameSite`` ensures that cookies can only be requested from the same
domain that created them. It is not supported by Flask yet. | <mask> Enhances security and prevents common web vulnerabilities such as cross-site scripting (XSS) and man-in-the-middle (MITM) related attacks.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Content-Security-Policy: default-src https:; script-src 'nonce-{random}'; object-src '... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
:: | <mask> .. sourcecode:: none
<mask>
<mask> Content-Security-Policy: default-src https:; script-src 'nonce-{random}'; object-src 'none'
<mask>
<mask> See also `Content Security Policy <https://csp.withgoogle.com/docs/index.html>`_.
<mask>
<mask> Cookie Options
<mask> --------------
<mask>
<mask> While... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
app.config.update(
SESSION_COOKIE_SECURE=True,
SESSION_COOKIE_HTTPONLY=True,
) | <mask> Content-Security-Policy: default-src https:; script-src 'nonce-{random}'; object-src 'none'
<mask>
<mask> See also `Content Security Policy <https://csp.withgoogle.com/docs/index.html>`_.
<mask>
<mask> Cookie Options
<mask> --------------
<mask>
<mask> While these headers are not directly security ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
response.set_cookie('username', 'flask', secure=True, httponly=True) | <mask>
<mask> Cookie Options
<mask> --------------
<mask>
<mask> While these headers are not directly security related, they have important options that may affect your Flask application.
<mask>
<mask> - ``Secure`` limits your cookies to HTTPS traffic only.
<mask> - ``HttpOnly`` protects the contents of your... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies | <mask> --------------
<mask>
<mask> While these headers are not directly security related, they have important options that may affect your Flask application.
<mask>
<mask> - ``Secure`` limits your cookies to HTTPS traffic only.
<mask> - ``HttpOnly`` protects the contents of your cookie from being visible to XS... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
HTTP Public Key Pinning (HPKP)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | <mask> - ``Secure`` limits your cookies to HTTPS traffic only.
<mask> - ``HttpOnly`` protects the contents of your cookie from being visible to XSS.
<mask> - ``SameSite`` ensures that cookies can only be requested from the same domain that created them but this feature is not yet fully supported across all browsers.... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
This tells the browser to authenticate with the server using only the specific
certificate key to prevent MITM attacks. | <mask> - ``SameSite`` ensures that cookies can only be requested from the same domain that created them but this feature is not yet fully supported across all browsers.
<mask>
<mask> Example:
<mask>
<mask> .. sourcecode:: none
<mask>
<mask> Set-Cookie: [cookie-name]=[cookie-value]
<mask>
<mask> Se... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
.. warning::
Be careful when enabling this, as it is very difficult to undo if you set up
or upgrade your key incorrectly. | <mask> .. sourcecode:: none
<mask>
<mask> Set-Cookie: [cookie-name]=[cookie-value]
<mask>
<mask> See also:
<mask>
<mask> - Mozilla guide to `HTTP cookies <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies>`_.
<mask> - `OWASP HTTP Only <https://www.owasp.org/index.p... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning | <mask> Set-Cookie: [cookie-name]=[cookie-value]
<mask>
<mask> See also:
<mask>
<mask> - Mozilla guide to `HTTP cookies <https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies#Secure_and_HttpOnly_cookies>`_.
<mask> - `OWASP HTTP Only <https://www.owasp.org/index.php/HttpOnly>`_.
</s> clean up security ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace"
] | https://github.com/pallets/flask/commit/8eff9bda3dbd4363a046778e9a98027c30b7e22c | docs/security.rst |
$ python3 -m venv .venv
$ . .venv/bin/activate | <mask> - Linux/macOS
<mask>
<mask> .. code-block:: text
<mask>
<mask> $ python3 -m venv env
<mask> $ . env/bin/activate
<mask>
<mask> - Windows
<mask>
<mask> .. code-block:: text
<mask>
</s> update docs and examples for pyproject
setup.py -> pyproject.toml
venv ->... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8f13f5b6d672f1ba434f9c8ebe2c1b1dd385962e | CONTRIBUTING.rst |
> py -3 -m venv .venv | <mask> - Windows
<mask>
<mask> .. code-block:: text
<mask>
<mask> > py -3 -m venv env
<mask> > env\Scripts\activate
<mask>
<mask> - Upgrade pip and setuptools.
<mask>
<mask> .. code-block:: text
</s> update docs and examples for pyproject
setup.py -> pyproject.toml
venv... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8f13f5b6d672f1ba434f9c8ebe2c1b1dd385962e | CONTRIBUTING.rst |
Unix Bash, :file:`.venv/bin/activate`:: | <mask> .. tabs::
<mask>
<mask> .. group-tab:: Bash
<mask>
<mask> Unix Bash, :file:`venv/bin/activate`::
<mask>
<mask> $ export FLASK_APP=hello
<mask>
<mask> .. group-tab:: Fish
<mask>
</s> update docs and examples for pyproject
setup.py -> pyproject.toml
venv -> .venv </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8f13f5b6d672f1ba434f9c8ebe2c1b1dd385962e | docs/cli.rst |
Fish, :file:`.venv/bin/activate.fish`:: | <mask> $ export FLASK_APP=hello
<mask>
<mask> .. group-tab:: Fish
<mask>
<mask> Fish, :file:`venv/bin/activate.fish`::
<mask>
<mask> $ set -x FLASK_APP hello
<mask>
<mask> .. group-tab:: CMD
<mask>
</s> update docs and examples for pyproject
setup.py -> pyproject.toml
ve... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8f13f5b6d672f1ba434f9c8ebe2c1b1dd385962e | docs/cli.rst |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.