@@ -68,8 +68,7 @@ def get_docstring_arg_type(t: str, is_list: bool = False, is_pyrogram_type: bool
6868
6969 t = (("e" if is_list else "E" ) + "ither " if n else "" ) + ", " .join (
7070 ":obj:`{1} <{0}.{1}>`" .format (
71- "pyrogram.types" if is_pyrogram_type else "pyrogram.api.types" ,
72- i .replace ("pyrogram." , "" )
71+ "pyrogram.types" if is_pyrogram_type else "pyrogram.api.types" , i .replace ("pyrogram." , "" )
7372 )
7473 for i in t
7574 )
@@ -87,10 +86,7 @@ def get_references(t: str):
8786 if t :
8887 n = len (t ) - 1
8988
90- t = ", " .join (
91- ":obj:`{0} <pyrogram.api.functions.{0}>`" .format (i )
92- for i in t
93- )
89+ t = ", " .join (":obj:`{0} <pyrogram.api.functions.{0}>`" .format (i ) for i in t )
9490
9591 if n :
9692 t = t .split (", " )
@@ -126,15 +122,9 @@ def get_argument_type(arg):
126122
127123
128124class Combinator :
129- def __init__ (self ,
130- section : str ,
131- namespace : str ,
132- name : str ,
133- id : str ,
134- args : list ,
135- has_flags : bool ,
136- return_type : str ,
137- docs : str ):
125+ def __init__ (
126+ self , section : str , namespace : str , name : str , id : str , args : list , has_flags : bool , return_type : str , docs : str
127+ ):
138128 self .section = section
139129 self .namespace = namespace
140130 self .name = name
@@ -170,9 +160,9 @@ def start():
170160 shutil .rmtree ("{}/types" .format (DESTINATION ), ignore_errors = True )
171161 shutil .rmtree ("{}/functions" .format (DESTINATION ), ignore_errors = True )
172162
173- 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 :
163+ with open ("{}/source/auth_key.tl" .format (HOME ), encoding = "utf-8" ) as auth , open (
164+ "{}/source/sys_msgs.tl" .format (HOME ), encoding = "utf-8"
165+ ) as system , open ("{}/source/main_api.tl" .format (HOME ), encoding = "utf-8" ) as api :
176166 schema = (auth .read () + system .read () + api .read ()).splitlines ()
177167
178168 with open ("{}/template/mtproto.txt" .format (HOME ), encoding = "utf-8" ) as f :
@@ -236,11 +226,8 @@ def start():
236226 "0x{}" .format (id .zfill (8 )),
237227 args ,
238228 has_flags ,
239- "." .join (
240- return_type .split ("." )[:- 1 ]
241- + [capit (return_type .split ("." )[- 1 ])]
242- ),
243- docs
229+ "." .join (return_type .split ("." )[:- 1 ] + [capit (return_type .split ("." )[- 1 ])]),
230+ docs ,
244231 )
245232 )
246233
@@ -267,10 +254,13 @@ def start():
267254 total = len (combinators )
268255 current = 0
269256 for c in combinators : # type: Combinator
270- print ("Compiling APIs... [{}%] {}" .format (
271- str (round (current * 100 / total )).rjust (3 ),
272- "." .join (filter (None , [c .section , c .namespace , c .name ]))
273- ), end = " \r " , flush = True )
257+ print (
258+ "Compiling APIs... [{}%] {}" .format (
259+ str (round (current * 100 / total )).rjust (3 ), "." .join (filter (None , [c .section , c .namespace , c .name ]))
260+ ),
261+ end = " \r " ,
262+ flush = True ,
263+ )
274264 current += 1
275265
276266 path = "{}/{}/{}" .format (DESTINATION , c .section , c .namespace )
@@ -287,13 +277,15 @@ def start():
287277
288278 sorted_args = sort_args (c .args )
289279
290- arguments = ", " + ", " . join (
291- [get_argument_type (i ) for i in sorted_args if i != ("flags" , "#" )]
292- ) if c . args else ""
280+ arguments = (
281+ ", " + ", " . join ( [get_argument_type (i ) for i in sorted_args if i != ("flags" , "#" )]) if c . args else ""
282+ )
293283
294- fields = "\n " .join (
295- ["self.{0} = {0} # {1}" .format (i [0 ], i [1 ]) for i in c .args if i != ("flags" , "#" )]
296- ) if c .args else "pass"
284+ fields = (
285+ "\n " .join (["self.{0} = {0} # {1}" .format (i [0 ], i [1 ]) for i in c .args if i != ("flags" , "#" )])
286+ if c .args
287+ else "pass"
288+ )
297289
298290 docstring_args = []
299291 docs = c .docs .split ("|" )[1 :] if c .docs else None
@@ -313,15 +305,15 @@ def start():
313305 arg_name ,
314306 get_docstring_arg_type (arg_type , is_pyrogram_type = True ),
315307 ", optional" if "Optional" in docs [i ] else "" ,
316- re .sub ("Optional\. " , "" , docs [i ].split ("§" )[1 ].rstrip ("." ) + "." )
308+ re .sub ("Optional\. " , "" , docs [i ].split ("§" )[1 ].rstrip ("." ) + "." ),
317309 )
318310 )
319311 else :
320312 docstring_args .append (
321313 "{}{}: {}" .format (
322314 arg_name ,
323315 " (optional)" .format (flag_number ) if is_optional else "" ,
324- get_docstring_arg_type (arg_type , is_pyrogram_type = c .namespace == "pyrogram" )
316+ get_docstring_arg_type (arg_type , is_pyrogram_type = c .namespace == "pyrogram" ),
325317 )
326318 )
327319
@@ -353,13 +345,12 @@ def start():
353345 flag = FLAGS_RE .match (i [1 ])
354346 if flag :
355347 write_flags .append (
356- "flags |= (1 << {}) if self.{} is not None else 0" .format (flag .group (1 ), i [0 ]))
348+ "flags |= (1 << {}) if self.{} is not None else 0" .format (flag .group (1 ), i [0 ])
349+ )
357350
358- write_flags = "\n " .join ([
359- "flags = 0" ,
360- "\n " .join (write_flags ),
361- "b.write(Int(flags))\n "
362- ])
351+ write_flags = "\n " .join (
352+ ["flags = 0" , "\n " .join (write_flags ), "b.write(Int(flags))\n " ]
353+ )
363354
364355 write_types += write_flags
365356 read_types += "flags = Int.read(b)\n "
@@ -400,9 +391,7 @@ def start():
400391 write_types += "b.write(self.{}.write())\n " .format (arg_name )
401392
402393 read_types += "\n "
403- read_types += "{} = Object.read(b) if flags & (1 << {}) else None\n " .format (
404- arg_name , index
405- )
394+ read_types += "{} = Object.read(b) if flags & (1 << {}) else None\n " .format (arg_name , index )
406395 else :
407396 if arg_type in core_types :
408397 write_types += "\n "
@@ -442,7 +431,7 @@ def start():
442431 docstring_args = docstring_args ,
443432 object_id = c .id ,
444433 arguments = arguments ,
445- fields = fields
434+ fields = fields ,
446435 )
447436 )
448437 else :
@@ -456,7 +445,7 @@ def start():
456445 fields = fields ,
457446 read_types = read_types ,
458447 write_types = write_types ,
459- return_arguments = ", " .join ([i [0 ] for i in sorted_args if i != ("flags" , "#" )])
448+ return_arguments = ", " .join ([i [0 ] for i in sorted_args if i != ("flags" , "#" )]),
460449 )
461450 )
462451
@@ -467,17 +456,17 @@ def start():
467456
468457 for c in combinators :
469458 path = "." .join (filter (None , [c .section , c .namespace , capit (c .name )]))
470- f .write (" \n {}: \ " pyrogram.api.{}\" ," .format (c .id , path ))
471-
472- f .write (" \n 0xbc799737: \ " pyrogram.api.core.BoolFalse\" ," )
473- f .write (" \n 0x997275b5: \ " pyrogram.api.core.BoolTrue\" ," )
474- f .write (" \n 0x56730bcc: \ " pyrogram.api.core.Null\" ," )
475- f .write (" \n 0x1cb5c415: \ " pyrogram.api.core.Vector\" ," )
476- f .write (" \n 0x73f1f8dc: \ " pyrogram.api.core.MsgContainer\" ," )
477- f .write (" \n 0xae500895: \ " pyrogram.api.core.FutureSalts\" ," )
478- f .write (" \n 0x0949d9dc: \ " pyrogram.api.core.FutureSalt\" ," )
479- f .write (" \n 0x3072cfa1: \ " pyrogram.api.core.GzipPacked\" ," )
480- f .write (" \n 0x5bb8e511: \ " pyrogram.api.core.Message\" ," )
459+ f .write (' \n {}: "pyrogram.api.{}",' .format (c .id , path ))
460+
461+ f .write (' \n 0xbc799737: "pyrogram.api.core.BoolFalse",' )
462+ f .write (' \n 0x997275b5: "pyrogram.api.core.BoolTrue",' )
463+ f .write (' \n 0x56730bcc: "pyrogram.api.core.Null",' )
464+ f .write (' \n 0x1cb5c415: "pyrogram.api.core.Vector",' )
465+ f .write (' \n 0x73f1f8dc: "pyrogram.api.core.MsgContainer",' )
466+ f .write (' \n 0xae500895: "pyrogram.api.core.FutureSalts",' )
467+ f .write (' \n 0x0949d9dc: "pyrogram.api.core.FutureSalt",' )
468+ f .write (' \n 0x3072cfa1: "pyrogram.api.core.GzipPacked",' )
469+ f .write (' \n 0x5bb8e511: "pyrogram.api.core.Message",' )
481470
482471 f .write ("\n }\n " )
483472
0 commit comments