Make exception types correspond to Python docs

This commit is contained in:
Dmitry D. Chernov
2017-12-28 09:22:28 +10:00
parent 1a746e1464
commit 6ec6967ff9
10 changed files with 29 additions and 38 deletions

View File

@@ -6,7 +6,7 @@ from datetime import datetime
from io import BufferedReader, BytesIO
from struct import unpack
from ..errors import InvalidParameterError, TypeNotFoundError
from ..errors import TypeNotFoundError
from ..tl.all_tlobjects import tlobjects
@@ -22,8 +22,7 @@ class BinaryReader:
elif stream:
self.stream = stream
else:
raise InvalidParameterError(
'Either bytes or a stream must be provided')
raise ValueError('Either bytes or a stream must be provided')
self.reader = BufferedReader(self.stream)
self._last = None # Should come in handy to spot -404 errors
@@ -110,7 +109,7 @@ class BinaryReader:
elif value == 0xbc799737: # boolFalse
return False
else:
raise ValueError('Invalid boolean code {}'.format(hex(value)))
raise RuntimeError('Invalid boolean code {}'.format(hex(value)))
def tgread_date(self):
"""Reads and converts Unix time (used by Telegram)
@@ -141,7 +140,7 @@ class BinaryReader:
def tgread_vector(self):
"""Reads a vector (a list) of Telegram objects."""
if 0x1cb5c415 != self.read_int(signed=False):
raise ValueError('Invalid constructor code, vector was expected')
raise RuntimeError('Invalid constructor code, vector was expected')
count = self.read_int()
return [self.tgread_object() for _ in range(count)]

View File

@@ -26,7 +26,7 @@ class TcpClient:
elif isinstance(timeout, (int, float)):
self.timeout = float(timeout)
else:
raise ValueError('Invalid timeout type', type(timeout))
raise TypeError('Invalid timeout type: {}'.format(type(timeout)))
def _recreate_socket(self, mode):
if self.proxy is None: