fix(request): parse_multipart_form should return RequestParameters

I have this code:

```
form = FileForm(request.files)
```

and it raise error because the `request.files` is `dict` but `RequestParameters` is expected =/
This commit is contained in:
Pahaz Blinov 2016-11-09 00:36:37 +05:00 committed by GitHub
parent aaee40aabd
commit 0e9819fba1

View File

@ -134,8 +134,8 @@ def parse_multipart_form(body, boundary):
:param boundary: Bytes multipart boundary
:return: fields (dict), files (dict)
"""
files = {}
fields = {}
files = RequestParameters()
fields = RequestParameters()
form_parts = body.split(boundary)
for form_part in form_parts[1:-1]:
@ -166,9 +166,16 @@ def parse_multipart_form(body, boundary):
post_data = form_part[line_index:-4]
if file_name or file_type:
files[field_name] = File(
type=file_type, name=file_name, body=post_data)
file = File(type=file_type, name=file_name, body=post_data)
if field_name in files:
files[field_name].append(file)
else:
fields[field_name] = post_data.decode('utf-8')
files[field_name] = [file]
else:
value = post_data.decode('utf-8')
if field_name in fields:
fields[field_name].append(value)
else:
fields[field_name] = [value]
return fields, files