py3 support errors

master
inpos 2017-12-18 09:04:57 +03:00
parent 9d0be7fcdc
commit b9da8c1323
5 changed files with 37 additions and 37 deletions

View File

@ -170,7 +170,7 @@ def _SSLSocket_init(self, sock=None, keyfile=None, certfile=None,
# see if it's connected # see if it's connected
try: try:
socket.getpeername(self) socket.getpeername(self)
except socket_error, e: except socket_error as e:
if e.errno != errno.ENOTCONN: if e.errno != errno.ENOTCONN:
raise raise
# no, no connection yet # no, no connection yet

View File

@ -56,13 +56,13 @@ def main():
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
if peer_address: if peer_address:
print "Completed listening for peer: %s" % str(peer_address) print("Completed listening for peer: %s" % str(peer_address))
break break
print "Accepting..." print("Accepting...")
conn = scn.accept()[0] conn = scn.accept()[0]
sck.settimeout(5) sck.settimeout(5)
conn.get_socket(True).settimeout(5) conn.get_socket(True).settimeout(5)
@ -70,26 +70,26 @@ def main():
cnt = 0 cnt = 0
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
assert not peer_address assert not peer_address
print "Handshake invocation: %d" % cnt print("Handshake invocation: %d" % cnt)
try: try:
conn.do_handshake() conn.do_handshake()
except SSLError as err: except SSLError as err:
if err.errno == 504: if err.errno == 504:
continue continue
raise raise
print "Completed handshaking with peer" print("Completed handshaking with peer")
break break
cnt = 0 cnt = 0
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
assert not peer_address assert not peer_address
print "Read invocation: %d" % cnt print("Read invocation: %d" % cnt)
try: try:
message = conn.read() message = conn.read()
except SSLError as err: except SSLError as err:
@ -98,16 +98,16 @@ def main():
if err.args[0] == SSL_ERROR_ZERO_RETURN: if err.args[0] == SSL_ERROR_ZERO_RETURN:
break break
raise raise
print message print(message)
conn.write("Back to you: " + message) conn.write("Back to you: " + message)
cnt = 0 cnt = 0
while True: while True:
cnt += 1 cnt += 1
print "Listen invocation: %d" % cnt print("Listen invocation: %d" % cnt)
peer_address = scn.listen() peer_address = scn.listen()
assert not peer_address assert not peer_address
print "Shutdown invocation: %d" % cnt print("Shutdown invocation: %d" % cnt)
try: try:
s = conn.shutdown() s = conn.shutdown()
s.shutdown(socket.SHUT_RDWR) s.shutdown(socket.SHUT_RDWR)

View File

@ -10,6 +10,6 @@ cert_path = path.join(path.abspath(path.dirname(__file__)), "certs")
sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM), cert_reqs=ssl.CERT_REQUIRED, ca_certs=path.join(cert_path, "ca-cert.pem")) sock = ssl.wrap_socket(socket(AF_INET, SOCK_DGRAM), cert_reqs=ssl.CERT_REQUIRED, ca_certs=path.join(cert_path, "ca-cert.pem"))
sock.connect(('localhost', 28000)) sock.connect(('localhost', 28000))
sock.send('Hi there') sock.send('Hi there')
print sock.recv() print(sock.recv())
sock.unwrap() sock.unwrap()
sock.shutdown(SHUT_RDWR) sock.shutdown(SHUT_RDWR)

View File

