diff options
| author | Rapptz <[email protected]> | 2015-12-04 00:16:34 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2015-12-04 00:16:34 -0500 |
| commit | f197c345832ff09fe081b7cb542de9288d0b780e (patch) | |
| tree | 868d84f0708f9ceb9d3395bfd0223ef3c59a2514 /discord/utils.py | |
| parent | Point to the docs in the README and clear up notes on breaking changes (diff) | |
| download | discord.py-f197c345832ff09fe081b7cb542de9288d0b780e.tar.xz discord.py-f197c345832ff09fe081b7cb542de9288d0b780e.zip | |
Begin working on asyncio port.
Diffstat (limited to 'discord/utils.py')
| -rw-r--r-- | discord/utils.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/discord/utils.py b/discord/utils.py index 423ddc8a..3e22c710 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE. from re import split as re_split from .errors import HTTPException, InvalidArgument import datetime - +import asyncio def parse_time(timestamp): if timestamp: @@ -60,11 +60,13 @@ def find(predicate, seq): def _null_event(*args, **kwargs): pass def _verify_successful_response(response): - code = response.status_code + code = response.status success = code >= 200 and code < 300 if not success: - raise HTTPException(response) + data = yield from response.json() + raise HTTPException(response, data.get('message')) def _get_mime_type_for_image(data): if data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'): @@ -73,3 +75,8 @@ def _get_mime_type_for_image(data): return 'image/jpeg' else: raise InvalidArgument('Unsupported image type given') + +try: + create_task = asyncio.ensure_future +except AttributeError: + create_task = asyncio.async |