Rename constructor/subclass_of_id to upper case, keep only static

This commit is contained in:
Lonami Exo 2017-09-29 13:11:33 +02:00
parent b3f04fd359
commit afc4bd9cab
7 changed files with 17 additions and 17 deletions

View File

@ -329,7 +329,7 @@ class MtProtoSender:
if self.session.report_errors and request:
error = rpc_message_to_error(
reader.read_int(), reader.tgread_string(),
report_method=type(request).constructor_id
report_method=type(request).CONSTRUCTOR_ID
)
else:
error = rpc_message_to_error(

View File

@ -581,7 +581,7 @@ class TelegramClient(TelegramBareClient):
return reply_to
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
return reply_to.id

View File

@ -5,7 +5,7 @@ from . import TLObject
class GzipPacked(TLObject):
constructor_id = 0x3072cfa1
CONSTRUCTOR_ID = 0x3072cfa1
def __init__(self, data):
super().__init__()
@ -29,7 +29,7 @@ class GzipPacked(TLObject):
def to_bytes(self):
# 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))
@staticmethod

View File

@ -4,7 +4,7 @@ from . import TLObject
class MessageContainer(TLObject):
constructor_id = 0x73f1f8dc
CONSTRUCTOR_ID = 0x73f1f8dc
def __init__(self, messages):
super().__init__()
@ -13,7 +13,7 @@ class MessageContainer(TLObject):
def to_bytes(self):
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)
@staticmethod

View File

@ -9,7 +9,6 @@ class TLObject:
self.rpc_error = None
# These should be overrode
self.constructor_id = 0
self.content_related = False # Only requests/functions/queries are
# These should not be overrode

View File

@ -77,7 +77,7 @@ def get_input_peer(entity):
if not isinstance(entity, TLObject):
_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
if isinstance(entity, User):
@ -118,7 +118,7 @@ def get_input_channel(entity):
if not isinstance(entity, TLObject):
_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
if isinstance(entity, Channel) or isinstance(entity, ChannelForbidden):
@ -135,7 +135,7 @@ def get_input_user(entity):
if not isinstance(entity, TLObject):
_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
if isinstance(entity, User):
@ -161,7 +161,7 @@ def get_input_document(document):
if not isinstance(document, TLObject):
_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
if isinstance(document, Document):
@ -184,7 +184,7 @@ def get_input_photo(photo):
if not isinstance(photo, TLObject):
_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
if isinstance(photo, Photo):
@ -201,7 +201,7 @@ def get_input_geo(geo):
if not isinstance(geo, TLObject):
_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
if isinstance(geo, GeoPoint):
@ -228,7 +228,7 @@ def get_input_media(media, user_caption=None, is_photo=False):
if not isinstance(media, TLObject):
_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
if isinstance(media, MessageMediaPhoto):

View File

@ -175,9 +175,10 @@ class TLGenerator:
builder.writeln('class {}(TLObject):'.format(tlobject.class_name()))
# Class-level variable to store its Telegram's constructor ID
builder.writeln('constructor_id = {}'.format(hex(tlobject.id)))
builder.writeln('subclass_of_id = {}'.format(
hex(crc32(tlobject.result.encode('ascii')))))
builder.writeln('CONSTRUCTOR_ID = {}'.format(hex(tlobject.id)))
builder.writeln('SUBCLASS_OF_ID = {}'.format(
hex(crc32(tlobject.result.encode('ascii'))))
)
builder.writeln()
# Flag arguments must go last