From 060f976cf86e6205b13edf858eb40d51117cb0af Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Sat, 13 Jul 2019 19:50:56 +0100 Subject: [PATCH] update Msg/MsgProto __repr__ --- steam/core/msg/__init__.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/steam/core/msg/__init__.py b/steam/core/msg/__init__.py index c714bcb..92ef76b 100644 --- a/steam/core/msg/__init__.py +++ b/steam/core/msg/__init__.py @@ -5,6 +5,8 @@ from steam.core.msg.headers import MsgHdr, ExtendedMsgHdr, MsgHdrProtoBuf, GCMsg from steam.enums import EResult from steam.enums.emsg import EMsg from steam.exceptions import SteamError +from steam.core.msg.structs import StructMessage as _StructMessage +from google.protobuf.message import Message as _ProtoMessageType from steam.protobufs import steammessages_base_pb2 from steam.protobufs import steammessages_clientserver_pb2 from steam.protobufs import steammessages_clientserver_2_pb2 @@ -125,13 +127,17 @@ class Msg(object): self.header.sessionID = value def __repr__(self): - return "" % ( - repr(self.msg), - ' (No Body)' if isinstance(self.body, str) else '', - ) + if isinstance(self.body, _StructMessage): + suffix = self.body.__class__.__name__ + elif self.payload: + suffix = 'not parsed' + else: + suffix = 'n/a' + + return "" % (self.msg, suffix) def __str__(self): - rows = ["Msg"] + rows = [repr(self)] header = str(self.header) rows.append("-------------- header --") @@ -209,13 +215,17 @@ class MsgProto(object): self.header.client_sessionid = value def __repr__(self): - return "" % ( - repr(self.msg), - ' (No Body)' if isinstance(self.body, str) else '', - ) + if isinstance(self.body, _ProtoMessageType): + suffix = self.body.__class__.__name__ + elif self.payload: + suffix = 'not parsed' + else: + suffix = 'n/a' + + return "" % (self.msg, suffix) def __str__(self): - rows = ["MsgProto %s" % repr(self.msg)] + rows = [repr(self)] header = str(self.header).rstrip() rows.append("-------------- header --")