fix(client+server): dont show debug messages when not in debug mode

This commit is contained in:
minhtrannhat 2023-12-14 07:12:40 -05:00
parent de1e931fe9
commit 74c01a613e
Signed by: minhtrannhat
GPG Key ID: E13CFA85C53F8062
2 changed files with 5 additions and 5 deletions

View File

@ -164,7 +164,7 @@ class Client:
payload: bytes = first_byte.to_bytes(1, "big") # type: ignore payload: bytes = first_byte.to_bytes(1, "big") # type: ignore
print( 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.debug else None
if self.protocol == "UDP": if self.protocol == "UDP":
@ -280,7 +280,7 @@ class Client:
print( print(
f"myftp> - {self.protocol} - Filename: {filename}, File_size: {file_size} bytes" 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: with open(os.path.join(self.directory_path, filename), "wb") as file:
file.write(file_content) file.write(file_content)
@ -312,7 +312,7 @@ class Client:
print( print(
f"myftp> - {self.protocol} - Filename: {filename}, File_size: {file_size} bytes" 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: with open(os.path.join(self.directory_path, filename), "wb") as file:
file.write(file_content) file.write(file_content)

View File

@ -95,7 +95,7 @@ class Server:
) )
print( 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 ) if self.debug else None
# help request handling # help request handling
@ -186,7 +186,7 @@ class Server:
client_socket.sendall(res_payload) # type: ignore client_socket.sendall(res_payload) # type: ignore
print( 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 ) if self.debug else None
except KeyboardInterrupt: except KeyboardInterrupt: