Skip to content

Commit

Permalink
Rename loader keyword argument in web.Request.json method.
Browse files Browse the repository at this point in the history
This adds consistency to the library as:

* `loads` alredy used in `client.Response.json` method
* `dumps` used in `web.json_response` function (introduced in 0.19.0)
  • Loading branch information
playpauseandstop committed Nov 27, 2015
1 parent 1fba9c9 commit e50da35
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,10 @@ def text(self):
return bytes_body.decode(encoding)

@asyncio.coroutine
def json(self, *, loader=json.loads):
def json(self, *, loads=json.loads):
"""Return BODY as JSON."""
body = yield from self.text()
return loader(body)
return loads(body)

@asyncio.coroutine
def post(self):
Expand Down
4 changes: 2 additions & 2 deletions docs/web_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ like one using :meth:`Request.copy`.
The method **does** store read data internally, subsequent
:meth:`~Request.text` call will return the same value.

.. coroutinemethod:: json(*, loader=json.loads)
.. coroutinemethod:: json(*, loads=json.loads)

Read request body decoded as *json*.

The method is just a boilerplate :ref:`coroutine <coroutine>`
implemented as::

async def json(self, *, loader=json.loads):
async def json(self, *, loads=json.loads):
body = await self.text()
return loader(body)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def test_post_json(self):
def handler(request):
data = yield from request.json()
self.assertEqual(dct, data)
data2 = yield from request.json()
data2 = yield from request.json(loads=json.loads)
self.assertEqual(data, data2)
resp = web.Response()
resp.content_type = 'application/json'
Expand Down

0 comments on commit e50da35

Please sign in to comment.