Skip to content
Myr

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

6 files+17 added−74 removed

modified:flask/testsuite/helpers.py+1 added-13 removed
31 unmodified lines
32 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)4041 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'])5241 def test_json_body_encoding(self):42 app = flask.Flask(__name__)43 app.testing = True44 @app.route('/')
475 unmodified lines
modified:flask/ctx.py+2 added
7 unmodified lines
8 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""1112from __future__ import with_statement1314import sys15from functools import update_wrapper1617from werkzeug.exceptions import HTTPException
357 unmodified lines
deleted:flask/exceptions.py-48 removed
1# -*- coding: utf-8 -*-2"""3 flask.exceptions4 ~~~~~~~~~~~~56 Flask specific additions to :class:`~werkzeug.exceptions.HTTPException`78 :copyright: (c) 2011 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11from werkzeug.exceptions import HTTPException, BadRequest12from . import json131415class JSONHTTPException(HTTPException):16 """A base class for HTTP exceptions with ``Content-Type:17 application/json``.1819 The ``description`` attribute of this class must set to a string (*not* an20 HTML string) which describes the error.2122 """2324 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.2728 """29 return json.dumps(dict(description=self.get_description(environ)))3031 def get_headers(self, environ):32 """Returns a list of headers including ``Content-Type:33 application/json``.3435 """36 return [('Content-Type', 'application/json')]373839class 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 """4344 #: 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 lines
16from werkzeug.http import http_date1718# Use the same json implementation as itsdangerous on which we19# depend anyways.20try:21 from itsdangerous import simplejson as _json22except ImportError:20from itsdangerous import json as _json23 from itsdangerous import json as _json242526# figure out if simplejson escapes slashes. This behavior was changed27# from one version to another without reason.
148 unmodified lines
modified:flask/wrappers.py+7 added-12 removed
9 unmodified lines
10"""1112from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase13from werkzeug.utils import cached_property14from werkzeug.exceptions import BadRequest1515from .exceptions import JSONBadRequest16from .debughelpers import attach_enctype_error_multidict17from . import json18from .globals import _request_ctx_stack19
84 unmodified lines
104105 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.109113 {"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.114116 .. versionchanged:: 0.9117 Return a :class:`JSONBadRequest` instead of a118 :class:`~werkzeug.exceptions.BadRequest` by default.119115 .. versionadded:: 0.8116 """122 raise JSONBadRequest()117 raise BadRequest()118119 def _load_form_data(self):120 RequestBase._load_form_data(self)121
18 unmodified lines
modified:CHANGES+3 added
52 unmodified lines
53 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.6263Version 0.9
367 unmodified lines