[Python 3]: New except syntax.

This commit is contained in:
Dorian 2013-08-13 15:57:38 -04:00
parent 0847ac780b
commit b1e235d820
24 changed files with 64 additions and 64 deletions

View File

@ -110,7 +110,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, e: except Exception as e:
print('*** Connect failed: ' + str(e)) print('*** Connect failed: ' + str(e))
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)
@ -168,7 +168,7 @@ try:
chan.close() chan.close()
t.close() t.close()
except Exception, e: except Exception as e:
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e)) print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
traceback.print_exc() traceback.print_exc()
try: try:

View File

@ -85,7 +85,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, e: except Exception as e:
print('*** Bind failed: ' + str(e)) print('*** Bind failed: ' + str(e))
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)
@ -94,7 +94,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, e: except Exception as e:
print('*** Listen/accept failed: ' + str(e)) print('*** Listen/accept failed: ' + str(e))
traceback.print_exc() traceback.print_exc()
sys.exit(1) sys.exit(1)
@ -112,7 +112,7 @@ try:
server = Server() server = Server()
try: try:
t.start_server(server=server) t.start_server(server=server)
except paramiko.SSHException, x: except paramiko.SSHException as x:
print('*** SSH negotiation failed.') print('*** SSH negotiation failed.')
sys.exit(1) sys.exit(1)
@ -137,7 +137,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, e: except Exception as e:
print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e)) print('*** Caught exception: ' + str(e.__class__) + ': ' + str(e))
traceback.print_exc() traceback.print_exc()
try: try:

View File

@ -111,7 +111,7 @@ try:
t.close() t.close()
except Exception, e: except Exception as e:
print('*** Caught exception: %s: %s' % (e.__class__, e)) print('*** Caught exception: %s: %s' % (e.__class__, e))
traceback.print_exc() traceback.print_exc()
try: try:

View File

@ -75,7 +75,7 @@ try:
chan.close() chan.close()
client.close() client.close()
except Exception, e: except Exception as e:
print('*** Caught exception: %s: %s' % (e.__class__, e)) print('*** Caught exception: %s: %s' % (e.__class__, e))
traceback.print_exc() traceback.print_exc()
try: try:

View File

@ -56,7 +56,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, e: except Exception as e:
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)))
@ -165,7 +165,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, e: except Exception as e:
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)

View File

@ -48,7 +48,7 @@ def handler(chan, host, port):
sock = socket.socket() sock = socket.socket()
try: try:
sock.connect((host, port)) sock.connect((host, port))
except Exception, e: except Exception as e:
verbose('Forwarding request to %s:%d failed: %r' % (host, port, e)) verbose('Forwarding request to %s:%d failed: %r' % (host, port, e))
return return
@ -152,7 +152,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, e: except Exception as e:
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)

View File

@ -308,7 +308,7 @@ class AuthHandler (object):
keyblob = m.get_string() keyblob = m.get_string()
try: try:
key = self.transport._key_info[keytype](Message(keyblob)) key = self.transport._key_info[keytype](Message(keyblob))
except SSHException, e: except SSHException as e:
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:

View File

@ -615,7 +615,7 @@ class Channel (object):
""" """
try: try:
out = self.in_buffer.read(nbytes, self.timeout) out = self.in_buffer.read(nbytes, self.timeout)
except PipeTimeout, e: except PipeTimeout as e:
raise socket.timeout() raise socket.timeout()
ack = self._check_add_window(len(out)) ack = self._check_add_window(len(out))
@ -665,7 +665,7 @@ class Channel (object):
""" """
try: try:
out = self.in_stderr_buffer.read(nbytes, self.timeout) out = self.in_stderr_buffer.read(nbytes, self.timeout)
except PipeTimeout, e: except PipeTimeout as e:
raise socket.timeout() raise socket.timeout()
ack = self._check_add_window(len(out)) ack = self._check_add_window(len(out))

View File

@ -452,7 +452,7 @@ 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, e: except SSHException as e:
saved_exception = e saved_exception = e
if not two_factor: if not two_factor:
@ -466,7 +466,7 @@ class SSHClient (object):
if not two_factor: if not two_factor:
return return
break break
except SSHException, e: except SSHException as e:
saved_exception = e saved_exception = e
if not two_factor and allow_agent: if not two_factor and allow_agent:
@ -482,7 +482,7 @@ class SSHClient (object):
if not two_factor: if not two_factor:
return return
break break
except SSHException, e: except SSHException as e:
saved_exception = e saved_exception = e
if not two_factor: if not two_factor:
@ -514,16 +514,16 @@ class SSHClient (object):
if not two_factor: if not two_factor:
return return
break break
except SSHException, e: except SSHException as e:
saved_exception = e saved_exception = e
except IOError, e: except IOError as e:
saved_exception = e saved_exception = e
if password is not None: if password is not None:
try: try:
self._transport.auth_password(username, password) self._transport.auth_password(username, password)
return return
except SSHException, e: except SSHException as e:
saved_exception = e saved_exception = e
elif two_factor: elif two_factor:
raise SSHException('Two-factor authentication requires a password') raise SSHException('Two-factor authentication requires a password')

