mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-09 13:29:47 +00:00
Properly ignore core types when generating code
This commit is contained in:
@@ -4,7 +4,12 @@ from zlib import crc32
|
||||
|
||||
class TLObject:
|
||||
""".tl core types IDs (such as vector, booleans, etc.)"""
|
||||
CORE_TYPES = (0x1cb5c415, 0xbc799737, 0x997275b5, 0x3fedd339)
|
||||
CORE_TYPES = (
|
||||
0xbc799737, # boolFalse#bc799737 = Bool;
|
||||
0x997275b5, # boolTrue#997275b5 = Bool;
|
||||
0x3fedd339, # true#3fedd339 = True;
|
||||
0x1cb5c415, # vector#1cb5c415 {t:Type} # [ t ] = Vector t;
|
||||
)
|
||||
|
||||
def __init__(self, fullname, object_id, args, result, is_function):
|
||||
"""
|
||||
@@ -65,6 +70,10 @@ class TLObject:
|
||||
;$ # Finally, the line should always end with ;
|
||||
''', tl, re.IGNORECASE | re.VERBOSE)
|
||||
|
||||
if match is None:
|
||||
# Probably "vector#1cb5c415 {t:Type} # [ t ] = Vector t;"
|
||||
raise ValueError('Cannot parse TLObject', tl)
|
||||
|
||||
# Sub-regex to match the arguments (sadly, it cannot be embedded in the first regex)
|
||||
args_match = re.findall(r'''
|
||||
({)? # We may or may not capture the opening brace
|
||||
|
@@ -7,7 +7,7 @@ class TLParser:
|
||||
"""Class used to parse .tl files"""
|
||||
|
||||
@staticmethod
|
||||
def parse_file(file_path):
|
||||
def parse_file(file_path, ignore_core=False):
|
||||
"""This method yields TLObjects from a given .tl file"""
|
||||
|
||||
with open(file_path, encoding='utf-8') as file:
|
||||
@@ -28,7 +28,13 @@ class TLParser:
|
||||
is_function = following_types == 'functions'
|
||||
|
||||
else:
|
||||
yield TLObject.from_tl(line, is_function)
|
||||
try:
|
||||
result = TLObject.from_tl(line, is_function)
|
||||
if not ignore_core or not result.is_core_type():
|
||||
yield result
|
||||
except ValueError as e:
|
||||
if 'vector#1cb5c415' not in str(e):
|
||||
raise
|
||||
|
||||
@staticmethod
|
||||
def find_layer(file_path):
|
||||
|
Reference in New Issue
Block a user