Change all exceptions to modern format (not Py2.5 compatible)
This commit is contained in:
parent
3ce336c88b
commit
25dd096da0
|
@ -113,8 +113,7 @@ if hostname.find(':') >= 0:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.connect((hostname, port))
|
sock.connect((hostname, port))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Connect failed: ' + str(e))
|
print('*** Connect failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -171,8 +170,7 @@ try:
|
||||||
chan.close()
|
chan.close()
|
||||||
t.close()
|
t.close()
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -84,8 +84,7 @@ try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
sock.bind(('', 2200))
|
sock.bind(('', 2200))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Bind failed: ' + str(e))
|
print('*** Bind failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -94,8 +93,7 @@ try:
|
||||||
sock.listen(100)
|
sock.listen(100)
|
||||||
print('Listening for connection ...')
|
print('Listening for connection ...')
|
||||||
client, addr = sock.accept()
|
client, addr = sock.accept()
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Listen/accept failed: ' + str(e))
|
print('*** Listen/accept failed: ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@ -138,8 +136,7 @@ try:
|
||||||
chan.send('\r\nI don\'t like you, ' + username + '.\r\n')
|
chan.send('\r\nI don\'t like you, ' + username + '.\r\n')
|
||||||
chan.close()
|
chan.close()
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -114,8 +114,7 @@ try:
|
||||||
|
|
||||||
t.close()
|
t.close()
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Caught exception: %s: %s' % (e.__class__, e))
|
print('*** Caught exception: %s: %s' % (e.__class__, e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -77,8 +77,7 @@ try:
|
||||||
chan.close()
|
chan.close()
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Caught exception: %s: %s' % (e.__class__, e))
|
print('*** Caught exception: %s: %s' % (e.__class__, e))
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -58,8 +58,7 @@ class Handler (SocketServer.BaseRequestHandler):
|
||||||
chan = self.ssh_transport.open_channel('direct-tcpip',
|
chan = self.ssh_transport.open_channel('direct-tcpip',
|
||||||
(self.chain_host, self.chain_port),
|
(self.chain_host, self.chain_port),
|
||||||
self.request.getpeername())
|
self.request.getpeername())
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
verbose('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
verbose('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
||||||
self.chain_port,
|
self.chain_port,
|
||||||
repr(e)))
|
repr(e)))
|
||||||
|
@ -170,8 +169,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
||||||
look_for_keys=options.look_for_keys, password=password)
|
look_for_keys=options.look_for_keys, password=password)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
|
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
@ -46,8 +46,7 @@ def handler(chan, host, port):
|
||||||
sock = socket.socket()
|
sock = socket.socket()
|
||||||
try:
|
try:
|
||||||
sock.connect((host, port))
|
sock.connect((host, port))
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
verbose('Forwarding request to %s:%d failed: %r' % (host, port, e))
|
verbose('Forwarding request to %s:%d failed: %r' % (host, port, e))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -151,8 +150,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
client.connect(server[0], server[1], username=options.user, key_filename=options.keyfile,
|
||||||
look_for_keys=options.look_for_keys, password=password)
|
look_for_keys=options.look_for_keys, password=password)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
|
print('*** Failed to connect to %s:%d: %r' % (server[0], server[1], e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
@ -306,8 +306,7 @@ class AuthHandler (object):
|
||||||
keyblob = m.get_binary()
|
keyblob = m.get_binary()
|
||||||
try:
|
try:
|
||||||
key = self.transport._key_info[keytype](Message(keyblob))
|
key = self.transport._key_info[keytype](Message(keyblob))
|
||||||
except SSHException:
|
except SSHException as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self.transport._log(INFO, 'Auth rejected: public key: %s' % str(e))
|
self.transport._log(INFO, 'Auth rejected: public key: %s' % str(e))
|
||||||
key = None
|
key = None
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -452,8 +452,8 @@ class SSHClient (object):
|
||||||
two_factor = (allowed_types == ['password'])
|
two_factor = (allowed_types == ['password'])
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
except SSHException:
|
except SSHException as e:
|
||||||
saved_exception = sys.exc_info()[1]
|
saved_exception = e
|
||||||
|
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
for key_filename in key_filenames:
|
for key_filename in key_filenames:
|
||||||
|
@ -466,8 +466,8 @@ class SSHClient (object):
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
break
|
break
|
||||||
except SSHException:
|
except SSHException as e:
|
||||||
saved_exception = sys.exc_info()[1]
|
saved_exception = e
|
||||||
|
|
||||||
if not two_factor and allow_agent:
|
if not two_factor and allow_agent:
|
||||||
if self._agent == None:
|
if self._agent == None:
|
||||||
|
@ -482,8 +482,8 @@ class SSHClient (object):
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
break
|
break
|
||||||
except SSHException:
|
except SSHException as e:
|
||||||
saved_exception = sys.exc_info()[1]
|
saved_exception = e
|
||||||
|
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
keyfiles = []
|
keyfiles = []
|
||||||
|
@ -514,8 +514,8 @@ class SSHClient (object):
|
||||||
if not two_factor:
|
if not two_factor:
|
||||||
return
|
return
|
||||||
break
|
break
|
||||||
except (SSHException, IOError):
|
except (SSHException, IOError) as e:
|
||||||
saved_exception = sys.exc_info()[1]
|
saved_exception = e
|
||||||
|
|
||||||
if password is not None:
|
if password is not None:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -187,8 +187,8 @@ class DSSKey (PKey):
|
||||||
# DSAPrivateKey = { version = 0, p, q, g, y, x }
|
# DSAPrivateKey = { version = 0, p, q, g, y, x }
|
||||||
try:
|
try:
|
||||||
keylist = BER(data).decode()
|
keylist = BER(data).decode()
|
||||||
except BERException:
|
except BERException as e:
|
||||||
raise SSHException('Unable to parse key file: ' + str(sys.exc_info()[1]))
|
raise SSHException('Unable to parse key file: ' + str(e))
|
||||||
if (type(keylist) is not list) or (len(keylist) < 6) or (keylist[0] != 0):
|
if (type(keylist) is not list) or (len(keylist) < 6) or (keylist[0] != 0):
|
||||||
raise SSHException('not a valid DSA private key file (bad ber encoding)')
|
raise SSHException('not a valid DSA private key file (bad ber encoding)')
|
||||||
self.p = keylist[1]
|
self.p = keylist[1]
|
||||||
|
|
|
@ -92,7 +92,7 @@ class HostKeyEntry:
|
||||||
log.info("Unable to handle key of type %s" % (keytype,))
|
log.info("Unable to handle key of type %s" % (keytype,))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
except binascii.Error:
|
except binascii.Error as e:
|
||||||
raise InvalidHostKey(line, sys.exc_info()[1])
|
raise InvalidHostKey(line, sys.exc_info()[1])
|
||||||
|
|
||||||
return cls(names, key)
|
return cls(names, key)
|
||||||
|
|
|
@ -216,8 +216,7 @@ class Packetizer (object):
|
||||||
n -= len(x)
|
n -= len(x)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
got_timeout = True
|
got_timeout = True
|
||||||
except socket.error:
|
except socket.error as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
# on Linux, sometimes instead of socket.timeout, we get
|
# on Linux, sometimes instead of socket.timeout, we get
|
||||||
# EAGAIN. this is a bug in recent (> 2.6.9) kernels but
|
# EAGAIN. this is a bug in recent (> 2.6.9) kernels but
|
||||||
# we need to work around it.
|
# we need to work around it.
|
||||||
|
@ -246,8 +245,7 @@ class Packetizer (object):
|
||||||
n = self.__socket.send(out)
|
n = self.__socket.send(out)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
retry_write = True
|
retry_write = True
|
||||||
except socket.error:
|
except socket.error as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EAGAIN):
|
if (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EAGAIN):
|
||||||
retry_write = True
|
retry_write = True
|
||||||
elif (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EINTR):
|
elif (type(e.args) is tuple) and (len(e.args) > 0) and (e.args[0] == errno.EINTR):
|
||||||
|
@ -472,8 +470,7 @@ class Packetizer (object):
|
||||||
break
|
break
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
except EnvironmentError:
|
except EnvironmentError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if ((type(e.args) is tuple) and (len(e.args) > 0) and
|
if ((type(e.args) is tuple) and (len(e.args) > 0) and
|
||||||
(e.args[0] == errno.EINTR)):
|
(e.args[0] == errno.EINTR)):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -312,8 +312,8 @@ class PKey (object):
|
||||||
# if we trudged to the end of the file, just try to cope.
|
# if we trudged to the end of the file, just try to cope.
|
||||||
try:
|
try:
|
||||||
data = decodebytes(b(''.join(lines[start:end])))
|
data = decodebytes(b(''.join(lines[start:end])))
|
||||||
except base64.binascii.Error:
|
except base64.binascii.Error as e:
|
||||||
raise SSHException('base64 decoding error: ' + str(sys.exc_info()[1]))
|
raise SSHException('base64 decoding error: ' + str(e))
|
||||||
if 'proc-type' not in headers:
|
if 'proc-type' not in headers:
|
||||||
# unencryped: done
|
# unencryped: done
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -60,8 +60,7 @@ class ProxyCommand(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.process.stdin.write(content)
|
self.process.stdin.write(content)
|
||||||
except IOError:
|
except IOError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
# There was a problem with the child process. It probably
|
# There was a problem with the child process. It probably
|
||||||
# died and we can't proceed. The best option here is to
|
# died and we can't proceed. The best option here is to
|
||||||
# raise an exception informing the user that the informed
|
# raise an exception informing the user that the informed
|
||||||
|
@ -81,8 +80,7 @@ class ProxyCommand(object):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return os.read(self.process.stdout.fileno(), size)
|
return os.read(self.process.stdout.fileno(), size)
|
||||||
except IOError:
|
except IOError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
raise ProxyCommandFailure(' '.join(self.cmd), e.strerror)
|
raise ProxyCommandFailure(' '.join(self.cmd), e.strerror)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
|
|
@ -623,8 +623,7 @@ class SubsystemHandler (threading.Thread):
|
||||||
try:
|
try:
|
||||||
self.__transport._log(DEBUG, 'Starting handler for subsystem %s' % self.__name)
|
self.__transport._log(DEBUG, 'Starting handler for subsystem %s' % self.__name)
|
||||||
self.start_subsystem(self.__name, self.__transport, self.__channel)
|
self.start_subsystem(self.__name, self.__transport, self.__channel)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self.__transport._log(ERROR, 'Exception in subsystem handler for "%s": %s' %
|
self.__transport._log(ERROR, 'Exception in subsystem handler for "%s": %s' %
|
||||||
(self.__name, str(e)))
|
(self.__name, str(e)))
|
||||||
self.__transport._log(ERROR, util.tb_strings())
|
self.__transport._log(ERROR, util.tb_strings())
|
||||||
|
|
|
@ -717,8 +717,8 @@ class SFTPClient (BaseSFTP):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
t, data = self._read_packet()
|
t, data = self._read_packet()
|
||||||
except EOFError:
|
except EOFError as e:
|
||||||
raise SSHException('Server connection dropped: %s' % str(sys.exc_info()[1]))
|
raise SSHException('Server connection dropped: %s' % str(e))
|
||||||
msg = Message(data)
|
msg = Message(data)
|
||||||
num = msg.get_int()
|
num = msg.get_int()
|
||||||
if num not in self._expecting:
|
if num not in self._expecting:
|
||||||
|
|
|
@ -464,8 +464,8 @@ class SFTPFile (BufferedFile):
|
||||||
# save exception and re-raise it on next file operation
|
# save exception and re-raise it on next file operation
|
||||||
try:
|
try:
|
||||||
self.sftp._convert_status(msg)
|
self.sftp._convert_status(msg)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
self._saved_exception = sys.exc_info()[1]
|
self._saved_exception = e
|
||||||
return
|
return
|
||||||
if t != CMD_DATA:
|
if t != CMD_DATA:
|
||||||
raise SFTPError('Expected data')
|
raise SFTPError('Expected data')
|
||||||
|
|
|
@ -100,8 +100,7 @@ class SFTPHandle (object):
|
||||||
readfile.seek(offset)
|
readfile.seek(offset)
|
||||||
self.__tell = offset
|
self.__tell = offset
|
||||||
data = readfile.read(length)
|
data = readfile.read(length)
|
||||||
except IOError:
|
except IOError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self.__tell = None
|
self.__tell = None
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
self.__tell += len(data)
|
self.__tell += len(data)
|
||||||
|
@ -140,8 +139,7 @@ class SFTPHandle (object):
|
||||||
self.__tell = offset
|
self.__tell = offset
|
||||||
writefile.write(data)
|
writefile.write(data)
|
||||||
writefile.flush()
|
writefile.flush()
|
||||||
except IOError:
|
except IOError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self.__tell = None
|
self.__tell = None
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
if self.__tell is not None:
|
if self.__tell is not None:
|
||||||
|
|
|
@ -92,8 +92,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
||||||
except EOFError:
|
except EOFError:
|
||||||
self._log(DEBUG, 'EOF -- end of session')
|
self._log(DEBUG, 'EOF -- end of session')
|
||||||
return
|
return
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self._log(DEBUG, 'Exception on channel: ' + str(e))
|
self._log(DEBUG, 'Exception on channel: ' + str(e))
|
||||||
self._log(DEBUG, util.tb_strings())
|
self._log(DEBUG, util.tb_strings())
|
||||||
return
|
return
|
||||||
|
@ -101,8 +100,7 @@ class SFTPServer (BaseSFTP, SubsystemHandler):
|
||||||
request_number = msg.get_int()
|
request_number = msg.get_int()
|
||||||
try:
|
try:
|
||||||
self._process(t, request_number, msg)
|
self._process(t, request_number, msg)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self._log(DEBUG, 'Exception in server processing: ' + str(e))
|
self._log(DEBUG, 'Exception in server processing: ' + str(e))
|
||||||
self._log(DEBUG, util.tb_strings())
|
self._log(DEBUG, util.tb_strings())
|
||||||
# send some kind of failure message, at least
|
# send some kind of failure message, at least
|
||||||
|
|
|
@ -295,8 +295,8 @@ class Transport (threading.Thread):
|
||||||
sock = socket.socket(af, socket.SOCK_STREAM)
|
sock = socket.socket(af, socket.SOCK_STREAM)
|
||||||
try:
|
try:
|
||||||
retry_on_signal(lambda: sock.connect((hostname, port)))
|
retry_on_signal(lambda: sock.connect((hostname, port)))
|
||||||
except socket.error:
|
except socket.error as e:
|
||||||
reason = str(sys.exc_info()[1])
|
reason = str(e)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -1184,10 +1184,9 @@ class Transport (threading.Thread):
|
||||||
return []
|
return []
|
||||||
try:
|
try:
|
||||||
return self.auth_handler.wait_for_response(my_event)
|
return self.auth_handler.wait_for_response(my_event)
|
||||||
except BadAuthenticationType:
|
except BadAuthenticationType as e:
|
||||||
x = sys.exc_info()[1]
|
|
||||||
# if password auth isn't allowed, but keyboard-interactive *is*, try to fudge it
|
# if password auth isn't allowed, but keyboard-interactive *is*, try to fudge it
|
||||||
if not fallback or ('keyboard-interactive' not in x.allowed_types):
|
if not fallback or ('keyboard-interactive' not in e.allowed_types):
|
||||||
raise
|
raise
|
||||||
try:
|
try:
|
||||||
def handler(title, instructions, fields):
|
def handler(title, instructions, fields):
|
||||||
|
@ -1203,7 +1202,7 @@ class Transport (threading.Thread):
|
||||||
return self.auth_interactive(username, handler)
|
return self.auth_interactive(username, handler)
|
||||||
except SSHException:
|
except SSHException:
|
||||||
# attempt failed; just raise the original exception
|
# attempt failed; just raise the original exception
|
||||||
raise x
|
raise e
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def auth_publickey(self, username, key, event=None):
|
def auth_publickey(self, username, key, event=None):
|
||||||
|
@ -1608,26 +1607,22 @@ class Transport (threading.Thread):
|
||||||
msg.add_byte(cMSG_UNIMPLEMENTED)
|
msg.add_byte(cMSG_UNIMPLEMENTED)
|
||||||
msg.add_int(m.seqno)
|
msg.add_int(m.seqno)
|
||||||
self._send_message(msg)
|
self._send_message(msg)
|
||||||
except SSHException:
|
except SSHException as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self._log(ERROR, 'Exception: ' + str(e))
|
self._log(ERROR, 'Exception: ' + str(e))
|
||||||
self._log(ERROR, util.tb_strings())
|
self._log(ERROR, util.tb_strings())
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
except EOFError:
|
except EOFError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self._log(DEBUG, 'EOF in transport thread')
|
self._log(DEBUG, 'EOF in transport thread')
|
||||||
#self._log(DEBUG, util.tb_strings())
|
#self._log(DEBUG, util.tb_strings())
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
except socket.error:
|
except socket.error as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if type(e.args) is tuple:
|
if type(e.args) is tuple:
|
||||||
emsg = '%s (%d)' % (e.args[1], e.args[0])
|
emsg = '%s (%d)' % (e.args[1], e.args[0])
|
||||||
else:
|
else:
|
||||||
emsg = e.args
|
emsg = e.args
|
||||||
self._log(ERROR, 'Socket exception: ' + emsg)
|
self._log(ERROR, 'Socket exception: ' + emsg)
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self._log(ERROR, 'Unknown exception: ' + str(e))
|
self._log(ERROR, 'Unknown exception: ' + str(e))
|
||||||
self._log(ERROR, util.tb_strings())
|
self._log(ERROR, util.tb_strings())
|
||||||
self.saved_exception = e
|
self.saved_exception = e
|
||||||
|
@ -1687,9 +1682,8 @@ class Transport (threading.Thread):
|
||||||
buf = self.packetizer.readline(timeout)
|
buf = self.packetizer.readline(timeout)
|
||||||
except ProxyCommandFailure:
|
except ProxyCommandFailure:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception as e:
|
||||||
x = sys.exc_info()[1]
|
raise SSHException('Error reading SSH protocol banner' + str(e))
|
||||||
raise SSHException('Error reading SSH protocol banner' + str(x))
|
|
||||||
if buf[:4] == 'SSH-':
|
if buf[:4] == 'SSH-':
|
||||||
break
|
break
|
||||||
self._log(DEBUG, 'Banner: ' + buf)
|
self._log(DEBUG, 'Banner: ' + buf)
|
||||||
|
|
|
@ -272,8 +272,7 @@ def retry_on_signal(function):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
return function()
|
return function()
|
||||||
except EnvironmentError:
|
except EnvironmentError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
if e.errno != errno.EINTR:
|
if e.errno != errno.EINTR:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,7 @@ class StubSFTPHandle (SFTPHandle):
|
||||||
def stat(self):
|
def stat(self):
|
||||||
try:
|
try:
|
||||||
return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
|
return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def chattr(self, attr):
|
def chattr(self, attr):
|
||||||
|
@ -50,8 +49,7 @@ class StubSFTPHandle (SFTPHandle):
|
||||||
try:
|
try:
|
||||||
SFTPServer.set_file_attr(self.filename, attr)
|
SFTPServer.set_file_attr(self.filename, attr)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,24 +71,21 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
attr.filename = fname
|
attr.filename = fname
|
||||||
out.append(attr)
|
out.append(attr)
|
||||||
return out
|
return out
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def stat(self, path):
|
def stat(self, path):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
return SFTPAttributes.from_stat(os.stat(path))
|
return SFTPAttributes.from_stat(os.stat(path))
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def lstat(self, path):
|
def lstat(self, path):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
return SFTPAttributes.from_stat(os.lstat(path))
|
return SFTPAttributes.from_stat(os.lstat(path))
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
|
|
||||||
def open(self, path, flags, attr):
|
def open(self, path, flags, attr):
|
||||||
|
@ -105,8 +100,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
# os.open() defaults to 0777 which is
|
# os.open() defaults to 0777 which is
|
||||||
# an odd default mode for files
|
# an odd default mode for files
|
||||||
fd = os.open(path, flags, o666)
|
fd = os.open(path, flags, o666)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
if (flags & os.O_CREAT) and (attr is not None):
|
if (flags & os.O_CREAT) and (attr is not None):
|
||||||
attr._flags &= ~attr.FLAG_PERMISSIONS
|
attr._flags &= ~attr.FLAG_PERMISSIONS
|
||||||
|
@ -126,8 +120,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
fstr = 'rb'
|
fstr = 'rb'
|
||||||
try:
|
try:
|
||||||
f = os.fdopen(fd, fstr)
|
f = os.fdopen(fd, fstr)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
fobj = StubSFTPHandle(flags)
|
fobj = StubSFTPHandle(flags)
|
||||||
fobj.filename = path
|
fobj.filename = path
|
||||||
|
@ -139,8 +132,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -149,8 +141,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
newpath = self._realpath(newpath)
|
newpath = self._realpath(newpath)
|
||||||
try:
|
try:
|
||||||
os.rename(oldpath, newpath)
|
os.rename(oldpath, newpath)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -160,8 +151,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
if attr is not None:
|
if attr is not None:
|
||||||
SFTPServer.set_file_attr(path, attr)
|
SFTPServer.set_file_attr(path, attr)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -169,8 +159,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
os.rmdir(path)
|
os.rmdir(path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -178,8 +167,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
SFTPServer.set_file_attr(path, attr)
|
SFTPServer.set_file_attr(path, attr)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -199,8 +187,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
target_path = '<error>'
|
target_path = '<error>'
|
||||||
try:
|
try:
|
||||||
os.symlink(target_path, path)
|
os.symlink(target_path, path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
return SFTP_OK
|
return SFTP_OK
|
||||||
|
|
||||||
|
@ -208,8 +195,7 @@ class StubSFTPServer (SFTPServerInterface):
|
||||||
path = self._realpath(path)
|
path = self._realpath(path)
|
||||||
try:
|
try:
|
||||||
symlink = os.readlink(path)
|
symlink = os.readlink(path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
return SFTPServer.convert_errno(e.errno)
|
return SFTPServer.convert_errno(e.errno)
|
||||||
# if it's absolute, remove the root
|
# if it's absolute, remove the root
|
||||||
if os.path.isabs(symlink):
|
if os.path.isabs(symlink):
|
||||||
|
|
|
@ -650,8 +650,7 @@ class SFTPTest (unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
sftp.rename(FOLDER + '/something', FOLDER + '/' + unicode_folder)
|
sftp.rename(FOLDER + '/something', FOLDER + '/' + unicode_folder)
|
||||||
sftp.open(b(FOLDER) + utf8_folder, 'r')
|
sftp.open(b(FOLDER) + utf8_folder, 'r')
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = sys.exc_info()[1]
|
|
||||||
self.fail('exception ' + str(e))
|
self.fail('exception ' + str(e))
|
||||||
sftp.unlink(b(FOLDER) + utf8_folder)
|
sftp.unlink(b(FOLDER) + utf8_folder)
|
||||||
|
|
||||||
|
|
|
@ -302,9 +302,8 @@ class TransportTest(ParamikoTest):
|
||||||
try:
|
try:
|
||||||
chan = self.tc.open_channel('bogus')
|
chan = self.tc.open_channel('bogus')
|
||||||
self.fail('expected exception')
|
self.fail('expected exception')
|
||||||
except ChannelException:
|
except ChannelException as e:
|
||||||
x = sys.exc_info()[1]
|
self.assertTrue(e.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
|
||||||
self.assertTrue(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
|
|
||||||
|
|
||||||
def test_9_exit_status(self):
|
def test_9_exit_status(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue