Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename loader keyword argument in web.Request.json method. #646

Merged
merged 2 commits into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,15 @@ def text(self):
return bytes_body.decode(encoding)

@asyncio.coroutine
def json(self, *, loader=json.loads):
def json(self, *, loads=json.loads, loader=None):
"""Return BODY as JSON."""
if loader:
warnings.warn(
'Using `loader` is deprecated, use `loads` instead',
DeprecationWarning)
loads = loader
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
4 changes: 3 additions & 1 deletion tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ 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)
data3 = yield from request.json(loader=json.loads)
self.assertEqual(data, data3)
resp = web.Response()
resp.content_type = 'application/json'
resp.body = json.dumps(data).encode('utf8')
Expand Down