Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move JSONHTTPException and JSONBadRequest to new module flask.excepti…

…ons.
  • Loading branch information...
commit 71b351173b1440d6ca2dc36284d080fda2a22006 1 parent 9711fd4
@aisipos aisipos authored
Showing with 50 additions and 38 deletions.
  1. +49 −0 flask/exceptions.py
  2. +1 −38 flask/wrappers.py
View
49 flask/exceptions.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+"""
+ flask.exceptions
+ ~~~~~~~~~~~~
+
+ Flask specific additions to :class:`~werkzeug.exceptions.HTTPException`
+
+ :copyright: (c) 2011 by Armin Ronacher.
+ :license: BSD, see LICENSE for more details.
+"""
+from werkzeug.exceptions import HTTPException, BadRequest
+from .helpers import json
+
+
+class JSONHTTPException(HTTPException):
+ """A base class for HTTP exceptions with ``Content-Type:
+ application/json``.
+
+ The ``description`` attribute of this class must set to a string (*not* an
+ HTML string) which describes the error.
+
+ """
+
+ def get_body(self, environ):
+ """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to
+ return the description of this error in JSON format instead of HTML.
+
+ """
+ return json.dumps(dict(description=self.get_description(environ)))
+
+ def get_headers(self, environ):
+ """Returns a list of headers including ``Content-Type:
+ application/json``.
+
+ """
+ return [('Content-Type', 'application/json')]
+
+
+class JSONBadRequest(JSONHTTPException, BadRequest):
+ """Represents an HTTP ``400 Bad Request`` error whose body contains an
+ error message in JSON format instead of HTML format (as in the superclass).
+
+ """
+
+ #: The description of the error which occurred as a string.
+ description = (
+ 'The browser (or proxy) sent a request that this server could not '
+ 'understand.'
+ )
View
39 flask/wrappers.py
@@ -10,51 +10,14 @@
"""
from werkzeug.wrappers import Request as RequestBase, Response as ResponseBase
-from werkzeug.exceptions import BadRequest, HTTPException
from werkzeug.utils import cached_property
+from .exceptions import JSONBadRequest
from .debughelpers import attach_enctype_error_multidict
from .helpers import json, _assert_have_json
from .globals import _request_ctx_stack
-class JSONHTTPException(HTTPException):
- """A base class for HTTP exceptions with ``Content-Type:
- application/json``.
-
- The ``description`` attribute of this class must set to a string (*not* an
- HTML string) which describes the error.
-
- """
-
- def get_body(self, environ):
- """Overrides :meth:`werkzeug.exceptions.HTTPException.get_body` to
- return the description of this error in JSON format instead of HTML.
-
- """
- return json.dumps(dict(description=self.get_description(environ)))
-
- def get_headers(self, environ):
- """Returns a list of headers including ``Content-Type:
- application/json``.
-
- """
- return [('Content-Type', 'application/json')]
-
-
-class JSONBadRequest(JSONHTTPException, BadRequest):
- """Represents an HTTP ``400 Bad Request`` error whose body contains an
- error message in JSON format instead of HTML format (as in the superclass).
-
- """
-
- #: The description of the error which occurred as a string.
- description = (
- 'The browser (or proxy) sent a request that this server could not '
- 'understand.'
- )
-
-
class Request(RequestBase):
"""The request object used by default in Flask. Remembers the
matched endpoint and view arguments.
Please sign in to comment.
Something went wrong with that request. Please try again.