From 0e9819fba168ee2aa6b32827db751bb4c0a70dab Mon Sep 17 00:00:00 2001 From: Pahaz Blinov Date: Wed, 9 Nov 2016 00:36:37 +0500 Subject: [PATCH 1/2] 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 =/ --- sanic/request.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index 109b1483..a843b73b 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -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: + files[field_name] = [file] else: - fields[field_name] = post_data.decode('utf-8') + value = post_data.decode('utf-8') + if field_name in fields: + fields[field_name].append(value) + else: + fields[field_name] = [value] return fields, files From 0d9fb2f9279e3303f51a0b18204a88d6cfbb1a0e Mon Sep 17 00:00:00 2001 From: Pahaz Blinov Date: Wed, 9 Nov 2016 18:04:15 +0500 Subject: [PATCH 2/2] docs(request): return value docstring --- sanic/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/request.py b/sanic/request.py index a843b73b..7373a104 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -132,7 +132,7 @@ def parse_multipart_form(body, boundary): Parses a request body and returns fields and files :param body: Bytes request body :param boundary: Bytes multipart boundary - :return: fields (dict), files (dict) + :return: fields (RequestParameters), files (RequestParameters) """ files = RequestParameters() fields = RequestParameters()