diff --git a/telethon/sessions/abstract.py b/telethon/sessions/abstract.py index dd1541ab..d92e0754 100644 --- a/telethon/sessions/abstract.py +++ b/telethon/sessions/abstract.py @@ -1,13 +1,18 @@ from abc import ABC, abstractmethod import time import platform +import struct +import os class Session(ABC): def __init__(self): + self.id = struct.unpack('q', os.urandom(8))[0] + self._sequence = 0 self._last_msg_id = 0 self._time_offset = 0 + self._salt = 0 system = platform.uname() self._device_model = system.system or 'Unknown' @@ -53,16 +58,6 @@ class Session(ABC): def auth_key(self, value): raise NotImplementedError - @property - @abstractmethod - def salt(self): - raise NotImplementedError - - @salt.setter - @abstractmethod - def salt(self, value): - raise NotImplementedError - @abstractmethod def close(self): raise NotImplementedError @@ -96,6 +91,14 @@ class Session(ABC): def get_file(self, md5_digest, file_size, cls): raise NotImplementedError + @property + def salt(self): + return self._salt + + @salt.setter + def salt(self, value): + self._salt = value + @property def device_model(self): return self._device_model diff --git a/telethon/sessions/memory.py b/telethon/sessions/memory.py index 71d6e551..7ab31b21 100644 --- a/telethon/sessions/memory.py +++ b/telethon/sessions/memory.py @@ -28,10 +28,10 @@ class _SentFileType(Enum): class MemorySession(Session): def __init__(self): super().__init__() + self._dc_id = None self._server_address = None self._port = None - self._salt = None self._auth_key = None self._files = {} @@ -58,14 +58,6 @@ class MemorySession(Session): def auth_key(self, value): self._auth_key = value - @property - def salt(self): - return self._salt - - @salt.setter - def salt(self, value): - self._salt = value - def close(self): pass diff --git a/telethon/sessions/sqlite.py b/telethon/sessions/sqlite.py index 0ea26ae5..0423d88a 100644 --- a/telethon/sessions/sqlite.py +++ b/telethon/sessions/sqlite.py @@ -1,21 +1,13 @@ import json import os -import platform import sqlite3 -import struct -import time from base64 import b64decode from os.path import isfile as file_exists from threading import Lock, RLock -from .. import utils -from .abstract import Session from .memory import MemorySession, _SentFileType from ..crypto import AuthKey -from ..tl import TLObject from ..tl.types import ( - PeerUser, PeerChat, PeerChannel, - InputPeerUser, InputPeerChat, InputPeerChannel, InputPhoto, InputDocument ) @@ -47,8 +39,6 @@ class SQLiteSession(MemorySession): if not self.filename.endswith(EXTENSION): self.filename += EXTENSION - self.id = struct.unpack('q', os.urandom(8))[0] - # Cross-thread safety self._seq_no_lock = Lock() self._msg_id_lock = Lock() @@ -193,7 +183,7 @@ class SQLiteSession(MemorySession): self._auth_key = None c.close() - @Session.auth_key.setter + @MemorySession.auth_key.setter def auth_key(self, value): self._auth_key = value self._update_session_table()