Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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