Add a BadRequest resource to help with BAD REQUEST

This commit is contained in:
Jean-Paul Calderone 2020-09-18 14:10:09 -04:00
parent 9682e68528
commit 059bb2250b
2 changed files with 11 additions and 1 deletions

View File

@ -21,7 +21,8 @@ from allmydata.util.encodingutil import to_bytes, quote_output
# Originally part of this module, so still part of its API:
from .common_py3 import ( # noqa: F401
get_arg, abbreviate_time, MultiFormatResource, WebError
get_arg, abbreviate_time, MultiFormatResource, WebError,
BadRequest,
)

View File

@ -23,6 +23,15 @@ class WebError(Exception):
self.code = code
class BadRequest(resource.ErrorPage):
"""
``BadRequest`` is a specialiation of ``ErrorPage`` which returns the HTTP
response code **BAD REQUEST**.
"""
def __init__(self, message=""):
resource.ErrorPage.__init__(self, http.BAD_REQUEST, "Bad Request", message)
def get_arg(ctx_or_req, argname, default=None, multiple=False):
"""Extract an argument from either the query args (req.args) or the form
body fields (req.fields). If multiple=False, this returns a single value