View File

@ -184,7 +184,7 @@ 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, x: except BERException as x:
raise SSHException('Unable to parse key file: ' + str(x)) raise SSHException('Unable to parse key file: ' + str(x))
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)')

View File

@ -84,7 +84,7 @@ class HostKeyEntry:
else: else:
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, e: except binascii.Error as e:
raise InvalidHostKey(line, e) raise InvalidHostKey(line, e)
return cls(names, key) return cls(names, key)

View File

@ -219,7 +219,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, e: except socket.error as e:
# 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.
@ -248,7 +248,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, e: except socket.error as e:
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):
@ -473,7 +473,7 @@ class Packetizer (object):
break break
except socket.timeout: except socket.timeout:
pass pass
except EnvironmentError, e: except EnvironmentError as e:
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

View File

@ -304,7 +304,7 @@ 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 = base64.decodestring(''.join(lines[start:end])) data = base64.decodestring(''.join(lines[start:end]))
except base64.binascii.Error, e: except base64.binascii.Error as e:
raise SSHException('base64 decoding error: ' + str(e)) raise SSHException('base64 decoding error: ' + str(e))
if 'proc-type' not in headers: if 'proc-type' not in headers:
# unencryped: done # unencryped: done

View File

@ -59,7 +59,7 @@ class ProxyCommand(object):
""" """
try: try:
self.process.stdin.write(content) self.process.stdin.write(content)
except IOError, e: except IOError as e:
# 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
@ -79,7 +79,7 @@ class ProxyCommand(object):
""" """
try: try:
return os.read(self.process.stdout.fileno(), size) return os.read(self.process.stdout.fileno(), size)
except IOError, e: except IOError as e:
raise BadProxyCommand(' '.join(self.cmd), e.strerror) raise BadProxyCommand(' '.join(self.cmd), e.strerror)
def close(self): def close(self):

View File

@ -602,7 +602,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, e: except Exception as e:
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())

View File

@ -85,7 +85,7 @@ class SFTPClient (BaseSFTP):
self.ultra_debug = transport.get_hexdump() self.ultra_debug = transport.get_hexdump()
try: try:
server_version = self._send_version() server_version = self._send_version()
except EOFError, x: except EOFError as x:
raise SSHException('EOF during negotiation') raise SSHException('EOF during negotiation')
self._log(INFO, 'Opened sftp connection (server version %d)' % server_version) self._log(INFO, 'Opened sftp connection (server version %d)' % server_version)
@ -178,7 +178,7 @@ class SFTPClient (BaseSFTP):
while True: while True:
try: try:
t, msg = self._request(CMD_READDIR, handle) t, msg = self._request(CMD_READDIR, handle)
except EOFError, e: except EOFError as e:
# done with handle # done with handle
break break
if t != CMD_NAME: if t != CMD_NAME:
@ -717,7 +717,7 @@ class SFTPClient (BaseSFTP):
while True: while True:
try: try:
t, data = self._read_packet() t, data = self._read_packet()
except EOFError, e: except EOFError as e:
raise SSHException('Server connection dropped: %s' % (str(e),)) raise SSHException('Server connection dropped: %s' % (str(e),))
msg = Message(data) msg = Message(data)
num = msg.get_int() num = msg.get_int()

View File

@ -464,7 +464,7 @@ 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, x: except Exception as x:
self._saved_exception = x self._saved_exception = x
return return
if t != CMD_DATA: if t != CMD_DATA:

View File

@ -100,7 +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, e: except IOError as e:
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)
@ -139,7 +139,7 @@ class SFTPHandle (object):
self.__tell = offset self.__tell = offset
writefile.write(data) writefile.write(data)
writefile.flush() writefile.flush()
except IOError, e: except IOError as e:
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:

View File

@ -92,7 +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, e: except Exception as e:
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
@ -100,7 +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, e: except Exception as e:
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

View File

