11# Pyrogram - Telegram MTProto API Client Library for Python
2- # Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
2+ # Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
33#
44# This file is part of Pyrogram.
55#
2626SECTION_RE = re .compile (r"---(\w+)---" )
2727LAYER_RE = re .compile (r"//\sLAYER\s(\d+)" )
2828COMBINATOR_RE = re .compile (r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);(?: // Docs: (.+))?$" , re .MULTILINE )
29- ARGS_RE = re .compile ("[^{](\w+):([\w?!.<>]+)" )
29+ ARGS_RE = re .compile ("[^{](\w+):([\w?!.<># ]+)" )
3030FLAGS_RE = re .compile (r"flags\.(\d+)\?" )
3131FLAGS_RE_2 = re .compile (r"flags\.(\d+)\?([\w<>.]+)" )
3232FLAGS_RE_3 = re .compile (r"flags:#" )
@@ -171,8 +171,8 @@ def start():
171171 shutil .rmtree ("{}/functions" .format (DESTINATION ), ignore_errors = True )
172172
173173 with open ("{}/source/auth_key.tl" .format (HOME ), encoding = "utf-8" ) as auth , \
174- open ("{}/source/sys_msgs.tl" .format (HOME ), encoding = "utf-8" ) as system , \
175- open ("{}/source/main_api.tl" .format (HOME ), encoding = "utf-8" ) as api :
174+ open ("{}/source/sys_msgs.tl" .format (HOME ), encoding = "utf-8" ) as system , \
175+ open ("{}/source/main_api.tl" .format (HOME ), encoding = "utf-8" ) as api :
176176 schema = (auth .read () + system .read () + api .read ()).splitlines ()
177177
178178 with open ("{}/template/mtproto.txt" .format (HOME ), encoding = "utf-8" ) as f :
@@ -287,18 +287,23 @@ def start():
287287
288288 sorted_args = sort_args (c .args )
289289
290- arguments = ", " + ", " .join (
291- [get_argument_type (i ) for i in sorted_args ]
292- ) if c .args else ""
290+ arguments = (
291+ ", "
292+ + ("*, " if c .args else "" )
293+ + (", " .join ([get_argument_type (i ) for i in sorted_args if i != ("flags" , "#" )]) if c .args else "" )
294+ )
293295
294296 fields = "\n " .join (
295- ["self.{0} = {0} # {1}" .format (i [0 ], i [1 ]) for i in c .args ]
297+ ["self.{0} = {0} # {1}" .format (i [0 ], i [1 ]) for i in c .args if i != ( "flags" , "#" ) ]
296298 ) if c .args else "pass"
297299
298300 docstring_args = []
299301 docs = c .docs .split ("|" )[1 :] if c .docs else None
300302
301303 for i , arg in enumerate (sorted_args ):
304+ if arg == ("flags" , "#" ):
305+ continue
306+
302307 arg_name , arg_type = arg
303308 is_optional = FLAGS_RE .match (arg_type )
304309 flag_number = is_optional .group (1 ) if is_optional else - 1
@@ -338,28 +343,31 @@ def start():
338343 if references :
339344 docstring_args += "\n \n See Also:\n This object can be returned by " + references + "."
340345
341- if c .has_flags :
342- write_flags = []
343- for i in c .args :
344- flag = FLAGS_RE .match (i [1 ])
345- if flag :
346- write_flags .append ("flags |= (1 << {}) if self.{} is not None else 0" .format (flag .group (1 ), i [0 ]))
347-
348- write_flags = "\n " .join ([
349- "flags = 0" ,
350- "\n " .join (write_flags ),
351- "b.write(Int(flags))"
352- ])
353- else :
354- write_flags = "# No flags"
355-
356- read_flags = "flags = Int.read(b)" if c .has_flags else "# No flags"
357-
358- write_types = read_types = ""
346+ write_types = read_types = "" if c .has_flags else "# No flags\n "
359347
360348 for arg_name , arg_type in c .args :
361349 flag = FLAGS_RE_2 .findall (arg_type )
362350
351+ if arg_name == "flags" and arg_type == "#" :
352+ write_flags = []
353+
354+ for i in c .args :
355+ flag = FLAGS_RE .match (i [1 ])
356+ if flag :
357+ write_flags .append (
358+ "flags |= (1 << {}) if self.{} is not None else 0" .format (flag .group (1 ), i [0 ]))
359+
360+ write_flags = "\n " .join ([
361+ "flags = 0" ,
362+ "\n " .join (write_flags ),
363+ "b.write(Int(flags))\n "
364+ ])
365+
366+ write_types += write_flags
367+ read_types += "flags = Int.read(b)\n "
368+
369+ continue
370+
363371 if flag :
364372 index , flag_type = flag [0 ]
365373
@@ -448,11 +456,13 @@ def start():
448456 object_id = c .id ,
449457 arguments = arguments ,
450458 fields = fields ,
451- read_flags = read_flags ,
452459 read_types = read_types ,
453- write_flags = write_flags ,
454460 write_types = write_types ,
455- return_arguments = ", " .join ([i [0 ] for i in sorted_args ])
461+ return_arguments = ", " .join (
462+ ["{0}={0}" .format (i [0 ]) for i in sorted_args if i != ("flags" , "#" )]
463+ ),
464+ slots = ", " .join (['"{}"' .format (i [0 ]) for i in sorted_args if i != ("flags" , "#" )]),
465+ qualname = "{}{}" .format ("{}." .format (c .namespace ) if c .namespace else "" , c .name )
456466 )
457467 )
458468
@@ -475,40 +485,6 @@ def start():
475485 f .write ("\n 0x3072cfa1: \" pyrogram.api.core.GzipPacked\" ," )
476486 f .write ("\n 0x5bb8e511: \" pyrogram.api.core.Message\" ," )
477487
478- f .write ("\n 0xb0700000: \" pyrogram.client.types.Update\" ," )
479- f .write ("\n 0xb0700001: \" pyrogram.client.types.User\" ," )
480- f .write ("\n 0xb0700002: \" pyrogram.client.types.Chat\" ," )
481- f .write ("\n 0xb0700003: \" pyrogram.client.types.Message\" ," )
482- f .write ("\n 0xb0700004: \" pyrogram.client.types.MessageEntity\" ," )
483- f .write ("\n 0xb0700005: \" pyrogram.client.types.PhotoSize\" ," )
484- f .write ("\n 0xb0700006: \" pyrogram.client.types.Audio\" ," )
485- f .write ("\n 0xb0700007: \" pyrogram.client.types.Document\" ," )
486- f .write ("\n 0xb0700008: \" pyrogram.client.types.Video\" ," )
487- f .write ("\n 0xb0700009: \" pyrogram.client.types.Voice\" ," )
488- f .write ("\n 0xb0700010: \" pyrogram.client.types.VideoNote\" ," )
489- f .write ("\n 0xb0700011: \" pyrogram.client.types.Contact\" ," )
490- f .write ("\n 0xb0700012: \" pyrogram.client.types.Location\" ," )
491- f .write ("\n 0xb0700013: \" pyrogram.client.types.Venue\" ," )
492- f .write ("\n 0xb0700014: \" pyrogram.client.types.UserProfilePhotos\" ," )
493- f .write ("\n 0xb0700015: \" pyrogram.client.types.ChatPhoto\" ," )
494- f .write ("\n 0xb0700016: \" pyrogram.client.types.ChatMember\" ," )
495- f .write ("\n 0xb0700017: \" pyrogram.client.types.Sticker\" ," )
496- f .write ("\n 0xb0700018: \" pyrogram.client.types.bots.ForceReply\" ," )
497- f .write ("\n 0xb0700019: \" pyrogram.client.types.bots.InlineKeyboardButton\" ," )
498- f .write ("\n 0xb0700020: \" pyrogram.client.types.bots.InlineKeyboardMarkup\" ," )
499- f .write ("\n 0xb0700021: \" pyrogram.client.types.bots.KeyboardButton\" ," )
500- f .write ("\n 0xb0700022: \" pyrogram.client.types.bots.ReplyKeyboardMarkup\" ," )
501- f .write ("\n 0xb0700023: \" pyrogram.client.types.bots.ReplyKeyboardRemove\" ," )
502- f .write ("\n 0xb0700024: \" pyrogram.client.types.CallbackQuery\" ," )
503- f .write ("\n 0xb0700025: \" pyrogram.client.types.Animation\" ," )
504- f .write ("\n 0xb0700026: \" pyrogram.client.types.Messages\" ," )
505- f .write ("\n 0xb0700027: \" pyrogram.client.types.Photo\" ," )
506- f .write ("\n 0xb0700028: \" pyrogram.client.types.Dialog\" ," )
507- f .write ("\n 0xb0700029: \" pyrogram.client.types.Dialogs\" ," )
508- f .write ("\n 0xb0700030: \" pyrogram.client.types.ChatMembers\" ," )
509- f .write ("\n 0xb0700031: \" pyrogram.client.types.UserStatus\" ," )
510- f .write ("\n 0xb0700032: \" pyrogram.client.types.InlineQuery\" " )
511-
512488 f .write ("\n }\n " )
513489
514490 for k , v in namespaces .items ():
0 commit comments