mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 04:30:22 +03:00
(Add) Add to_dict() method
This commit is contained in:
parent
a07c7bd0d0
commit
921e2eae54
|
@ -212,6 +212,31 @@ class TLGenerator:
|
||||||
for arg in args:
|
for arg in args:
|
||||||
builder.writeln('self.{0} = {0}'.format(arg.name))
|
builder.writeln('self.{0} = {0}'.format(arg.name))
|
||||||
builder.end_block()
|
builder.end_block()
|
||||||
|
|
||||||
|
# Write the to_dict(self) method
|
||||||
|
builder.writeln('def to_dict(self):')
|
||||||
|
if args:
|
||||||
|
builder.writeln('return {')
|
||||||
|
|
||||||
|
base_types = ["string", "bytes", "int", "long", "int128", "int256", "double", "Bool", "true",
|
||||||
|
"date"]
|
||||||
|
|
||||||
|
for arg in args:
|
||||||
|
if arg.is_vector:
|
||||||
|
builder.writeln("\'{}\': [_{} for _ in self.{}] if self.{} is not None else [],"
|
||||||
|
.format(arg.name, ".to_dict() if _ is not None else None"
|
||||||
|
if arg.type not in base_types else "",
|
||||||
|
arg.name, arg.name))
|
||||||
|
else:
|
||||||
|
builder.writeln("\'{}\': self.{}{}, "
|
||||||
|
.format(arg.name, arg.name,
|
||||||
|
".to_dict() if self.{} is not None else None".format(arg.name)
|
||||||
|
if arg.type not in base_types else ""))
|
||||||
|
builder.write("}")
|
||||||
|
else:
|
||||||
|
builder.writeln('return {}')
|
||||||
|
builder.writeln()
|
||||||
|
builder.end_block()
|
||||||
|
|
||||||
# Write the on_send(self, writer) function
|
# Write the on_send(self, writer) function
|
||||||
builder.writeln('def on_send(self, writer):')
|
builder.writeln('def on_send(self, writer):')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user