Merge branch 'master' into sprint-branch
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parents 79ec3d8, 4c27f7a · Browse files · 6 files·+17 added−74 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+17 added−74 removed
- other:+17 added−74 removed
Provenance
- Commit
16df96c- Tree
e985976- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
79ec3d8- Parent 2
4c27f7a
6 files changed+17 added−74 removed
modified:flask/testsuite/helpers.py+1 added-13 removed
31 unmodified lines32 def test_json_bad_requests(self):33 app = flask.Flask(__name__)34 @app.route('/json', methods=['POST'])35 def return_json():36- return text_type(flask.request.json)36+ return flask.jsonify(foo=text_type(flask.request.json))37 c = app.test_client()38 rv = c.post('/json', data='malformed', content_type='application/json')39 self.assert_equal(rv.status_code, 400)40 41- def test_json_bad_requests_content_type(self):42- app = flask.Flask(__name__)43- @app.route('/json', methods=['POST'])44- def return_json():45- return text_type(flask.request.json)46- c = app.test_client()47- rv = c.post('/json', data='malformed', content_type='application/json')48- self.assert_equal(rv.status_code, 400)49- self.assert_equal(rv.mimetype, 'application/json')50- self.assert_in('description', flask.json.loads(rv.data))51- self.assert_not_in('<p>', flask.json.loads(rv.data)['description'])52-41 def test_json_body_encoding(self):42 app = flask.Flask(__name__)43 app.testing = True44 @app.route('/')475 unmodified linesmodified:flask/ctx.py+2 added
7 unmodified lines8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10 """11 12+from __future__ import with_statement13+14 import sys15 from functools import update_wrapper16 17 from werkzeug.exceptions import HTTPException357 unmodified linesdeleted:flask/exceptions.py-48 removed
1-# -*- coding: utf-8 -*-2-"""3- flask.exceptions4- ~~~~~~~~~~~~5-6- Flask specific additions to :class:`~werkzeug.exceptions.HTTPException`7-8- :copyright: (c) 2011 by Armin Ronacher.9- :license: BSD, see LICENSE for more details.10-"""11-from werkzeug.exceptions import HTTPException, BadRequest12-from . import json13-14-15-class JSONHTTPException(HTTPException):16- """A base class for HTTP exceptions with ``Content-Type:17- application/json``.18-19- The ``description`` attribute of this class must set to a string (*not* an20- HTML string) which describes the error.21-22- """23-24- def get_body(self, environ):25- """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to26- return the description of this error in JSON format instead of HTML.27-28- """29- return json.dumps(dict(description=self.get_description(environ)))30-31- def get_headers(self, environ):32- """Returns a list of headers including ``Content-Type:33- application/json``.34-35- """36- return [('Content-Type', 'application/json')]37-38-39-class JSONBadRequest(JSONHTTPException, BadRequest):40- """Represents an HTTP ``400 Bad Request`` error whose body contains an41- error message in JSON format instead of HTML format (as in the superclass).42- """43-44- #: The description of the error which occurred as a string.45- description = (46- 'The browser (or proxy) sent a request that this server could not '47- 'understand.'48- )modified:flask/json.py+4 added-1 removed
15 unmodified lines16 from werkzeug.http import http_date17 18 # Use the same json implementation as itsdangerous on which we19 # depend anyways.20+try:21+ from itsdangerous import simplejson as _json22+except ImportError:20-from itsdangerous import json as _json23+ from itsdangerous import json as _json24 25 26 # figure out if simplejson escapes slashes. This behavior was changed27 # from one version to another without reason.148 unmodified linesmodified:flask/wrappers.py+7 added-12 removed
9 unmodified lines10 """11 12 from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase13 from werkzeug.utils import cached_property14+from werkzeug.exceptions import BadRequest15 15-from .exceptions import JSONBadRequest16 from .debughelpers import attach_enctype_error_multidict17 from . import json18 from .globals import _request_ctx_stack19 84 unmodified lines104 105 def on_json_loading_failed(self, e):106 """Called if decoding of the JSON data failed. The return value of107 this method is used by :attr:`json` when an error occurred. The default108- implementation raises a :class:`JSONBadRequest`, which is a subclass of109- :class:`~werkzeug.exceptions.BadRequest` which sets the110- ``Content-Type`` to ``application/json`` and provides a JSON-formatted111- error description::108+ implementation just raises a :class:`BadRequest` exception.109 113- {"description": "The browser (or proxy) sent a request that \114- this server could not understand."}110+ .. versionchanged:: 0.10111+ Removed buggy previous behavior of generating a random JSON112+ response. If you want that behavior back you can trivially113+ add it by subclassing.114 116- .. versionchanged:: 0.9117- Return a :class:`JSONBadRequest` instead of a118- :class:`~werkzeug.exceptions.BadRequest` by default.119-115 .. versionadded:: 0.8116 """122- raise JSONBadRequest()117+ raise BadRequest()118 119 def _load_form_data(self):120 RequestBase._load_form_data(self)121 18 unmodified linesmodified:CHANGES+3 added
52 unmodified lines53 to work better with Google Chrome.54 - Added `message_flashed` signal that simplifies flashing testing.55 - Added support for copying of request contexts for better working with56 greenlets.57+- Removed custom JSON HTTP exception subclasses. If you were relying on them58+ you can reintroduce them again yourself trivially. Using them however is59+ strongly discouraged as the interface was flawed.60 - Python requirements changed: requiring Python 2.6 or 2.7 now to prepare61 for Python 3.3 port.62 63 Version 0.9367 unmodified lines