Remove report_errors/flood_sleep_threshold from the session

This commit is contained in:
Lonami Exo 2018-06-26 16:09:16 +02:00
parent 1eb4af33df
commit 9159e2a720
3 changed files with 13 additions and 46 deletions

View File

@ -77,8 +77,7 @@ class TelegramBaseClient(abc.ABC):
when Telegram is having internal issues (due to either when Telegram is having internal issues (due to either
``errors.ServerError`` or ``errors.RpcCallFailError``), ``errors.ServerError`` or ``errors.RpcCallFailError``),
when there is a ``errors.FloodWaitError`` less than when there is a ``errors.FloodWaitError`` less than
``session.flood_sleep_threshold``, or when there's a `flood_sleep_threshold`, or when there's a migrate error.
migrate error.
May set to a false-y value (``0`` or ``None``) for infinite May set to a false-y value (``0`` or ``None``) for infinite
retries, but this is not recommended, since some requests can retries, but this is not recommended, since some requests can
@ -95,9 +94,13 @@ class TelegramBaseClient(abc.ABC):
Whether reconnection should be retried `connection_retries` Whether reconnection should be retried `connection_retries`
times automatically if Telegram disconnects us or not. times automatically if Telegram disconnects us or not.
report_errors (`bool`, optional): flood_sleep_threshold (`int` | `float`, optional):
Whether to report RPC errors or not. Defaults to ``True``, The threshold below which the library should automatically
see :ref:`api-status` for more information. sleep on flood wait errors (inclusive). For instance, if a
``FloodWaitError`` for 17s occurs and `flood_sleep_threshold`
is 20s, the library will ``sleep`` automatically. If the error
was for 21s, it would ``raise FloodWaitError`` instead. Values
larger than a day (like ``float('inf')``) will be changed to a day.
device_model (`str`, optional): device_model (`str`, optional):
"Device model" to be sent when creating the initial connection. "Device model" to be sent when creating the initial connection.
@ -138,7 +141,7 @@ class TelegramBaseClient(abc.ABC):
request_retries=5, request_retries=5,
connection_retries=5, connection_retries=5,
auto_reconnect=True, auto_reconnect=True,
report_errors=True, flood_sleep_threshold=60,
device_model=None, device_model=None,
system_version=None, system_version=None,
app_version=None, app_version=None,
@ -170,7 +173,7 @@ class TelegramBaseClient(abc.ABC):
DEFAULT_PORT DEFAULT_PORT
) )
session.report_errors = report_errors self.flood_sleep_threshold = flood_sleep_threshold
self.session = session self.session = session
self.api_id = int(api_id) self.api_id = int(api_id)
self.api_hash = api_hash self.api_hash = api_hash

View File

@ -37,7 +37,7 @@ class UserMethods(TelegramBaseClient):
__log__.warning('Telegram is having internal issues %s: %s', __log__.warning('Telegram is having internal issues %s: %s',
e.__class__.__name__, e) e.__class__.__name__, e)
except (errors.FloodWaitError, errors.FloodTestPhoneWaitError) as e: except (errors.FloodWaitError, errors.FloodTestPhoneWaitError) as e:
if e.seconds <= self.session.flood_sleep_threshold: if e.seconds <= self.flood_sleep_threshold:
__log__.info('Sleeping for %ds on flood wait', e.seconds) __log__.info('Sleeping for %ds on flood wait', e.seconds)
await asyncio.sleep(e.seconds, loop=self._loop) await asyncio.sleep(e.seconds, loop=self._loop)
else: else:

View File

@ -3,18 +3,13 @@ from abc import ABC, abstractmethod
class Session(ABC): class Session(ABC):
def __init__(self): def __init__(self):
# Session IDs can be random on every connection pass
self._report_errors = True
self._flood_sleep_threshold = 60
def clone(self, to_instance=None): def clone(self, to_instance=None):
""" """
Creates a clone of this session file. Creates a clone of this session file.
""" """
cloned = to_instance or self.__class__() return to_instance or self.__class__()
cloned._report_errors = self.report_errors
cloned._flood_sleep_threshold = self.flood_sleep_threshold
return cloned
@abstractmethod @abstractmethod
def set_dc(self, dc_id, server_address, port): def set_dc(self, dc_id, server_address, port):
@ -145,34 +140,3 @@ class Session(ABC):
``id`` and ``access_hash`` in that order. ``id`` and ``access_hash`` in that order.
""" """
raise NotImplementedError raise NotImplementedError
@property
def report_errors(self):
"""
Whether RPC errors should be reported
to https://rpc.pwrtelegram.xyz or not.
"""
return self._report_errors
@report_errors.setter
def report_errors(self, value):
"""
Sets the boolean value that indicates whether RPC errors
should be reported to https://rpc.pwrtelegram.xyz or not.
"""
self._report_errors = value
@property
def flood_sleep_threshold(self):
"""
Threshold below which the library should automatically sleep
whenever a FloodWaitError occurs to prevent it from raising.
"""
return self._flood_sleep_threshold
@flood_sleep_threshold.setter
def flood_sleep_threshold(self, value):
"""
Sets the new time threshold (integer, float or timedelta).
"""
self._flood_sleep_threshold = value