padding = ord(packet[-1])
if not (0 < padding <= crypter.block_size):
# wrong padding
- raise RuntimeError, "Truncated packet %s"
+ raise RuntimeError("Truncated packet %s")
packet = packet[:-padding]
return packet
try:
rdrdy, wrdy, errs = select(rset,wset,eset,1)
- except selecterror, e:
+ except selecterror as e:
if e.args[0] == errno.EINTR:
# just retry
continue
if not rnonblock or not fpacketReady(fwbuf):
break
- except OSError,e:
+ except OSError as e:
# This except handles the entire While block on PURPOSE
# as an optimization (setting a try/except block is expensive)
# The only operation that can raise this exception is rwrite
if slowlocal:
# Give some time for the kernel to process the packets
time.sleep(0)
- except OSError,e:
+ except OSError as e:
# This except handles the entire While block on PURPOSE
# as an optimization (setting a try/except block is expensive)
# The only operation that can raise this exception is os_write
if not tnonblock or len(fwbuf) >= maxfwbuf:
break
- except OSError,e:
+ except OSError as e:
# This except handles the entire While block on PURPOSE
# as an optimization (setting a try/except block is expensive)
# The only operation that can raise this exception is os_read
elif not packet:
if not udp and packet == "":
# Connection broken, try to reconnect (or just die)
- raise RuntimeError, "Connection broken"
+ raise RuntimeError("Connection broken")
else:
continue
if not rnonblock or len(bkbuf) >= maxbkbuf:
break
- except OSError,e:
+ except OSError as e:
# This except handles the entire While block on PURPOSE
# as an optimization (setting a try/except block is expensive)
# The only operation that can raise this exception is rread
if e.errno not in retrycodes:
raise
- except Exception, e:
+ except Exception as e:
if reconnect is not None:
# in UDP mode, sometimes connected sockets can return a connection refused
# on read. Give the caller a chance to reconnect
# TERMINATE is a array. An item can be added to TERMINATE, from
# outside this function to force termination of the loop
if TERMINATE:
- raise OSError, "Killed"
+ raise OSError("Killed")
try:
rsock.bind((local_addr, local_port))
break
keepalive_thread.start()
for i in xrange(900):
if TERMINATE:
- raise OSError, "Killed"
+ raise OSError("Killed")
try:
heartbeat = rsock.recv(10)
break
if stop:
break
if TERMINATE:
- raise OSError, "Killed"
+ raise OSError("Killed")
try:
rsock.connect((peer_addr, peer_port))
sock = rsock
if stop:
break
if TERMINATE:
- raise OSError, "Killed"
+ raise OSError("Killed")
try:
lsock.bind((local_addr, local_port))
break
lsock.listen(1)
for i in xrange(30):
if TERMINATE:
- raise OSError, "Killed"
+ raise OSError("Killed")
rlist, wlist, xlist = select.select([lsock], [], [], timeout)
if stop:
break
if end:
break
if TERMINATE:
- raise OSError, "Killed"
+ raise OSError("Killed")
hand = struct.pack("!L", random.randint(0, 2**30))
stop = []
lresult = []
end = True
if not sock:
- raise OSError, "Error: tcp_establish could not establish connection."
+ raise OSError("Error: tcp_establish could not establish connection.")
return sock