示例#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
示例#2
0
文件: http.py 项目: mpicard/apistar
 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
示例#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
示例#4
0
文件: http.py 项目: wlmgithub/apistar
    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
示例#5
0
文件: http.py 项目: wlmgithub/apistar
    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