summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Al-Gaaf <danny.al-gaaf@bisect.de>2013-04-05 13:28:05 +0200
committerDanny Al-Gaaf <danny.al-gaaf@bisect.de>2013-04-07 18:26:56 +0200
commit059c512f3a95e32b9c380b36de98c9109db6943b (patch)
tree90db694c8c7d2a11e41755a7e6d457a8502d1434
parent5559e1d7c81bf6eb1a7564834f368daede812878 (diff)
downloadceph-059c512f3a95e32b9c380b36de98c9109db6943b.tar.gz
pybind: unify make_ex() code in cephfs.py and rados.py
Signed-off-by: Danny Al-Gaaf <danny.al-gaaf@bisect.de>
-rw-r--r--src/pybind/cephfs.py22
-rwxr-xr-xsrc/pybind/rados.py22
2 files changed, 20 insertions, 24 deletions
diff --git a/src/pybind/cephfs.py b/src/pybind/cephfs.py
index 443c7334f9d..6a769b2a8aa 100644
--- a/src/pybind/cephfs.py
+++ b/src/pybind/cephfs.py
@@ -45,19 +45,17 @@ def make_ex(ret, msg):
:returns: a subclass of :class:`Error`
"""
+ errors = {
+ errno.EPERM : PermissionError,
+ errno.ENOENT : ObjectNotFound,
+ errno.EIO : IOError,
+ errno.ENOSPC : NoSpace,
+ errno.EEXIST : ObjectExists,
+ errno.ENODATA : NoData
+ }
ret = abs(ret)
- if ret == errno.EPERM:
- return PermissionError(msg)
- elif ret == errno.ENOENT:
- return ObjectNotFound(msg)
- elif ret == errno.EIO:
- return IOError(msg)
- elif ret == errno.ENOSPC:
- return NoSpace(msg)
- elif ret == errno.EEXIST:
- return ObjectExists(msg)
- elif ret == errno.ENODATA:
- return NoData(msg)
+ if ret in errors:
+ return errors[ret](msg)
else:
return Error(msg + (": error code %d" % ret))
diff --git a/src/pybind/rados.py b/src/pybind/rados.py
index 0f1ea31bdfb..dee4d800dff 100755
--- a/src/pybind/rados.py
+++ b/src/pybind/rados.py
@@ -62,19 +62,17 @@ def make_ex(ret, msg):
:returns: a subclass of :class:`Error`
"""
+ errors = {
+ errno.EPERM : PermissionError,
+ errno.ENOENT : ObjectNotFound,
+ errno.EIO : IOError,
+ errno.ENOSPC : NoSpace,
+ errno.EEXIST : ObjectExists,
+ errno.ENODATA : NoData
+ }
ret = abs(ret)
- if (ret == errno.EPERM):
- return PermissionError(msg)
- elif (ret == errno.ENOENT):
- return ObjectNotFound(msg)
- elif (ret == errno.EIO):
- return IOError(msg)
- elif (ret == errno.ENOSPC):
- return NoSpace(msg)
- elif (ret == errno.EEXIST):
- return ObjectExists(msg)
- elif (ret == errno.ENODATA):
- return NoData(msg)
+ if ret in errors:
+ return errors[ret](msg)
else:
return Error(msg + (": error code %d" % ret))