|
def | __init__ (self, typing.Optional[str] location=None, *typing.Optional[str] unknown=_UNKNOWN_DEFAULT_PARAM, typing.Optional[ErrorHandler] error_handler=None, typing.Optional[typing.Type] schema_class=None) |
|
def | parse (self, ArgMap argmap, typing.Optional[Request] req=None, *typing.Optional[str] location=None, typing.Optional[str] unknown=_UNKNOWN_DEFAULT_PARAM, ValidateArg validate=None, typing.Optional[int] error_status_code=None, typing.Optional[typing.Mapping[str, str]] error_headers=None) |
|
typing.Optional[Request] | get_default_request (self) |
|
typing.Optional[Request] | get_request_from_view_args (self, typing.Callable view, typing.Tuple args, typing.Mapping[str, typing.Any] kwargs) |
|
typing.Callable[..., typing.Callable] | use_args (self, ArgMap argmap, typing.Optional[Request] req=None, *typing.Optional[str] location=None, typing.Optional[str] unknown=_UNKNOWN_DEFAULT_PARAM, bool as_kwargs=False, ValidateArg validate=None, typing.Optional[int] error_status_code=None, typing.Optional[typing.Mapping[str, str]] error_headers=None) |
|
typing.Callable | use_kwargs (self, *args, **kwargs) |
|
def | location_loader (self, str name) |
|
ErrorHandler | error_handler (self, ErrorHandler func) |
|
Mapping | pre_load (self, Mapping location_data, *ma.Schema schema, Request req, str location) |
|
typing.Any | load_json (self, Request req, ma.Schema schema) |
|
def | load_json_or_form (self, Request req, ma.Schema schema) |
|
def | load_querystring (self, Request req, ma.Schema schema) |
|
def | load_form (self, Request req, ma.Schema schema) |
|
def | load_headers (self, Request req, ma.Schema schema) |
|
def | load_cookies (self, Request req, ma.Schema schema) |
|
def | load_files (self, Request req, ma.Schema schema) |
|
typing.NoReturn | handle_error (self, ValidationError error, Request req, ma.Schema schema, *int error_status_code, typing.Mapping[str, str] error_headers) |
|
Base parser class that provides high-level implementation for parsing
a request.
Descendant classes must provide lower-level implementations for reading
data from different locations, e.g. ``load_json``, ``load_querystring``,
etc.
:param str location: Default location to use for data
:param str unknown: A default value to pass for ``unknown`` when calling the
schema's ``load`` method. Defaults to EXCLUDE for non-body
locations and RAISE for request bodies. Pass ``None`` to use the
schema's setting instead.
:param callable error_handler: Custom error handler function.
Decorator that registers a custom error handling function. The
function should receive the raised error, request object,
`marshmallow.Schema` instance used to parse the request, error status code,
and headers to use for the error response. Overrides
the parser's ``handle_error`` method.
Example: ::
from webargs import flaskparser
parser = flaskparser.FlaskParser()
class CustomError(Exception):
pass
@parser.error_handler
def handle_error(error, req, schema, *, error_status_code, error_headers):
raise CustomError(error.messages)
:param callable func: The error callback to register.
def parse |
( |
|
self, |
|
|
ArgMap |
argmap, |
|
|
typing.Optional[Request] |
req = None , |
|
|
*typing.Optional[str] |
location = None , |
|
|
typing.Optional[str] |
unknown = _UNKNOWN_DEFAULT_PARAM , |
|
|
ValidateArg |
validate = None , |
|
|
typing.Optional[int] |
error_status_code = None , |
|
|
typing.Optional[typing.Mapping[str, str]] |
error_headers = None |
|
) |
| |
Main request parsing method.
:param argmap: Either a `marshmallow.Schema`, a `dict`
of argname -> `marshmallow.fields.Field` pairs, or a callable
which accepts a request and returns a `marshmallow.Schema`.
:param req: The request object to parse.
:param str location: Where on the request to load values.
Can be any of the values in :py:attr:`~__location_map__`. By
default, that means one of ``('json', 'query', 'querystring',
'form', 'headers', 'cookies', 'files', 'json_or_form')``.
:param str unknown: A value to pass for ``unknown`` when calling the
schema's ``load`` method. Defaults to EXCLUDE for non-body
locations and RAISE for request bodies. Pass ``None`` to use the
schema's setting instead.
:param callable validate: Validation function or list of validation functions
that receives the dictionary of parsed arguments. Validator either returns a
boolean or raises a :exc:`ValidationError`.
:param int error_status_code: Status code passed to error handler functions when
a `ValidationError` is raised.
:param dict error_headers: Headers passed to error handler functions when a
a `ValidationError` is raised.
:return: A dictionary of parsed arguments
typing.Callable[..., typing.Callable] use_args |
( |
|
self, |
|
|
ArgMap |
argmap, |
|
|
typing.Optional[Request] |
req = None , |
|
|
*typing.Optional[str] |
location = None , |
|
|
typing.Optional[str] |
unknown = _UNKNOWN_DEFAULT_PARAM , |
|
|
bool |
as_kwargs = False , |
|
|
ValidateArg |
validate = None , |
|
|
typing.Optional[int] |
error_status_code = None , |
|
|
typing.Optional[typing.Mapping[str, str]] |
error_headers = None |
|
) |
| |
Decorator that injects parsed arguments into a view function or method.
Example usage with Flask: ::
@app.route('/echo', methods=['get', 'post'])
@parser.use_args({'name': fields.Str()}, location="querystring")
def greet(args):
return 'Hello ' + args['name']
:param argmap: Either a `marshmallow.Schema`, a `dict`
of argname -> `marshmallow.fields.Field` pairs, or a callable
which accepts a request and returns a `marshmallow.Schema`.
:param str location: Where on the request to load values.
:param str unknown: A value to pass for ``unknown`` when calling the
schema's ``load`` method.
:param bool as_kwargs: Whether to insert arguments as keyword arguments.
:param callable validate: Validation function that receives the dictionary
of parsed arguments. If the function returns ``False``, the parser
will raise a :exc:`ValidationError`.
:param int error_status_code: Status code passed to error handler functions when
a `ValidationError` is raised.
:param dict error_headers: Headers passed to error handler functions when a
a `ValidationError` is raised.