@@ -81,7 +81,8 @@ def __init__(
8181 ):
8282 self .credential = decode_credential (inner )
8383 except Exception as e :
84- self ._log (f"Cannot parse credential: { e } " )
84+ if __debug__ :
85+ self ._log (f"cannot parse credential: { e } " )
8586
8687 def channel_id_bytes (self ) -> bytes :
8788 return self .channel_id .to_bytes (2 , "big" )
@@ -91,7 +92,11 @@ def iface(self) -> WireInterface:
9192 return self .iface_ctx ._iface
9293
9394 def clear (self , exc : Exception | None = None ) -> None :
94- self ._log (f"Closing channel (exception: { exc is not None } )" )
95+ if __debug__ :
96+ if exc :
97+ self ._log (f"closing channel (exception: { exc .__class__ .__name__ } )" )
98+ else :
99+ self ._log ("closing channel" )
95100 clear_sessions_with_channel_id (self .channel_id_bytes ())
96101 trezorthp .channel_close (self .iface .iface_num (), self .channel_id )
97102 self .expecting_message = False
@@ -126,7 +131,8 @@ def get_last_write(self) -> int | None:
126131 return None
127132
128133 def set_channel_state (self , state : ChannelState ) -> None :
129- self ._log (f"set state { state } " )
134+ if __debug__ :
135+ self ._log (f"set state { state } " )
130136 self .state = state
131137
132138 def end_pairing_and_replace (self ) -> None :
@@ -163,7 +169,8 @@ async def read(self) -> tuple[int, Message]:
163169 finally :
164170 # wake up write loop to send ACKs or DECRYPTION_FAILED
165171 self .iface_ctx .request_write ()
166- self ._log ("message is ready" )
172+ if __debug__ and _TRACE :
173+ self ._log ("message is ready" )
167174 message = Message (
168175 message_type ,
169176 self .receive_buffer [3 :][:message_bytes_len ],
@@ -235,7 +242,7 @@ def write_packet(self, packet: AnyBuffer) -> bool:
235242 res = trezorthp .packet_out (
236243 self .iface .iface_num (), self .channel_id , buffer , packet
237244 )
238- if res is False and self .send_buffer is not None :
245+ if self .send_buffer :
239246 self .expecting_ack = True
240247 self .iface_ctx .request_read ()
241248 return res
0 commit comments