mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2026-09-04 16:10:39 +00:00
Detect current MTProtoLayer automatically
This commit is contained in:
@@ -29,3 +29,13 @@ class TLParser:
|
||||
|
||||
else:
|
||||
yield TLObject.from_tl(line, is_function)
|
||||
|
||||
@staticmethod
|
||||
def find_layer(file_path):
|
||||
"""Finds the layer used on the specified scheme.tl file"""
|
||||
layer_regex = re.compile(r'^//\s*LAYER\s*(\d+)$')
|
||||
with open(file_path, encoding='utf-8') as file:
|
||||
for line in file:
|
||||
match = layer_regex.match(line)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
|
||||
@@ -167,6 +167,10 @@ class TLGenerator:
|
||||
builder.writeln('import {}'.format(TLGenerator.get_full_file_name(tlobject)))
|
||||
builder.writeln()
|
||||
|
||||
# Create a variable to indicate which layer this is
|
||||
builder.writeln('layer = {} # Current generated layer'.format(TLParser.find_layer(scheme_file)))
|
||||
builder.writeln()
|
||||
|
||||
# Then create the dictionary containing constructor_id: class
|
||||
builder.writeln('tlobjects = {')
|
||||
builder.current_indent += 1
|
||||
|
||||
Reference in New Issue
Block a user