Skip to content
Myr

Use app_ctx instead of request_ctx to access the app

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Adam Byrtek · committed by Markus Unterwaditzer · parent f0d3b71 · Browse files · 1 file+13 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+13 added−20 removed

  • other:+13 added−20 removed

1 file+13 added−20 removed

modified:flask/wrappers.py+13 added-20 removed
11 unmodified lines
12from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase13from werkzeug.exceptions import BadRequest1415from . import json16from .globals import _request_ctx_stack16from .globals import _app_ctx_stack1718_missing = object()1920
79 unmodified lines
100 def on_json_loading_failed(self, e):101 """Called if decoding of the JSON data failed. The return value of102 this method is used by :meth:`get_json` when an error occurred. The103 default implementation just raises a :class:`BadRequest` exception.104105 .. versionchanged:: 0.10106 Removed buggy previous behavior of generating a random JSON107 response. If you want that behavior back you can trivially108 add it by subclassing.109110 .. versionadded:: 0.8111 """112 ctx = _app_ctx_stack.top113 if ctx is not None and ctx.app.debug:114 raise BadRequest('Failed to decode JSON object: {0}'.format(e))115 raise BadRequest()116117118class Request(RequestBase, JSONMixin):
32 unmodified lines
151152 @property153 def max_content_length(self):154 """Read-only view of the ``MAX_CONTENT_LENGTH`` config key."""145 ctx = _request_ctx_stack.top155 ctx = _app_ctx_stack.top156 if ctx is not None:157 return ctx.app.config['MAX_CONTENT_LENGTH']158159 @property
24 unmodified lines
184 """The name of the current blueprint"""185 if self.url_rule and '.' in self.url_rule.endpoint:186 return self.url_rule.endpoint.rsplit('.', 1)[0]187178 def on_json_loading_failed(self, e):179 """Called if decoding of the JSON data failed. The return value of180 this method is used by :meth:`get_json` when an error occurred. The181 default implementation just raises a :class:`BadRequest` exception.182183 .. versionchanged:: 0.10184 Removed buggy previous behavior of generating a random JSON185 response. If you want that behavior back you can trivially186 add it by subclassing.187188 .. versionadded:: 0.8189 """190 ctx = _request_ctx_stack.top191 if ctx is not None and ctx.app.config.get('DEBUG', False):192 raise BadRequest('Failed to decode JSON object: {0}'.format(e))193 raise BadRequest()194188 def _load_form_data(self):189 RequestBase._load_form_data(self)190191 # In debug mode we're replacing the files multidict with an ad-hoc192 # subclass that raises a different error for key errors.200 ctx = _request_ctx_stack.top193 ctx = _app_ctx_stack.top194 if ctx is not None and ctx.app.debug and \195 self.mimetype != 'multipart/form-data' and not self.files:196 from .debughelpers import attach_enctype_error_multidict197 attach_enctype_error_multidict(self)
19 unmodified lines