2121import inspect
2222import logging
2323import os
24+ import platform
2425import re
2526import shutil
27+ import sys
2628import tempfile
2729from concurrent .futures .thread import ThreadPoolExecutor
2830from configparser import ConfigParser
2931from hashlib import sha256
3032from importlib import import_module
33+ from io import StringIO
34+ from mimetypes import MimeTypes
3135from pathlib import Path
32- from typing import Union , List , Optional
36+ from typing import Union , List , Optional , Callable
3337
3438import pyrogram
3539from pyrogram import __version__ , __license__
5155from pyrogram .utils import ainput
5256from .dispatcher import Dispatcher
5357from .file_id import FileId , FileType , ThumbnailSource
54- from .scaffold import Scaffold
58+ from .mime_types import mime_types
59+ from .parser import Parser
60+ from .session .internals import MsgId
5561
5662log = logging .getLogger (__name__ )
5763
5864
59- class Client (Methods , Scaffold ):
65+ class Client (Methods ):
6066 """Pyrogram Client, the main means for interacting with Telegram.
6167
6268 Parameters:
@@ -177,10 +183,26 @@ class Client(Methods, Scaffold):
177183 terminal environments.
178184 """
179185
186+ APP_VERSION = f"Pyrogram { __version__ } "
187+ DEVICE_MODEL = f"{ platform .python_implementation ()} { platform .python_version ()} "
188+ SYSTEM_VERSION = f"{ platform .system ()} { platform .release ()} "
189+
190+ LANG_CODE = "en"
191+
192+ PARENT_DIR = Path (sys .argv [0 ]).parent
193+
194+ INVITE_LINK_RE = re .compile (r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/(?:joinchat/|\+))([\w-]+)$" )
195+ WORKERS = min (32 , (os .cpu_count () or 0 ) + 4 ) # os.cpu_count() can be None
196+ WORKDIR = PARENT_DIR
197+ CONFIG_FILE = PARENT_DIR / "config.ini"
198+
199+ mimetypes = MimeTypes ()
200+ mimetypes .readfp (StringIO (mime_types ))
201+
180202 def __init__ (
181203 self ,
182204 session_name : Union [str , Storage ],
183- api_id : Union [ int , str ] = None ,
205+ api_id : int = None ,
184206 api_hash : str = None ,
185207 app_version : str = None ,
186208 device_model : str = None ,
@@ -194,9 +216,9 @@ def __init__(
194216 phone_code : str = None ,
195217 password : str = None ,
196218 force_sms : bool = False ,
197- workers : int = Scaffold . WORKERS ,
198- workdir : str = Scaffold . WORKDIR ,
199- config_file : str = Scaffold . CONFIG_FILE ,
219+ workers : int = WORKERS ,
220+ workdir : str = WORKDIR ,
221+ config_file : str = CONFIG_FILE ,
200222 plugins : dict = None ,
201223 parse_mode : "enums.ParseMode" = enums .ParseMode .DEFAULT ,
202224 no_updates : bool = None ,
@@ -207,7 +229,7 @@ def __init__(
207229 super ().__init__ ()
208230
209231 self .session_name = session_name
210- self .api_id = int ( api_id ) if api_id else None
232+ self .api_id = api_id
211233 self .api_hash = api_hash
212234 self .app_version = app_version
213235 self .device_model = device_model
@@ -246,6 +268,24 @@ def __init__(
246268 raise ValueError ("Unknown storage engine" )
247269
248270 self .dispatcher = Dispatcher (self )
271+
272+ self .rnd_id = MsgId
273+
274+ self .parser = Parser (self )
275+ self .parse_mode = enums .ParseMode .DEFAULT
276+
277+ self .session = None
278+
279+ self .media_sessions = {}
280+ self .media_sessions_lock = asyncio .Lock ()
281+
282+ self .is_connected = None
283+ self .is_initialized = None
284+
285+ self .takeout_id = None
286+
287+ self .disconnect_handler = None
288+
249289 self .loop = asyncio .get_event_loop ()
250290
251291 def __enter__ (self ):
@@ -790,7 +830,7 @@ async def get_file(
790830 self ,
791831 file_id : FileId ,
792832 file_size : int ,
793- progress : callable ,
833+ progress : Callable ,
794834 progress_args : tuple = ()
795835 ) -> str :
796836 dc_id = file_id .dc_id
0 commit comments