From bb458f69e99ee3bfdd18d3ccd2397cf990d442d3 Mon Sep 17 00:00:00 2001 From: cclauss Date: Fri, 19 Jul 2019 10:34:27 +0200 Subject: [PATCH 1/3] if __name == '__main__': to allow doctests --- file_transfer_protocol/ftp_client_server.py | 99 ++++++++++----------- file_transfer_protocol/ftp_send_receive.py | 9 +- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/file_transfer_protocol/ftp_client_server.py b/file_transfer_protocol/ftp_client_server.py index 414c336dee9f..0fc224e9f1e7 100644 --- a/file_transfer_protocol/ftp_client_server.py +++ b/file_transfer_protocol/ftp_client_server.py @@ -2,56 +2,55 @@ import socket # Import socket module -port = 60000 # Reserve a port for your service. -s = socket.socket() # Create a socket object -host = socket.gethostname() # Get local machine name -s.bind((host, port)) # Bind to the port -s.listen(5) # Now wait for client connection. - -print('Server listening....') - -while True: - conn, addr = s.accept() # Establish connection with client. - print('Got connection from', addr) - data = conn.recv(1024) - print('Server received', repr(data)) - - filename = 'mytext.txt' - with open(filename, 'rb') as f: - in_data = f.read(1024) - while in_data: - conn.send(in_data) - print('Sent ', repr(in_data)) - in_data = f.read(1024) - - print('Done sending') - conn.send('Thank you for connecting') - conn.close() - +if __name__ == '__main__': + port = 60000 # Reserve a port for your service. + s = socket.socket() # Create a socket object + host = socket.gethostname() # Get local machine name + s.bind((host, port)) # Bind to the port + s.listen(5) # Now wait for client connection. -# client side server - -import socket # Import socket module + print('Server listening....') -s = socket.socket() # Create a socket object -host = socket.gethostname() # Get local machine name -port = 60000 # Reserve a port for your service. - -s.connect((host, port)) -s.send("Hello server!") - -with open('received_file', 'wb') as f: - print('file opened') while True: - print('receiving data...') - data = s.recv(1024) - print('data=%s', (data)) - if not data: - break - # write data to a file - f.write(data) - -f.close() -print('Successfully get the file') -s.close() -print('connection closed') + conn, addr = s.accept() # Establish connection with client. + print('Got connection from', addr) + data = conn.recv(1024) + print('Server received', repr(data)) + + filename = 'mytext.txt' + with open(filename, 'rb') as f: + in_data = f.read(1024) + while in_data: + conn.send(in_data) + print('Sent ', repr(in_data)) + in_data = f.read(1024) + + print('Done sending') + conn.send('Thank you for connecting') + conn.close() + + + # client side server + + s = socket.socket() # Create a socket object + host = socket.gethostname() # Get local machine name + port = 60000 # Reserve a port for your service. + + s.connect((host, port)) + s.send("Hello server!") + + with open('received_file', 'wb') as f: + print('file opened') + while True: + print('receiving data...') + data = s.recv(1024) + print('data=%s', (data)) + if not data: + break + # write data to a file + f.write(data) + + f.close() + print('Successfully get the file') + s.close() + print('connection closed') diff --git a/file_transfer_protocol/ftp_send_receive.py b/file_transfer_protocol/ftp_send_receive.py index 6a9819ef3f21..b6dc0869369e 100644 --- a/file_transfer_protocol/ftp_send_receive.py +++ b/file_transfer_protocol/ftp_send_receive.py @@ -9,9 +9,12 @@ """ from ftplib import FTP -ftp = FTP('xxx.xxx.x.x') # Enter the ip address or the domain name here -ftp.login(user='username', passwd='password') -ftp.cwd('/Enter the directory here/') + + +if __name__ == '__main__': + ftp = FTP('xxx.xxx.x.x') # Enter the ip address or the domain name here + ftp.login(user='username', passwd='password') + ftp.cwd('/Enter the directory here/') """ The file which will be received via the FTP server From c33d479e31e49d0a6b45c3a031859451ac62ea84 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 20 Jul 2019 11:10:36 +0200 Subject: [PATCH 2/3] Travis CI: Run pytest on the FTP files --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3ff22fb09b7..398d5f2d554a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,8 +12,6 @@ script: - pytest . --doctest-modules --ignore=data_structures/stacks/balanced_parentheses.py --ignore=data_structures/stacks/infix_to_postfix_conversion.py - --ignore=file_transfer_protocol/ftp_send_receive.py - --ignore=file_transfer_protocol/ftp_client_server.py --ignore=machine_learning/linear_regression.py --ignore=machine_learning/perceptron.py --ignore=machine_learning/random_forest_classification/random_forest_classification.py From 6f6ce9f1f793c663d9c4bf20c5d04224bf21f1e0 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 21 Jul 2019 12:44:06 +0200 Subject: [PATCH 3/3] pytest --ignore=virtualenv # do not test our dependencies --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 398d5f2d554a..03ced6ed9251 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ script: --ignore=maths/binary_exponentiation.py --ignore=maths/lucas_series.py --ignore=maths/sieve_of_eratosthenes.py + --ignore=virtualenv # do not test our dependencies after_success: - python scripts/build_directory_md.py - cat DIRECTORY.md