mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-03 10:45:52 +03:00
Move salt and ID to base session and remove unused imports
This commit is contained in:
parent
e1d7cc541f
commit
dc2229fdba
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user