Add __str__ methods to TLMessage and MessageContainer

This commit is contained in:
Lonami Exo 2017-10-21 20:23:53 +02:00
parent d7f917ebfc
commit 6759beac21
2 changed files with 8 additions and 0 deletions

View File

@ -16,6 +16,10 @@ class MessageContainer(TLObject):
'<Ii', MessageContainer.CONSTRUCTOR_ID, len(self.messages) '<Ii', MessageContainer.CONSTRUCTOR_ID, len(self.messages)
) + b''.join(bytes(m) for m in self.messages) ) + b''.join(bytes(m) for m in self.messages)
def __str__(self):
return 'MessageContainer(messages=[{}])'\
.format(', '.join(str(m) for m in self.messages))
@staticmethod @staticmethod
def iter_read(reader): def iter_read(reader):
reader.read_int(signed=False) # code reader.read_int(signed=False) # code

View File

@ -15,3 +15,7 @@ class TLMessage(TLObject):
def __bytes__(self): def __bytes__(self):
body = GzipPacked.gzip_if_smaller(self.request) body = GzipPacked.gzip_if_smaller(self.request)
return struct.pack('<qii', self.msg_id, self.seq_no, len(body)) + body return struct.pack('<qii', self.msg_id, self.seq_no, len(body)) + body
def __str__(self):
return 'TLMessage(msg_id={}, seq_no={}, body={})'\
.format(self.msg_id, self.seq_no, self.request)