psf/black code formatting (#1277)

This commit is contained in:
William Zhang
2019-10-05 01:14:13 -04:00
committed by Christian Clauss
parent 07f04a2e55
commit 9eac17a408
291 changed files with 6014 additions and 4571 deletions

View File

@@ -1,4 +1,4 @@
if __name__ == '__main__':
if __name__ == "__main__":
import socket # Import socket module
sock = socket.socket() # Create a socket object
@@ -6,11 +6,11 @@ if __name__ == '__main__':
port = 12312
sock.connect((host, port))
sock.send(b'Hello server!')
sock.send(b"Hello server!")
with open('Received_file', 'wb') as out_file:
print('File opened')
print('Receiving data...')
with open("Received_file", "wb") as out_file:
print("File opened")
print("Receiving data...")
while True:
data = sock.recv(1024)
print(f"data={data}")
@@ -18,6 +18,6 @@ if __name__ == '__main__':
break
out_file.write(data) # Write data to a file
print('Successfully got the file')
print("Successfully got the file")
sock.close()
print('Connection closed')
print("Connection closed")

View File

@@ -1,16 +1,18 @@
if __name__ == '__main__':
if __name__ == "__main__":
import socket # Import socket module
ONE_CONNECTION_ONLY = True # Set this to False if you wish to continuously accept connections
ONE_CONNECTION_ONLY = (
True
) # Set this to False if you wish to continuously accept connections
filename='mytext.txt'
filename = "mytext.txt"
port = 12312 # Reserve a port for your service.
sock = socket.socket() # Create a socket object
host = socket.gethostname() # Get local machine name
sock.bind((host, port)) # Bind to the port
sock.listen(5) # Now wait for client connection.
print('Server listening....')
print("Server listening....")
while True:
conn, addr = sock.accept() # Establish connection with client.
@@ -18,16 +20,18 @@ if __name__ == '__main__':
data = conn.recv(1024)
print(f"Server received {data}")
with open(filename,'rb') as in_file:
with open(filename, "rb") as in_file:
data = in_file.read(1024)
while (data):
conn.send(data)
print(f"Sent {data!r}")
data = in_file.read(1024)
while data:
conn.send(data)
print(f"Sent {data!r}")
data = in_file.read(1024)
print('Done sending')
print("Done sending")
conn.close()
if ONE_CONNECTION_ONLY: # This is to make sure that the program doesn't hang while testing
if (
ONE_CONNECTION_ONLY
): # This is to make sure that the program doesn't hang while testing
break
sock.shutdown(1)