Significantly clean-up imports

Sure wish I would've automated this.
This commit is contained in:
Lonami Exo 2023-09-02 23:05:28 +02:00
parent f75acee7e8
commit 4b2d252fe1
52 changed files with 447 additions and 231 deletions

View File

@ -1 +1,6 @@
from ._impl import tl as _tl
from ._impl.client import Client, Config
from ._impl.session import Session
from .version import __version__ from .version import __version__
__all__ = ["_tl", "Client", "Config", "Session"]

View File

View File

@ -0,0 +1,3 @@
from .client import Client, Config
__all__ = ["Client", "Config"]

View File

@ -0,0 +1,15 @@
from .bots import InlineResult, InlineResults
from .client import Client
from .files import File, InFileLike, MediaLike, OutFileLike
from .net import Config
__all__ = [
"InlineResult",
"InlineResults",
"Client",
"File",
"InFileLike",
"MediaLike",
"OutFileLike",
"Config",
]

View File

@ -2,13 +2,11 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Optional, Union from typing import TYPE_CHECKING, Optional, Union
from ...mtproto.mtp.types import RpcError from ...mtproto import RpcError
from ...session.message_box.defs import Session from ...session import Session
from ...session.message_box.defs import User as SessionUser from ...session import User as SessionUser
from ...tl import abcs, functions, types from ...tl import abcs, functions, types
from ..types.chat.user import User from ..types import LoginToken, PasswordToken, User
from ..types.login_token import LoginToken
from ..types.password_token import PasswordToken
from .net import connect_sender from .net import connect_sender
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@ -2,10 +2,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING, AsyncIterator, List, Optional, Self, Union from typing import TYPE_CHECKING, AsyncIterator, List, Optional, Self, Union
from ...._impl.tl import abcs, functions, types from ...tl import abcs, functions, types
from ..types.chat import ChatLike from ..types import ChatLike, Message, NoPublicConstructor
from ..types.message import Message
from ..types.meta import NoPublicConstructor
from ..utils import generate_random_id from ..utils import generate_random_id
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@ -15,19 +15,10 @@ from typing import (
Union, Union,
) )
from ...mtsender.sender import Sender from ...mtsender import Sender
from ...session.chat.hash_cache import ChatHashCache from ...session import ChatHashCache, MessageBox, PackedChat, Session
from ...session.chat.packed import PackedChat from ...tl import Request, abcs
from ...session.message_box.defs import Session from ..types import AsyncList, ChatLike, LoginToken, Message, PasswordToken, User
from ...session.message_box.messagebox import MessageBox
from ...tl import abcs
from ...tl.core.request import Request
from ..types.async_list import AsyncList
from ..types.chat import ChatLike
from ..types.chat.user import User
from ..types.login_token import LoginToken
from ..types.message import Message
from ..types.password_token import PasswordToken
from .account import edit_2fa, end_takeout, takeout from .account import edit_2fa, end_takeout, takeout
from .auth import ( from .auth import (
bot_sign_in, bot_sign_in,

View File

@ -7,9 +7,7 @@ from pathlib import Path
from typing import TYPE_CHECKING, Any, Coroutine, List, Optional, Protocol, Self, Union from typing import TYPE_CHECKING, Any, Coroutine, List, Optional, Protocol, Self, Union
from ...tl import abcs, functions, types from ...tl import abcs, functions, types
from ..types.chat import ChatLike from ..types import ChatLike, Message, NoPublicConstructor
from ..types.message import Message
from ..types.meta import NoPublicConstructor
from ..utils import generate_random_id from ..utils import generate_random_id
from .messages import parse_message from .messages import parse_message

View File

@ -2,25 +2,12 @@ from __future__ import annotations
import datetime import datetime
import sys import sys
from typing import ( from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, Union
TYPE_CHECKING,
Any,
Coroutine,
Dict,
List,
Literal,
Optional,
Tuple,
Union,
)
from telethon._impl.client.types.async_list import AsyncList
from telethon._impl.session.chat.packed import PackedChat
from ...session import PackedChat
from ...tl import abcs, functions, types from ...tl import abcs, functions, types
from ..parsers import parse_html_message, parse_markdown_message from ..parsers import parse_html_message, parse_markdown_message
from ..types.chat import ChatLike from ..types import AsyncList, ChatLike, Message
from ..types.message import Message
from ..utils import generate_random_id from ..utils import generate_random_id
if TYPE_CHECKING: if TYPE_CHECKING:

View File

@ -7,14 +7,12 @@ from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Optional, TypeVar from typing import TYPE_CHECKING, Optional, TypeVar
from ....version import __version__ from ....version import __version__
from ...mtproto.mtp.types import RpcError from ...mtproto import Full, RpcError
from ...mtproto.transport.full import Full from ...mtsender import Sender
from ...mtsender.sender import Sender from ...mtsender import connect as connect_without_auth
from ...mtsender.sender import connect as connect_without_auth from ...mtsender import connect_with_auth
from ...mtsender.sender import connect_with_auth from ...session import DataCenter, Session
from ...session.message_box.defs import DataCenter, Session from ...tl import LAYER, Request, functions
from ...tl import LAYER, functions
from ...tl.core.request import Request
if TYPE_CHECKING: if TYPE_CHECKING:
from .client import Client from .client import Client

View File

@ -2,9 +2,9 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Optional from typing import TYPE_CHECKING, Optional
from ...session.chat.packed import PackedChat, PackedType from ...session import PackedChat, PackedType
from ...tl import abcs, types from ...tl import abcs, types
from ..types.chat import Channel, ChatLike, Group, User from ..types import Channel, ChatLike, Group, User
if TYPE_CHECKING: if TYPE_CHECKING:
from .client import Client from .client import Client

View File

@ -0,0 +1,20 @@
from .async_list import AsyncList
from .chat import Channel, Chat, ChatLike, Group, RestrictionReason, User
from .login_token import LoginToken
from .message import Message
from .meta import NoPublicConstructor
from .password_token import PasswordToken
__all__ = [
"AsyncList",
"Channel",
"Chat",
"ChatLike",
"Group",
"RestrictionReason",
"User",
"LoginToken",
"Message",
"NoPublicConstructor",
"PasswordToken",
]

View File

@ -1,6 +1,6 @@
from typing import Union from typing import Union
from ....session.chat.packed import PackedChat from ....session import PackedChat
from ....tl import abcs from ....tl import abcs
from .channel import Channel from .channel import Channel
from .group import Group from .group import Group
@ -9,4 +9,4 @@ from .user import RestrictionReason, User
Chat = Union[Channel, Group, User] Chat = Union[Channel, Group, User]
ChatLike = Union[Chat, PackedChat, int, str, abcs.InputPeer] ChatLike = Union[Chat, PackedChat, int, str, abcs.InputPeer]
__all__ = ["Chat", "Channel", "Group", "RestrictionReason", "User"] __all__ = ["Chat", "ChatLike", "Channel", "Group", "RestrictionReason", "User"]

View File

@ -1,6 +1,6 @@
from typing import Optional, Self, Union from typing import Optional, Self, Union
from ....session.chat.packed import PackedChat, PackedType from ....session import PackedChat, PackedType
from ....tl import abcs, types from ....tl import abcs, types
from ..meta import NoPublicConstructor from ..meta import NoPublicConstructor

View File

@ -1,6 +1,6 @@
from typing import Optional, Self, Union from typing import Optional, Self, Union
from ....session.chat.packed import PackedChat, PackedType from ....session import PackedChat, PackedType
from ....tl import abcs, types from ....tl import abcs, types
from ..meta import NoPublicConstructor from ..meta import NoPublicConstructor

View File

@ -1,6 +1,6 @@
from typing import List, Optional, Self from typing import List, Optional, Self
from ....session.chat.packed import PackedChat, PackedType from ....session import PackedChat, PackedType
from ....tl import abcs, types from ....tl import abcs, types
from ..meta import NoPublicConstructor from ..meta import NoPublicConstructor

View File

@ -1,7 +1,6 @@
from typing import Self from typing import Self
from telethon._impl.tl import types from ...tl import types
from .meta import NoPublicConstructor from .meta import NoPublicConstructor

View File

@ -1,8 +1,8 @@
import datetime import datetime
from typing import Optional, Self from typing import Optional, Self
from ...client.types.chat import Chat
from ...tl import abcs, types from ...tl import abcs, types
from .chat import Chat
from .meta import NoPublicConstructor from .meta import NoPublicConstructor

View File

@ -1,7 +1,6 @@
from typing import Self from typing import Self
from telethon._impl.tl import types from ...tl import types
from .meta import NoPublicConstructor from .meta import NoPublicConstructor

View File

@ -1,115 +1,26 @@
import os
from collections import namedtuple
from enum import IntEnum
from hashlib import sha1, sha256
from .aes import ige_decrypt, ige_encrypt
from .auth_key import AuthKey from .auth_key import AuthKey
from .crypto import (
Side,
calc_key,
decrypt_data_v2,
decrypt_ige,
encrypt_data_v2,
encrypt_ige,
generate_key_data_from_nonce,
)
from .factorize import factorize
from .rsa import RSA_KEYS, encrypt_hashed
__all__ = [
# "where x = 0 for messages from client to server and x = 8 for those from server to client" "AuthKey",
class Side(IntEnum): "Side",
CLIENT = 0 "calc_key",
SERVER = 8 "decrypt_data_v2",
"decrypt_ige",
"encrypt_data_v2",
CalcKey = namedtuple("CalcKey", ("key", "iv")) "encrypt_ige",
"generate_key_data_from_nonce",
"factorize",
# https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector "RSA_KEYS",
def calc_key(auth_key: AuthKey, msg_key: bytes, side: Side) -> CalcKey: "encrypt_hashed",
x = int(side) ]
# sha256_a = SHA256 (msg_key + substr (auth_key, x, 36))
sha256_a = sha256(msg_key + auth_key.data[x : x + 36]).digest()
# sha256_b = SHA256 (substr (auth_key, 40+x, 36) + msg_key)
sha256_b = sha256(auth_key.data[x + 40 : x + 76] + msg_key).digest()
# aes_key = substr (sha256_a, 0, 8) + substr (sha256_b, 8, 16) + substr (sha256_a, 24, 8)
aes_key = sha256_a[:8] + sha256_b[8:24] + sha256_a[24:32]
# aes_iv = substr (sha256_b, 0, 8) + substr (sha256_a, 8, 16) + substr (sha256_b, 24, 8)
aes_iv = sha256_b[:8] + sha256_a[8:24] + sha256_b[24:32]
return CalcKey(aes_key, aes_iv)
def determine_padding_v2_length(length: int) -> int:
return 16 + (16 - (length % 16))
def _do_encrypt_data_v2(
plaintext: bytes, auth_key: AuthKey, random_padding: bytes
) -> bytes:
padded_plaintext = (
plaintext + random_padding[: determine_padding_v2_length(len(plaintext))]
)
side = Side.CLIENT
x = int(side)
# msg_key_large = SHA256 (substr (auth_key, 88+x, 32) + plaintext + random_padding)
msg_key_large = sha256(auth_key.data[x + 88 : x + 120] + padded_plaintext).digest()
# msg_key = substr (msg_key_large, 8, 16)
msg_key = msg_key_large[8:24]
key, iv = calc_key(auth_key, msg_key, side)
ciphertext = ige_encrypt(padded_plaintext, key, iv)
return auth_key.key_id + msg_key + ciphertext
def encrypt_data_v2(plaintext: bytes, auth_key: AuthKey) -> bytes:
random_padding = os.urandom(32)
return _do_encrypt_data_v2(plaintext, auth_key, random_padding)
def decrypt_data_v2(ciphertext: bytes, auth_key: AuthKey) -> bytes:
side = Side.SERVER
x = int(side)
if len(ciphertext) < 24 or (len(ciphertext) - 24) % 16 != 0:
raise ValueError("invalid ciphertext buffer length")
# TODO Check salt, session_id and sequence_number
key_id = ciphertext[:8]
if auth_key.key_id != key_id:
raise ValueError("server authkey mismatches with ours")
msg_key = ciphertext[8:24]
key, iv = calc_key(auth_key, msg_key, side)
plaintext = ige_decrypt(ciphertext[24:], key, iv)
# https://core.telegram.org/mtproto/security_guidelines#mtproto-encrypted-messages
our_key = sha256(auth_key.data[x + 88 : x + 120] + plaintext).digest()
if msg_key != our_key[8:24]:
raise ValueError("server msgkey mismatches with ours")
return plaintext
def generate_key_data_from_nonce(server_nonce: int, new_nonce: int) -> CalcKey:
server_bytes = server_nonce.to_bytes(16)
new_bytes = new_nonce.to_bytes(32)
hash1 = sha1(new_bytes + server_bytes).digest()
hash2 = sha1(server_bytes + new_bytes).digest()
hash3 = sha1(new_bytes + new_bytes).digest()
key = hash1 + hash2[:12]
iv = hash2[12:20] + hash3 + new_bytes[:4]
return CalcKey(key, iv)
def encrypt_ige(plaintext: bytes, key: bytes, iv: bytes) -> bytes:
if len(plaintext) % 16 != 0:
plaintext += os.urandom((16 - (len(plaintext) % 16)) % 16)
return ige_encrypt(plaintext, key, iv)
def decrypt_ige(padded_ciphertext: bytes, key: bytes, iv: bytes) -> bytes:
return ige_decrypt(padded_ciphertext, key, iv)
__all__ = ["AuthKey", "encrypt_data_v2", "decrypt_data_v2"]

View File

@ -0,0 +1,112 @@
import os
from collections import namedtuple
from enum import IntEnum
from hashlib import sha1, sha256
from .aes import ige_decrypt, ige_encrypt
from .auth_key import AuthKey
# "where x = 0 for messages from client to server and x = 8 for those from server to client"
class Side(IntEnum):
CLIENT = 0
SERVER = 8
CalcKey = namedtuple("CalcKey", ("key", "iv"))
# https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector
def calc_key(auth_key: AuthKey, msg_key: bytes, side: Side) -> CalcKey:
x = int(side)
# sha256_a = SHA256 (msg_key + substr (auth_key, x, 36))
sha256_a = sha256(msg_key + auth_key.data[x : x + 36]).digest()
# sha256_b = SHA256 (substr (auth_key, 40+x, 36) + msg_key)
sha256_b = sha256(auth_key.data[x + 40 : x + 76] + msg_key).digest()
# aes_key = substr (sha256_a, 0, 8) + substr (sha256_b, 8, 16) + substr (sha256_a, 24, 8)
aes_key = sha256_a[:8] + sha256_b[8:24] + sha256_a[24:32]
# aes_iv = substr (sha256_b, 0, 8) + substr (sha256_a, 8, 16) + substr (sha256_b, 24, 8)
aes_iv = sha256_b[:8] + sha256_a[8:24] + sha256_b[24:32]
return CalcKey(aes_key, aes_iv)
def determine_padding_v2_length(length: int) -> int:
return 16 + (16 - (length % 16))
def _do_encrypt_data_v2(
plaintext: bytes, auth_key: AuthKey, random_padding: bytes
) -> bytes:
padded_plaintext = (
plaintext + random_padding[: determine_padding_v2_length(len(plaintext))]
)
side = Side.CLIENT
x = int(side)
# msg_key_large = SHA256 (substr (auth_key, 88+x, 32) + plaintext + random_padding)
msg_key_large = sha256(auth_key.data[x + 88 : x + 120] + padded_plaintext).digest()
# msg_key = substr (msg_key_large, 8, 16)
msg_key = msg_key_large[8:24]
key, iv = calc_key(auth_key, msg_key, side)
ciphertext = ige_encrypt(padded_plaintext, key, iv)
return auth_key.key_id + msg_key + ciphertext
def encrypt_data_v2(plaintext: bytes, auth_key: AuthKey) -> bytes:
random_padding = os.urandom(32)
return _do_encrypt_data_v2(plaintext, auth_key, random_padding)
def decrypt_data_v2(ciphertext: bytes, auth_key: AuthKey) -> bytes:
side = Side.SERVER
x = int(side)
if len(ciphertext) < 24 or (len(ciphertext) - 24) % 16 != 0:
raise ValueError("invalid ciphertext buffer length")
# TODO Check salt, session_id and sequence_number
key_id = ciphertext[:8]
if auth_key.key_id != key_id:
raise ValueError("server authkey mismatches with ours")
msg_key = ciphertext[8:24]
key, iv = calc_key(auth_key, msg_key, side)
plaintext = ige_decrypt(ciphertext[24:], key, iv)
# https://core.telegram.org/mtproto/security_guidelines#mtproto-encrypted-messages
our_key = sha256(auth_key.data[x + 88 : x + 120] + plaintext).digest()
if msg_key != our_key[8:24]:
raise ValueError("server msgkey mismatches with ours")
return plaintext
def generate_key_data_from_nonce(server_nonce: int, new_nonce: int) -> CalcKey:
server_bytes = server_nonce.to_bytes(16)
new_bytes = new_nonce.to_bytes(32)
hash1 = sha1(new_bytes + server_bytes).digest()
hash2 = sha1(server_bytes + new_bytes).digest()
hash3 = sha1(new_bytes + new_bytes).digest()
key = hash1 + hash2[:12]
iv = hash2[12:20] + hash3 + new_bytes[:4]
return CalcKey(key, iv)
def encrypt_ige(plaintext: bytes, key: bytes, iv: bytes) -> bytes:
if len(plaintext) % 16 != 0:
plaintext += os.urandom((16 - (len(plaintext) % 16)) % 16)
return ige_encrypt(plaintext, key, iv)
def decrypt_ige(padded_ciphertext: bytes, key: bytes, iv: bytes) -> bytes:
return ige_decrypt(padded_ciphertext, key, iv)

View File

@ -0,0 +1,31 @@
from .authentication import CreatedKey, Step1, Step2, Step3, create_key
from .authentication import step1 as auth_step1
from .authentication import step2 as auth_step2
from .authentication import step3 as auth_step3
from .mtp import BadMessage, Deserialization, Encrypted, MsgId, Mtp, Plain, RpcError
from .transport import Abridged, Full, Intermediate, MissingBytes, Transport
from .utils import DEFAULT_COMPRESSION_THRESHOLD
__all__ = [
"CreatedKey",
"Step1",
"Step2",
"Step3",
"create_key",
"auth_step1",
"auth_step2",
"auth_step3",
"BadMessage",
"Deserialization",
"Encrypted",
"MsgId",
"Mtp",
"Plain",
"RpcError",
"Abridged",
"Full",
"Intermediate",
"MissingBytes",
"Transport",
"DEFAULT_COMPRESSION_THRESHOLD",
]

View File

@ -5,12 +5,16 @@ from dataclasses import dataclass
from hashlib import sha1 from hashlib import sha1
from typing import Tuple from typing import Tuple
from telethon._impl.crypto import decrypt_ige, encrypt_ige, generate_key_data_from_nonce from ..crypto import (
from telethon._impl.crypto.auth_key import AuthKey RSA_KEYS,
from telethon._impl.crypto.factorize import factorize AuthKey,
from telethon._impl.crypto.rsa import RSA_KEYS, encrypt_hashed decrypt_ige,
from telethon._impl.tl.core.reader import Reader encrypt_hashed,
encrypt_ige,
factorize,
generate_key_data_from_nonce,
)
from ..tl.core import Reader
from ..tl.mtproto.abcs import ServerDhInnerData as AbcServerDhInnerData from ..tl.mtproto.abcs import ServerDhInnerData as AbcServerDhInnerData
from ..tl.mtproto.abcs import ServerDhParams, SetClientDhParamsAnswer from ..tl.mtproto.abcs import ServerDhParams, SetClientDhParamsAnswer
from ..tl.mtproto.functions import req_dh_params, req_pq_multi, set_client_dh_params from ..tl.mtproto.functions import req_dh_params, req_pq_multi, set_client_dh_params

View File

@ -1,10 +1,11 @@
from .encrypted import Encrypted from .encrypted import Encrypted
from .plain import Plain from .plain import Plain
from .types import Deserialization, MsgId, Mtp, RpcError from .types import BadMessage, Deserialization, MsgId, Mtp, RpcError
__all__ = [ __all__ = [
"Encrypted", "Encrypted",
"Plain", "Plain",
"BadMessage",
"Deserialization", "Deserialization",
"MsgId", "MsgId",
"Mtp", "Mtp",

View File

@ -1,10 +1,10 @@
import os import os
import struct import struct
import time import time
from typing import List, Optional, Tuple, Union from typing import List, Optional, Tuple
from ...crypto import AuthKey, decrypt_data_v2, encrypt_data_v2 from ...crypto import AuthKey, decrypt_data_v2, encrypt_data_v2
from ...tl.core.reader import Reader from ...tl.core import Reader
from ...tl.mtproto.abcs import BadMsgNotification as AbcBadMsgNotification from ...tl.mtproto.abcs import BadMsgNotification as AbcBadMsgNotification
from ...tl.mtproto.abcs import DestroySessionRes from ...tl.mtproto.abcs import DestroySessionRes
from ...tl.mtproto.abcs import MsgDetailedInfo as AbcMsgDetailedInfo from ...tl.mtproto.abcs import MsgDetailedInfo as AbcMsgDetailedInfo

View File

@ -1,7 +1,7 @@
import re import re
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from dataclasses import dataclass from dataclasses import dataclass
from typing import List, NewType, Optional, Self, Tuple, Union from typing import List, NewType, Optional, Self, Tuple
from ...tl.mtproto.types import RpcError as GeneratedRpcError from ...tl.mtproto.types import RpcError as GeneratedRpcError

View File

@ -1,3 +1,6 @@
from .abcs import Transport from .abcs import MissingBytes, Transport
from .abridged import Abridged
from .full import Full
from .intermediate import Intermediate
__all__ = ["Transport"] __all__ = ["MissingBytes", "Transport", "Abridged", "Full", "Intermediate"]

View File

@ -0,0 +1,17 @@
from .sender import (
MAXIMUM_DATA,
NO_PING_DISCONNECT,
PING_DELAY,
Sender,
connect,
connect_with_auth,
)
__all__ = [
"MAXIMUM_DATA",
"NO_PING_DISCONNECT",
"PING_DELAY",
"Sender",
"connect",
"connect_with_auth",
]

View File

@ -6,14 +6,20 @@ from asyncio import FIRST_COMPLETED, Event, Future, StreamReader, StreamWriter
from dataclasses import dataclass from dataclasses import dataclass
from typing import Generic, List, Optional, Self, TypeVar from typing import Generic, List, Optional, Self, TypeVar
from ..crypto.auth_key import AuthKey from ..crypto import AuthKey
from ..mtproto import authentication from ..mtproto import (
from ..mtproto.mtp.encrypted import Encrypted BadMessage,
from ..mtproto.mtp.plain import Plain Encrypted,
from ..mtproto.mtp.types import BadMessage, MsgId, Mtp, RpcError MissingBytes,
from ..mtproto.transport.abcs import MissingBytes, Transport MsgId,
Mtp,
Plain,
RpcError,
Transport,
authentication,
)
from ..tl import Request as RemoteCall
from ..tl.abcs import Updates from ..tl.abcs import Updates
from ..tl.core.request import Request as RemoteCall
from ..tl.mtproto.functions import ping_delay_disconnect from ..tl.mtproto.functions import ping_delay_disconnect
MAXIMUM_DATA = (1024 * 1024) + (8 * 1024) MAXIMUM_DATA = (1024 * 1024) + (8 * 1024)

View File

@ -0,0 +1,37 @@
from .chat import ChatHashCache, PackedChat, PackedType
from .message_box import (
BOT_CHANNEL_DIFF_LIMIT,
NO_UPDATES_TIMEOUT,
USER_CHANNEL_DIFF_LIMIT,
ChannelState,
DataCenter,
Gap,
MessageBox,
PossibleGap,
PrematureEndReason,
PtsInfo,
Session,
State,
UpdateState,
User,
)
__all__ = [
"ChatHashCache",
"PackedChat",
"PackedType",
"BOT_CHANNEL_DIFF_LIMIT",
"NO_UPDATES_TIMEOUT",
"USER_CHANNEL_DIFF_LIMIT",
"ChannelState",
"DataCenter",
"Gap",
"PossibleGap",
"PrematureEndReason",
"PtsInfo",
"Session",
"State",
"UpdateState",
"User",
"MessageBox",
]

View File

@ -2,7 +2,7 @@ import struct
from enum import Enum from enum import Enum
from typing import Optional, Self from typing import Optional, Self
from telethon._impl.tl import abcs, types from ...tl import abcs, types
class PackedType(Enum): class PackedType(Enum):

View File

@ -0,0 +1,33 @@
from .defs import (
BOT_CHANNEL_DIFF_LIMIT,
NO_UPDATES_TIMEOUT,
USER_CHANNEL_DIFF_LIMIT,
ChannelState,
DataCenter,
Gap,
PossibleGap,
PrematureEndReason,
PtsInfo,
Session,
State,
UpdateState,
User,
)
from .messagebox import MessageBox
__all__ = [
"BOT_CHANNEL_DIFF_LIMIT",
"NO_UPDATES_TIMEOUT",
"USER_CHANNEL_DIFF_LIMIT",
"ChannelState",
"DataCenter",
"Gap",
"PossibleGap",
"PrematureEndReason",
"PtsInfo",
"Session",
"State",
"UpdateState",
"User",
"MessageBox",
]

View File

@ -1,7 +1,7 @@
from typing import Optional from typing import Optional
from ...tl import abcs, types from ...tl import abcs, types
from ..chat.hash_cache import ChatHashCache from ..chat import ChatHashCache
from .defs import ENTRY_ACCOUNT, ENTRY_SECRET, NO_SEQ, Gap, PtsInfo from .defs import ENTRY_ACCOUNT, ENTRY_SECRET, NO_SEQ, Gap, PtsInfo

View File

@ -4,9 +4,8 @@ import logging
import time import time
from typing import Dict, List, Optional, Set, Tuple from typing import Dict, List, Optional, Set, Tuple
from ...tl import abcs, functions, types from ...tl import Request, abcs, functions, types
from ...tl.core.request import Request from ..chat import ChatHashCache
from ..chat.hash_cache import ChatHashCache
from .adaptor import adapt, pts_info_from_update from .adaptor import adapt, pts_info_from_update
from .defs import ( from .defs import (
BOT_CHANNEL_DIFF_LIMIT, BOT_CHANNEL_DIFF_LIMIT,

View File

@ -1,4 +1,14 @@
from . import abcs, core, functions, mtproto, types from . import abcs, functions, mtproto, types
from .core import Request
from .layer import LAYER, TYPE_MAPPING from .layer import LAYER, TYPE_MAPPING
__all__ = ["abcs", "core", "functions", "mtproto", "types", "LAYER", "TYPE_MAPPING"] __all__ = [
"abcs",
"core",
"functions",
"mtproto",
"types",
"Request",
"LAYER",
"TYPE_MAPPING",
]

View File

@ -1,4 +1,4 @@
from telethon._impl.crypto.auth_key import AuthKey from telethon._impl.crypto import AuthKey
def get_auth_key() -> AuthKey: def get_auth_key() -> AuthKey:

View File

@ -1,4 +1,4 @@
from telethon._impl.crypto.auth_key import AuthKey from telethon._impl.crypto import AuthKey
from telethon._impl.mtproto.authentication import ( from telethon._impl.mtproto.authentication import (
CreatedKey, CreatedKey,
_do_step1, _do_step1,

View File

@ -2,10 +2,8 @@ import os
import random import random
from pytest import mark from pytest import mark
from telethon._impl.client.client.client import Client from telethon import Client, Config, Session
from telethon._impl.client.client.net import Config from telethon import _tl as tl
from telethon._impl.session.message_box.defs import Session
from telethon._impl.tl.mtproto import functions, types
@mark.api @mark.api
@ -27,6 +25,6 @@ async def test_ping_pong() -> None:
assert client.connected assert client.connected
ping_id = random.randrange(-(2**63), 2**63) ping_id = random.randrange(-(2**63), 2**63)
pong = await client(functions.ping(ping_id=ping_id)) pong = await client(tl.mtproto.functions.ping(ping_id=ping_id))
assert isinstance(pong, types.Pong) assert isinstance(pong, tl.mtproto.types.Pong)
assert pong.ping_id == ping_id assert pong.ping_id == ping_id

View File

@ -1,13 +1,13 @@
from telethon._impl.crypto import ( from telethon._impl.crypto import (
AuthKey,
Side, Side,
_do_encrypt_data_v2,
calc_key, calc_key,
decrypt_data_v2, decrypt_data_v2,
decrypt_ige, decrypt_ige,
encrypt_ige, encrypt_ige,
generate_key_data_from_nonce, generate_key_data_from_nonce,
) )
from telethon._impl.crypto.auth_key import AuthKey from telethon._impl.crypto.crypto import _do_encrypt_data_v2
def get_test_auth_key() -> AuthKey: def get_test_auth_key() -> AuthKey:

View File

@ -1,4 +1,4 @@
from telethon._impl.crypto.factorize import factorize from telethon._impl.crypto import factorize
def test_factorization_1() -> None: def test_factorization_1() -> None:

View File

@ -1,8 +1,8 @@
import struct import struct
from pytest import raises from pytest import raises
from telethon._impl.crypto.auth_key import AuthKey from telethon._impl.crypto import AuthKey
from telethon._impl.mtproto.mtp import Encrypted, Plain, RpcError from telethon._impl.mtproto import Encrypted, Plain, RpcError
from telethon._impl.tl.mtproto.types import RpcError as GeneratedRpcError from telethon._impl.tl.mtproto.types import RpcError as GeneratedRpcError

View File

@ -2,8 +2,8 @@ import asyncio
import logging import logging
from pytest import LogCaptureFixture, mark from pytest import LogCaptureFixture, mark
from telethon._impl.mtproto.transport.full import Full from telethon._impl.mtproto import Full
from telethon._impl.mtsender.sender import connect from telethon._impl.mtsender import connect
from telethon._impl.tl import LAYER, abcs, functions, types from telethon._impl.tl import LAYER, abcs, functions, types
TELEGRAM_TEST_DC_2 = "149.154.167.40:443" TELEGRAM_TEST_DC_2 = "149.154.167.40:443"

View File

@ -1,4 +1,4 @@
from telethon._impl.session.chat.packed import PackedChat, PackedType from telethon._impl.session import PackedChat, PackedType
def test_hash_optional() -> None: def test_hash_optional() -> None:

View File

@ -1,8 +1,7 @@
import struct import struct
from pytest import mark from pytest import mark
from telethon._impl.tl.core import Reader from telethon._impl.tl.core import Reader, Serializable
from telethon._impl.tl.core.serializable import Serializable
from telethon._impl.tl.mtproto.types import BadServerSalt from telethon._impl.tl.mtproto.types import BadServerSalt
from telethon._impl.tl.types import GeoPoint from telethon._impl.tl.types import GeoPoint

View File

@ -1,7 +1,7 @@
from typing import Tuple from typing import Tuple
from pytest import raises from pytest import raises
from telethon._impl.mtproto.transport.abridged import Abridged from telethon._impl.mtproto import Abridged
class Output(bytearray): class Output(bytearray):

View File

@ -1,7 +1,7 @@
from typing import Tuple from typing import Tuple
from pytest import raises from pytest import raises
from telethon._impl.mtproto.transport.full import Full from telethon._impl.mtproto import Full
class Output(bytearray): class Output(bytearray):

View File

@ -1,7 +1,7 @@
from typing import Tuple from typing import Tuple
from pytest import raises from pytest import raises
from telethon._impl.mtproto.transport.intermediate import Intermediate from telethon._impl.mtproto import Intermediate
class Output(bytearray): class Output(bytearray):

View File

@ -1,7 +1,7 @@
from pathlib import Path from pathlib import Path
from typing import Set from typing import Set
from ..tl_parser.tl.parameter_type import NormalParameter from ..tl_parser import NormalParameter
from .fakefs import FakeFs, SourceWriter from .fakefs import FakeFs, SourceWriter
from .loader import ParsedTl from .loader import ParsedTl
from .serde.common import ( from .serde.common import (

View File

@ -2,7 +2,7 @@ import re
from dataclasses import dataclass from dataclasses import dataclass
from typing import List, Optional from typing import List, Optional
from ...tl_parser import Definition, FunctionDef, TypeDef, parse_tl_file from ..tl_parser import Definition, FunctionDef, TypeDef, parse_tl_file
@dataclass @dataclass

View File

@ -0,0 +1,26 @@
from .tl import (
BaseParameter,
Definition,
Flag,
FlagsParameter,
NormalParameter,
Parameter,
Type,
TypeDefNotImplemented,
)
from .tl_iterator import FunctionDef, TypeDef
from .tl_iterator import iterate as parse_tl_file
__all__ = [
"FunctionDef",
"TypeDef",
"parse_tl_file",
"Definition",
"Flag",
"Parameter",
"TypeDefNotImplemented",
"BaseParameter",
"FlagsParameter",
"NormalParameter",
"Type",
]

View File

@ -0,0 +1,16 @@
from .definition import Definition
from .flag import Flag
from .parameter import Parameter, TypeDefNotImplemented
from .parameter_type import BaseParameter, FlagsParameter, NormalParameter
from .ty import Type
__all__ = [
"Definition",
"Flag",
"Parameter",
"TypeDefNotImplemented",
"BaseParameter",
"FlagsParameter",
"NormalParameter",
"Type",
]

View File

@ -1,14 +1,16 @@
from .._impl.tl_parser.tl.definition import Definition from .._impl.tl_parser import (
from .._impl.tl_parser.tl.flag import Flag
from .._impl.tl_parser.tl.parameter import Parameter, TypeDefNotImplemented
from .._impl.tl_parser.tl.parameter_type import (
BaseParameter, BaseParameter,
Definition,
Flag,
FlagsParameter, FlagsParameter,
FunctionDef,
NormalParameter, NormalParameter,
Parameter,
Type,
TypeDef,
TypeDefNotImplemented,
parse_tl_file,
) )
from .._impl.tl_parser.tl.ty import Type
from .._impl.tl_parser.tl_iterator import FunctionDef, TypeDef
from .._impl.tl_parser.tl_iterator import iterate as parse_tl_file
__all__ = [ __all__ = [
"Definition", "Definition",