Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Update docstrings on all load_* methods returning MultiDictProxy
objects.

Minor fixes to typo, docstring conversion to comments

Co-Authored-By: Steven Loria <sloria1@gmail.com>
  • Loading branch information
sirosen and sloria committed Sep 10, 2019
1 parent 85d9963 commit 176a9f7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 43 deletions.
18 changes: 5 additions & 13 deletions src/webargs/bottleparser.py
Expand Up @@ -50,31 +50,23 @@ def _raw_load_json(self, req):
return data

def load_querystring(self, req, schema):
"""Read querystring values from the request.
Is a multidict."""
"""Return query params from the request as a MultiDictProxy."""
return MultiDictProxy(req.query, schema)

def load_form(self, req, schema):
"""Read form values from the request.
Is a multidict."""
"""Return form values from the request as a MultiDictProxy."""
return MultiDictProxy(req.forms, schema)

def load_headers(self, req, schema):
"""Read headers from the request.
Is a multidict."""
"""Return headers from the request as a MultiDictProxy."""
return MultiDictProxy(req.headers, schema)

def load_cookies(self, req, schema):
"""Read cookies from the request."""
"""Return cookies from the request."""
return req.cookies

def load_files(self, req, schema):
"""Read files from the request.
Is a multidict."""
"""Return files from the request as a MultiDictProxy."""
return MultiDictProxy(req.files, schema)

def handle_error(self, error, req, schema, error_status_code, error_headers):
Expand Down
14 changes: 4 additions & 10 deletions src/webargs/djangoparser.py
Expand Up @@ -38,19 +38,15 @@ def _raw_load_json(self, req):
return core.parse_json(req.body)

def load_querystring(self, req, schema):
"""Read query params from the request.
Is a multidict."""
"""Return query params from the request as a MultiDictProxy."""
return MultiDictProxy(req.GET, schema)

def load_form(self, req, schema):
"""Read form values from the request.
Is a multidict."""
"""Return form values from the request as a MultiDictProxy."""
return MultiDictProxy(req.POST, schema)

def load_cookies(self, req, schema):
"""Read cookies from the request."""
"""Return cookies from the request."""
return req.COOKIES

def load_headers(self, req, schema):
Expand All @@ -59,9 +55,7 @@ def load_headers(self, req, schema):
)

def load_files(self, req, schema):
"""Read files from the request.
Is a multidict."""
"""Return files from the request as a MultiDictProxy."""
return MultiDictProxy(req.FILES, schema)

def get_request_from_view_args(self, view, args, kwargs):
Expand Down
22 changes: 7 additions & 15 deletions src/webargs/flaskparser.py
Expand Up @@ -54,7 +54,7 @@ class FlaskParser(core.Parser):
)

def _raw_load_json(self, req):
"""Read a json payload from the request for the core parser's load_json
"""Return a json payload from the request for the core parser's load_json
Checks the input mimetype and may return 'missing' if the mimetype is
non-json, even if the request body is parseable as json."""
Expand All @@ -67,35 +67,27 @@ def _handle_invalid_json_error(self, error, req, *args, **kwargs):
abort(400, exc=error, messages={"json": ["Invalid JSON body."]})

def load_view_args(self, req, schema):
"""Read the request's ``view_args`` or ``missing`` if there are none."""
"""Return the request's ``view_args`` or ``missing`` if there are none."""
return req.view_args or core.missing

def load_querystring(self, req, schema):
"""Read query params from the request.
Is a multidict."""
"""Return query params from the request as a MultiDictProxy."""
return MultiDictProxy(req.args, schema)

def load_form(self, req, schema):
"""Read form values from the request.
Is a multidict."""
"""Return form values from the request as a MultiDictProxy."""
return MultiDictProxy(req.form, schema)

def load_headers(self, req, schema):
"""Read headers from the request.
Is a multidict."""
"""Return headers from the request as a MultiDictProxy."""
return MultiDictProxy(req.headers, schema)

def load_cookies(self, req, schema):
"""Read cookies from the request."""
"""Return cookies from the request."""
return req.cookies

def load_files(self, req, schema):
"""Read files from the request.
Is a multidict."""
"""Return files from the request as a MultiDictProxy."""
return MultiDictProxy(req.files, schema)

def handle_error(self, error, req, schema, error_status_code, error_headers):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_core.py
Expand Up @@ -104,10 +104,8 @@ def test_parse(parser, web_request):
MARSHMALLOW_VERSION_INFO[0] < 3, reason="unknown=EXCLUDE added in marshmallow3"
)
def test_parse_with_excluding_schema(parser, web_request):
"""
This is new in webargs 6.x ; it's the way you can "get back" the behavior
of webargs 5.x in which extra args are ignored
"""
# This is new in webargs 6.x ; it's the way you can "get back" the behavior
# of webargs 5.x in which extra args are ignored
from marshmallow import EXCLUDE

web_request.json = {"username": 42, "password": 42, "fjords": 42}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flaskparser.py
Expand Up @@ -50,7 +50,7 @@ def test_nested_many_with_data_key(self, testapp):
"/echo_nested_many_data_key",
{"x_field": [{"id": 42}]},
)
# under marhsmallow2 this is allowed and works
# under marshmallow 2 this is allowed and works
if MARSHMALLOW_VERSION_INFO[0] < 3:
res = testapp.post_json(*post_with_raw_fieldname_args)
assert res.json == {"x_field": [{"id": 42}]}
Expand Down

0 comments on commit 176a9f7

Please sign in to comment.