@@ -50,33 +50,23 @@ def __init__(self, format_size=None):
5050 def deserialize (self , response ):
5151 self .timestamp = datetime .now ()
5252 _msg_length = len (response )
53- if _msg_length != len (self ):
54- raise InvalidMessageLength (
55- "Invalid message length received for %s, expected %s bytes got %s" ,
56- self .__class__ .__name__ ,
57- str (len (self )),
58- str (_msg_length ),
59- )
6053 if response [:4 ] != MESSAGE_HEADER :
6154 raise InvalidMessageHeader (
62- "Invalid message header %s for %s" ,
63- str (response [:4 ]),
64- self .__class__ .__name__ ,
55+ f"Invalid message header { str (response [:4 ])} for { self .__class__ .__name__ } "
6556 )
6657 if response [_msg_length - 2 :] != MESSAGE_FOOTER :
6758 raise InvalidMessageFooter (
68- "Invalid message footer %s for %s" ,
69- str (response [_msg_length - 2 :]),
70- self .__class__ .__name__ ,
59+ f"Invalid message footer { str (response [_msg_length - 2 :])} for { self .__class__ .__name__ } "
7160 )
7261 _calculated_checksum = self .calculate_checksum (response [4 : _msg_length - 6 ])
7362 _message_checksum = response [_msg_length - 6 : _msg_length - 2 ]
7463 if _calculated_checksum != _message_checksum :
7564 raise InvalidMessageChecksum (
76- "Invalid checksum for %s, expected %s got %s" ,
77- self .__class__ .__name__ ,
78- str (_calculated_checksum ),
79- str (_message_checksum ),
65+ f"Invalid checksum for { self .__class__ .__name__ } , expected { str (_calculated_checksum )} got { str (_message_checksum )} " ,
66+ )
67+ if _msg_length != len (self ):
68+ raise InvalidMessageLength (
69+ f"Invalid message length received for { self .__class__ .__name__ } , expected { str (len (self ))} bytes got { str (_msg_length )} "
8070 )
8171
8272 self .msg_id = response [4 :8 ]
0 commit comments