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 |
|---|---|---|---|---|
'PREFERRED_URL_SCHEME': 'http',
'JSON_AS_ASCII': True | <mask> 'MAX_CONTENT_LENGTH': None,
<mask> 'SEND_FILE_MAX_AGE_DEFAULT': 12 * 60 * 60, # 12 hours
<mask> 'TRAP_BAD_REQUEST_ERRORS': False,
<mask> 'TRAP_HTTP_EXCEPTIONS': False,
<mask> 'PREFERRED_URL_SCHEME': ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/app.py |
def _dump_arg_defaults(kwargs):
"""Inject default arguments for dump functions."""
if current_app:
kwargs.setdefault('cls', current_app.json_encoder)
if not current_app.config['JSON_AS_ASCII']:
kwargs.setdefault('ensure_ascii', False)
def _load_arg_defaults(kwargs):
"""Inject d... | <mask>
<mask>
<mask> def dumps(obj, **kwargs):
<mask> """Serialize ``obj`` to a JSON formatted ``str`` by using the application's
<mask> configured encoder (:attr:`~flask.Flask.json_encoder`) if there is an
<mask> application on the stack.
<mask>
<mask> This function can return ``unicode`` st... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/json.py |
This function can return ``unicode`` strings or ascii-only bytestrings by
default which coerce into unicode strings automatically. That behavior by
default is controlled by the ``JSON_AS_ASCII`` configuration variable
and can be overriden by the simplejson ``ensure_ascii`` parameter. | <mask> def dumps(obj, **kwargs):
<mask> """Serialize ``obj`` to a JSON formatted ``str`` by using the application's
<mask> configured encoder (:attr:`~flask.Flask.json_encoder`) if there is an
<mask> application on the stack.
<mask> """
<mask> _dump_arg_defaults(kwargs)
<mask> return _jso... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/json.py |
_dump_arg_defaults(kwargs) | <mask> """Serialize ``obj`` to a JSON formatted ``str`` by using the application's
<mask> configured encoder (:attr:`~flask.Flask.json_encoder`) if there is an
<mask> application on the stack.
<mask> """
<mask> if current_app:
<mask> kwargs.setdefault('cls', current_app.json_encoder)
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/json.py |
_dump_arg_defaults(kwargs) | <mask>
<mask>
<mask> def dump(obj, fp, **kwargs):
<mask> """Like :func:`dumps` but writes into a file object."""
<mask> if current_app:
<mask> kwargs.setdefault('cls', current_app.json_encoder)
<mask> return _json.dump(obj, fp, **kwargs)
<mask>
<mask>
<mask> def loads(s, **kwargs):
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/json.py |
_load_arg_defaults(kwargs) | <mask> """Unserialize a JSON object from a string ``s`` by using the application's
<mask> configured decoder (:attr:`~flask.Flask.json_decoder`) if there is an
<mask> application on the stack.
<mask> """
<mask> if current_app:
<mask> kwargs.setdefault('cls', current_app.json_decoder)
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/json.py |
_load_arg_defaults(kwargs) | <mask>
<mask> def load(fp, **kwargs):
<mask> """Like :func:`loads` but reads from a file object.
<mask> """
<mask> if current_app:
<mask> kwargs.setdefault('cls', current_app.json_decoder)
<mask> return _json.load(fp, **kwargs)
<mask>
<mask>
<mask> def htmlsafe_dumps(obj, **kwargs):... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/json.py |
def test_json_as_unicode(self):
app = flask.Flask(__name__)
app.config['JSON_AS_ASCII'] = True
with app.app_context():
rv = flask.json.dumps(u'\N{SNOWMAN}')
self.assert_equal(rv, '"\\u2603"')
app.config['JSON_AS_ASCII'] = False
with app.app_context()... | <mask> rv = c.get(url)
<mask> self.assert_equal(rv.mimetype, 'application/json')
<mask> self.assert_equal(flask.json.loads(rv.data), d)
<mask>
<mask> def test_json_attr(self):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/add', methods=['POST'])
... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8339cb35082fc93d3a9c98616aed7fe0c1c642dc | flask/testsuite/helpers.py |
#: Maps registered blueprint names to blueprint objects. The
#: dict retains the order the blueprints were registered in.
#: Blueprints can be registered multiple times, this dict does
#: not track how often they were attached. | <mask> #:
<mask> #: .. versionadded:: 0.11
<mask> self.shell_context_processors = []
<mask>
<mask> #: all the attached blueprints in a dictionary by name. Blueprints
<mask> #: can be attached multiple times so this dictionary does not tell
<mask> #: you how often... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83d358d2c43c79b7d7fe5365e079447296c65eaf | src/flask/app.py |
<mask> #: you how often they got attached.
<mask> #:
<mask> #: .. versionadded:: 0.7
<mask> self.blueprints = {}
<mask> self._blueprint_order = []
<mask>
<mask> #: a place where extensions can store application specific state. For
<mask> #: example this ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83d358d2c43c79b7d7fe5365e079447296c65eaf | src/flask/app.py | |
<mask> f" names."
<mask> )
<mask> else:
<mask> self.blueprints[blueprint.name] = blueprint
<mask> self._blueprint_order.append(blueprint)
<mask> first_registration = True
<mask>
<mask> blueprint.register(self, options, first_regist... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83d358d2c43c79b7d7fe5365e079447296c65eaf | src/flask/app.py | |
return self.blueprints.values() | <mask> """Iterates over all blueprints by the order they were registered.
<mask>
<mask> .. versionadded:: 0.11
<mask> """
<mask> return iter(self._blueprint_order)
<mask>
<mask> @setupmethod
<mask> def add_url_rule(
<mask> self,
<mask> rule,
</s> remo... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83d358d2c43c79b7d7fe5365e079447296c65eaf | src/flask/app.py |
from ._compat import with_metaclass | <mask> :license: BSD, see LICENSE for more details.
<mask> """
<mask> from .globals import request
<mask>
<mask>
<mask> http_method_funcs = frozenset(['get', 'post', 'head', 'options',
<mask> 'delete', 'put', 'trace', 'patch'])
</s> fix metaclass usage for py3 </s> remove ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83f76585725fd380b61f35576bb1c307fe2a1a5e | flask/views.py |
class MethodView(with_metaclass(MethodViewType, View)): | <mask> rv.methods = sorted(methods)
<mask> return rv
<mask>
<mask>
<mask> class MethodView(View):
<mask> """Like a regular class-based view but that dispatches requests to
<mask> particular methods. For instance if you implement a method called
<mask> :meth:`get` it means ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83f76585725fd380b61f35576bb1c307fe2a1a5e | flask/views.py |
<mask> return 'OK'
<mask>
<mask> app.add_url_rule('/counter', view_func=CounterAPI.as_view('counter'))
<mask> """
<mask> __metaclass__ = MethodViewType
<mask>
<mask> def dispatch_request(self, *args, **kwargs):
<mask> meth = getattr(self, request.method.lower(), Non... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/83f76585725fd380b61f35576bb1c307fe2a1a5e | flask/views.py | |
- Mimetype guessing for ``send_file`` has been removed, as per issue ``#104``.
See pull request ``#1849``. | <mask> ------------
<mask>
<mask> - the cli command now responds to `--version`.
<mask>
<mask> Version 0.11
<mask> ------------
<mask>
<mask> Released on May 29th 2016, codename Absinthe.
<mask>
</s> Remove deprecation warnings for add_etags & mimetype guessing for send_file()
Fix #1849 </s> remove ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | CHANGES |
<mask> from warnings import warn
<mask> file = filename_or_fp
<mask> filename = getattr(file, 'name', None)
<mask>
<mask> # XXX: this behavior is now deprecated because it was unreliable.
<mask> # removed in Flask 1.0
<mask> if not attachment_filename and not mime... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | flask/helpers.py | |
if add_etags and filename is not None and file is None:
from warnings import warn
| <mask> if cache_timeout is not None:
<mask> rv.cache_control.max_age = cache_timeout
<mask> rv.expires = int(time() + cache_timeout)
<mask>
<mask> if add_etags and filename is not None:
<mask> try:
<mask> rv.set_etag('%s-%s-%s' % (
<mask> os.path.getm... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | flask/helpers.py |
def test_send_file_object(self): | <mask> os.path.join(app.root_path, 'static/index.html')
<mask> assert rv.mimetype == 'text/html'
<mask> rv.close()
<mask>
<mask> def test_send_file_object(self, recwarn):
<mask> app = flask.Flask(__name__)
<mask>
<mask> with app.test_request_context(... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py |
<mask> assert rv.data == f.read()
<mask> assert rv.mimetype == 'text/html'
<mask> rv.close()
<mask>
<mask> # mimetypes + etag
<mask> recwarn.pop(DeprecationWarning)
<mask> recwarn.pop(DeprecationWarning)
<mask>
<mask> app.use... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py | |
<mask> assert rv.headers['x-sendfile'] == \
<mask> os.path.join(app.root_path, 'static/index.html')
<mask> rv.close()
<mask>
<mask> # mimetypes + etag
<mask> recwarn.pop(DeprecationWarning)
<mask> recwarn.pop(DeprecationWarning)
<mask>... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py | |
<mask> assert rv.data == b'Test'
<mask> assert rv.mimetype == 'application/octet-stream'
<mask> rv.close()
<mask>
<mask> # etags
<mask> recwarn.pop(DeprecationWarning)
<mask>
<mask> class PyStringIO(object):
<mask> def __... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py | |
<mask> assert rv.data == b'Test'
<mask> assert rv.mimetype == 'text/plain'
<mask> rv.close()
<mask>
<mask> # attachment_filename and etags
<mask> a = recwarn.pop(DeprecationWarning)
<mask> b = recwarn.pop(DeprecationWarning)
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py | |
<mask> assert rv.data == b'Test'
<mask> assert rv.mimetype == 'text/plain'
<mask> rv.close()
<mask>
<mask> # etags
<mask> recwarn.pop(DeprecationWarning)
<mask>
<mask> app.use_x_sendfile = True
<mask>
<mask> with app.test_request_c... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py | |
def test_attachment(self): | <mask> rv = flask.send_file(f)
<mask> assert 'x-sendfile' not in rv.headers
<mask> rv.close()
<mask>
<mask> # etags
<mask> recwarn.pop(DeprecationWarning)
<mask>
<mask> def test_attachment(self, recwarn):
<mask> app = flask.Flask(__name__)
<mas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py |
<mask> parse_options_header(rv.headers['Content-Disposition'])
<mask> assert value == 'attachment'
<mask> rv.close()
<mask>
<mask> # mimetypes + etag
<mask> assert len(recwarn.list) == 2
<mask> recwarn.clear()
<mask>
<mask> w... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8458cc5cd10bac1dabea3dae86424bce46926a49 | tests/test_helpers.py | |
assert issubclass(
exc_class, Exception
), "Custom exceptions must be subclasses of Exception." | <mask> exc_class = default_exceptions[exc_class_or_code]
<mask> else:
<mask> exc_class = exc_class_or_code
<mask>
<mask> assert issubclass(exc_class, Exception)
<mask>
<mask> if issubclass(exc_class, HTTPException):
<mask> return exc_class, exc_class... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/846ee2c62e369ed06190b8791088748bd3a83557 | src/flask/app.py |
class UnacceptableCustomException(BaseException):
pass
| <mask> class CustomException(Exception):
<mask> pass
<mask>
<mask> @app.errorhandler(CustomException)
<mask> def custom_exception_handler(e):
<mask> assert isinstance(e, CustomException)
<mask> return "custom"
</s> add assert message for errorhandler exception type </s> remo... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/846ee2c62e369ed06190b8791088748bd3a83557 | tests/test_user_error_handler.py |
with pytest.raises(
AssertionError, match="Custom exceptions must be subclasses of Exception."
):
app.register_error_handler(UnacceptableCustomException, None)
| <mask> return "custom"
<mask>
<mask> @app.errorhandler(500)
<mask> def handle_500(e):
<mask> assert isinstance(e, InternalServerError)
<mask> original = getattr(e, "original_exception", None)
<mask>
</s> add assert message for errorhandler exception type </s> remove ass... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/846ee2c62e369ed06190b8791088748bd3a83557 | tests/test_user_error_handler.py |
- Exceptions during teardown handling will no longer leave bad application
contexts lingering around. | <mask> the server OS (pull request ``#1763``).
<mask> - Added the ``JSONIFY_MIMETYPE`` configuration variable (pull request ``#1728``).
<mask>
<mask> Version 0.10.2
<mask> --------------
<mask>
</s> Improve application context popping
Exceptions during teardown handling will no longer leave application
cont... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8482ce6b8ca9f1110b86bff4c3f998655fdecf8a | CHANGES |
try:
self._refcnt -= 1
if self._refcnt <= 0:
if exc is _sentinel:
exc = sys.exc_info()[1]
self.app.do_teardown_appcontext(exc)
finally:
rv = _app_ctx_stack.pop() | <mask> appcontext_pushed.send(self.app)
<mask>
<mask> def pop(self, exc=_sentinel):
<mask> """Pops the app context."""
<mask> self._refcnt -= 1
<mask> if self._refcnt <= 0:
<mask> if exc is _sentinel:
<mask> exc = sys.exc_info()[1]
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8482ce6b8ca9f1110b86bff4c3f998655fdecf8a | flask/ctx.py |
try:
clear_request = False
if not self._implicit_app_ctx_stack:
self.preserved = False
self._preserved_exc = None
if exc is _sentinel:
exc = sys.exc_info()[1]
self.app.do_teardown_request(exc)
... | <mask> Added the `exc` argument.
<mask> """
<mask> app_ctx = self._implicit_app_ctx_stack.pop()
<mask>
<mask> clear_request = False
<mask> if not self._implicit_app_ctx_stack:
<mask> self.preserved = False
<mask> self._preserved_exc = None
<ma... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/pallets/flask/commit/8482ce6b8ca9f1110b86bff4c3f998655fdecf8a | flask/ctx.py |
def read_source(input_file):
with open(input_file, "r") as source_code:
red = RedBaron(source_code.read())
return red | <mask> from redbaron import RedBaron
<mask> import sys
<mask>
<mask>
<mask> with open("test.py", "r") as source_code:
<mask> red = RedBaron(source_code.read())
<mask>
<mask> print red.dumps()
<mask>
<mask> # with open("code.py", "w") as source_code:
<mask> # source_code.write(red.dumps())
</s> C... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8488a3afa97e12297bdb22586e17b4c0ddf54175 | scripts/flaskext_migrate.py |
<mask>
<mask> with open("test.py", "r") as source_code:
<mask> red = RedBaron(source_code.read())
<mask>
<mask> print red.dumps()
<mask>
<mask> # with open("code.py", "w") as source_code:
<mask> # source_code.write(red.dumps())
</s> Change parsing format to use AST via RedBaron
Moved away from usin... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8488a3afa97e12297bdb22586e17b4c0ddf54175 | scripts/flaskext_migrate.py | |
def write_source(red, input_file):
with open(input_file, "w") as source_code:
source_code.write(red.dumps())
def fix_imports(red):
from_imports = red.find_all("FromImport")
for x in range(len(from_imports)):
values = from_imports[x].value
if (values[0].value == 'flask') and (values... | <mask> red = RedBaron(source_code.read())
<mask>
<mask> print red.dumps()
<mask>
<mask> # with open("code.py", "w") as source_code:
<mask> # source_code.write(red.dumps())
</s> Change parsing format to use AST via RedBaron
Moved away from using manual parsing. Source is parsed using RedBaron to make t... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace"
] | https://github.com/pallets/flask/commit/8488a3afa97e12297bdb22586e17b4c0ddf54175 | scripts/flaskext_migrate.py |
from flask.ext.foo import \
bam, \
crackle
from flask.ext import foo
from flask.ext.foo import (bam,
a,
b
)
| <mask> from flask.ext.foo import bam
<mask> from flask.ext import foo
<mask>
<mask>
<mask> def migrate(old_file):
<mask> new_file = open("temp.py", "w")
</s> Change parsing format to use AST via RedBaron
Moved away from using manual parsing. Source is parsed using RedBaron to make the FST. Some import for... | [
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8488a3afa97e12297bdb22586e17b4c0ddf54175 | scripts/test.py |
import sys | <mask>
<mask>
<mask> from flask.ext import foo
<mask>
<mask>
<mask> def migrate(old_file):
<mask> new_file = open("temp.py", "w")
<mask> for line in old_file:
<mask> if line[0, 15] is "from flask.ext":
<mask> if line[15] == '.':
</s> Change parsing format to use AST via RedBar... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/8488a3afa97e12297bdb22586e17b4c0ddf54175 | scripts/test.py |
<mask>
<mask> new_file.write(line)
<mask>
<mask> if __name__ == "__main__":
<mask> old_file = open(sys.arv[1]) </s> Change parsing format to use AST via RedBaron
Moved away from using manual parsing. Source is parsed using RedBaron to make the FST. Some import formats not yet implemented, and still ... | [
"keep",
"keep",
"keep",
"keep",
"replace"
] | https://github.com/pallets/flask/commit/8488a3afa97e12297bdb22586e17b4c0ddf54175 | scripts/test.py | |
- Flask will now log by default even if debug is disabled. The log format is
now hardcoded but the default log handling can be disabled through the
``LOGGER_HANDLER_POLICY`` configuration key. | <mask> for an extension author to create exceptions that will by default
<mask> result in the HTTP error of their choosing, but may be caught with
<mask> a custom error handler if desired.
<mask> - Added :meth:`flask.Config.from_mapping`.
<mask>
<mask> Version 0.10.2
<mask> --------------
<mask>
<mask>... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | CHANGES |
``TEMPLATES_AUTO_RELOAD``, ``LOGGER_HANDLER_POLICY`` | <mask> .. versionadded:: 1.0
<mask> ``SESSION_REFRESH_EACH_REQUEST``
<mask>
<mask> .. versionadded:: 1.0
<mask> ``TEMPLATES_AUTO_RELOAD``
<mask>
<mask> Configuring from Files
<mask> ----------------------
<mask>
<mask> Configuration becomes more useful if you can store it in a separate file,
</s> Al... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | docs/config.rst |
.. _upgrading-to-10:
Version 1.0
-----------
Flask 1.0 removed the ``debug_log_format`` attribute from Flask
applications. Instead the new ``LOGGER_HANDLER_POLICY`` configuration can
be used to disable the default log handlers and custom log handlers can be
set up.
| <mask> installation, make sure to pass it the ``-U`` parameter::
<mask>
<mask> $ easy_install -U Flask
<mask>
<mask> .. _upgrading-to-010:
<mask>
<mask> Version 0.10
<mask> ------------
</s> Always log now, even if debug is off. </s> remove #: The logging format used for the debug logger. This is o... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | docs/upgrading.rst |
<mask> #: in 0.7 but will be changed to False in 0.8. With Flask 1.0 modules
<mask> #: will be removed in favor of Blueprints
<mask> enable_modules = True
<mask>
<mask> #: The logging format used for the debug logger. This is only used when
<mask> #: the application is in debug mode, otherw... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/app.py | |
'LOGGER_HANDLER_POLICY': 'always', | <mask> 'USE_X_SENDFILE': False,
<mask> 'LOGGER_NAME': None,
<mask> 'SERVER_NAME': None,
<mask> 'APPLICATION_ROOT': None,
<mask> 'SESSION_COOKIE_NAME': 'session',
<ma... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/app.py |
from logging import getLogger, StreamHandler, Formatter, getLoggerClass, \
DEBUG, ERROR
PROD_LOG_FORMAT = '[%(asctime)s] %(levelname)s in %(module)s: %(message)s'
DEBUG_LOG_FORMAT = (
'-' * 80 + '\n' +
'%(levelname)s in %(module)s [%(pathname)s:%(lineno)d]:\n' +
'%(message)s\n' +
'-' * 80
)
def... | <mask> """
<mask>
<mask> from __future__ import absolute_import
<mask>
<mask> from logging import getLogger, StreamHandler, Formatter, getLoggerClass, DEBUG
<mask>
<mask>
<mask> def create_logger(app):
<mask> """Creates a logger for the given application. This logger works
<mask> similar to a reg... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/logging.py |
def emit(self, record):
if app.debug and should_log_for(app, 'debug'):
StreamHandler.emit(self, record)
class ProductionHandler(StreamHandler):
def emit(self, record):
if not app.debug and should_log_for(app, 'production'):
StreamHandler.emit(... | <mask> return DEBUG
<mask> return Logger.getEffectiveLevel(x)
<mask>
<mask> class DebugHandler(StreamHandler):
<mask> def emit(x, record):
<mask> StreamHandler.emit(x, record) if app.debug else None
<mask>
<mask> handler = DebugHandler()
<mask> hand... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/logging.py |
<mask> class DebugHandler(StreamHandler):
<mask> def emit(x, record):
<mask> StreamHandler.emit(x, record) if app.debug else None
<mask>
<mask> handler = DebugHandler()
<mask> handler.setLevel(DEBUG)
<mask> handler.setFormatter(Formatter(app.debug_log_format))
<mask> log... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/logging.py | |
logger.addHandler(debug_handler)
logger.addHandler(prod_handler) | <mask> # just in case that was not a new logger, get rid of all the handlers
<mask> # already attached to it.
<mask> del logger.handlers[:]
<mask> logger.__class__ = DebugLogger
<mask> logger.addHandler(handler)
<mask> return logger
</s> Always log now, even if debug is off. </s> remove ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/logging.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask> def test_teardown_request_handler_error(self):
<mask> called = []
<mask> app = flask.Flask(__name__)
<mask> @app.teardown_request
<mask> def teardown_request1(exc):
<mask> self.assert_equal(type(exc), ZeroDivisionError)
<mask> called.append(True)... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/basic.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask> self.assert_equal(called, [1, 2, 3, 4, 5, 6])
<mask>
<mask> def test_error_handling(self):
<mask> app = flask.Flask(__name__)
<mask> @app.errorhandler(404)
<mask> def not_found(e):
<mask> return 'not found', 404
<mask> @app.errorhandler(500)
<mask... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/basic.py |
app.testing = True | <mask> def test_none_response(self):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/')
<mask> def test():
<mask> return None
<mask> try:
<mask> app.test_client().get('/')
<mask> except ValueError as e:
</s> Always log now, even if debu... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/basic.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask>
<mask> def test_exception_propagation(self):
<mask> def apprunner(configkey):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/')
<mask> def index():
<mask> 1 // 0
<mask> c = app.test_client()
</s> Always log now, even if... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/basic.py |
c.get('/') | <mask> c = app.test_client()
<mask> if config_key is not None:
<mask> app.config[config_key] = True
<mask> try:
<mask> resp = c.get('/')
<mask> except Exception:
<mask> pass
<mask> els... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/basic.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask> @emits_module_deprecation_warning
<mask> def test_error_handling(self):
<mask> app = flask.Flask(__name__)
<mask> admin = flask.Module(__name__, 'admin')
<mask> @admin.app_errorhandler(404)
<mask> def not_found(e):
<mask> return 'not found', 404
<mask> ... | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/blueprints.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask> out = StringIO()
<mask> app = flask.Flask(__name__)
<mask> app.logger_name = 'flask_tests/test_exception_logging'
<mask> app.logger.addHandler(StreamHandler(out))
<mask>
<mask> @app.route('/')
<mask> def index():
</s> Always log now, even if debug is off. | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/helpers.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask> self.assert_in('ZeroDivisionError:', err)
<mask>
<mask> def test_processor_exceptions(self):
<mask> app = flask.Flask(__name__)
<mask> @app.before_request
<mask> def before_request():
<mask> if trigger == 'before':
<mask> 1 // 0
</s> Alway... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/helpers.py |
app.config['LOGGER_HANDLER_POLICY'] = 'never' | <mask> def test_test_client_context_binding(self):
<mask> app = flask.Flask(__name__)
<mask> @app.route('/')
<mask> def index():
<mask> flask.g.value = 42
<mask> return 'Hello World!'
<mask>
</s> Always log now, even if debug is off. | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84ad89ffa4390d3327b4d35983dbb4d84293b8e2 | flask/testsuite/testing.py |
- The ``routes`` command shows each rule's ``subdomain`` or ``host`` when domain
matching is in use. :issue:`5004` | <mask> a subdomain match. Warnings about ``localhost`` and IP addresses are also removed.
<mask> :issue:`5051`
<mask>
<mask>
<mask> Version 2.2.4
<mask> -------------
</s> show subdomain or host in routes output </s> remove 'Method to sort routes by. "match" is the order that Flask will match '... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | CHANGES.rst |
from operator import itemgetter | <mask> import sys
<mask> import traceback
<mask> import typing as t
<mask> from functools import update_wrapper
<mask> from operator import attrgetter
<mask>
<mask> import click
<mask> from click.core import ParameterSource
<mask> from werkzeug import run_simple
<mask> from werkzeug.serving import is_running... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
type=click.Choice(("endpoint", "methods", "domain", "rule", "match")), | <mask> @click.command("routes", short_help="Show the routes for the app.")
<mask> @click.option(
<mask> "--sort",
<mask> "-s",
<mask> type=click.Choice(("endpoint", "methods", "rule", "match")),
<mask> default="endpoint",
<mask> help=(
<mask> 'Method to sort routes by. "match" is the... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
"Method to sort routes by. 'match' is the order that Flask will match routes"
" when dispatching a request." | <mask> "-s",
<mask> type=click.Choice(("endpoint", "methods", "rule", "match")),
<mask> default="endpoint",
<mask> help=(
<mask> 'Method to sort routes by. "match" is the order that Flask will match '
<mask> "routes when dispatching a request."
<mask> ),
<mask> )
<mask> @cli... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
ignored_methods = set() if all_methods else {"HEAD", "OPTIONS"}
host_matching = current_app.url_map.host_matching
has_domain = any(rule.host if host_matching else rule.subdomain for rule in rules)
rows = [] | <mask> if not rules:
<mask> click.echo("No routes were registered.")
<mask> return
<mask>
<mask> ignored_methods = set(() if all_methods else ("HEAD", "OPTIONS"))
<mask>
<mask> if sort in ("endpoint", "rule"):
<mask> rules = sorted(rules, key=attrgetter(sort))
<mask> e... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
for rule in rules:
row = [
rule.endpoint,
", ".join(sorted((rule.methods or set()) - ignored_methods)),
] | <mask> return
<mask>
<mask> ignored_methods = set(() if all_methods else ("HEAD", "OPTIONS"))
<mask>
<mask> if sort in ("endpoint", "rule"):
<mask> rules = sorted(rules, key=attrgetter(sort))
<mask> elif sort == "methods":
<mask> rules = sorted(rules, key=lambda rule: sorte... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
if has_domain:
row.append((rule.host if host_matching else rule.subdomain) or "") | <mask> rules = sorted(rules, key=attrgetter(sort))
<mask> elif sort == "methods":
<mask> rules = sorted(rules, key=lambda rule: sorted(rule.methods)) # type: ignore
<mask>
<mask> rule_methods = [
<mask> ", ".join(sorted(rule.methods - ignored_methods)) # type: ignore
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
row.append(rule.rule)
rows.append(row)
headers = ["Endpoint", "Methods"]
sorts = ["endpoint", "methods"]
if has_domain:
headers.append("Host" if host_matching else "Subdomain")
sorts.append("domain")
headers.append("Rule")
sorts.append("rule")
try:
row... | <mask> ", ".join(sorted(rule.methods - ignored_methods)) # type: ignore
<mask> for rule in rules
<mask> ]
<mask>
<mask> headers = ("Endpoint", "Methods", "Rule")
<mask> widths = (
<mask> max(len(rule.endpoint) for rule in rules),
<mask> max(len(methods) for methods ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
rows.insert(0, headers)
widths = [max(len(row[i]) for row in rows) for i in range(len(headers))]
rows.insert(1, ["-" * w for w in widths])
template = " ".join(f"{{{i}:<{w}}}" for i, w in enumerate(widths)) | <mask> )
<mask> widths = [max(len(h), w) for h, w in zip(headers, widths)]
<mask> row = "{{0:<{0}}} {{1:<{1}}} {{2:<{2}}}".format(*widths)
<mask>
<mask> click.echo(row.format(*headers).strip())
<mask> click.echo(row.format(*("-" * width for width in widths)))
<mask>
<mask> for rule, ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
for row in rows:
click.echo(template.format(*row)) | <mask>
<mask> click.echo(row.format(*headers).strip())
<mask> click.echo(row.format(*("-" * width for width in widths)))
<mask>
<mask> for rule, methods in zip(rules, rule_methods):
<mask> click.echo(row.format(rule.endpoint, methods, rule.rule).rstrip())
<mask>
<mask>
<mask> cli = Flas... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | src/flask/cli.py |
app.add_url_rule(
"/get_post/<int:x>/<int:y>",
methods=["GET", "POST"],
endpoint="yyy_get_post",
)
app.add_url_rule("/zzz_post", methods=["POST"], endpoint="aaa_post") | <mask> class TestRoutes:
<mask> @pytest.fixture
<mask> def app(self):
<mask> app = Flask(__name__)
<mask> app.testing = True
<mask>
<mask> @app.route("/get_post/<int:x>/<int:y>", methods=["GET", "POST"])
<mask> def yyy_get_post(x, y):
<mask> pass
<mask>
<... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | tests/test_cli.py |
<mask> def invoke(self, app, runner):
<mask> cli = FlaskGroup(create_app=lambda: app)
<mask> return partial(runner.invoke, cli)
<mask>
<mask> @pytest.fixture
<mask> def invoke_no_routes(self, runner):
<mask> def create_app():
<mask> app = Flask(__name__, static_f... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | tests/test_cli.py | |
def test_no_routes(self, runner):
app = Flask(__name__, static_folder=None)
cli = FlaskGroup(create_app=lambda: app)
result = runner.invoke(cli, ["routes"]) | <mask> assert "GET, HEAD, OPTIONS, POST" not in output
<mask> output = invoke(["routes", "--all-methods"]).output
<mask> assert "GET, HEAD, OPTIONS, POST" in output
<mask>
<mask> def test_no_routes(self, invoke_no_routes):
<mask> result = invoke_no_routes(["routes"])
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c007d34f7f0b8737310fe4d67be12c463e0130 | tests/test_cli.py |
- A new implementation of context preservation during debugging and
testing. :pr:`4666`
- ``request``, ``g``, and other context-locals point to the
correct data when running code in the interactive debugger
console. :issue:`2836`
- Teardown functions are always run at the end of the r... | <mask> - View functions can return generators directly instead of wrapping
<mask> them in a ``Response``. :pr:`4629`
<mask> - Add ``stream_template`` and ``stream_template_string`` functions to
<mask> render a template as a stream of pieces. :pr:`4629`
<mask>
<mask>
<mask> Version 2.1.3
<mask> ---... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | CHANGES.rst |
<mask> is enabled.
<mask>
<mask> Default: ``None``
<mask>
<mask> .. py:data:: PRESERVE_CONTEXT_ON_EXCEPTION
<mask>
<mask> Don't pop the request context when an exception occurs. If not set, this
<mask> is true if ``DEBUG`` is true. This allows debuggers to introspect the
<mask> request d... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | docs/config.rst | |
.. versionchanged:: 2.2
Removed ``PRESERVE_CONTEXT_ON_EXCEPTION``.
| <mask> Added :data:`MAX_COOKIE_SIZE` to control a warning from Werkzeug.
<mask>
<mask>
<mask> Configuring from Python Files
<mask> -----------------------------
<mask>
<mask> Configuration becomes more useful if you can store it in a separate file,
</s> new debug/test preserve context implementation </s>... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | docs/config.rst |
<mask> #. :data:`request_tearing_down` is sent after the
<mask> :meth:`~Flask.teardown_request` functions are called.
<mask>
<mask>
<mask> Context Preservation on Error
<mask> -----------------------------
<mask>
<mask> At the end of a request, the request context is popped and all data
<mask> associat... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
... | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | docs/reqcontext.rst | |
<mask> "ENV": None,
<mask> "DEBUG": None,
<mask> "TESTING": False,
<mask> "PROPAGATE_EXCEPTIONS": None,
<mask> "PRESERVE_CONTEXT_ON_EXCEPTION": None,
<mask> "SECRET_KEY": None,
<mask> "PERMANENT_SESSION_LIFETIME": timedelta(days=... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/app.py | |
<mask> if rv is not None:
<mask> return rv
<mask> return self.testing or self.debug
<mask>
<mask> @property
<mask> def preserve_context_on_exception(self) -> bool:
<mask> """Returns the value of the ``PRESERVE_CONTEXT_ON_EXCEPTION``
<mask> configuration value... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/app.py | |
if "werkzeug.debug.preserve_context" in environ:
environ["werkzeug.debug.preserve_context"](_app_ctx_stack.top)
environ["werkzeug.debug.preserve_context"](_request_ctx_stack.top)
if error is not None and self.should_ignore_error(error): | <mask> error = sys.exc_info()[1]
<mask> raise
<mask> return response(environ, start_response)
<mask> finally:
<mask> if self.should_ignore_error(error):
<mask> error = None
<mask> ctx.auto_pop(error)
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/app.py |
ctx.pop(error) | <mask> return response(environ, start_response)
<mask> finally:
<mask> if self.should_ignore_error(error):
<mask> error = None
<mask> ctx.auto_pop(error)
<mask>
<mask> def __call__(self, environ: dict, start_response: t.Callable) -> t.Any:
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/app.py |
The request context is automatically popped at the end of the
request. When using the interactive debugger, the context will be
restored so ``request`` is still accessible. Similarly, the test
client can preserve the context after the request ends. However,
teardown functions may already have closed... | <mask> When the request context is popped, it will evaluate all the
<mask> functions registered on the application for teardown execution
<mask> (:meth:`~flask.Flask.teardown_request`).
<mask>
<mask> The request context is automatically popped at the end of the request
<mask> for you. In deb... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/ctx.py |
<mask> # get rid of them. Additionally if an application context is missing
<mask> # one is created implicitly so for each level we add this information
<mask> self._implicit_app_ctx_stack: t.List[t.Optional["AppContext"]] = []
<mask>
<mask> # indicator if the context was preserve... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/ctx.py | |
<mask> except HTTPException as e:
<mask> self.request.routing_exception = e
<mask>
<mask> def push(self) -> None:
<mask> """Binds the request context to the current context."""
<mask> # If an exception occurs in debug mode or if context preservation is
<mask> # ac... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/ctx.py | |
<mask> clear_request = False
<mask>
<mask> try:
<mask> if not self._implicit_app_ctx_stack:
<mask> self.preserved = False
<mask> self._preserved_exc = None
<mask> if exc is _sentinel:
<mask> exc = sys.exc_info()[1]
... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/ctx.py | |
"""
.. deprecated:: 2.2
Will be removed in Flask 2.3.
"""
import warnings
warnings.warn(
"'ctx.auto_pop' is deprecated and will be removed in Flask 2.3.",
DeprecationWarning,
stacklevel=2,
)
self.pop(exc) | <mask> rv is self
<mask> ), f"Popped wrong request context. ({rv!r} instead of {self!r})"
<mask>
<mask> def auto_pop(self, exc: t.Optional[BaseException]) -> None:
<mask> if self.request.environ.get("flask._preserve_context") or (
<mask> exc is not None and sel... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/ctx.py |
self.pop(exc_value) | <mask> exc_type: t.Optional[type],
<mask> exc_value: t.Optional[BaseException],
<mask> tb: t.Optional[TracebackType],
<mask> ) -> None:
<mask> # do not pop the request stack if we are in debug mode and an
<mask> # exception happened. This will allow the debugger to sti... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/ctx.py |
<mask> When a teardown function was called because of an exception it will
<mask> be passed an error object.
<mask>
<mask> The return values of teardown functions are ignored.
<mask>
<mask> .. admonition:: Debug Note
<mask>
<mask> In debug mode Flask will not tear d... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/scaffold.py | |
from contextlib import ExitStack | <mask> import typing as t
<mask> from contextlib import contextmanager
<mask> from copy import copy
<mask> from types import TracebackType
<mask>
<mask> import werkzeug.test
<mask> from click.testing import CliRunner
</s> new debug/test preserve context implementation </s> remove if self.request.enviro... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py |
<mask> Basic usage is outlined in the :doc:`/testing` chapter.
<mask> """
<mask>
<mask> application: "Flask"
<mask> preserve_context = False
<mask>
<mask> def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
<mask> super().__init__(*args, **kwargs)
<mask> self.enviro... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py | |
self.preserve_context = False
self._new_contexts: t.List[t.ContextManager[t.Any]] = []
self._context_stack = ExitStack() | <mask> application: "Flask"
<mask>
<mask> def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:
<mask> super().__init__(*args, **kwargs)
<mask> self.environ_base = {
<mask> "REMOTE_ADDR": "127.0.0.1",
<mask> "HTTP_USER_AGENT": f"werkzeug/{werkzeug.__version__... | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py |
out = {**self.environ_base, **other}
if self.preserve_context:
out["werkzeug.debug.preserve_context"] = self._new_contexts.append
return out | <mask> headers = resp.get_wsgi_headers(c.request.environ)
<mask> self.cookie_jar.extract_wsgi(c.request.environ, headers)
<mask>
<mask> def _copy_environ(self, other):
<mask> return {
<mask> **self.environ_base,
<mask> **other,
<mask> "fla... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py |
# Pop any previously preserved contexts. This prevents contexts
# from being preserved across redirects or multiple requests
# within a single block.
self._context_stack.close()
response = super().open( | <mask> else:
<mask> # request is None
<mask> request = self._request_from_builder_args(args, kwargs)
<mask>
<mask> return super().open(
<mask> request,
<mask> buffered=buffered,
<mask> follow_redirects=follow_redirects,
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py |
# Re-push contexts that were preserved during the request.
while self._new_contexts:
cm = self._new_contexts.pop()
self._context_stack.enter_context(cm)
return response
| <mask> )
<mask>
<mask> def __enter__(self) -> "FlaskClient":
<mask> if self.preserve_context:
<mask> raise RuntimeError("Cannot nest client invocations")
<mask> self.preserve_context = True
<mask> return self
</s> new debug/test preserve context implementation </... | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py |
self._context_stack.close() | <mask> exc_value: t.Optional[BaseException],
<mask> tb: t.Optional[TracebackType],
<mask> ) -> None:
<mask> self.preserve_context = False
<mask>
<mask> # Normally the request context is preserved until the next
<mask> # request in the same thread comes. When the clien... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | src/flask/testing.py |
with pytest.raises(KeyboardInterrupt):
client.get("/") | <mask> @app.route("/")
<mask> def broken_func():
<mask> raise KeyboardInterrupt()
<mask>
<mask> with client:
<mask> with pytest.raises(KeyboardInterrupt):
<mask> client.get("/")
<mask>
<mask> ctx = flask._request_ctx_stack.top
<mask> assert ctx.preserv... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_basic.py |
<mask> assert client.get("/bar/").data == b"bar"
<mask> assert client.get("/bar/123").data == b"123"
<mask>
<mask>
<mask> def test_preserve_only_once(app, client):
<mask> app.debug = True
<mask>
<mask> @app.route("/fail")
<mask> def fail_func():
<mask> 1 // 0
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_basic.py | |
def test_appcontext_signals(app, client): | <mask> finally:
<mask> flask.got_request_exception.disconnect(record, app)
<mask>
<mask>
<mask> def test_appcontext_signals():
<mask> app = flask.Flask(__name__)
<mask> recorded = []
<mask>
<mask> def record_push(sender, **kwargs):
<mask> recorded.append("push")
<mask>
</... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_signals.py |
rv = client.get("/")
assert rv.data == b"Hello" | <mask>
<mask> flask.appcontext_pushed.connect(record_push, app)
<mask> flask.appcontext_popped.connect(record_pop, app)
<mask> try:
<mask> with app.test_client() as c:
<mask> rv = c.get("/")
<mask> assert rv.data == b"Hello"
<mask> assert recorded == ["pu... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_signals.py |
def test_appcontext_tearing_down_signal(app, client):
app.testing = False | <mask> finally:
<mask> flask.message_flashed.disconnect(record, app)
<mask>
<mask>
<mask> def test_appcontext_tearing_down_signal():
<mask> app = flask.Flask(__name__)
<mask> recorded = []
<mask>
<mask> def record_teardown(sender, **kwargs):
<mask> recorded.append(("tear_dow... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_signals.py |
def record_teardown(sender, exc):
recorded.append(exc) | <mask> def test_appcontext_tearing_down_signal():
<mask> app = flask.Flask(__name__)
<mask> recorded = []
<mask>
<mask> def record_teardown(sender, **kwargs):
<mask> recorded.append(("tear_down", kwargs))
<mask>
<mask> @app.route("/")
<mask> def index():
<mask> 1 // 0
<m... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_signals.py |
rv = client.get("/")
assert rv.status_code == 500
assert len(recorded) == 1
assert isinstance(recorded[0], ZeroDivisionError) | <mask> 1 // 0
<mask>
<mask> flask.appcontext_tearing_down.connect(record_teardown, app)
<mask> try:
<mask> with app.test_client() as c:
<mask> rv = c.get("/")
<mask> assert rv.status_code == 500
<mask> assert recorded == []
<mask> assert reco... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_signals.py |
<mask>
<mask>
<mask> def test_session_transactions_no_null_sessions():
<mask> app = flask.Flask(__name__)
<mask> app.testing = True
<mask>
<mask> with app.test_client() as c:
<mask> with pytest.raises(RuntimeError) as e:
<mask> with c.session_transaction():
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_testing.py | |
<mask> with c:
<mask> assert client.get("/").status_code == 404
<mask>
<mask>
<mask> def test_test_client_calls_teardown_handlers(app, client):
<mask> called = []
<mask>
<mask> @app.teardown_request
<mask> def remember(error):
<mask> called.append(error)
<mask>
<mask> ... | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"re... | https://github.com/pallets/flask/commit/84c722044ad03f7f5384f5314c8350b3a13d8dfa | tests/test_testing.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.