summaryrefslogtreecommitdiffhomepage
path: root/tests/stub_sftp.py
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/stub_sftp.py
parent3ce336c88b7bfbfad03fab17bff8cb3c3a77176c (diff)
Change all exceptions to modern format (not Py2.5 compatible)
Diffstat (limited to 'tests/stub_sftp.py')
-rw-r--r--tests/stub_sftp.py42
1 files changed, 14 insertions, 28 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):