Make session leaner by removing some redundant parameters

Related to #86
This commit is contained in:
Dan 2018-06-24 18:26:11 +02:00
parent 56f616c753
commit f4c0793a0b
3 changed files with 47 additions and 58 deletions

View File

@ -187,12 +187,9 @@ class Client(Methods, BaseClient):
self.load_session()
self.session = Session(
self,
self.dc_id,
self.test_mode,
self._proxy,
self.auth_key,
self.api_id,
client=self
self.auth_key
)
self.session.start()
@ -372,12 +369,9 @@ class Client(Methods, BaseClient):
self.auth_key = Auth(self.dc_id, self.test_mode, self._proxy).create()
self.session = Session(
self,
self.dc_id,
self.test_mode,
self._proxy,
self.auth_key,
self.api_id,
client=self
self.auth_key
)
self.session.start()
@ -420,12 +414,9 @@ class Client(Methods, BaseClient):
self.auth_key = Auth(self.dc_id, self.test_mode, self._proxy).create()
self.session = Session(
self,
self.dc_id,
self.test_mode,
self._proxy,
self.auth_key,
self.api_id,
client=self
self.auth_key
)
self.session.start()
@ -1033,7 +1024,7 @@ class Client(Methods, BaseClient):
file_id = file_id or self.rnd_id()
md5_sum = md5() if not is_big and not is_missing_part else None
session = Session(self.dc_id, self.test_mode, self._proxy, self.auth_key, self.api_id)
session = Session(self, self.dc_id, self.auth_key, is_media=True)
session.start()
try:
@ -1117,11 +1108,10 @@ class Client(Methods, BaseClient):
)
session = Session(
self,
dc_id,
self.test_mode,
self._proxy,
Auth(dc_id, self.test_mode, self._proxy).create(),
self.api_id
is_media=True
)
session.start()
@ -1136,11 +1126,10 @@ class Client(Methods, BaseClient):
)
else:
session = Session(
self,
dc_id,
self.test_mode,
self._proxy,
self.auth_key,
self.api_id
is_media=True
)
session.start()
@ -1206,11 +1195,10 @@ class Client(Methods, BaseClient):
if cdn_session is None:
cdn_session = Session(
self,
r.dc_id,
self.test_mode,
self._proxy,
Auth(r.dc_id, self.test_mode, self._proxy).create(),
self.api_id,
is_media=True,
is_cdn=True
)

View File

@ -16,17 +16,34 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import platform
import re
from queue import Queue
from threading import Lock
from pyrogram import __version__
from ..style import Markdown, HTML
from ...api.core import Object
from ...session.internals import MsgId
from ...session import Session
from ...session.internals import MsgId
class BaseClient:
APP_VERSION = "Pyrogram \U0001f525 {}".format(__version__)
DEVICE_MODEL = "{} {}".format(
platform.python_implementation(),
platform.python_version()
)
SYSTEM_VERSION = "{} {}".format(
platform.system(),
platform.release()
)
SYSTEM_LANG_CODE = "en"
LANG_CODE = "en"
INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/joinchat/)([\w-]+)$")
BOT_TOKEN_RE = re.compile(r"^\d+:[\w-]+$")
DIALOGS_AT_ONCE = 100

View File

@ -17,7 +17,6 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
import logging
import platform
import threading
import time
from datetime import timedelta, datetime
@ -47,19 +46,6 @@ class Result:
class Session:
VERSION = __version__
APP_VERSION = "Pyrogram \U0001f525 {}".format(VERSION)
DEVICE_MODEL = "{} {}".format(
platform.python_implementation(),
platform.python_version()
)
SYSTEM_VERSION = "{} {}".format(
platform.system(),
platform.release()
)
INITIAL_SALT = 0x616e67656c696361
NET_WORKERS = 1
WAIT_TIMEOUT = 15
@ -84,28 +70,24 @@ class Session:
}
def __init__(self,
client: pyrogram,
dc_id: int,
test_mode: bool,
proxy: dict,
auth_key: bytes,
api_id: int,
is_cdn: bool = False,
client: pyrogram = None):
is_media: bool = False,
is_cdn: bool = False):
if not Session.notice_displayed:
print("Pyrogram v{}, {}".format(__version__, __copyright__))
print("Licensed under the terms of the " + __license__, end="\n\n")
Session.notice_displayed = True
self.dc_id = dc_id
self.test_mode = test_mode
self.proxy = proxy
self.api_id = api_id
self.is_cdn = is_cdn
self.client = client
self.dc_id = dc_id
self.auth_key = auth_key
self.is_media = is_media
self.is_cdn = is_cdn
self.connection = None
self.auth_key = auth_key
self.auth_key_id = sha1(auth_key).digest()[-8:]
self.session_id = Long(MsgId())
@ -130,7 +112,7 @@ class Session:
def start(self):
while True:
self.connection = Connection(DataCenter(self.dc_id, self.test_mode), self.proxy)
self.connection = Connection(DataCenter(self.dc_id, self.client.test_mode), self.client.proxy)
try:
self.connection.connect()
@ -159,12 +141,14 @@ class Session:
functions.InvokeWithLayer(
layer,
functions.InitConnection(
self.api_id,
self.DEVICE_MODEL,
self.SYSTEM_VERSION,
self.APP_VERSION,
"en", "", "en",
functions.help.GetConfig(),
api_id=self.client.api_id,
device_model=self.client.DEVICE_MODEL,
system_version=self.client.SYSTEM_VERSION,
app_version=self.client.APP_VERSION,
system_lang_code=self.client.SYSTEM_LANG_CODE,
lang_code=self.client.LANG_CODE,
lang_pack="",
query=functions.help.GetConfig(),
)
)
)