summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorScott Maxwell <scott@codecobblers.com>2013-11-19 08:06:35 -0800
committerScott Maxwell <scott@codecobblers.com>2013-11-19 08:06:35 -0800
commit25dd096da065b1bc2f35c1a62d8a7055b022818b (patch)
tree94e87015ebcb83660452c79093e1ac407e360306 /tests
parent3ce336c88b7bfbfad03fab17bff8cb3c3a77176c (diff)
Change all exceptions to modern format (not Py2.5 compatible)
Diffstat (limited to 'tests')
-rw-r--r--tests/stub_sftp.py42
-rwxr-xr-xtests/test_sftp.py3
-rw-r--r--tests/test_transport.py5
3 files changed, 17 insertions, 33 deletions
diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py
index 26ca13b3..58e4be26 100644
--- a/tests/stub_sftp.py
+++ b/tests/stub_sftp.py
@@ -40,8 +40,7 @@ class StubSFTPHandle (SFTPHandle):
def stat(self):
try:
return SFTPAttributes.from_stat(os.fstat(self.readfile.fileno()))
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
def chattr(self, attr):
@@ -50,8 +49,7 @@ class StubSFTPHandle (SFTPHandle):
try:
SFTPServer.set_file_attr(self.filename, attr)
return SFTP_OK
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
@@ -73,24 +71,21 @@ class StubSFTPServer (SFTPServerInterface):
attr.filename = fname
out.append(attr)
return out
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
def stat(self, path):
path = self._realpath(path)
try:
return SFTPAttributes.from_stat(os.stat(path))
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
def lstat(self, path):
path = self._realpath(path)
try:
return SFTPAttributes.from_stat(os.lstat(path))
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
def open(self, path, flags, attr):
@@ -105,8 +100,7 @@ class StubSFTPServer (SFTPServerInterface):
# os.open() defaults to 0777 which is
# an odd default mode for files
fd = os.open(path, flags, o666)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
if (flags & os.O_CREAT) and (attr is not None):
attr._flags &= ~attr.FLAG_PERMISSIONS
@@ -126,8 +120,7 @@ class StubSFTPServer (SFTPServerInterface):
fstr = 'rb'
try:
f = os.fdopen(fd, fstr)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
fobj = StubSFTPHandle(flags)
fobj.filename = path
@@ -139,8 +132,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
os.remove(path)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -149,8 +141,7 @@ class StubSFTPServer (SFTPServerInterface):
newpath = self._realpath(newpath)
try:
os.rename(oldpath, newpath)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -160,8 +151,7 @@ class StubSFTPServer (SFTPServerInterface):
os.mkdir(path)
if attr is not None:
SFTPServer.set_file_attr(path, attr)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -169,8 +159,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
os.rmdir(path)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -178,8 +167,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
SFTPServer.set_file_attr(path, attr)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -199,8 +187,7 @@ class StubSFTPServer (SFTPServerInterface):
target_path = '<error>'
try:
os.symlink(target_path, path)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
return SFTP_OK
@@ -208,8 +195,7 @@ class StubSFTPServer (SFTPServerInterface):
path = self._realpath(path)
try:
symlink = os.readlink(path)
- except OSError:
- e = sys.exc_info()[1]
+ except OSError as e:
return SFTPServer.convert_errno(e.errno)
# if it's absolute, remove the root
if os.path.isabs(symlink):
diff --git a/tests/test_sftp.py b/tests/test_sftp.py
index 4a412582..1a7ad02c 100755
--- a/tests/test_sftp.py
+++ b/tests/test_sftp.py
@@ -650,8 +650,7 @@ class SFTPTest (unittest.TestCase):
try:
sftp.rename(FOLDER + '/something', FOLDER + '/' + unicode_folder)
sftp.open(b(FOLDER) + utf8_folder, 'r')
- except Exception:
- e = sys.exc_info()[1]
+ except Exception as e:
self.fail('exception ' + str(e))
sftp.unlink(b(FOLDER) + utf8_folder)
diff --git a/tests/test_transport.py b/tests/test_transport.py
index 397b00ca..6f6843ba 100644
--- a/tests/test_transport.py
+++ b/tests/test_transport.py
@@ -302,9 +302,8 @@ class TransportTest(ParamikoTest):
try:
chan = self.tc.open_channel('bogus')
self.fail('expected exception')
- except ChannelException:
- x = sys.exc_info()[1]
- self.assertTrue(x.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
+ except ChannelException as e:
+ self.assertTrue(e.code == OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)
def test_9_exit_status(self):
"""