Handle FloodWaitError in client.download_media

Fixes #1426. Not entirely happy with the new indirection layer,
but the original __call__ method is already a mess anyway and
the additional cost of an extra call should be neglible compared
to the actual IO.
This commit is contained in:
Lonami Exo 2020-04-28 20:49:57 +02:00
parent 7f3aa43ad4
commit 7ea4686d6c
3 changed files with 6 additions and 3 deletions

View File

@ -68,7 +68,7 @@ class _DirectDownloadIter(RequestIter):
async def _request(self):
try:
result = await self._sender.send(self.request)
result = await self.client._call(self._sender, self.request)
if isinstance(result, types.upload.FileCdnRedirect):
raise NotImplementedError # TODO Implement
else:

View File

@ -1039,7 +1039,7 @@ class MessageMethods:
if exported:
try:
sender = await self._borrow_exported_sender(entity.dc_id)
return await sender.send(request)
return await self._call(sender, request)
finally:
await self._return_exported_sender(sender)
else:

View File

@ -27,6 +27,9 @@ def _fmt_flood(delay, request, *, early=False, td=datetime.timedelta):
class UserMethods:
async def __call__(self: 'TelegramClient', request, ordered=False):
return await self._call(self._sender, request, ordered=ordered)
async def _call(self: 'TelegramClient', sender, request, ordered=False):
requests = (request if utils.is_list_like(request) else (request,))
for r in requests:
if not isinstance(r, TLRequest):
@ -50,7 +53,7 @@ class UserMethods:
self._last_request = time.time()
for attempt in retry_range(self._request_retries):
try:
future = self._sender.send(request, ordered=ordered)
future = sender.send(request, ordered=ordered)
if isinstance(future, list):
results = []
exceptions = []