Add __str__ to RpcResult/GzipPacked

This commit is contained in:
Lonami Exo 2018-06-21 09:52:47 +02:00
parent a99fce471a
commit 5c602d4ba7
4 changed files with 22 additions and 19 deletions

View File

@ -8,7 +8,6 @@ class GzipPacked(TLObject):
CONSTRUCTOR_ID = 0x3072cfa1
def __init__(self, data):
super().__init__()
self.data = data
@staticmethod
@ -38,3 +37,9 @@ class GzipPacked(TLObject):
@classmethod
def from_reader(cls, reader):
return GzipPacked(gzip.decompress(reader.tgread_bytes()))
def to_dict(self):
return {
'_': 'GzipPacked',
'data': self.data
}

View File

@ -13,12 +13,13 @@ class MessageContainer(TLObject):
def __init__(self, messages):
self.messages = messages
def to_dict(self, recursive=True):
def to_dict(self):
return {
'_': 'MessageContainer',
'messages':
([] if self.messages is None else [
[] if self.messages is None else [
None if x is None else x.to_dict() for x in self.messages
]) if recursive else self.messages,
],
}
def __bytes__(self):
@ -26,12 +27,6 @@ class MessageContainer(TLObject):
'<Ii', MessageContainer.CONSTRUCTOR_ID, len(self.messages)
) + b''.join(bytes(m) for m in self.messages)
def __str__(self):
return TLObject.pretty_format(self)
def stringify(self):
return TLObject.pretty_format(self, indent=0)
@classmethod
def from_reader(cls, reader):
# This assumes that .read_* calls are done in the order they appear

View File

@ -1,8 +1,9 @@
from .gzippacked import GzipPacked
from .. import TLObject
from ..types import RpcError
class RpcResult:
class RpcResult(TLObject):
CONSTRUCTOR_ID = 0xf35c6d01
def __init__(self, req_msg_id, body, error):
@ -21,3 +22,11 @@ class RpcResult:
reader.seek(-4)
return RpcResult(msg_id, reader.read(), None)
def to_dict(self):
return {
'_': 'RpcResult',
'req_msg_id': self.req_msg_id,
'body': self.body,
'error': self.error
}

View File

@ -22,7 +22,6 @@ class TLMessage(TLObject):
that will eventually be set with either a result, error or cancelled.
"""
def __init__(self, msg_id, seq_no, obj=None, after_id=0):
super().__init__()
self.msg_id = msg_id
self.seq_no = seq_no
self.obj = obj
@ -34,8 +33,9 @@ class TLMessage(TLObject):
# easily invoke after while confirming the original request.
self.after_id = after_id
def to_dict(self, recursive=True):
def to_dict(self):
return {
'_': 'TLMessage',
'msg_id': self.msg_id,
'seq_no': self.seq_no,
'obj': self.obj,
@ -51,9 +51,3 @@ class TLMessage(TLObject):
InvokeAfterMsgRequest(self.after_id, self.obj))
return struct.pack('<qii', self.msg_id, self.seq_no, len(body)) + body
def __str__(self):
return TLObject.pretty_format(self)
def stringify(self):
return TLObject.pretty_format(self, indent=0)