예제 #1
0
def get_request_data(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'):
        parser = FormDataParser()
        stream, form, files = parser.parse_from_environ(environ)
        value = ImmutableMultiDict(list(form.items()) + list(files.items()))
    else:
        raise exceptions.UnsupportedMediaType()

    return value
예제 #2
0
 def test_parse_from_environ(self):
     parser = FormDataParser()
     stream, _, _ = parser.parse_from_environ({'wsgi.input': ''})
     assert stream is not None
예제 #3
0
 def test_parse_from_environ(self):
     parser = FormDataParser()
     stream, _, _ = parser.parse_from_environ({'wsgi.input': ''})
     assert stream is not None