-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from lamenezes/support-aiohttp-over-3.1.0
Fix aiohttp stub to support version >= 3.1.0
- Loading branch information
Showing
8 changed files
with
53 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.pyc | ||
.tox | ||
.cache | ||
.pytest_cache/ | ||
build/ | ||
dist/ | ||
*.egg/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
# flake8: noqa | ||
import asyncio | ||
|
||
import aiohttp | ||
|
||
|
||
@asyncio.coroutine | ||
def aiohttp_request(loop, method, url, output='text', **kwargs): | ||
with aiohttp.ClientSession(loop=loop) as session: | ||
response = yield from session.request(method, url, **kwargs) # NOQA: E999 | ||
if output == 'text': | ||
content = yield from response.text() # NOQA: E999 | ||
elif output == 'json': | ||
content = yield from response.json() # NOQA: E999 | ||
elif output == 'raw': | ||
content = yield from response.read() # NOQA: E999 | ||
return response, content | ||
def aiohttp_request(loop, method, url, output='text', encoding='utf-8', **kwargs): | ||
session = aiohttp.ClientSession(loop=loop) | ||
response_ctx = session.request(method, url, **kwargs) | ||
|
||
response = yield from response_ctx.__aenter__() | ||
if output == 'text': | ||
content = yield from response.text() | ||
elif output == 'json': | ||
content = yield from response.json(encoding=encoding) | ||
elif output == 'raw': | ||
content = yield from response.read() | ||
|
||
response_ctx._resp.close() | ||
yield from session.close() | ||
|
||
return response, content |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters