mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-26 03:13:45 +03:00
Move device info out of Session
This commit is contained in:
parent
5e88b21aa9
commit
47cdcda9e2
|
@ -1,6 +1,5 @@
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
import time
|
import time
|
||||||
import platform
|
|
||||||
import struct
|
import struct
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -13,23 +12,11 @@ class Session(ABC):
|
||||||
self._last_msg_id = 0
|
self._last_msg_id = 0
|
||||||
self._time_offset = 0
|
self._time_offset = 0
|
||||||
self._salt = 0
|
self._salt = 0
|
||||||
|
|
||||||
system = platform.uname()
|
|
||||||
self._device_model = system.system or 'Unknown'
|
|
||||||
self._system_version = system.release or '1.0'
|
|
||||||
self._app_version = '1.0'
|
|
||||||
self._lang_code = 'en'
|
|
||||||
self._system_lang_code = self.lang_code
|
|
||||||
self._report_errors = True
|
self._report_errors = True
|
||||||
self._flood_sleep_threshold = 60
|
self._flood_sleep_threshold = 60
|
||||||
|
|
||||||
def clone(self, to_instance=None):
|
def clone(self, to_instance=None):
|
||||||
cloned = to_instance or self.__class__()
|
cloned = to_instance or self.__class__()
|
||||||
cloned._device_model = self.device_model
|
|
||||||
cloned._system_version = self.system_version
|
|
||||||
cloned._app_version = self.app_version
|
|
||||||
cloned._lang_code = self.lang_code
|
|
||||||
cloned._system_lang_code = self.system_lang_code
|
|
||||||
cloned._report_errors = self.report_errors
|
cloned._report_errors = self.report_errors
|
||||||
cloned._flood_sleep_threshold = self.flood_sleep_threshold
|
cloned._flood_sleep_threshold = self.flood_sleep_threshold
|
||||||
return cloned
|
return cloned
|
||||||
|
@ -99,46 +86,6 @@ class Session(ABC):
|
||||||
def salt(self, value):
|
def salt(self, value):
|
||||||
self._salt = value
|
self._salt = value
|
||||||
|
|
||||||
@property
|
|
||||||
def device_model(self):
|
|
||||||
return self._device_model
|
|
||||||
|
|
||||||
@device_model.setter
|
|
||||||
def device_model(self, value):
|
|
||||||
self._device_model = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def system_version(self):
|
|
||||||
return self._system_version
|
|
||||||
|
|
||||||
@system_version.setter
|
|
||||||
def system_version(self, value):
|
|
||||||
self._system_version = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def app_version(self):
|
|
||||||
return self._app_version
|
|
||||||
|
|
||||||
@app_version.setter
|
|
||||||
def app_version(self, value):
|
|
||||||
self._app_version = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def lang_code(self):
|
|
||||||
return self._lang_code
|
|
||||||
|
|
||||||
@lang_code.setter
|
|
||||||
def lang_code(self, value):
|
|
||||||
self._lang_code = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def system_lang_code(self):
|
|
||||||
return self._system_lang_code
|
|
||||||
|
|
||||||
@system_lang_code.setter
|
|
||||||
def system_lang_code(self, value):
|
|
||||||
self._system_lang_code = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def report_errors(self):
|
def report_errors(self):
|
||||||
return self._report_errors
|
return self._report_errors
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import threading
|
import threading
|
||||||
from datetime import timedelta, datetime
|
from datetime import timedelta, datetime
|
||||||
from signal import signal, SIGINT, SIGTERM, SIGABRT
|
from signal import signal, SIGINT, SIGTERM, SIGABRT
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from . import version, utils
|
from . import version, utils
|
||||||
from .crypto import rsa
|
from .crypto import rsa
|
||||||
from .errors import (
|
from .errors import (
|
||||||
|
@ -73,7 +73,12 @@ class TelegramBareClient:
|
||||||
update_workers=None,
|
update_workers=None,
|
||||||
spawn_read_thread=False,
|
spawn_read_thread=False,
|
||||||
timeout=timedelta(seconds=5),
|
timeout=timedelta(seconds=5),
|
||||||
**kwargs):
|
loop=None,
|
||||||
|
device_model=None,
|
||||||
|
system_version=None,
|
||||||
|
app_version=None,
|
||||||
|
lang_code='en',
|
||||||
|
system_lang_code='en'):
|
||||||
"""Refer to TelegramClient.__init__ for docs on this method"""
|
"""Refer to TelegramClient.__init__ for docs on this method"""
|
||||||
if not api_id or not api_hash:
|
if not api_id or not api_hash:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
@ -125,11 +130,12 @@ class TelegramBareClient:
|
||||||
self.updates = UpdateState(workers=update_workers)
|
self.updates = UpdateState(workers=update_workers)
|
||||||
|
|
||||||
# Used on connection - the user may modify these and reconnect
|
# Used on connection - the user may modify these and reconnect
|
||||||
kwargs['app_version'] = kwargs.get('app_version', self.__version__)
|
system = platform.uname()
|
||||||
for name, value in kwargs.items():
|
self.device_model = device_model or system.system or 'Unknown'
|
||||||
if not hasattr(self.session, name):
|
self.system_version = system_version or system.release or '1.0'
|
||||||
raise ValueError('Unknown named parameter', name)
|
self.app_version = app_version or self.__version__
|
||||||
setattr(self.session, name, value)
|
self.lang_code = lang_code
|
||||||
|
self.system_lang_code = system_lang_code
|
||||||
|
|
||||||
# Despite the state of the real connection, keep track of whether
|
# Despite the state of the real connection, keep track of whether
|
||||||
# the user has explicitly called .connect() or .disconnect() here.
|
# the user has explicitly called .connect() or .disconnect() here.
|
||||||
|
@ -233,11 +239,11 @@ class TelegramBareClient:
|
||||||
"""Wraps query around InvokeWithLayerRequest(InitConnectionRequest())"""
|
"""Wraps query around InvokeWithLayerRequest(InitConnectionRequest())"""
|
||||||
return InvokeWithLayerRequest(LAYER, InitConnectionRequest(
|
return InvokeWithLayerRequest(LAYER, InitConnectionRequest(
|
||||||
api_id=self.api_id,
|
api_id=self.api_id,
|
||||||
device_model=self.session.device_model,
|
device_model=self.device_model,
|
||||||
system_version=self.session.system_version,
|
system_version=self.system_version,
|
||||||
app_version=self.session.app_version,
|
app_version=self.app_version,
|
||||||
lang_code=self.session.lang_code,
|
lang_code=self.lang_code,
|
||||||
system_lang_code=self.session.system_lang_code,
|
system_lang_code=self.system_lang_code,
|
||||||
lang_pack='', # "langPacks are for official apps only"
|
lang_pack='', # "langPacks are for official apps only"
|
||||||
query=query
|
query=query
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user