Move device info out of Session

This commit is contained in:
Tulir Asokan 2018-03-02 21:05:09 +02:00
parent 5e88b21aa9
commit 47cdcda9e2
2 changed files with 18 additions and 65 deletions

View File

@ -1,6 +1,5 @@
from abc import ABC, abstractmethod
import time
import platform
import struct
import os
@ -13,23 +12,11 @@ class Session(ABC):
self._last_msg_id = 0
self._time_offset = 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._flood_sleep_threshold = 60
def clone(self, to_instance=None):
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._flood_sleep_threshold = self.flood_sleep_threshold
return cloned
@ -99,46 +86,6 @@ class Session(ABC):
def salt(self, 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
def report_errors(self):
return self._report_errors

View File

@ -1,11 +1,11 @@
import logging
import os
import platform
import threading
from datetime import timedelta, datetime
from signal import signal, SIGINT, SIGTERM, SIGABRT
from threading import Lock
from time import sleep
from . import version, utils
from .crypto import rsa
from .errors import (
@ -73,7 +73,12 @@ class TelegramBareClient:
update_workers=None,
spawn_read_thread=False,
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"""
if not api_id or not api_hash:
raise ValueError(
@ -125,11 +130,12 @@ class TelegramBareClient:
self.updates = UpdateState(workers=update_workers)
# Used on connection - the user may modify these and reconnect
kwargs['app_version'] = kwargs.get('app_version', self.__version__)
for name, value in kwargs.items():
if not hasattr(self.session, name):
raise ValueError('Unknown named parameter', name)
setattr(self.session, name, value)
system = platform.uname()
self.device_model = device_model or system.system or 'Unknown'
self.system_version = system_version or system.release or '1.0'
self.app_version = app_version or self.__version__
self.lang_code = lang_code
self.system_lang_code = system_lang_code
# Despite the state of the real connection, keep track of whether
# the user has explicitly called .connect() or .disconnect() here.
@ -233,11 +239,11 @@ class TelegramBareClient:
"""Wraps query around InvokeWithLayerRequest(InitConnectionRequest())"""
return InvokeWithLayerRequest(LAYER, InitConnectionRequest(
api_id=self.api_id,
device_model=self.session.device_model,
system_version=self.session.system_version,
app_version=self.session.app_version,
lang_code=self.session.lang_code,
system_lang_code=self.session.system_lang_code,
device_model=self.device_model,
system_version=self.system_version,
app_version=self.app_version,
lang_code=self.lang_code,
system_lang_code=self.system_lang_code,
lang_pack='', # "langPacks are for official apps only"
query=query
))