| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 34a1a84 commit 1185ac1
324 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,14 +34,26 @@ | |||
| 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,11 +77,7 @@ | |||
| 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 | ||
@@ -274,7 +283,7 @@ def start(format: bool = False): | |||
| 274 | 283 | args=args, | |
| 275 | 284 | qualtype=qualtype, | |
| 276 | 285 | typespace=typespace, | |
| 277 | - type=type | ||
| 286 | + type=type, | ||
| 278 | 287 | ) | |
| 279 | 288 | ||
| 280 | 289 | combinators.append(combinator) | |
@@ -335,22 +344,26 @@ def start(format: bool = False): | |||
| 335 | 344 | ||
| 336 | 345 | docstring = type_docs | |
| 337 | 346 | ||
| 338 | - docstring += f"\n\n Constructors:\n" \ | ||
| 339 | - f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" \ | ||
| 340 | - f" .. currentmodule:: hydrogram.raw.types\n\n" \ | ||
| 341 | - f" .. autosummary::\n" \ | ||
| 342 | - f" :nosignatures:\n\n" \ | ||
| 343 | - f" {items}" | ||
| 347 | + docstring += ( | ||
| 348 | + f"\n\n Constructors:\n" | ||
| 349 | + f" This base type has {constr_count} constructor{'s' if constr_count > 1 else ''} available.\n\n" | ||
| 350 | + f" .. currentmodule:: hydrogram.raw.types\n\n" | ||
| 351 | + f" .. autosummary::\n" | ||
| 352 | + f" :nosignatures:\n\n" | ||
| 353 | + f" {items}" | ||
| 354 | + ) | ||
| 344 | 355 | ||
| 345 | 356 | references, ref_count = get_references(qualtype, "types") | |
| 346 | 357 | ||
| 347 | 358 | if references: | |
| 348 | - docstring += f"\n\n Functions:\n This object can be returned by " \ | ||
| 349 | - f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n" \ | ||
| 350 | - f" .. currentmodule:: hydrogram.raw.functions\n\n" \ | ||
| 351 | - f" .. autosummary::\n" \ | ||
| 352 | - f" :nosignatures:\n\n" \ | ||
| 353 | - f" " + references | ||
| 359 | + docstring += ( | ||
| 360 | + f"\n\n Functions:\n This object can be returned by " | ||
| 361 | + f"{ref_count} function{'s' if ref_count > 1 else ''}.\n\n" | ||
| 362 | + f" .. currentmodule:: hydrogram.raw.functions\n\n" | ||
| 363 | + f" .. autosummary::\n" | ||
| 364 | + f" :nosignatures:\n\n" | ||
| 365 | + f" " + references | ||
| 366 | + ) | ||
| 354 | 367 | ||
| 355 | 368 | with open(dir_path / f"{snake(module)}.py", "w") as f: | |
| 356 | 369 | f.write( | |
@@ -361,25 +374,24 @@ def start(format: bool = False): | |||
| 361 | 374 | name=type, | |
| 362 | 375 | qualname=qualtype, | |
| 363 | 376 | types=", ".join([f"raw.types.{c}" for c in constructors]), | |
| 364 | - doc_name=snake(type).replace("_", "-") | ||
| 377 | + doc_name=snake(type).replace("_", "-"), | ||
| 365 | 378 | ) | |
| 366 | 379 | ) | |
| 367 | 380 | ||
| 368 | 381 | for c in combinators: | |
| 369 | 382 | sorted_args = sort_args(c.args) | |
| 370 | 383 | ||
| 371 | - arguments = ( | ||
| 372 | - (", *, " if c.args else "") + | ||
| 373 | - (", ".join( | ||
| 374 | - [f"{i[0]}: {get_type_hint(i[1])}" | ||
| 375 | - for i in sorted_args] | ||
| 376 | - ) if sorted_args else "") | ||
| 384 | + arguments = (", *, " if c.args else "") + ( | ||
| 385 | + ", ".join([f"{i[0]}: {get_type_hint(i[1])}" for i in sorted_args]) | ||
| 386 | + if sorted_args | ||
| 387 | + else "" | ||
| 377 | 388 | ) | |
| 378 | 389 | ||
| 379 | - fields = "\n ".join( | ||
| 380 | - [f"self.{i[0]} = {i[0]} # {i[1]}" | ||
| 381 | - for i in sorted_args] | ||
| 382 | - ) if sorted_args else "pass" | ||
| 390 | + fields = ( | ||
| 391 | + "\n ".join([f"self.{i[0]} = {i[0]} # {i[1]}" for i in sorted_args]) | ||
| 392 | + if sorted_args | ||
| 393 | + else "pass" | ||
| 394 | + ) | ||
| 383 | 395 | ||
| 384 | 396 | docstring = "" | |
| 385 | 397 | docstring_args = [] | |
@@ -407,7 +419,7 @@ def start(format: bool = False): | |||
| 407 | 419 | arg_name, | |
| 408 | 420 | get_docstring_arg_type(arg_type), | |
| 409 | 421 | ", *optional*".format(flag_number) if is_optional else "", | |
| 410 | - arg_docs | ||
| 422 | + arg_docs, | ||
| 411 | 423 | ) | |
| 412 | 424 | ) | |
| 413 | 425 | ||
@@ -420,7 +432,9 @@ def start(format: bool = False): | |||
| 420 | 432 | constructor_docs = "Telegram API type." | |
| 421 | 433 | ||
| 422 | 434 | docstring += constructor_docs + "\n" | |
| 423 | - docstring += f"\n Constructor of :obj:`~hydrogram.raw.base.{c.qualtype}`." | ||
| 435 | + docstring += ( | ||
| 436 | + f"\n Constructor of :obj:`~hydrogram.raw.base.{c.qualtype}`." | ||
| 437 | + ) | ||
| 424 | 438 | else: | |
| 425 | 439 | function_docs = docs["method"].get(c.qualname, None) | |
| 426 | 440 | ||
@@ -430,21 +444,26 @@ def start(format: bool = False): | |||
| 430 | 444 | docstring += f"Telegram API function." | |
| 431 | 445 | ||
| 432 | 446 | docstring += f"\n\n Details:\n - Layer: ``{layer}``\n - ID: ``{c.id[2:].upper()}``\n\n" | |
| 433 | - docstring += f" Parameters:\n " + \ | ||
| 434 | - (f"\n ".join(docstring_args) if docstring_args else "No parameters required.\n") | ||
| 447 | + docstring += f" Parameters:\n " + ( | ||
| 448 | + f"\n ".join(docstring_args) | ||
| 449 | + if docstring_args | ||
| 450 | + else "No parameters required.\n" | ||
| 451 | + ) | ||
| 435 | 452 | ||
| 436 | 453 | if c.section == "functions": | |
| 437 | 454 | docstring += "\n Returns:\n " + get_docstring_arg_type(c.qualtype) | |
| 438 | 455 | else: | |
| 439 | 456 | references, count = get_references(c.qualname, "constructors") | |
| 440 | 457 | ||
| 441 | 458 | if references: | |
| 442 | - docstring += f"\n Functions:\n This object can be returned by " \ | ||
| 443 | - f"{count} function{'s' if count > 1 else ''}.\n\n" \ | ||
| 444 | - f" .. currentmodule:: hydrogram.raw.functions\n\n" \ | ||
| 445 | - f" .. autosummary::\n" \ | ||
| 446 | - f" :nosignatures:\n\n" \ | ||
| 447 | - f" " + references | ||
| 459 | + docstring += ( | ||
| 460 | + f"\n Functions:\n This object can be returned by " | ||
| 461 | + f"{count} function{'s' if count > 1 else ''}.\n\n" | ||
| 462 | + f" .. currentmodule:: hydrogram.raw.functions\n\n" | ||
| 463 | + f" .. autosummary::\n" | ||
| 464 | + f" :nosignatures:\n\n" | ||
| 465 | + f" " + references | ||
| 466 | + ) | ||
| 448 | 467 | ||
| 449 | 468 | write_types = read_types = "" if c.has_flags else "# No flags\n " | |
| 450 | 469 | ||
@@ -461,17 +480,24 @@ def start(format: bool = False): | |||
| 461 | 480 | if arg_name != f"flags{flag.group(1)}": | |
| 462 | 481 | continue | |
| 463 | 482 | ||
| 464 | - if flag.group(3) == "true" or flag.group(3).startswith("Vector"): | ||
| 465 | - write_flags.append(f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0") | ||
| 483 | + if flag.group(3) == "true" or flag.group(3).startswith( | ||
| 484 | + "Vector" | ||
| 485 | + ): | ||
| 486 | + write_flags.append( | ||
| 487 | + f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} else 0" | ||
| 488 | + ) | ||
| 466 | 489 | else: | |
| 467 | 490 | write_flags.append( | |
| 468 | - f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0") | ||
| 469 | - | ||
| 470 | - write_flags = "\n ".join([ | ||
| 471 | - f"{arg_name} = 0", | ||
| 472 | - "\n ".join(write_flags), | ||
| 473 | - f"b.write(Int({arg_name}))\n " | ||
| 474 | - ]) | ||
| 491 | + f"{arg_name} |= (1 << {flag.group(2)}) if self.{i[0]} is not None else 0" | ||
| 492 | + ) | ||
| 493 | + | ||
| 494 | + write_flags = "\n ".join( | ||
| 495 | + [ | ||
| 496 | + f"{arg_name} = 0", | ||
| 497 | + "\n ".join(write_flags), | ||
| 498 | + f"b.write(Int({arg_name}))\n ", | ||
| 499 | + ] | ||
| 500 | + ) | ||
| 475 | 501 | ||
| 476 | 502 | write_types += write_flags | |
| 477 | 503 | read_types += f"\n {arg_name} = Int.read(b)\n " | |
@@ -487,7 +513,9 @@ def start(format: bool = False): | |||
| 487 | 513 | elif flag_type in CORE_TYPES: | |
| 488 | 514 | write_types += "\n " | |
| 489 | 515 | write_types += f"if self.{arg_name} is not None:\n " | |
| 490 | - write_types += f"b.write({flag_type.title()}(self.{arg_name}))\n " | ||
| 516 | + write_types += ( | ||
| 517 | + f"b.write({flag_type.title()}(self.{arg_name}))\n " | ||
| 518 | + ) | ||
| 491 | 519 | ||
| 492 | 520 | read_types += "\n " | |
| 493 | 521 | read_types += f"{arg_name} = {flag_type.title()}.read(b) if flags{number} & (1 << {index}) else None" | |
@@ -497,12 +525,16 @@ def start(format: bool = False): | |||
| 497 | 525 | write_types += "\n " | |
| 498 | 526 | write_types += f"if self.{arg_name} is not None:\n " | |
| 499 | 527 | write_types += "b.write(Vector(self.{}{}))\n ".format( | |
| 500 | - arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "" | ||
| 528 | + arg_name, | ||
| 529 | + f", {sub_type.title()}" if sub_type in CORE_TYPES else "", | ||
| 501 | 530 | ) | |
| 502 | 531 | ||
| 503 | 532 | read_types += "\n " | |
| 504 | 533 | read_types += "{} = TLObject.read(b{}) if flags{} & (1 << {}) else []\n ".format( | |
| 505 | - arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "", number, index | ||
| 534 | + arg_name, | ||
| 535 | + f", {sub_type.title()}" if sub_type in CORE_TYPES else "", | ||
| 536 | + number, | ||
| 537 | + index, | ||
| 506 | 538 | ) | |
| 507 | 539 | else: | |
| 508 | 540 | write_types += "\n " | |
@@ -514,7 +546,9 @@ def start(format: bool = False): | |||
| 514 | 546 | else: | |
| 515 | 547 | if arg_type in CORE_TYPES: | |
| 516 | 548 | write_types += "\n " | |
| 517 | - write_types += f"b.write({arg_type.title()}(self.{arg_name}))\n " | ||
| 549 | + write_types += ( | ||
| 550 | + f"b.write({arg_type.title()}(self.{arg_name}))\n " | ||
| 551 | + ) | ||
| 518 | 552 | ||
| 519 | 553 | read_types += "\n " | |
| 520 | 554 | read_types += f"{arg_name} = {arg_type.title()}.read(b)\n " | |
@@ -523,12 +557,14 @@ def start(format: bool = False): | |||
| 523 | 557 | ||
| 524 | 558 | write_types += "\n " | |
| 525 | 559 | write_types += "b.write(Vector(self.{}{}))\n ".format( | |
| 526 | - arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "" | ||
| 560 | + arg_name, | ||
| 561 | + f", {sub_type.title()}" if sub_type in CORE_TYPES else "", | ||
| 527 | 562 | ) | |
| 528 | 563 | ||
| 529 | 564 | read_types += "\n " | |
| 530 | 565 | read_types += "{} = TLObject.read(b{})\n ".format( | |
| 531 | - arg_name, f", {sub_type.title()}" if sub_type in CORE_TYPES else "" | ||
| 566 | + arg_name, | ||
| 567 | + f", {sub_type.title()}" if sub_type in CORE_TYPES else "", | ||
| 532 | 568 | ) | |
| 533 | 569 | else: | |
| 534 | 570 | write_types += "\n " | |
@@ -552,7 +588,7 @@ def start(format: bool = False): | |||
| 552 | 588 | fields=fields, | |
| 553 | 589 | read_types=read_types, | |
| 554 | 590 | write_types=write_types, | |
| 555 | - return_arguments=return_arguments | ||
| 591 | + return_arguments=return_arguments, | ||
| 556 | 592 | ) | |
| 557 | 593 | ||
| 558 | 594 | directory = "types" if c.section == "types" else c.section | |
@@ -569,7 +605,11 @@ def start(format: bool = False): | |||
| 569 | 605 | with open(dir_path / f"{snake(module)}.py", "w") as f: | |
| 570 | 606 | f.write(compiled_combinator) | |
| 571 | 607 | ||
| 572 | - d = namespaces_to_constructors if c.section == "types" else namespaces_to_functions | ||
| 608 | + d = ( | ||
| 609 | + namespaces_to_constructors | ||
| 610 | + if c.section == "types" | ||
| 611 | + else namespaces_to_functions | ||
| 612 | + ) | ||
| 573 | 613 | ||
| 574 | 614 | if c.namespace not in d: | |
| 575 | 615 | d[c.namespace] = [] | |
@@ -606,7 +646,9 @@ def start(format: bool = False): | |||
| 606 | 646 | f.write(f"from .{snake(module)} import {t}\n") | |
| 607 | 647 | ||
| 608 | 648 | if not namespace: | |
| 609 | - f.write(f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n") | ||
| 649 | + f.write( | ||
| 650 | + f"from . import {', '.join(filter(bool, namespaces_to_constructors))}\n" | ||
| 651 | + ) | ||
| 610 | 652 | ||
| 611 | 653 | for namespace, types in namespaces_to_functions.items(): | |
| 612 | 654 | with open(DESTINATION_PATH / "functions" / namespace / "__init__.py", "w") as f: | |
@@ -622,7 +664,9 @@ def start(format: bool = False): | |||
| 622 | 664 | f.write(f"from .{snake(module)} import {t}\n") | |
| 623 | 665 | ||
| 624 | 666 | if not namespace: | |
| 625 | - f.write(f"from . import {', '.join(filter(bool, namespaces_to_functions))}") | ||
| 667 | + f.write( | ||
| 668 | + f"from . import {', '.join(filter(bool, namespaces_to_functions))}" | ||
| 669 | + ) | ||
| 626 | 670 | ||
| 627 | 671 | with open(DESTINATION_PATH / "all.py", "w", encoding="utf-8") as f: | |
| 628 | 672 | f.write(notice + "\n\n") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments