From 499fc9f603c62f63c53120e5ecdbd43b575ebcb5 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 12 Sep 2021 16:58:06 +0200 Subject: [PATCH] Move alltlobjects.py and fix imports --- telethon/__init__.py | 1 - telethon/_client/auth.py | 6 +- telethon/_client/bots.py | 6 +- telethon/_client/buttons.py | 8 +- telethon/_client/chats.py | 12 +-- telethon/_client/dialogs.py | 6 +- telethon/_client/downloads.py | 4 +- telethon/_client/telegrambaseclient.py | 3 +- telethon/_client/telegramclient.py | 104 +++++++++++----------- telethon/_client/uploads.py | 4 +- telethon/_crypto/rsa.py | 6 +- telethon/_misc/binaryreader.py | 7 +- telethon/_misc/markdown.py | 3 +- telethon/_misc/messagepacker.py | 3 +- telethon/_network/authenticator.py | 2 +- telethon/_network/mtprotoplainsender.py | 2 +- telethon/_network/mtprotosender.py | 6 +- telethon/_network/mtprotostate.py | 7 +- telethon/events/album.py | 12 +-- telethon/events/callbackquery.py | 8 +- telethon/events/common.py | 7 +- telethon/events/inlinequery.py | 6 +- telethon/events/userupdate.py | 6 +- telethon/sessions/memory.py | 8 +- telethon/types/_core/gzippacked.py | 6 +- telethon/types/_core/messagecontainer.py | 2 +- telethon/types/_core/rpcresult.py | 7 +- telethon/types/_core/tlmessage.py | 4 +- telethon/types/_custom/dialog.py | 6 +- telethon/types/_custom/draft.py | 6 +- telethon/types/_custom/message.py | 4 +- telethon_generator/generators/tlobject.py | 31 +++---- 32 files changed, 145 insertions(+), 158 deletions(-) diff --git a/telethon/__init__.py b/telethon/__init__.py index 59ea6691..edbd4126 100644 --- a/telethon/__init__.py +++ b/telethon/__init__.py @@ -6,7 +6,6 @@ from ._misc import hints # depends on types/custom from ._client.telegramclient import TelegramClient from ._network import connection -from ._tl.custom import Button from . import version, events, utils, errors __version__ = version.__version__ diff --git a/telethon/_client/auth.py b/telethon/_client/auth.py index 4ae32c43..992d44e1 100644 --- a/telethon/_client/auth.py +++ b/telethon/_client/auth.py @@ -7,7 +7,7 @@ import warnings from .._misc import utils, helpers, password as pwd_mod from .. import errors, _tl -from .._tl import custom +from ..types import _custom if typing.TYPE_CHECKING: from .telegramclient import TelegramClient @@ -343,8 +343,8 @@ async def send_code_request( return result -async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> custom.QRLogin: - qr_login = custom.QRLogin(self, ignored_ids or []) +async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QRLogin: + qr_login = _custom.QRLogin(self, ignored_ids or []) await qr_login.recreate() return qr_login diff --git a/telethon/_client/bots.py b/telethon/_client/bots.py index 8c2d50fe..9360d7f3 100644 --- a/telethon/_client/bots.py +++ b/telethon/_client/bots.py @@ -1,7 +1,7 @@ import typing from .. import hints, _tl -from .._tl import custom +from ..types import _custom if typing.TYPE_CHECKING: from .telegramclient import TelegramClient @@ -14,7 +14,7 @@ async def inline_query( *, entity: 'hints.EntityLike' = None, offset: str = None, - geo_point: '_tl.GeoPoint' = None) -> custom.InlineResults: + geo_point: '_tl.GeoPoint' = None) -> _custom.InlineResults: bot = await self.get_input_entity(bot) if entity: peer = await self.get_input_entity(entity) @@ -29,4 +29,4 @@ async def inline_query( geo_point=geo_point )) - return custom.InlineResults(self, result, entity=peer if entity else None) + return _custom.InlineResults(self, result, entity=peer if entity else None) diff --git a/telethon/_client/buttons.py b/telethon/_client/buttons.py index 897b4703..fbd0f51c 100644 --- a/telethon/_client/buttons.py +++ b/telethon/_client/buttons.py @@ -2,7 +2,7 @@ import typing from .._misc import utils, hints from .. import _tl -from .._tl import custom +from ..types import _custom def build_reply_markup( @@ -32,7 +32,7 @@ def build_reply_markup( for row in buttons: current = [] for button in row: - if isinstance(button, custom.Button): + if isinstance(button, _custom.Button): if button.resize is not None: resize = button.resize if button.single_use is not None: @@ -41,10 +41,10 @@ def build_reply_markup( selective = button.selective button = button.button - elif isinstance(button, custom.MessageButton): + elif isinstance(button, _custom.MessageButton): button = button.button - inline = custom.Button._is_inline(button) + inline = _custom.Button._is_inline(button) is_inline |= inline is_normal |= not inline diff --git a/telethon/_client/chats.py b/telethon/_client/chats.py index 0fb88ed8..0ff93c02 100644 --- a/telethon/_client/chats.py +++ b/telethon/_client/chats.py @@ -5,8 +5,8 @@ import string import typing from .. import hints, errors, _tl -from .._misc import helpers, utils, requestiter -from .._tl import custom +from .._misc import helpers, utils, requestiter, tlobject +from ..types import _custom if typing.TYPE_CHECKING: from .telegramclient import TelegramClient @@ -302,7 +302,7 @@ class _AdminLogIter(requestiter.RequestIter): ev.action.message._finish_init( self.client, entities, self.entity) - self.buffer.append(custom.AdminLogEvent(ev, entities)) + self.buffer.append(_custom.AdminLogEvent(ev, entities)) if len(r.events) < self.request.limit: return True @@ -516,7 +516,7 @@ def action( except KeyError: raise ValueError( 'No such action "{}"'.format(action)) from None - elif not isinstance(action, _tl.TLObject) or action.SUBCLASS_OF_ID != 0x20b2cc21: + elif not isinstance(action, tlobject.TLObject) or action.SUBCLASS_OF_ID != 0x20b2cc21: # 0x20b2cc21 = crc32(b'SendMessageAction') if isinstance(action, type): raise ValueError('You must pass an instance, not the class') @@ -716,7 +716,7 @@ async def get_permissions( entity, user )) - return custom.ParticipantPermissions(participant.participant, False) + return _custom.ParticipantPermissions(participant.participant, False) elif helpers._entity_type(entity) == helpers._EntityType.CHAT: chat = await self(_tl.fn.messages.GetFullChat( entity @@ -725,7 +725,7 @@ async def get_permissions( user = await self.get_me(input_peer=True) for participant in chat.full_chat.participants.participants: if participant.user_id == user.user_id: - return custom.ParticipantPermissions(participant, True) + return _custom.ParticipantPermissions(participant, True) raise errors.UserNotParticipantError(None) raise ValueError('You must pass either a channel or a chat') diff --git a/telethon/_client/dialogs.py b/telethon/_client/dialogs.py index bfd76f61..850e3ac9 100644 --- a/telethon/_client/dialogs.py +++ b/telethon/_client/dialogs.py @@ -5,7 +5,7 @@ import typing from .. import hints, errors, _tl from .._misc import helpers, utils, requestiter -from .._tl import custom +from ..types import _custom _MAX_CHUNK_SIZE = 100 @@ -80,7 +80,7 @@ class _DialogsIter(requestiter.RequestIter): # Real world example: https://t.me/TelethonChat/271471 continue - cd = custom.Dialog(self.client, d, entities, message) + cd = _custom.Dialog(self.client, d, entities, message) if cd.dialog.pts: self.client._channel_pts[cd.id] = cd.dialog.pts @@ -128,7 +128,7 @@ class _DraftsIter(requestiter.RequestIter): for x in itertools.chain(r.users, r.chats)} self.buffer.extend( - custom.Draft(self.client, entities[utils.get_peer_id(d.peer)], d.draft) + _custom.Draft(self.client, entities[utils.get_peer_id(d.peer)], d.draft) for d in items ) diff --git a/telethon/_client/downloads.py b/telethon/_client/downloads.py index 25a461cb..6cd34b10 100644 --- a/telethon/_client/downloads.py +++ b/telethon/_client/downloads.py @@ -7,7 +7,7 @@ import inspect import asyncio from .._crypto import AES -from .._misc import utils, helpers, requestiter +from .._misc import utils, helpers, requestiter, tlobject from .. import errors, hints, _tl try: @@ -198,7 +198,7 @@ async def download_profile_photo( ENTITIES = (0x2da17977, 0xc5af5d94, 0x1f4661b9, 0xd49a2697) # ('InputPeer', 'InputUser', 'InputChannel') INPUTS = (0xc91c90b6, 0xe669bf46, 0x40f202fd) - if not isinstance(entity, _tl.TLObject) or entity.SUBCLASS_OF_ID in INPUTS: + if not isinstance(entity, tlobject.TLObject) or entity.SUBCLASS_OF_ID in INPUTS: entity = await self.get_entity(entity) thumb = -1 if download_big else 0 diff --git a/telethon/_client/telegrambaseclient.py b/telethon/_client/telegrambaseclient.py index b45ac6d3..0ac127f0 100644 --- a/telethon/_client/telegrambaseclient.py +++ b/telethon/_client/telegrambaseclient.py @@ -11,7 +11,6 @@ from .. import version, helpers, __name__ as __base_name__, _tl from .._crypto import rsa from .._misc import markdown, entitycache, statecache from .._network import MTProtoSender, Connection, ConnectionTcpFull, TcpMTProxy -from .._tl.alltlobjects import LAYER from ..sessions import Session, SQLiteSession, MemorySession DEFAULT_DC_ID = 2 @@ -322,7 +321,7 @@ async def connect(self: 'TelegramClient') -> None: self._init_request.query = _tl.fn.help.GetConfig() await self._sender.send(_tl.fn.InvokeWithLayer( - LAYER, self._init_request + _tl.LAYER, self._init_request )) self._updates_handle = self.loop.create_task(self._update_loop()) diff --git a/telethon/_client/telegramclient.py b/telethon/_client/telegramclient.py index 3596a506..85b28cd3 100644 --- a/telethon/_client/telegramclient.py +++ b/telethon/_client/telegramclient.py @@ -9,7 +9,7 @@ from . import ( telegrambaseclient, updates, uploads, users ) from .. import helpers, version, _tl -from .._tl import custom +from ..types import _custom from .._network import ConnectionTcpFull from ..events.common import EventBuilder, EventCommon @@ -500,7 +500,7 @@ class TelegramClient: """ return await auth.send_code_request(**locals()) - async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> custom.QRLogin: + async def qr_login(self: 'TelegramClient', ignored_ids: typing.List[int] = None) -> _custom.QRLogin: """ Initiates the QR login procedure. @@ -630,7 +630,7 @@ class TelegramClient: *, entity: 'hints.EntityLike' = None, offset: str = None, - geo_point: '_tl.GeoPoint' = None) -> custom.InlineResults: + geo_point: '_tl.GeoPoint' = None) -> _custom.InlineResults: """ Makes an inline query to the specified bot (``@vote New Poll``). @@ -658,8 +658,8 @@ class TelegramClient: for localised results. Available under some bots. Returns - A list of `custom.InlineResult - `. + A list of `_custom.InlineResult + `. Example .. code-block:: python @@ -923,7 +923,7 @@ class TelegramClient: If `True`, events related to group calls will be returned. Yields - Instances of `AdminLogEvent `. + Instances of `AdminLogEvent `. Example .. code-block:: python @@ -1161,8 +1161,8 @@ class TelegramClient: .. note:: Users may be able to identify the anonymous admin by its - custom title, so additional care is needed when using both - ``anonymous`` and custom titles. For example, if multiple + _custom title, so additional care is needed when using both + ``anonymous`` and _custom titles. For example, if multiple anonymous admins share the same title, users won't be able to distinguish them. @@ -1178,7 +1178,7 @@ class TelegramClient: permissions, but you can still disable those you need. title (`str`, optional): - The custom title (also known as "rank") to show for this admin. + The _custom title (also known as "rank") to show for this admin. This text will be shown instead of the "admin" badge. This will only work in channels and megagroups. @@ -1340,7 +1340,7 @@ class TelegramClient: The user to kick. Returns - Returns the service `Message ` + Returns the service `Message ` produced about a user being kicked, if any. Example @@ -1359,7 +1359,7 @@ class TelegramClient: self: 'TelegramClient', entity: 'hints.EntityLike', user: 'hints.EntityLike' = None - ) -> 'typing.Optional[custom.ParticipantPermissions]': + ) -> 'typing.Optional[_custom.ParticipantPermissions]': """ Fetches the permissions of a user in a specific chat or channel or get Default Restricted Rights of Chat or Channel. @@ -1377,7 +1377,7 @@ class TelegramClient: Target user. Returns - A `ParticipantPermissions ` + A `ParticipantPermissions ` instance. Refer to its documentation to see what properties are available. @@ -1509,7 +1509,7 @@ class TelegramClient: Alias for `folder`. If unspecified, all will be returned, `False` implies ``folder=0`` and `True` implies ``folder=1``. Yields - Instances of `Dialog `. + Instances of `Dialog `. Example .. code-block:: python @@ -1563,7 +1563,7 @@ class TelegramClient: If left unspecified, all draft messages will be returned. Yields - Instances of `Draft `. + Instances of `Draft `. Example .. code-block:: python @@ -1670,7 +1670,7 @@ class TelegramClient: bots will only be able to use it to leave groups and channels (trying to delete a private conversation will do nothing). - See also `Dialog.delete() `. + See also `Dialog.delete() `. Arguments entity (entities): @@ -1765,10 +1765,10 @@ class TelegramClient: ``cryptg`` (through ``pip install cryptg``) so that decrypting the received data is done in C instead of Python (much faster). - See also `Message.download_media() `. + See also `Message.download_media() `. Arguments - message (`Message ` | :tl:`Media`): + message (`Message ` | :tl:`Media`): The media or message containing the media that will be downloaded. file (`str` | `file`, optional): @@ -2186,7 +2186,7 @@ class TelegramClient: All other parameter will be ignored for this, except `entity`. Yields - Instances of `Message `. + Instances of `Message `. Example .. code-block:: python @@ -2232,7 +2232,7 @@ class TelegramClient: specified it makes sense that it should return the entirety of it. If `ids` is present in the *named* arguments and is not a list, - a single `Message ` will be + a single `Message ` will be returned for convenience instead of a list. Example @@ -2278,7 +2278,7 @@ class TelegramClient: Sends a message to the specified user, chat or channel. The default parse mode is the same as the official applications - (a custom flavour of markdown). ``**bold**, `code` or __italic__`` + (a _custom flavour of markdown). ``**bold**, `code` or __italic__`` are available. In addition you can send ``[links](https://example.com)`` and ``[mentions](@username)`` (or using IDs like in the Bot API: ``[mention](tg://user?id=123456789)``) and ``pre`` blocks with three @@ -2288,14 +2288,14 @@ class TelegramClient: is also done through this method. Simply send ``'/start data'`` to the bot. - See also `Message.respond() ` - and `Message.reply() `. + See also `Message.respond() ` + and `Message.reply() `. Arguments entity (`entity`): To who will it be sent. - message (`str` | `Message `): + message (`str` | `Message `): The message to be sent, or another message object to resend. The maximum length for a message is 35,000 bytes or 4,096 @@ -2303,7 +2303,7 @@ class TelegramClient: and you should slice them manually if the text to send is longer than said length. - reply_to (`int` | `Message `, optional): + reply_to (`int` | `Message `, optional): Whether to reply to a message or not. If an integer is provided, it should be the ID of the message that it should reply to. @@ -2344,7 +2344,7 @@ class TelegramClient: clear_draft (`bool`, optional): Whether the existing draft should be cleared or not. - buttons (`list`, `custom.Button `, :tl:`KeyboardButton`): + buttons (`list`, `_custom.Button `, :tl:`KeyboardButton`): The matrix (list of lists), row list or button to be shown after sending the message. This parameter will only work if you have signed in as a bot. You can also pass your own @@ -2378,7 +2378,7 @@ class TelegramClient: it will be scheduled to be automatically sent at a later time. - comment_to (`int` | `Message `, optional): + comment_to (`int` | `Message `, optional): Similar to ``reply_to``, but replies in the linked group of a broadcast channel instead (effectively leaving a "comment to" the specified message). @@ -2387,7 +2387,7 @@ class TelegramClient: no linked chat, `telethon.errors.sgIdInvalidError` is raised. Returns - The sent `custom.Message `. + The sent `_custom.Message `. Example .. code-block:: python @@ -2466,13 +2466,13 @@ class TelegramClient: (the "forwarded from" text), you should use `send_message` with the original message instead. This will send a copy of it. - See also `Message.forward_to() `. + See also `Message.forward_to() `. Arguments entity (`entity`): To which entity the message(s) will be forwarded. - messages (`list` | `int` | `Message `): + messages (`list` | `int` | `Message `): The message(s) to forward, or their integer IDs. from_peer (`entity`): @@ -2502,7 +2502,7 @@ class TelegramClient: at a later time. Returns - The list of forwarded `Message `, + The list of forwarded `Message `, or a single one if a list wasn't provided as input. Note that if all messages are invalid (i.e. deleted) the call @@ -2560,10 +2560,10 @@ class TelegramClient: """ Edits the given message to change its text or media. - See also `Message.edit() `. + See also `Message.edit() `. Arguments - entity (`entity` | `Message `): + entity (`entity` | `Message `): From which chat to edit the message. This can also be the message to be edited, and the entity will be inferred from it, so the next parameter will be assumed to be the @@ -2573,16 +2573,16 @@ class TelegramClient: which is the only way to edit messages that were sent after the user selects an inline query result. - message (`int` | `Message ` | `str`): + message (`int` | `Message ` | `str`): The ID of the message (or `Message - ` itself) to be edited. + ` itself) to be edited. If the `entity` was a `Message - `, then this message + `, then this message will be treated as the new text. text (`str`, optional): The new text of the message. Does nothing if the `entity` - was a `Message `. + was a `Message `. parse_mode (`object`, optional): See the `TelegramClient.parse_mode @@ -2618,7 +2618,7 @@ class TelegramClient: force_document (`bool`, optional): Whether to send the given file as a document or not. - buttons (`list`, `custom.Button `, :tl:`KeyboardButton`): + buttons (`list`, `_custom.Button `, :tl:`KeyboardButton`): The matrix (list of lists), row list or button to be shown after sending the message. This parameter will only work if you have signed in as a bot. You can also pass your own @@ -2640,7 +2640,7 @@ class TelegramClient: trying to edit a message that was sent via inline bots. Returns - The edited `Message `, + The edited `Message `, unless `entity` was a :tl:`InputBotInlineMessageID` in which case this method returns a boolean. @@ -2678,7 +2678,7 @@ class TelegramClient: """ Deletes the given messages, optionally "for everyone". - See also `Message.delete() `. + See also `Message.delete() `. .. warning:: @@ -2693,7 +2693,7 @@ class TelegramClient: be `None` for normal chats, but **must** be present for channels and megagroups. - message_ids (`list` | `int` | `Message `): + message_ids (`list` | `int` | `Message `): The IDs (or ID) or messages to be deleted. revoke (`bool`, optional): @@ -2741,13 +2741,13 @@ class TelegramClient: including such ID will be marked as read (for all messages whose ID ≤ max_id). - See also `Message.mark_read() `. + See also `Message.mark_read() `. Arguments entity (`entity`): The chat where these messages are located. - message (`list` | `Message `): + message (`list` | `Message `): Either a list of messages or a single message. max_id (`int`): @@ -2787,13 +2787,13 @@ class TelegramClient: The default behaviour is to *not* notify members, unlike the official applications. - See also `Message.pin() `. + See also `Message.pin() `. Arguments entity (`entity`): The chat where the message should be pinned. - message (`int` | `Message `): + message (`int` | `Message `): The message or the message ID to pin. If it's `None`, all messages will be unpinned instead. @@ -2826,13 +2826,13 @@ class TelegramClient: If no message ID is specified, all pinned messages will be unpinned. - See also `Message.unpin() `. + See also `Message.unpin() `. Arguments entity (`entity`): The chat where the message should be pinned. - message (`int` | `Message `): + message (`int` | `Message `): The message or the message ID to unpin. If it's `None`, all messages will be unpinned instead. @@ -3277,7 +3277,7 @@ class TelegramClient: A callback function accepting two parameters: ``(sent bytes, total)``. - reply_to (`int` | `Message `): + reply_to (`int` | `Message `): Same as `reply_to` from `send_message`. attributes (`list`, optional): @@ -3318,7 +3318,7 @@ class TelegramClient: If `True` the video will be sent as a video note, also known as a round video message. - buttons (`list`, `custom.Button `, :tl:`KeyboardButton`): + buttons (`list`, `_custom.Button `, :tl:`KeyboardButton`): The matrix (list of lists), row list or button to be shown after sending the message. This parameter will only work if you have signed in as a bot. You can also pass your own @@ -3345,7 +3345,7 @@ class TelegramClient: it will be scheduled to be automatically sent at a later time. - comment_to (`int` | `Message `, optional): + comment_to (`int` | `Message `, optional): Similar to ``reply_to``, but replies in the linked group of a broadcast channel instead (effectively leaving a "comment to" the specified message). @@ -3366,7 +3366,7 @@ class TelegramClient: as text documents, which will fail with ``TtlMediaInvalidError``. Returns - The `Message ` (or messages) + The `Message ` (or messages) containing the sent file, or messages if a list of them was passed. Example @@ -3381,7 +3381,7 @@ class TelegramClient: await client.send_file(chat, '/my/songs/song.mp3', voice_note=True) await client.send_file(chat, '/my/videos/video.mp4', video_note=True) - # Custom thumbnails + # _custom thumbnails await client.send_file(chat, '/my/documents/doc.txt', thumb='photo.jpg') # Only documents @@ -3482,7 +3482,7 @@ class TelegramClient: Returns :tl:`InputFileBig` if the file size is larger than 10MB, - `InputSizedFile ` + `InputSizedFile ` (subclass of :tl:`InputFile`) otherwise. Example diff --git a/telethon/_client/uploads.py b/telethon/_client/uploads.py index c8fbcea7..fb5bfc0c 100644 --- a/telethon/_client/uploads.py +++ b/telethon/_client/uploads.py @@ -11,7 +11,7 @@ from .._crypto import AES from .._misc import utils, helpers from .. import hints, _tl -from .._tl import custom +from ..types import _custom try: import PIL @@ -363,7 +363,7 @@ async def upload_file( if is_big: return _tl.InputFileBig(file_id, part_count, file_name) else: - return custom.InputSizedFile( + return _custom.InputSizedFile( file_id, part_count, file_name, md5=hash_md5, size=file_size ) diff --git a/telethon/_crypto/rsa.py b/telethon/_crypto/rsa.py index d1f1b588..eca09743 100644 --- a/telethon/_crypto/rsa.py +++ b/telethon/_crypto/rsa.py @@ -11,7 +11,7 @@ except ImportError: rsa = None raise ImportError('Missing module "rsa", please install via pip.') -from .. import _tl +from .._misc import tlobject # {fingerprint: (Crypto.PublicKey.RSA._RSAobj, old)} dictionary @@ -41,8 +41,8 @@ def _compute_fingerprint(key): :param key: the Crypto.RSA key. :return: its 8-bytes-long fingerprint. """ - n = _tl.TLObject.serialize_bytes(get_byte_array(key.n)) - e = _tl.TLObject.serialize_bytes(get_byte_array(key.e)) + n = tlobject.TLObject.serialize_bytes(get_byte_array(key.n)) + e = tlobject.TLObject.serialize_bytes(get_byte_array(key.e)) # Telegram uses the last 8 bytes as the fingerprint return struct.unpack(' 1: return super().filter(event) - class Event(EventCommon, custom.sendergetter.SenderGetter): + class Event(EventCommon, _custom.sendergetter.SenderGetter): """ Represents the event of a new album. Members: - messages (Sequence[`Message `]): + messages (Sequence[`Message `]): The list of messages belonging to the same album. """ def __init__(self, messages): @@ -160,7 +160,7 @@ class Album(EventBuilder): super().__init__(chat_peer=chat_peer, msg_id=message.id, broadcast=bool(message.post)) - custom.sendergetter.SenderGetter.__init__(self, message.sender_id) + _custom.sendergetter.SenderGetter.__init__(self, message.sender_id) self.messages = messages def _set_client(self, client): @@ -217,7 +217,7 @@ class Album(EventBuilder): @property def forward(self): """ - The `Forward ` + The `Forward ` information for the first message in the album if it was forwarded. """ # Each individual message in an album all reply to the same message @@ -229,7 +229,7 @@ class Album(EventBuilder): async def get_reply_message(self): """ - The `Message ` + The `Message ` that this album is replying to, or `None`. The result will be cached after its first use. diff --git a/telethon/events/callbackquery.py b/telethon/events/callbackquery.py index f850ecd5..6d8ee00d 100644 --- a/telethon/events/callbackquery.py +++ b/telethon/events/callbackquery.py @@ -4,7 +4,7 @@ import struct from .common import EventBuilder, EventCommon, name_inner_event from .._misc import utils from .. import _tl -from .._tl import custom +from ..types import _custom @name_inner_event @@ -123,7 +123,7 @@ class CallbackQuery(EventBuilder): return self.func(event) return True - class Event(EventCommon, custom.sendergetter.SenderGetter): + class Event(EventCommon, _custom.sendergetter.SenderGetter): """ Represents the event of a new callback query. @@ -141,7 +141,7 @@ class CallbackQuery(EventBuilder): """ def __init__(self, query, peer, msg_id): super().__init__(peer, msg_id=msg_id) - custom.sendergetter.SenderGetter.__init__(self, query.user_id) + _custom.sendergetter.SenderGetter.__init__(self, query.user_id) self.query = query self.data_match = None self.pattern_match = None @@ -308,7 +308,7 @@ class CallbackQuery(EventBuilder): .. note:: This method won't respect the previous message unlike - `Message.edit `, + `Message.edit `, since the message object is normally not present. """ self._client.loop.create_task(self.answer()) diff --git a/telethon/events/common.py b/telethon/events/common.py index cce243e6..405537d2 100644 --- a/telethon/events/common.py +++ b/telethon/events/common.py @@ -2,8 +2,9 @@ import abc import asyncio import warnings -from .._misc import utils -from .._tl.custom.chatgetter import ChatGetter +from .. import _tl +from .._misc import utils, tlobject +from ..types._custom.chatgetter import ChatGetter async def _into_id_set(client, chats): @@ -25,7 +26,7 @@ async def _into_id_set(client, chats): utils.get_peer_id(_tl.PeerChat(chat)), utils.get_peer_id(_tl.PeerChannel(chat)), }) - elif isinstance(chat, _tl.TLObject) and chat.SUBCLASS_OF_ID == 0x2d45687: + elif isinstance(chat, tlobject.TLObject) and chat.SUBCLASS_OF_ID == 0x2d45687: # 0x2d45687 == crc32(b'Peer') result.add(utils.get_peer_id(chat)) else: diff --git a/telethon/events/inlinequery.py b/telethon/events/inlinequery.py index f2c13d3d..0af44dd0 100644 --- a/telethon/events/inlinequery.py +++ b/telethon/events/inlinequery.py @@ -6,7 +6,7 @@ import asyncio from .common import EventBuilder, EventCommon, name_inner_event from .._misc import utils from .. import _tl -from .._tl import custom +from ..types import _custom @name_inner_event @@ -74,7 +74,7 @@ class InlineQuery(EventBuilder): return super().filter(event) - class Event(EventCommon, custom.sendergetter.SenderGetter): + class Event(EventCommon, _custom.sendergetter.SenderGetter): """ Represents the event of a new callback query. @@ -91,7 +91,7 @@ class InlineQuery(EventBuilder): """ def __init__(self, query): super().__init__(chat_peer=_tl.PeerUser(query.user_id)) - custom.sendergetter.SenderGetter.__init__(self, query.user_id) + _custom.sendergetter.SenderGetter.__init__(self, query.user_id) self.query = query self.pattern_match = None self._answered = False diff --git a/telethon/events/userupdate.py b/telethon/events/userupdate.py index 8144cadb..61db39ea 100644 --- a/telethon/events/userupdate.py +++ b/telethon/events/userupdate.py @@ -4,7 +4,7 @@ import functools from .common import EventBuilder, EventCommon, name_inner_event from .._misc import utils from .. import _tl -from .._tl import custom +from ..types import _custom # TODO Either the properties are poorly named or they should be @@ -65,7 +65,7 @@ class UserUpdate(EventBuilder): return cls.Event(update.user_id, typing=update.action) - class Event(EventCommon, custom.sendergetter.SenderGetter): + class Event(EventCommon, _custom.sendergetter.SenderGetter): """ Represents the event of a user update such as gone online, started typing, etc. @@ -87,7 +87,7 @@ class UserUpdate(EventBuilder): """ def __init__(self, peer, *, status=None, chat_peer=None, typing=None): super().__init__(chat_peer or peer) - custom.sendergetter.SenderGetter.__init__(self, utils.get_peer_id(peer)) + _custom.sendergetter.SenderGetter.__init__(self, utils.get_peer_id(peer)) self.status = status self.action = typing diff --git a/telethon/sessions/memory.py b/telethon/sessions/memory.py index 9f5314a3..82067101 100644 --- a/telethon/sessions/memory.py +++ b/telethon/sessions/memory.py @@ -1,7 +1,7 @@ from enum import Enum from .abstract import Session -from .._misc import utils +from .._misc import utils, tlobject from .. import _tl @@ -89,7 +89,7 @@ class MemorySession(Session): return id, hash, username, phone, name def _entity_to_row(self, e): - if not isinstance(e, _tl.TLObject): + if not isinstance(e, tlobject.TLObject): return try: p = utils.get_input_peer(e, allow_self=False) @@ -118,7 +118,7 @@ class MemorySession(Session): ) def _entities_to_rows(self, tlo): - if not isinstance(tlo, _tl.TLObject) and utils.is_list_like(tlo): + if not isinstance(tlo, tlobject.TLObject) and utils.is_list_like(tlo): # This may be a list of users already for instance entities = tlo else: @@ -189,7 +189,7 @@ class MemorySession(Session): return utils.get_input_peer(key) except (AttributeError, TypeError): # Not a TLObject or can't be cast into InputPeer - if isinstance(key, _tl.TLObject): + if isinstance(key, tlobject.TLObject): key = utils.get_peer_id(key) exact = True else: diff --git a/telethon/types/_core/gzippacked.py b/telethon/types/_core/gzippacked.py index fb4094e4..fd153196 100644 --- a/telethon/types/_core/gzippacked.py +++ b/telethon/types/_core/gzippacked.py @@ -1,10 +1,10 @@ import gzip import struct -from .. import TLObject +from ..._misc import tlobject -class GzipPacked(TLObject): +class GzipPacked(tlobject.TLObject): CONSTRUCTOR_ID = 0x3072cfa1 def __init__(self, data): @@ -26,7 +26,7 @@ class GzipPacked(TLObject): def __bytes__(self): return struct.pack('