mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-14 05:26:36 +03:00
Make .get_input_user faster when the right type is given
This commit is contained in:
parent
279ee81bc3
commit
e7b0c06ca5
|
@ -52,9 +52,7 @@ def get_extension(media):
|
||||||
def get_input_peer(entity):
|
def get_input_peer(entity):
|
||||||
"""Gets the input peer for the given "entity" (user, chat or channel).
|
"""Gets the input peer for the given "entity" (user, chat or channel).
|
||||||
A ValueError is raised if the given entity isn't a supported type."""
|
A ValueError is raised if the given entity isn't a supported type."""
|
||||||
if any(isinstance(entity, c) for c in (
|
if type(entity).subclass_of_id == 0xc91c90b6: # crc32('InputUser')
|
||||||
InputPeerUser, InputPeerChat, InputPeerChannel,
|
|
||||||
InputPeerSelf, InputPeerEmpty)):
|
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
if isinstance(entity, User):
|
if isinstance(entity, User):
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
from zlib import crc32
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -214,6 +215,9 @@ class TLGenerator:
|
||||||
# Class-level variable to store its constructor ID
|
# Class-level variable to store its constructor ID
|
||||||
builder.writeln("# Telegram's constructor (U)ID for this class")
|
builder.writeln("# Telegram's constructor (U)ID for this class")
|
||||||
builder.writeln('constructor_id = {}'.format(hex(tlobject.id)))
|
builder.writeln('constructor_id = {}'.format(hex(tlobject.id)))
|
||||||
|
builder.writeln("# Also the ID of its resulting type for fast checks")
|
||||||
|
builder.writeln('subclass_of_id = {}'.format(
|
||||||
|
hex(crc32(tlobject.result.encode('ascii')))))
|
||||||
builder.writeln()
|
builder.writeln()
|
||||||
|
|
||||||
# Flag arguments must go last
|
# Flag arguments must go last
|
||||||
|
|
Loading…
Reference in New Issue
Block a user