mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-03-21 18:34:43 +03:00
Rename constructor/subclass_of_id to upper case, keep only static
This commit is contained in:
parent
b3f04fd359
commit
afc4bd9cab
|
@ -329,7 +329,7 @@ class MtProtoSender:
|
||||||
if self.session.report_errors and request:
|
if self.session.report_errors and request:
|
||||||
error = rpc_message_to_error(
|
error = rpc_message_to_error(
|
||||||
reader.read_int(), reader.tgread_string(),
|
reader.read_int(), reader.tgread_string(),
|
||||||
report_method=type(request).constructor_id
|
report_method=type(request).CONSTRUCTOR_ID
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
error = rpc_message_to_error(
|
error = rpc_message_to_error(
|
||||||
|
|
|
@ -581,7 +581,7 @@ class TelegramClient(TelegramBareClient):
|
||||||
return reply_to
|
return reply_to
|
||||||
|
|
||||||
if isinstance(reply_to, TLObject) and \
|
if isinstance(reply_to, TLObject) and \
|
||||||
type(reply_to).subclass_of_id == 0x790009e3:
|
type(reply_to).SUBCLASS_OF_ID == 0x790009e3:
|
||||||
# hex(crc32(b'Message')) = 0x790009e3
|
# hex(crc32(b'Message')) = 0x790009e3
|
||||||
return reply_to.id
|
return reply_to.id
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ from . import TLObject
|
||||||
|
|
||||||
|
|
||||||
class GzipPacked(TLObject):
|
class GzipPacked(TLObject):
|
||||||
constructor_id = 0x3072cfa1
|
CONSTRUCTOR_ID = 0x3072cfa1
|
||||||
|
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -29,7 +29,7 @@ class GzipPacked(TLObject):
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
# TODO Maybe compress level could be an option
|
# TODO Maybe compress level could be an option
|
||||||
return struct.pack('<I', GzipPacked.constructor_id) + \
|
return struct.pack('<I', GzipPacked.CONSTRUCTOR_ID) + \
|
||||||
TLObject.serialize_bytes(gzip.compress(self.data))
|
TLObject.serialize_bytes(gzip.compress(self.data))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -4,7 +4,7 @@ from . import TLObject
|
||||||
|
|
||||||
|
|
||||||
class MessageContainer(TLObject):
|
class MessageContainer(TLObject):
|
||||||
constructor_id = 0x73f1f8dc
|
CONSTRUCTOR_ID = 0x73f1f8dc
|
||||||
|
|
||||||
def __init__(self, messages):
|
def __init__(self, messages):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -13,7 +13,7 @@ class MessageContainer(TLObject):
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
return struct.pack(
|
return struct.pack(
|
||||||
'<Ii', MessageContainer.constructor_id, len(self.messages)
|
'<Ii', MessageContainer.CONSTRUCTOR_ID, len(self.messages)
|
||||||
) + b''.join(m.to_bytes() for m in self.messages)
|
) + b''.join(m.to_bytes() for m in self.messages)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -9,7 +9,6 @@ class TLObject:
|
||||||
self.rpc_error = None
|
self.rpc_error = None
|
||||||
|
|
||||||
# These should be overrode
|
# These should be overrode
|
||||||
self.constructor_id = 0
|
|
||||||
self.content_related = False # Only requests/functions/queries are
|
self.content_related = False # Only requests/functions/queries are
|
||||||
|
|
||||||
# These should not be overrode
|
# These should not be overrode
|
||||||
|
|
|
@ -77,7 +77,7 @@ def get_input_peer(entity):
|
||||||
if not isinstance(entity, TLObject):
|
if not isinstance(entity, TLObject):
|
||||||
_raise_cast_fail(entity, 'InputPeer')
|
_raise_cast_fail(entity, 'InputPeer')
|
||||||
|
|
||||||
if type(entity).subclass_of_id == 0xc91c90b6: # crc32(b'InputPeer')
|
if type(entity).SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer')
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
if isinstance(entity, User):
|
if isinstance(entity, User):
|
||||||
|
@ -118,7 +118,7 @@ def get_input_channel(entity):
|
||||||
if not isinstance(entity, TLObject):
|
if not isinstance(entity, TLObject):
|
||||||
_raise_cast_fail(entity, 'InputChannel')
|
_raise_cast_fail(entity, 'InputChannel')
|
||||||
|
|
||||||
if type(entity).subclass_of_id == 0x40f202fd: # crc32(b'InputChannel')
|
if type(entity).SUBCLASS_OF_ID == 0x40f202fd: # crc32(b'InputChannel')
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
if isinstance(entity, Channel) or isinstance(entity, ChannelForbidden):
|
if isinstance(entity, Channel) or isinstance(entity, ChannelForbidden):
|
||||||
|
@ -135,7 +135,7 @@ def get_input_user(entity):
|
||||||
if not isinstance(entity, TLObject):
|
if not isinstance(entity, TLObject):
|
||||||
_raise_cast_fail(entity, 'InputUser')
|
_raise_cast_fail(entity, 'InputUser')
|
||||||
|
|
||||||
if type(entity).subclass_of_id == 0xe669bf46: # crc32(b'InputUser')
|
if type(entity).SUBCLASS_OF_ID == 0xe669bf46: # crc32(b'InputUser')
|
||||||
return entity
|
return entity
|
||||||
|
|
||||||
if isinstance(entity, User):
|
if isinstance(entity, User):
|
||||||
|
@ -161,7 +161,7 @@ def get_input_document(document):
|
||||||
if not isinstance(document, TLObject):
|
if not isinstance(document, TLObject):
|
||||||
_raise_cast_fail(document, 'InputDocument')
|
_raise_cast_fail(document, 'InputDocument')
|
||||||
|
|
||||||
if type(document).subclass_of_id == 0xf33fdb68: # crc32(b'InputDocument')
|
if type(document).SUBCLASS_OF_ID == 0xf33fdb68: # crc32(b'InputDocument')
|
||||||
return document
|
return document
|
||||||
|
|
||||||
if isinstance(document, Document):
|
if isinstance(document, Document):
|
||||||
|
@ -184,7 +184,7 @@ def get_input_photo(photo):
|
||||||
if not isinstance(photo, TLObject):
|
if not isinstance(photo, TLObject):
|
||||||
_raise_cast_fail(photo, 'InputPhoto')
|
_raise_cast_fail(photo, 'InputPhoto')
|
||||||
|
|
||||||
if type(photo).subclass_of_id == 0x846363e0: # crc32(b'InputPhoto')
|
if type(photo).SUBCLASS_OF_ID == 0x846363e0: # crc32(b'InputPhoto')
|
||||||
return photo
|
return photo
|
||||||
|
|
||||||
if isinstance(photo, Photo):
|
if isinstance(photo, Photo):
|
||||||
|
@ -201,7 +201,7 @@ def get_input_geo(geo):
|
||||||
if not isinstance(geo, TLObject):
|
if not isinstance(geo, TLObject):
|
||||||
_raise_cast_fail(geo, 'InputGeoPoint')
|
_raise_cast_fail(geo, 'InputGeoPoint')
|
||||||
|
|
||||||
if type(geo).subclass_of_id == 0x430d225: # crc32(b'InputGeoPoint')
|
if type(geo).SUBCLASS_OF_ID == 0x430d225: # crc32(b'InputGeoPoint')
|
||||||
return geo
|
return geo
|
||||||
|
|
||||||
if isinstance(geo, GeoPoint):
|
if isinstance(geo, GeoPoint):
|
||||||
|
@ -228,7 +228,7 @@ def get_input_media(media, user_caption=None, is_photo=False):
|
||||||
if not isinstance(media, TLObject):
|
if not isinstance(media, TLObject):
|
||||||
_raise_cast_fail(media, 'InputMedia')
|
_raise_cast_fail(media, 'InputMedia')
|
||||||
|
|
||||||
if type(media).subclass_of_id == 0xfaf846f4: # crc32(b'InputMedia')
|
if type(media).SUBCLASS_OF_ID == 0xfaf846f4: # crc32(b'InputMedia')
|
||||||
return media
|
return media
|
||||||
|
|
||||||
if isinstance(media, MessageMediaPhoto):
|
if isinstance(media, MessageMediaPhoto):
|
||||||
|
|
|
@ -175,9 +175,10 @@ class TLGenerator:
|
||||||
builder.writeln('class {}(TLObject):'.format(tlobject.class_name()))
|
builder.writeln('class {}(TLObject):'.format(tlobject.class_name()))
|
||||||
|
|
||||||
# Class-level variable to store its Telegram's constructor ID
|
# Class-level variable to store its Telegram's constructor ID
|
||||||
builder.writeln('constructor_id = {}'.format(hex(tlobject.id)))
|
builder.writeln('CONSTRUCTOR_ID = {}'.format(hex(tlobject.id)))
|
||||||
builder.writeln('subclass_of_id = {}'.format(
|
builder.writeln('SUBCLASS_OF_ID = {}'.format(
|
||||||
hex(crc32(tlobject.result.encode('ascii')))))
|
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