From 74c01a613e1240af6b431b01b4717c90c204806d Mon Sep 17 00:00:00 2001 From: minhtrannhat Date: Thu, 14 Dec 2023 07:12:40 -0500 Subject: [PATCH] fix(client+server): dont show debug messages when not in debug mode --- src/myftp/client.py | 6 +++--- src/myftp/server.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/myftp/client.py b/src/myftp/client.py index ab017a4..f2e3efb 100644 --- a/src/myftp/client.py +++ b/src/myftp/client.py @@ -164,7 +164,7 @@ class Client: payload: bytes = first_byte.to_bytes(1, "big") # type: ignore print( - f"myftp> - {self.protocol} - sent payload {bin(int.from_bytes(payload, byteorder='big'))[2:]} to the server" # type: ignore + f"myftp> - {self.protocol} - sent payload {payload} to the server. Payload length is {len(payload)}" # type: ignore ) if self.debug else None if self.protocol == "UDP": @@ -280,7 +280,7 @@ class Client: print( f"myftp> - {self.protocol} - Filename: {filename}, File_size: {file_size} bytes" - ) + ) if self.debug else None with open(os.path.join(self.directory_path, filename), "wb") as file: file.write(file_content) @@ -312,7 +312,7 @@ class Client: print( f"myftp> - {self.protocol} - Filename: {filename}, File_size: {file_size} bytes" - ) + ) if self.debug else None with open(os.path.join(self.directory_path, filename), "wb") as file: file.write(file_content) diff --git a/src/myftp/server.py b/src/myftp/server.py index 07c1ef6..ad0a72c 100644 --- a/src/myftp/server.py +++ b/src/myftp/server.py @@ -95,7 +95,7 @@ class Server: ) print( - f"myftp> - {self.protocol} - Received message from client at {clientAddress}: {req_payload}" # type: ignore + f"myftp> - {self.protocol} - Received message from client at {clientAddress}: {req_payload}. Payload length is {len(req_payload)}" # type: ignore ) if self.debug else None # help request handling @@ -186,7 +186,7 @@ class Server: client_socket.sendall(res_payload) # type: ignore print( - f"myftp> - {self.protocol} - Sent message to client at {clientAddress}: {res_payload}" # type: ignore + f"myftp> - {self.protocol} - Sent message to client at {clientAddress}: {res_payload}. Payload length is {len(res_payload)}" # type: ignore ) if self.debug else None except KeyboardInterrupt: