def build(cls, params: QueryParams, arg_name: ArgName): value = params.get(arg_name) if value is None or cls.schema is None: return value if not isinstance(value, cls.schema): value = validate(cls.schema, value) return value
def build(cls, params: QueryParams, arg_name: ArgName): value = params.get(arg_name) if value is None or cls.schema is None: return value if not isinstance(value, cls.schema): value = validate(cls.schema, value, key=arg_name) return value
def build(cls, body: Body): value = json.loads(body.decode('utf-8')) if value is None or cls.schema is None: return value if not isinstance(value, cls.schema): value = validate(cls.schema, value) return value
def build(cls, data: RequestData, arg_name: ArgName): value = data[arg_name] # type: ignore if value is None or cls.schema is None: return value if not isinstance(value, cls.schema): value = validate(cls.schema, value, key=arg_name) return value
def build(cls, environ: WSGIEnviron): if not bool(environ.get('CONTENT_TYPE')): mimetype = None else: mimetype, _ = parse_options_header(environ['CONTENT_TYPE']) if mimetype is None: value = None elif mimetype == 'application/json': body = get_input_stream(environ).read() value = json.loads(body.decode('utf-8')) elif mimetype in ('multipart/form-data', 'application/x-www-form-urlencoded'): stream, form, files = parse_form_data(environ) value = ImmutableMultiDict(list(form.items()) + list(files.items())) else: raise exceptions.UnsupportedMediaType() if cls.schema is None: return value if not isinstance(value, cls.schema): value = validate(cls.schema, value) return value