34
34
35
35
SECTION_RE = re .compile (r"---(\w+)---" )
36
36
LAYER_RE = re .compile (r"//\sLAYER\s(\d+)" )
37
- COMBINATOR_RE = re .compile (r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);$" , re .MULTILINE )
37
+ COMBINATOR_RE = re .compile (
38
+ r"^([\w.]+)#([0-9a-f]+)\s(?:.*)=\s([\w<>.]+);$" , re .MULTILINE
39
+ )
38
40
ARGS_RE = re .compile (r"[^{](\w+):([\w?!.<>#]+)" )
39
41
FLAGS_RE = re .compile (r"flags(\d?)\.(\d+)\?" )
40
42
FLAGS_RE_2 = re .compile (r"flags(\d?)\.(\d+)\?([\w<>.]+)" )
41
43
FLAGS_RE_3 = re .compile (r"flags(\d?):#" )
42
44
INT_RE = re .compile (r"int(\d+)" )
43
45
44
- CORE_TYPES = ["int" , "long" , "int128" , "int256" , "double" , "bytes" , "string" , "Bool" , "true" ]
46
+ CORE_TYPES = [
47
+ "int" ,
48
+ "long" ,
49
+ "int128" ,
50
+ "int256" ,
51
+ "double" ,
52
+ "bytes" ,
53
+ "string" ,
54
+ "Bool" ,
55
+ "true" ,
56
+ ]
45
57
46
58
WARNING = """
47
59
# # # # # # # # # # # # # # # # # # # # # # # #
65
77
with open ("docs.json" ) as f :
66
78
docs = json .load (f )
67
79
except FileNotFoundError :
68
- docs = {
69
- "type" : {},
70
- "constructor" : {},
71
- "method" : {}
72
- }
80
+ docs = {"type" : {}, "constructor" : {}, "method" : {}}
73
81
74
82
75
83
class Combinator (NamedTuple ):
@@ -206,13 +214,14 @@ def start(format: bool = False):
206
214
shutil .rmtree (DESTINATION_PATH / "functions" , ignore_errors = True )
207
215
shutil .rmtree (DESTINATION_PATH / "base" , ignore_errors = True )
208
216
209
- with open (HOME_PATH / "source/auth_key.tl" ) as f1 , \
210
- open ( HOME_PATH / "source/sys_msgs.tl" ) as f2 , \
211
- open (HOME_PATH / "source/main_api.tl" ) as f3 :
217
+ with open (HOME_PATH / "source/auth_key.tl" ) as f1 , open (
218
+ HOME_PATH / "source/sys_msgs.tl"
219
+ ) as f2 , open (HOME_PATH / "source/main_api.tl" ) as f3 :
212
220
schema = (f1 .read () + f2 .read () + f3 .read ()).splitlines ()
213
221
214
- with open (HOME_PATH / "template/type.txt" ) as f1 , \
215
- open (HOME_PATH / "template/combinator.txt" ) as f2 :
222
+ with open (HOME_PATH / "template/type.txt" ) as f1 , open (
223
+ HOME_PATH / "template/combinator.txt"
224
+ ) as f2 :
216
225
type_tmpl = f1 .read ()
217
226
combinator_tmpl = f2 .read ()
218
227
@@ -277,7 +286,7 @@ def start(format: bool = False):
277
286
args = args ,
278
287
qualtype = qualtype ,
279
288
typespace = typespace ,
280
- type = type
289
+ type = type ,
281
290
)
282
291
283
292
combinators .append (combinator )
@@ -338,22 +347,26 @@ def start(format: bool = False):
338
347
339
348
docstring = type_docs
340
349
341
- docstring += f"\n \n Constructors:\n " \
342
- f" This base type has { constr_count } constructor{ 's' if constr_count > 1 else '' } available.\n \n " \
343
- f" .. currentmodule:: pyrogram.raw.types\n \n " \
344
- f" .. autosummary::\n " \
345
- f" :nosignatures:\n \n " \
346
- f" { items } "
350
+ docstring += (
351
+ f"\n \n Constructors:\n "
352
+ f" This base type has { constr_count } constructor{ 's' if constr_count > 1 else '' } available.\n \n "
353
+ f" .. currentmodule:: pyrogram.raw.types\n \n "
354
+ f" .. autosummary::\n "
355
+ f" :nosignatures:\n \n "
356
+ f" { items } "
357
+ )
347
358
348
359
references , ref_count = get_references (qualtype , "types" )
349
360
350
361
if references :
351
- docstring += f"\n \n Functions:\n This object can be returned by " \
352
- f"{ ref_count } function{ 's' if ref_count > 1 else '' } .\n \n " \
353
- f" .. currentmodule:: pyrogram.raw.functions\n \n " \
354
- f" .. autosummary::\n " \
355
- f" :nosignatures:\n \n " \
356
- f" " + references
362
+ docstring += (
363
+ f"\n \n Functions:\n This object can be returned by "
364
+ f"{ ref_count } function{ 's' if ref_count > 1 else '' } .\n \n "
365
+ f" .. currentmodule:: pyrogram.raw.functions\n \n "
366
+ f" .. autosummary::\n "
367
+ f" :nosignatures:\n \n "
368
+ f" " + references
369
+ )
357
370
358
371
with open (dir_path / f"{ snake (module )} .py" , "w" ) as f :
359
372
f .write (
@@ -364,25 +377,24 @@ def start(format: bool = False):
364
377
name = type ,
365
378
qualname = qualtype ,
366
379
types = ", " .join ([f"raw.types.{ c } " for c in constructors ]),
367
- doc_name = snake (type ).replace ("_" , "-" )
380
+ doc_name = snake (type ).replace ("_" , "-" ),
368
381
)
369
382
)
370
383
371
384
for c in combinators :
372
385
sorted_args = sort_args (c .args )
373
386
374
- arguments = (
375
- (", *, " if c .args else "" ) +
376
- (", " .join (
377
- [f"{ i [0 ]} : { get_type_hint (i [1 ])} "
378
- for i in sorted_args ]
379
- ) if sorted_args else "" )
387
+ arguments = (", *, " if c .args else "" ) + (
388
+ ", " .join ([f"{ i [0 ]} : { get_type_hint (i [1 ])} " for i in sorted_args ])
389
+ if sorted_args
390
+ else ""
380
391
)
381
392
382
- fields = "\n " .join (
383
- [f"self.{ i [0 ]} = { i [0 ]} # { i [1 ]} "
384
- for i in sorted_args ]
385
- ) if sorted_args else "pass"
393
+ fields = (
394
+ "\n " .join ([f"self.{ i [0 ]} = { i [0 ]} # { i [1 ]} " for i in sorted_args ])
395
+ if sorted_args
396
+ else "pass"
397
+ )
386
398
387
399
docstring = ""
388
400
docstring_args = []
@@ -410,7 +422,7 @@ def start(format: bool = False):
410
422
arg_name ,
411
423
get_docstring_arg_type (arg_type ),
412
424
", *optional*" .format (flag_number ) if is_optional else "" ,
413
- arg_docs
425
+ arg_docs ,
414
426
)
415
427
)
416
428
@@ -433,21 +445,26 @@ def start(format: bool = False):
433
445
docstring += f"Telegram API function."
434
446
435
447
docstring += f"\n \n Details:\n - Layer: ``{ layer } ``\n - ID: ``{ c .id [2 :].upper ()} ``\n \n "
436
- docstring += f" Parameters:\n " + \
437
- (f"\n " .join (docstring_args ) if docstring_args else "No parameters required.\n " )
448
+ docstring += f" Parameters:\n " + (
449
+ f"\n " .join (docstring_args )
450
+ if docstring_args
451
+ else "No parameters required.\n "
452
+ )
438
453
439
454
if c .section == "functions" :
440
455
docstring += "\n Returns:\n " + get_docstring_arg_type (c .qualtype )
441
456
else :
442
457
references , count = get_references (c .qualname , "constructors" )
443
458
444
459
if references :
445
- docstring += f"\n Functions:\n This object can be returned by " \
446
- f"{ count } function{ 's' if count > 1 else '' } .\n \n " \
447
- f" .. currentmodule:: pyrogram.raw.functions\n \n " \
448
- f" .. autosummary::\n " \
449
- f" :nosignatures:\n \n " \
450
- f" " + references
460
+ docstring += (
461
+ f"\n Functions:\n This object can be returned by "
462
+ f"{ count } function{ 's' if count > 1 else '' } .\n \n "
463
+ f" .. currentmodule:: pyrogram.raw.functions\n \n "
464
+ f" .. autosummary::\n "
465
+ f" :nosignatures:\n \n "
466
+ f" " + references
467
+ )
451
468
452
469
write_types = read_types = "" if c .has_flags else "# No flags\n "
453
470
@@ -464,17 +481,24 @@ def start(format: bool = False):
464
481
if arg_name != f"flags{ flag .group (1 )} " :
465
482
continue
466
483
467
- if flag .group (3 ) == "true" or flag .group (3 ).startswith ("Vector" ):
468
- write_flags .append (f"{ arg_name } |= (1 << { flag .group (2 )} ) if self.{ i [0 ]} else 0" )
484
+ if flag .group (3 ) == "true" or flag .group (3 ).startswith (
485
+ "Vector"
486
+ ):
487
+ write_flags .append (
488
+ f"{ arg_name } |= (1 << { flag .group (2 )} ) if self.{ i [0 ]} else 0"
489
+ )
469
490
else :
470
491
write_flags .append (
471
- f"{ arg_name } |= (1 << { flag .group (2 )} ) if self.{ i [0 ]} is not None else 0" )
472
-
473
- write_flags = "\n " .join ([
474
- f"{ arg_name } = 0" ,
475
- "\n " .join (write_flags ),
476
- f"b.write(Int({ arg_name } ))\n "
477
- ])
492
+ f"{ arg_name } |= (1 << { flag .group (2 )} ) if self.{ i [0 ]} is not None else 0"
493
+ )
494
+
495
+ write_flags = "\n " .join (
496
+ [
497
+ f"{ arg_name } = 0" ,
498
+ "\n " .join (write_flags ),
499
+ f"b.write(Int({ arg_name } ))\n " ,
500
+ ]
501
+ )
478
502
479
503
write_types += write_flags
480
504
read_types += f"\n { arg_name } = Int.read(b)\n "
@@ -490,7 +514,9 @@ def start(format: bool = False):
490
514
elif flag_type in CORE_TYPES :
491
515
write_types += "\n "
492
516
write_types += f"if self.{ arg_name } is not None:\n "
493
- write_types += f"b.write({ flag_type .title ()} (self.{ arg_name } ))\n "
517
+ write_types += (
518
+ f"b.write({ flag_type .title ()} (self.{ arg_name } ))\n "
519
+ )
494
520
495
521
read_types += "\n "
496
522
read_types += f"{ arg_name } = { flag_type .title ()} .read(b) if flags{ number } & (1 << { index } ) else None"
@@ -500,12 +526,16 @@ def start(format: bool = False):
500
526
write_types += "\n "
501
527
write_types += f"if self.{ arg_name } is not None:\n "
502
528
write_types += "b.write(Vector(self.{}{}))\n " .format (
503
- arg_name , f", { sub_type .title ()} " if sub_type in CORE_TYPES else ""
529
+ arg_name ,
530
+ f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
504
531
)
505
532
506
533
read_types += "\n "
507
534
read_types += "{} = TLObject.read(b{}) if flags{} & (1 << {}) else []\n " .format (
508
- arg_name , f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" , number , index
535
+ arg_name ,
536
+ f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
537
+ number ,
538
+ index ,
509
539
)
510
540
else :
511
541
write_types += "\n "
@@ -517,7 +547,9 @@ def start(format: bool = False):
517
547
else :
518
548
if arg_type in CORE_TYPES :
519
549
write_types += "\n "
520
- write_types += f"b.write({ arg_type .title ()} (self.{ arg_name } ))\n "
550
+ write_types += (
551
+ f"b.write({ arg_type .title ()} (self.{ arg_name } ))\n "
552
+ )
521
553
522
554
read_types += "\n "
523
555
read_types += f"{ arg_name } = { arg_type .title ()} .read(b)\n "
@@ -526,12 +558,14 @@ def start(format: bool = False):
526
558
527
559
write_types += "\n "
528
560
write_types += "b.write(Vector(self.{}{}))\n " .format (
529
- arg_name , f", { sub_type .title ()} " if sub_type in CORE_TYPES else ""
561
+ arg_name ,
562
+ f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
530
563
)
531
564
532
565
read_types += "\n "
533
566
read_types += "{} = TLObject.read(b{})\n " .format (
534
- arg_name , f", { sub_type .title ()} " if sub_type in CORE_TYPES else ""
567
+ arg_name ,
568
+ f", { sub_type .title ()} " if sub_type in CORE_TYPES else "" ,
535
569
)
536
570
else :
537
571
write_types += "\n "
@@ -555,7 +589,7 @@ def start(format: bool = False):
555
589
fields = fields ,
556
590
read_types = read_types ,
557
591
write_types = write_types ,
558
- return_arguments = return_arguments
592
+ return_arguments = return_arguments ,
559
593
)
560
594
561
595
directory = "types" if c .section == "types" else c .section
@@ -572,7 +606,11 @@ def start(format: bool = False):
572
606
with open (dir_path / f"{ snake (module )} .py" , "w" ) as f :
573
607
f .write (compiled_combinator )
574
608
575
- d = namespaces_to_constructors if c .section == "types" else namespaces_to_functions
609
+ d = (
610
+ namespaces_to_constructors
611
+ if c .section == "types"
612
+ else namespaces_to_functions
613
+ )
576
614
577
615
if c .namespace not in d :
578
616
d [c .namespace ] = []
@@ -609,7 +647,9 @@ def start(format: bool = False):
609
647
f .write (f"from .{ snake (module )} import { t } \n " )
610
648
611
649
if not namespace :
612
- f .write (f"from . import { ', ' .join (filter (bool , namespaces_to_constructors ))} \n " )
650
+ f .write (
651
+ f"from . import { ', ' .join (filter (bool , namespaces_to_constructors ))} \n "
652
+ )
613
653
614
654
for namespace , types in namespaces_to_functions .items ():
615
655
with open (DESTINATION_PATH / "functions" / namespace / "__init__.py" , "w" ) as f :
@@ -625,7 +665,9 @@ def start(format: bool = False):
625
665
f .write (f"from .{ snake (module )} import { t } \n " )
626
666
627
667
if not namespace :
628
- f .write (f"from . import { ', ' .join (filter (bool , namespaces_to_functions ))} " )
668
+ f .write (
669
+ f"from . import { ', ' .join (filter (bool , namespaces_to_functions ))} "
670
+ )
629
671
630
672
with open (DESTINATION_PATH / "all.py" , "w" , encoding = "utf-8" ) as f :
631
673
f .write (notice + "\n \n " )
0 commit comments