@ -84,7 +84,7 @@ fill = urandom(CHUNK_SIZE)
def transfer_out(sock, listen_sock=None, marker=False): def transfer_out(sock, listen_sock=None, marker=False):
max_i_len = 10 max_i_len = 10
start_char = "t" if marker else "s" start_char = "t" if marker else "s"
for i in xrange(CHUNKS): for i in range(CHUNKS):
prefix = start_char + str(i) + ":" prefix = start_char + str(i) + ":"
pad_prefix = prefix + "b" * (max_i_len - len(prefix)) pad_prefix = prefix + "b" * (max_i_len - len(prefix))
message = pad_prefix + fill[:CHUNK_SIZE - max_i_len - 1] + "e" message = pad_prefix + fill[:CHUNK_SIZE - max_i_len - 1] + "e"
@ -106,7 +106,7 @@ def transfer_out(sock, listen_sock=None, marker=False):
if not i % CHUNKS_PER_DOT: if not i % CHUNKS_PER_DOT:
sys.stdout.write('.') sys.stdout.write('.')
sys.stdout.flush() sys.stdout.flush()
print print()
def transfer_in(sock, listen_sock=None): def transfer_in(sock, listen_sock=None):
drops = 0 drops = 0
@ -168,7 +168,7 @@ def transfer_in(sock, listen_sock=None):
sys.stdout.flush() sys.stdout.flush()
i += 1 i += 1
drops += CHUNKS - 1 - pack_seq drops += CHUNKS - 1 - pack_seq
print print()
return drops return drops
# #
@ -260,7 +260,7 @@ def make_client_manager():
# Create the global client manager class in servers configured as client # Create the global client manager class in servers configured as client
# managers # managers
class ClientManager(object): class ClientManager(object):
from Queue import Queue from queue import Queue
queue = Queue() queue = Queue()
clients = -1 # creator does not count clients = -1 # creator does not count
@ -324,16 +324,16 @@ def remote_client(manager_address):
manager = Manager(manager_address, COMM_KEY) manager = Manager(manager_address, COMM_KEY)
manager.connect() manager.connect()
queue = manager.get_queue() queue = manager.get_queue()
print "Client connected; waiting for job..." print("Client connected; waiting for job...")
while True: while True:
command = queue.get() command = queue.get()
if command == "STOP": if command == "STOP":
break break
command = command[:-1] + [(manager_address[0], command[-1][1])] command = command[:-1] + [(manager_address[0], command[-1][1])]
print "Starting job: " + str(command) print("Starting job: " + str(command))
drops = client(*command) drops = client(*command)
print "%d drops" % drops print("%d drops" % drops)
print "Job completed; waiting for next job..." print("Job completed; waiting for next job...")
# #
# Test runner # Test runner
@ -349,7 +349,7 @@ def run_test(server_args, client_args, port):
# bind to loopback only, for local clients # bind to loopback only, for local clients
listen_addr = 'localhost', port listen_addr = 'localhost', port
svr = iter(server(*server_args, listen_addr=listen_addr)) svr = iter(server(*server_args, listen_addr=listen_addr))
listen_addr = svr.next() listen_addr = next(svr)
listen_addr = 'localhost', listen_addr[1] listen_addr = 'localhost', listen_addr[1]
client_args = list(client_args) client_args = list(client_args)
client_args.append(listen_addr) client_args.append(listen_addr)
@ -360,19 +360,19 @@ def run_test(server_args, client_args, port):
proc.start() proc.start()
in_size = CHUNK_SIZE * CHUNKS / 2**20 in_size = CHUNK_SIZE * CHUNKS / 2**20
out_size = CHUNK_SIZE * CHUNKS / 2**20 out_size = CHUNK_SIZE * CHUNKS / 2**20
print "Starting inbound: %dMiB" % in_size print("Starting inbound: %dMiB" % in_size)
svr_in_time, drops = svr.next() svr_in_time, drops = next(svr)
print "Inbound: %.3f seconds, %dMiB/s, %d drops" % ( print("Inbound: %.3f seconds, %dMiB/s, %d drops" % (
svr_in_time, in_size / svr_in_time, drops) svr_in_time, in_size / svr_in_time, drops))
print "Starting outbound: %dMiB" % out_size print("Starting outbound: %dMiB" % out_size)
svr_out_time = svr.next() svr_out_time = next(svr)
print "Outbound: %.3f seconds, %dMiB/s" % ( print("Outbound: %.3f seconds, %dMiB/s" % (
svr_out_time, out_size / svr_out_time) svr_out_time, out_size / svr_out_time))
if not QUEUE: if not QUEUE:
proc.join() proc.join()
print "Combined: %.3f seconds, %dMiB/s" % ( print("Combined: %.3f seconds, %dMiB/s" % (
svr_out_time + svr_in_time, svr_out_time + svr_in_time,
(in_size + out_size) / (svr_in_time + svr_out_time)) (in_size + out_size) / (svr_in_time + svr_out_time)))
# #
# Main entry point # Main entry point
@ -419,16 +419,16 @@ if __name__ == "__main__":
} }
do_patch() do_patch()
while True: while True:
print "\nSelect protocol:\n" print("\nSelect protocol:\n")
for key in sorted(selector): for key in sorted(selector):
print "\t" + str(key) + ": " + selector[key] print("\t" + str(key) + ": " + selector[key])
try: try:
choice = raw_input("\nProtocol: ") choice = input("\nProtocol: ")
choice = int(choice) choice = int(choice)
if choice < 0 or choice >= len(selector): if choice < 0 or choice >= len(selector):
raise ValueError("Invalid selection input") raise ValueError("Invalid selection input")
except (ValueError, OverflowError): except (ValueError, OverflowError):
print "Invalid selection input" print("Invalid selection input")
continue continue
except EOFError: except EOFError:
break break

View File

@ -59,7 +59,7 @@ class BasicTests(unittest.TestCase):
# A crude test for the legacy API # A crude test for the legacy API
try: try:
ssl.sslwrap_simple(socket.socket(AF_INET4_6, socket.SOCK_DGRAM)) ssl.sslwrap_simple(socket.socket(AF_INET4_6, socket.SOCK_DGRAM))
except IOError, e: except IOError as e:
if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
pass pass
else: else: