Skip to content

Commit afc4bd9

Browse files
committed
Rename constructor/subclass_of_id to upper case, keep only static
1 parent b3f04fd commit afc4bd9

File tree

7 files changed

+17
-17
lines changed

7 files changed

+17
-17
lines changed

telethon/network/mtproto_sender.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _handle_rpc_result(self, msg_id, sequence, reader):
329329
if self.session.report_errors and request:
330330
error = rpc_message_to_error(
331331
reader.read_int(), reader.tgread_string(),
332-
report_method=type(request).constructor_id
332+
report_method=type(request).CONSTRUCTOR_ID
333333
)
334334
else:
335335
error = rpc_message_to_error(

telethon/telegram_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def _get_reply_to(reply_to):
581581
return reply_to
582582

583583
if isinstance(reply_to, TLObject) and \
584-
type(reply_to).subclass_of_id == 0x790009e3:
584+
type(reply_to).SUBCLASS_OF_ID == 0x790009e3:
585585
# hex(crc32(b'Message')) = 0x790009e3
586586
return reply_to.id
587587

telethon/tl/gzip_packed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class GzipPacked(TLObject):
8-
constructor_id = 0x3072cfa1
8+
CONSTRUCTOR_ID = 0x3072cfa1
99

1010
def __init__(self, data):
1111
super().__init__()
@@ -29,7 +29,7 @@ def gzip_if_smaller(request):
2929

3030
def to_bytes(self):
3131
# TODO Maybe compress level could be an option
32-
return struct.pack('<I', GzipPacked.constructor_id) + \
32+
return struct.pack('<I', GzipPacked.CONSTRUCTOR_ID) + \
3333
TLObject.serialize_bytes(gzip.compress(self.data))
3434

3535
@staticmethod

telethon/tl/message_container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
class MessageContainer(TLObject):
7-
constructor_id = 0x73f1f8dc
7+
CONSTRUCTOR_ID = 0x73f1f8dc
88

99
def __init__(self, messages):
1010
super().__init__()
@@ -13,7 +13,7 @@ def __init__(self, messages):
1313

1414
def to_bytes(self):
1515
return struct.pack(
16-
'<Ii', MessageContainer.constructor_id, len(self.messages)
16+
'<Ii', MessageContainer.CONSTRUCTOR_ID, len(self.messages)
1717
) + b''.join(m.to_bytes() for m in self.messages)
1818

1919
@staticmethod

telethon/tl/tlobject.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ def __init__(self):
99
self.rpc_error = None
1010

1111
# These should be overrode
12-
self.constructor_id = 0
1312
self.content_related = False # Only requests/functions/queries are
1413

1514
# These should not be overrode

telethon/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_input_peer(entity):
7777
if not isinstance(entity, TLObject):
7878
_raise_cast_fail(entity, 'InputPeer')
7979

80-
if type(entity).subclass_of_id == 0xc91c90b6: # crc32(b'InputPeer')
80+
if type(entity).SUBCLASS_OF_ID == 0xc91c90b6: # crc32(b'InputPeer')
8181
return entity
8282

8383
if isinstance(entity, User):
@@ -118,7 +118,7 @@ def get_input_channel(entity):
118118
if not isinstance(entity, TLObject):
119119
_raise_cast_fail(entity, 'InputChannel')
120120

121-
if type(entity).subclass_of_id == 0x40f202fd: # crc32(b'InputChannel')
121+
if type(entity).SUBCLASS_OF_ID == 0x40f202fd: # crc32(b'InputChannel')
122122
return entity
123123

124124
if isinstance(entity, Channel) or isinstance(entity, ChannelForbidden):
@@ -135,7 +135,7 @@ def get_input_user(entity):
135135
if not isinstance(entity, TLObject):
136136
_raise_cast_fail(entity, 'InputUser')
137137

138-
if type(entity).subclass_of_id == 0xe669bf46: # crc32(b'InputUser')
138+
if type(entity).SUBCLASS_OF_ID == 0xe669bf46: # crc32(b'InputUser')
139139
return entity
140140

141141
if isinstance(entity, User):
@@ -161,7 +161,7 @@ def get_input_document(document):
161161
if not isinstance(document, TLObject):
162162
_raise_cast_fail(document, 'InputDocument')
163163

164-
if type(document).subclass_of_id == 0xf33fdb68: # crc32(b'InputDocument')
164+
if type(document).SUBCLASS_OF_ID == 0xf33fdb68: # crc32(b'InputDocument')
165165
return document
166166

167167
if isinstance(document, Document):
@@ -184,7 +184,7 @@ def get_input_photo(photo):
184184
if not isinstance(photo, TLObject):
185185
_raise_cast_fail(photo, 'InputPhoto')
186186

187-
if type(photo).subclass_of_id == 0x846363e0: # crc32(b'InputPhoto')
187+
if type(photo).SUBCLASS_OF_ID == 0x846363e0: # crc32(b'InputPhoto')
188188
return photo
189189

190190
if isinstance(photo, Photo):
@@ -201,7 +201,7 @@ def get_input_geo(geo):
201201
if not isinstance(geo, TLObject):
202202
_raise_cast_fail(geo, 'InputGeoPoint')
203203

204-
if type(geo).subclass_of_id == 0x430d225: # crc32(b'InputGeoPoint')
204+
if type(geo).SUBCLASS_OF_ID == 0x430d225: # crc32(b'InputGeoPoint')
205205
return geo
206206

207207
if isinstance(geo, GeoPoint):
@@ -228,7 +228,7 @@ def get_input_media(media, user_caption=None, is_photo=False):
228228
if not isinstance(media, TLObject):
229229
_raise_cast_fail(media, 'InputMedia')
230230

231-
if type(media).subclass_of_id == 0xfaf846f4: # crc32(b'InputMedia')
231+
if type(media).SUBCLASS_OF_ID == 0xfaf846f4: # crc32(b'InputMedia')
232232
return media
233233

234234
if isinstance(media, MessageMediaPhoto):

telethon_generator/tl_generator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,10 @@ def _write_source_code(tlobject, builder, depth, type_constructors):
175175
builder.writeln('class {}(TLObject):'.format(tlobject.class_name()))
176176

177177
# Class-level variable to store its Telegram's constructor ID
178-
builder.writeln('constructor_id = {}'.format(hex(tlobject.id)))
179-
builder.writeln('subclass_of_id = {}'.format(
180-
hex(crc32(tlobject.result.encode('ascii')))))
178+
builder.writeln('CONSTRUCTOR_ID = {}'.format(hex(tlobject.id)))
179+
builder.writeln('SUBCLASS_OF_ID = {}'.format(
180+
hex(crc32(tlobject.result.encode('ascii'))))
181+
)
181182
builder.writeln()
182183

183184
# Flag arguments must go last

0 commit comments

Comments
 (0)