mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Merge branch 'master' into asyncio
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import warnings
|
||||
from datetime import timedelta, datetime
|
||||
from hashlib import md5
|
||||
from io import BytesIO
|
||||
@@ -55,7 +56,7 @@ class TelegramBareClient:
|
||||
"""
|
||||
|
||||
# Current TelegramClient version
|
||||
__version__ = '0.15.1'
|
||||
__version__ = '0.15.2'
|
||||
|
||||
# TODO Make this thread-safe, all connections share the same DC
|
||||
_dc_options = None
|
||||
@@ -386,7 +387,7 @@ class TelegramBareClient:
|
||||
try:
|
||||
for _ in range(retries):
|
||||
result = await self._invoke(sender, *requests)
|
||||
if result:
|
||||
if result is not None:
|
||||
return result
|
||||
|
||||
raise ValueError('Number of retries reached 0.')
|
||||
@@ -412,7 +413,7 @@ class TelegramBareClient:
|
||||
pass # We will just retry
|
||||
|
||||
except ConnectionResetError:
|
||||
if not self._authorized:
|
||||
if not self._user_connected:
|
||||
# Only attempt reconnecting if we're authorized
|
||||
raise
|
||||
|
||||
@@ -459,10 +460,14 @@ class TelegramBareClient:
|
||||
'[ERROR] Telegram is having some internal issues', e
|
||||
)
|
||||
|
||||
except FloodWaitError:
|
||||
sender.disconnect()
|
||||
self.disconnect()
|
||||
raise
|
||||
except FloodWaitError as e:
|
||||
if e.seconds > self.session.flood_sleep_threshold | 0:
|
||||
raise
|
||||
|
||||
self._logger.debug(
|
||||
'Sleep of %d seconds below threshold, sleeping' % e.seconds
|
||||
)
|
||||
sleep(e.seconds)
|
||||
|
||||
# Some really basic functionality
|
||||
|
||||
@@ -609,10 +614,8 @@ class TelegramBareClient:
|
||||
cdn_decrypter = None
|
||||
|
||||
try:
|
||||
offset_index = 0
|
||||
offset = 0
|
||||
while True:
|
||||
offset = offset_index * part_size
|
||||
|
||||
try:
|
||||
if cdn_decrypter:
|
||||
result = await cdn_decrypter.get_file()
|
||||
@@ -633,7 +636,7 @@ class TelegramBareClient:
|
||||
client = await self._get_exported_client(e.new_dc)
|
||||
continue
|
||||
|
||||
offset_index += 1
|
||||
offset += part_size
|
||||
|
||||
# If we have received no data (0 bytes), the file is over
|
||||
# So there is nothing left to download and write
|
||||
@@ -670,6 +673,9 @@ class TelegramBareClient:
|
||||
def add_update_handler(self, handler):
|
||||
"""Adds an update handler (a function which takes a TLObject,
|
||||
an update, as its parameter) and listens for updates"""
|
||||
if not self.updates.get_workers:
|
||||
warnings.warn("There are no update workers running, so adding an update handler will have no effect.")
|
||||
|
||||
sync = not self.updates.handlers
|
||||
self.updates.handlers.append(handler)
|
||||
if sync:
|
||||
|
Reference in New Issue
Block a user