@ -292,7 +292,7 @@ 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, e: except socket.error as e:
reason = str(e) reason = str(e)
else: else:
break break
@ -1181,7 +1181,7 @@ 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, x: except BadAuthenticationType as x:
# 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 x.allowed_types):
raise raise
@ -1197,7 +1197,7 @@ class Transport (threading.Thread):
return [] return []
return [ password ] return [ password ]
return self.auth_interactive(username, handler) return self.auth_interactive(username, handler)
except SSHException, ignored: except SSHException as ignored:
# attempt failed; just raise the original exception # attempt failed; just raise the original exception
raise x raise x
return None return None
@ -1602,22 +1602,22 @@ class Transport (threading.Thread):
msg.add_byte(chr(MSG_UNIMPLEMENTED)) msg.add_byte(chr(MSG_UNIMPLEMENTED))
msg.add_int(m.seqno) msg.add_int(m.seqno)
self._send_message(msg) self._send_message(msg)
except SSHException, e: except SSHException as e:
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, e: except EOFError as e:
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, e: except socket.error as e:
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, e: except Exception as e:
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
@ -1677,7 +1677,7 @@ class Transport (threading.Thread):
buf = self.packetizer.readline(timeout) buf = self.packetizer.readline(timeout)
except ProxyCommandFailure: except ProxyCommandFailure:
raise raise
except Exception, x: except Exception as x:
raise SSHException('Error reading SSH protocol banner' + str(x)) raise SSHException('Error reading SSH protocol banner' + str(x))
if buf[:4] == 'SSH-': if buf[:4] == 'SSH-':
break break

View File

@ -276,7 +276,7 @@ def retry_on_signal(function):
while True: while True:
try: try:
return function() return function()
except EnvironmentError, e: except EnvironmentError as e:
if e.errno != errno.EINTR: if e.errno != errno.EINTR:
raise raise

View File

@ -38,7 +38,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, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
def chattr(self, attr): def chattr(self, attr):
@ -47,7 +47,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, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
@ -69,21 +69,21 @@ class StubSFTPServer (SFTPServerInterface):
attr.filename = fname attr.filename = fname
out.append(attr) out.append(attr)
return out return out
except OSError, e: except OSError as e:
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, e: except OSError as e:
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, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
def open(self, path, flags, attr): def open(self, path, flags, attr):
@ -98,7 +98,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, 0666) fd = os.open(path, flags, 0666)
except OSError, e: except OSError as e:
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
@ -118,7 +118,7 @@ class StubSFTPServer (SFTPServerInterface):
fstr = 'rb' fstr = 'rb'
try: try:
f = os.fdopen(fd, fstr) f = os.fdopen(fd, fstr)
except OSError, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
fobj = StubSFTPHandle(flags) fobj = StubSFTPHandle(flags)
fobj.filename = path fobj.filename = path
@ -130,7 +130,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path) path = self._realpath(path)
try: try:
os.remove(path) os.remove(path)
except OSError, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
return SFTP_OK return SFTP_OK
@ -139,7 +139,7 @@ class StubSFTPServer (SFTPServerInterface):
newpath = self._realpath(newpath) newpath = self._realpath(newpath)
try: try:
os.rename(oldpath, newpath) os.rename(oldpath, newpath)
except OSError, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
return SFTP_OK return SFTP_OK
@ -149,7 +149,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, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
return SFTP_OK return SFTP_OK
@ -157,7 +157,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path) path = self._realpath(path)
try: try:
os.rmdir(path) os.rmdir(path)
except OSError, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
return SFTP_OK return SFTP_OK
@ -165,7 +165,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, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
return SFTP_OK return SFTP_OK
@ -185,7 +185,7 @@ class StubSFTPServer (SFTPServerInterface):
target_path = '<error>' target_path = '<error>'
try: try:
os.symlink(target_path, path) os.symlink(target_path, path)
except OSError, e: except OSError as e:
return SFTPServer.convert_errno(e.errno) return SFTPServer.convert_errno(e.errno)
return SFTP_OK return SFTP_OK
@ -193,7 +193,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path) path = self._realpath(path)
try: try:
symlink = os.readlink(path) symlink = os.readlink(path)
except OSError, e: except OSError as e:
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):

View File

@ -644,7 +644,7 @@ class SFTPTest (unittest.TestCase):
try: try:
sftp.rename(FOLDER + '/something', FOLDER + u'/\u00fcnic\u00f8de') sftp.rename(FOLDER + '/something', FOLDER + u'/\u00fcnic\u00f8de')
sftp.open(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65', 'r') sftp.open(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65', 'r')
except Exception, e: except Exception as e:
self.fail('exception ' + e) self.fail('exception ' + e)
sftp.unlink(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65') sftp.unlink(FOLDER + '/\xc3\xbcnic\xc3\xb8\x64\x65')

View File

@ -249,7 +249,7 @@ class TransportTest(ParamikoTest):
try: try:
chan.exec_command('no') chan.exec_command('no')
self.assert_(False) self.assert_(False)
except SSHException, x: except SSHException as x:
pass pass
chan = self.tc.open_session() chan = self.tc.open_session()
@ -302,7 +302,7 @@ 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, x: except ChannelException as x:
self.assert_(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED) self.assert_(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
def test_9_exit_status(self): def test_9_exit_status(self):