Add a new .stringify() function to visualize TLObjects more easily

This commit is contained in:
Lonami Exo
2017-07-04 21:15:47 +02:00
parent 632fcb7c00
commit 8fd0d7eadd
2 changed files with 78 additions and 2 deletions

View File

@@ -179,6 +179,7 @@ class TLGenerator:
# Both types and functions inherit from
# MTProtoRequest so they all can be sent
# TODO MTProtoRequest is not the best name for a type
builder.writeln('from {}.tl.mtproto_request import MTProtoRequest'
.format('.' * depth))
@@ -408,9 +409,12 @@ class TLGenerator:
builder.end_block()
builder.writeln('def __str__(self):')
builder.writeln('return {}'.format(str(tlobject)))
# builder.end_block() # No need to end the last block
builder.writeln('return MTProtoRequest.pretty_format(self)')
builder.end_block()
builder.writeln('def stringify(self):')
builder.writeln('return MTProtoRequest.pretty_format(self, indent=0)')
# builder.end_block() # No need to end the last block
@staticmethod
def get_class_name(tlobject):