From 176a9f77967a83dcf2324c1afb193447f8d72a90 Mon Sep 17 00:00:00 2001 From: Stephen Rosen Date: Tue, 10 Sep 2019 00:24:27 +0000 Subject: [PATCH] Apply suggestions from code review Update docstrings on all load_* methods returning MultiDictProxy objects. Minor fixes to typo, docstring conversion to comments Co-Authored-By: Steven Loria --- src/webargs/bottleparser.py | 18 +++++------------- src/webargs/djangoparser.py | 14 ++++---------- src/webargs/flaskparser.py | 22 +++++++--------------- tests/test_core.py | 6 ++---- tests/test_flaskparser.py | 2 +- 5 files changed, 19 insertions(+), 43 deletions(-) diff --git a/src/webargs/bottleparser.py b/src/webargs/bottleparser.py index fb9347c7..37a501a1 100644 --- a/src/webargs/bottleparser.py +++ b/src/webargs/bottleparser.py @@ -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): diff --git a/src/webargs/djangoparser.py b/src/webargs/djangoparser.py index fd05d884..57cf1bde 100644 --- a/src/webargs/djangoparser.py +++ b/src/webargs/djangoparser.py @@ -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): @@ -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): diff --git a/src/webargs/flaskparser.py b/src/webargs/flaskparser.py index 45af7cf2..7fb549bc 100644 --- a/src/webargs/flaskparser.py +++ b/src/webargs/flaskparser.py @@ -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.""" @@ -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): diff --git a/tests/test_core.py b/tests/test_core.py index c8031324..378e99a5 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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} diff --git a/tests/test_flaskparser.py b/tests/test_flaskparser.py index 501075b6..97b447ef 100644 --- a/tests/test_flaskparser.py +++ b/tests/test_flaskparser.py @@ -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}]}