From 59f6b75391ac8f82fa63077849fb169c4b162a0b Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Mon, 25 Jun 2018 12:54:33 +0200 Subject: [PATCH] Stop showing "data left after" warning --- telethon/network/mtprotoplainsender.py | 5 ++++- telethon/network/mtprotostate.py | 4 ++++ telethon/tl/core/messagecontainer.py | 7 ++----- telethon/tl/core/rpcresult.py | 3 +++ 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/telethon/network/mtprotoplainsender.py b/telethon/network/mtprotoplainsender.py index ddbd4a30..e04e2934 100644 --- a/telethon/network/mtprotoplainsender.py +++ b/telethon/network/mtprotoplainsender.py @@ -42,5 +42,8 @@ class MTProtoPlainSender: assert reader.read_long() == 0 # auth_key_id assert reader.read_long() > msg_id # msg_id assert reader.read_int() # length - # No need to read "length" bytes first, just read the object + + # We could read length bytes and use those in a new reader to read + # the next TLObject without including the padding, but since the + # reader isn't used for anything else after this, it's unnecessary. return reader.tgread_object() diff --git a/telethon/network/mtprotostate.py b/telethon/network/mtprotostate.py index 2eb64427..61c31f6a 100644 --- a/telethon/network/mtprotostate.py +++ b/telethon/network/mtprotostate.py @@ -121,6 +121,10 @@ class MTProtoState: remote_msg_id = reader.read_long() remote_sequence = reader.read_int() reader.read_int() # msg_len for the inner object, padding ignored + + # We could read msg_len bytes and use those in a new reader to read + # the next TLObject without including the padding, but since the + # reader isn't used for anything else after this, it's unnecessary. obj = reader.tgread_object() return TLMessage(remote_msg_id, remote_sequence, obj) diff --git a/telethon/tl/core/messagecontainer.py b/telethon/tl/core/messagecontainer.py index 92c7bf7a..f5c3c378 100644 --- a/telethon/tl/core/messagecontainer.py +++ b/telethon/tl/core/messagecontainer.py @@ -36,10 +36,7 @@ class MessageContainer(TLObject): seq_no = reader.read_int() length = reader.read_int() before = reader.tell_position() - obj = reader.tgread_object() + obj = reader.tgread_object() # May over-read e.g. RpcResult + reader.set_position(before + length) messages.append(TLMessage(msg_id, seq_no, obj)) - if reader.tell_position() != before + length: - reader.set_position(before) - __log__.warning('Data left after TLObject {}: {!r}' - .format(obj, reader.read(length))) return MessageContainer(messages) diff --git a/telethon/tl/core/rpcresult.py b/telethon/tl/core/rpcresult.py index 4bda3451..e0dacc87 100644 --- a/telethon/tl/core/rpcresult.py +++ b/telethon/tl/core/rpcresult.py @@ -21,6 +21,9 @@ class RpcResult(TLObject): return RpcResult(msg_id, GzipPacked.from_reader(reader).data, None) reader.seek(-4) + # This reader.read() will read more than necessary, but it's okay. + # We could make use of MessageContainer's length here, but since + # it's not necessary we don't need to care about it. return RpcResult(msg_id, reader.read(), None) def to_dict(self):