Begin working on asyncio port.

This commit is contained in:
Rapptz
2015-12-04 00:16:34 -05:00
parent 5a666c3f0d
commit f197c34583
6 changed files with 811 additions and 25 deletions

View File

@ -24,11 +24,6 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
try:
import http.client as httplib
except ImportError:
import httplib
class DiscordException(Exception):
"""Base exception class for discord.py
@ -56,28 +51,19 @@ class HTTPException(DiscordException):
.. attribute:: response
The response of the failed HTTP request. This is an
instance of `requests.Response`__.
instance of `aiohttp.ClientResponse`__.
__ http://docs.python-requests.org/en/latest/api/#requests.Response
__ http://aiohttp.readthedocs.org/en/stable/client_reference.html#aiohttp.ClientResponse
"""
def __init__(self, response, message=None):
self.response = response
if message is None:
message = httplib.responses.get(response.status_code, 'HTTP error')
fmt = '{0.reason} (status code: {0.status})'
if message:
fmt = fmt + ': {1}'
message = '{0} (status code: {1.response.status_code})'.format(message, self)
try:
data = response.json()
response_error = data['message']
if response_error:
message = '{}: {}'.format(message, response_error)
except:
pass
super(HTTPException, self).__init__(message)
super().__init__(fmt.format(self.response, message))
class InvalidArgument(ClientException):
"""Exception that's thrown when an argument to a function