mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 21:24:35 +03:00
Simplify .get_input_entity code flow (since 591e34b
)
This commit is contained in:
parent
0cd44b245c
commit
3b2d065d35
|
@ -14,6 +14,7 @@ from io import BytesIO
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
|
|
||||||
from .crypto import CdnDecrypter
|
from .crypto import CdnDecrypter
|
||||||
|
from .tl import TLObject
|
||||||
from .tl.custom import InputSizedFile
|
from .tl.custom import InputSizedFile
|
||||||
from .tl.functions.upload import (
|
from .tl.functions.upload import (
|
||||||
SaveBigFilePartRequest, SaveFilePartRequest, GetFileRequest
|
SaveBigFilePartRequest, SaveFilePartRequest, GetFileRequest
|
||||||
|
@ -38,8 +39,7 @@ from .errors import (
|
||||||
RPCError, UnauthorizedError, PhoneCodeEmptyError, PhoneCodeExpiredError,
|
RPCError, UnauthorizedError, PhoneCodeEmptyError, PhoneCodeExpiredError,
|
||||||
PhoneCodeHashEmptyError, PhoneCodeInvalidError, LocationInvalidError,
|
PhoneCodeHashEmptyError, PhoneCodeInvalidError, LocationInvalidError,
|
||||||
SessionPasswordNeededError, FileMigrateError, PhoneNumberUnoccupiedError,
|
SessionPasswordNeededError, FileMigrateError, PhoneNumberUnoccupiedError,
|
||||||
PhoneNumberOccupiedError, EmailUnconfirmedError, PasswordEmptyError,
|
PhoneNumberOccupiedError, UsernameNotOccupiedError
|
||||||
UsernameNotOccupiedError
|
|
||||||
)
|
)
|
||||||
from .network import ConnectionMode
|
from .network import ConnectionMode
|
||||||
from .tl.custom import Draft, Dialog
|
from .tl.custom import Draft, Dialog
|
||||||
|
@ -2460,19 +2460,12 @@ class TelegramClient(TelegramBareClient):
|
||||||
if isinstance(peer, str):
|
if isinstance(peer, str):
|
||||||
return utils.get_input_peer(self._get_entity_from_string(peer))
|
return utils.get_input_peer(self._get_entity_from_string(peer))
|
||||||
|
|
||||||
original_peer = peer
|
if not isinstance(peer, int) and (not isinstance(peer, TLObject)
|
||||||
if not isinstance(peer, int):
|
or peer.SUBCLASS_OF_ID != 0x2d45687):
|
||||||
try:
|
# Try casting the object into an input peer. Might TypeError.
|
||||||
if getattr(peer, 'SUBCLASS_OF_ID', 0) != 0x2d45687:
|
# Don't do it if a not-found ID was given (instead ValueError).
|
||||||
# 0x2d45687 == crc32(b'Peer')
|
# Also ignore Peer (0x2d45687 == crc32(b'Peer'))'s, lacking hash.
|
||||||
return utils.get_input_peer(peer)
|
return utils.get_input_peer(peer)
|
||||||
except TypeError:
|
|
||||||
peer = None
|
|
||||||
|
|
||||||
if not peer:
|
|
||||||
raise TypeError(
|
|
||||||
'Cannot turn "{}" into an input entity.'.format(original_peer)
|
|
||||||
)
|
|
||||||
|
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Could not find the input entity corresponding to "{}". '
|
'Could not find the input entity corresponding to "{}". '
|
||||||
|
|
Loading…
Reference in New Issue
Block a user