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
def test_parse_from_environ(self): parser = FormDataParser() stream, _, _ = parser.parse_from_environ({'wsgi.input': ''}) assert stream is not None