diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index d4e353e4..4fae4cb8 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -398,11 +398,6 @@ class TelegramBaseClient(abc.ABC): self._authorized = None # None = unknown, False = no, True = yes - # Update state (for catching up after a disconnection) - # TODO Get state from channels too - self._state_cache = StateCache( - self.session.get_update_state(0), self._log) - # Some further state for subclasses self._event_builders = [] diff --git a/telethon/sessions/abstract.py b/telethon/sessions/abstract.py index 8c0a717e..11cc63a1 100644 --- a/telethon/sessions/abstract.py +++ b/telethon/sessions/abstract.py @@ -98,7 +98,7 @@ class Session(ABC): raise NotImplementedError @abstractmethod - async def get_update_states(self): + def get_update_states(self): """ Returns an iterable over all known pairs of ``(entity ID, update state)``. """ diff --git a/telethon/sessions/memory.py b/telethon/sessions/memory.py index 27d7907b..721b6d9a 100644 --- a/telethon/sessions/memory.py +++ b/telethon/sessions/memory.py @@ -77,7 +77,7 @@ class MemorySession(Session): def set_update_state(self, entity_id, state): self._update_states[entity_id] = state - async def get_update_states(self): + def get_update_states(self): return self._update_states.items() def close(self): diff --git a/telethon/sessions/sqlite.py b/telethon/sessions/sqlite.py index 6c9d042e..77105f64 100644 --- a/telethon/sessions/sqlite.py +++ b/telethon/sessions/sqlite.py @@ -215,7 +215,7 @@ class SQLiteSession(MemorySession): entity_id, state.pts, state.qts, state.date.timestamp(), state.seq) - async def get_update_states(self): + def get_update_states(self): c = self._cursor() try: rows = c.execute('select id, pts, qts, date, seq from update_state').fetchall() @@ -332,7 +332,7 @@ class SQLiteSession(MemorySession): return self._execute( 'select id, hash from entities where name = ?', name) - async def get_entity_rows_by_id(self, id, exact=True): + def get_entity_rows_by_id(self, id, exact=True): if exact: return self._execute( 'select id, hash from entities where id = ?', id) diff --git a/telethon/sessions/string.py b/telethon/sessions/string.py index 25646aa9..fb971d82 100644 --- a/telethon/sessions/string.py +++ b/telethon/sessions/string.py @@ -11,15 +11,6 @@ _STRUCT_PREFORMAT = '>B{}sH256s' CURRENT_VERSION = '1' -class _AsyncString(str): - """ - Ugly hack to enable awaiting strings. - """ - def __await__(self): - yield - return self - - class StringSession(MemorySession): """ This session file can be easily saved and loaded as a string. According @@ -59,17 +50,14 @@ class StringSession(MemorySession): return base64.urlsafe_b64decode(x) def save(self: Session): - # save should be async but that would break code which relies on sync StringSession. - # Return a type which behaves like a string for all intents and purposes, but can be awaited. - # The await is necessary for the library to save all sessions in the same way. if not self.auth_key: - return _AsyncString('') + return '' ip = ipaddress.ip_address(self.server_address).packed - return _AsyncString(CURRENT_VERSION + StringSession.encode(struct.pack( + return CURRENT_VERSION + StringSession.encode(struct.pack( _STRUCT_PREFORMAT.format(len(ip)), self.dc_id, ip, self.port, self.auth_key.key - ))) + ))