X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fscripts%2Flinux-udp-connect.py;fp=src%2Fnepi%2Fresources%2Flinux%2Fscripts%2Flinux-udp-connect.py;h=3e5706c7a89555d845499e2f1540cabef048c1b7;hb=bb6985326609602a117e65822ada42f2685c1a36;hp=6f6d83764f9458520fef6fc928f5e4d4917bcbfc;hpb=b4af9a40867beff8660612fe20d3838cb375f159;p=nepi.git diff --git a/src/nepi/resources/linux/scripts/linux-udp-connect.py b/src/nepi/resources/linux/scripts/linux-udp-connect.py index 6f6d8376..3e5706c7 100644 --- a/src/nepi/resources/linux/scripts/linux-udp-connect.py +++ b/src/nepi/resources/linux/scripts/linux-udp-connect.py @@ -139,9 +139,8 @@ if __name__ == '__main__': (local_host, local_port) = sock.getsockname() # Save local port information to file - f = open(local_port_file, 'w') - f.write("%d\n" % local_port) - f.close() + with open(local_port_file, 'w') as f: + f.write("%d\n" % local_port) # Wait until remote port information is available while not os.path.exists(remote_port_file): @@ -155,9 +154,8 @@ if __name__ == '__main__': # the read operation returns empty string! # Maybe a race condition? for i in range(10): - f = open(remote_port_file, 'r') - remote_port = f.read() - f.close() + with open(remote_port_file, 'r') as f: + remote_port = f.read() if remote_port: break @@ -174,9 +172,8 @@ if __name__ == '__main__': # TODO: Test connectivity! # Create a ret_file to indicate success - f = open(ret_file, 'w') - f.write("0") - f.close() + with open(ret_file, 'w') as f: + f.write("0") # Establish tunnel tunchannel.tun_fwd(tun, remote,