diff --git a/src/pybind/cephfs/cephfs.pyx b/src/pybind/cephfs/cephfs.pyx index b7b406cd95e32..94df1b21a995c 100644 --- a/src/pybind/cephfs/cephfs.pyx +++ b/src/pybind/cephfs/cephfs.pyx @@ -16,9 +16,7 @@ import os import sys # Are we running Python 2.x -_python2 = sys.hexversion < 0x03000000 - -if _python2: +if sys.version_info[0] < 3: str_type = basestring else: str_type = str @@ -153,51 +151,59 @@ class Error(Exception): pass -class PermissionError(Error): - pass +class OSError(Error): + def __init__(self, errno, strerror): + self.errno = errno + self.strerror = strerror + + def __str__(self): + return '[Errno {0}] {1}'.format(self.errno, self.strerror) -class ObjectNotFound(Error): +class PermissionError(OSError): pass -class NoData(Error): +class ObjectNotFound(OSError): pass -class ObjectExists(Error): +class NoData(OSError): pass -class IOError(Error): +class ObjectExists(OSError): pass -class NoSpace(Error): +class IOError(OSError): pass -class InvalidValue(Error): +class NoSpace(OSError): pass -class OperationNotSupported(Error): +class InvalidValue(OSError): pass -class IncompleteWriteError(Error): +class OperationNotSupported(OSError): pass class LibCephFSStateError(Error): pass -class WouldBlock(Error): + +class WouldBlock(OSError): pass -class OutOfRange(Error): + +class OutOfRange(OSError): pass + IF UNAME_SYSNAME == "FreeBSD": cdef errno_to_exception = { errno.EPERM : PermissionError, @@ -238,9 +244,9 @@ cdef make_ex(ret, msg): """ ret = abs(ret) if ret in errno_to_exception: - return errno_to_exception[ret](msg) + return errno_to_exception[ret](ret, msg) else: - return Error(msg + (": error code %d" % ret)) + return Error(ret, msg + (": error code %d" % ret)) class DirEntry(namedtuple('DirEntry', diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 983ea460efbe9..02c1f82d79807 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -28,9 +28,7 @@ from functools import partial, wraps from itertools import chain # Are we running Python 2.x -_python2 = sys.hexversion < 0x03000000 - -if _python2: +if sys.version_info[0] < 3: str_type = basestring else: str_type = str @@ -297,59 +295,68 @@ LIBRADOS_CREATE_IDEMPOTENT = _LIBRADOS_CREATE_IDEMPOTENT ANONYMOUS_AUID = 0xffffffffffffffff ADMIN_AUID = 0 + class Error(Exception): """ `Error` class, derived from `Exception` """ + pass class InvalidArgumentError(Error): pass -class InterruptedOrTimeoutError(Error): - """ `InterruptedOrTimeoutError` class, derived from `Error` """ - pass +class OSError(Error): + """ `OSError` class, derived from `Error` """ + def __init__(self, errno, strerror): + self.errno = errno + self.strerror = strerror + + def __str__(self): + return '[Errno {0}] {1}'.format(self.errno, self.strerror) -class PermissionError(Error): - """ `PermissionError` class, derived from `Error` """ +class InterruptedOrTimeoutError(OSError): + """ `InterruptedOrTimeoutError` class, derived from `OSError` """ pass -class PermissionDeniedError(Error): - """ deal with EACCES related. """ + +class PermissionError(OSError): + """ `PermissionError` class, derived from `OSError` """ pass -class ObjectNotFound(Error): - """ `ObjectNotFound` class, derived from `Error` """ + +class PermissionDeniedError(OSError): + """ deal with EACCES related. """ pass -class NoData(Error): - """ `NoData` class, derived from `Error` """ +class ObjectNotFound(OSError): + """ `ObjectNotFound` class, derived from `OSError` """ pass -class ObjectExists(Error): - """ `ObjectExists` class, derived from `Error` """ +class NoData(OSError): + """ `NoData` class, derived from `OSError` """ pass -class ObjectBusy(Error): - """ `ObjectBusy` class, derived from `Error` """ +class ObjectExists(OSError): + """ `ObjectExists` class, derived from `OSError` """ pass -class IOError(Error): - """ `IOError` class, derived from `Error` """ +class ObjectBusy(OSError): + """ `ObjectBusy` class, derived from `IOError` """ pass -class NoSpace(Error): - """ `NoSpace` class, derived from `Error` """ +class IOError(OSError): + """ `ObjectBusy` class, derived from `OSError` """ pass -class IncompleteWriteError(Error): - """ `IncompleteWriteError` class, derived from `Error` """ +class NoSpace(OSError): + """ `NoSpace` class, derived from `OSError` """ pass @@ -362,6 +369,7 @@ class IoctxStateError(Error): """ `IoctxStateError` class, derived from `Error` """ pass + class ObjectStateError(Error): """ `ObjectStateError` class, derived from `Error` """ pass @@ -372,8 +380,8 @@ class LogicError(Error): pass -class TimedOut(Error): - """ `TimedOut` class, derived from `Error` """ +class TimedOut(OSError): + """ `TimedOut` class, derived from `OSError` """ pass @@ -419,9 +427,9 @@ cdef make_ex(ret, msg): """ ret = abs(ret) if ret in errno_to_exception: - return errno_to_exception[ret](msg) + return errno_to_exception[ret](ret, msg) else: - return Error(msg + (": error code %d" % ret)) + return Error(ret, msg + (": error code %d" % ret)) # helper to specify an optional argument, where in addition to `cls`, `None` diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 08d067bf53479..ced4d5d8b1679 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -381,31 +381,41 @@ class Error(Exception): pass -class PermissionError(Error): +class OSError(Error): + """ `OSError` class, derived from `Error` """ + def __init__(self, errno, strerror): + self.errno = errno + self.strerror = strerror + + def __str__(self): + return '[Errno {0}] {1}'.format(self.errno, self.strerror) + + +class PermissionError(OSError): pass -class ImageNotFound(Error): +class ImageNotFound(OSError): pass -class ImageExists(Error): +class ImageExists(OSError): pass -class IOError(Error): +class IOError(OSError): pass -class NoSpace(Error): +class NoSpace(OSError): pass -class IncompleteWriteError(Error): +class IncompleteWriteError(OSError): pass -class InvalidArgument(Error): +class InvalidArgument(OSError): pass @@ -413,34 +423,34 @@ class LogicError(Error): pass -class ReadOnlyImage(Error): +class ReadOnlyImage(OSError): pass -class ImageBusy(Error): +class ImageBusy(OSError): pass -class ImageHasSnapshots(Error): +class ImageHasSnapshots(OSError): pass -class FunctionNotSupported(Error): +class FunctionNotSupported(OSError): pass -class ArgumentOutOfRange(Error): +class ArgumentOutOfRange(OSError): pass -class ConnectionShutdown(Error): +class ConnectionShutdown(OSError): pass -class Timeout(Error): +class Timeout(OSError): pass -class DiskQuotaExceeded(Error): +class DiskQuotaExceeded(OSError): pass @@ -473,9 +483,9 @@ cdef make_ex(ret, msg): """ ret = abs(ret) if ret in errno_to_exception: - return errno_to_exception[ret](msg) + return errno_to_exception[ret](ret, msg) else: - return Error(msg + (": error code %d" % ret)) + return Error(ret, msg + (": error code %d" % ret)) cdef rados_ioctx_t convert_ioctx(rados.Ioctx ioctx) except? NULL: diff --git a/src/pybind/rgw/rgw.pyx b/src/pybind/rgw/rgw.pyx index b492d70123ad9..f512d33f84ab9 100644 --- a/src/pybind/rgw/rgw.pyx +++ b/src/pybind/rgw/rgw.pyx @@ -183,11 +183,21 @@ class Error(Exception): pass -class PermissionError(Error): +class OSError(Error): + """ `OSError` class, derived from `Error` """ + def __init__(self, errno, strerror): + self.errno = errno + self.strerror = strerror + + def __str__(self): + return '[Errno {0}] {1}'.format(self.errno, self.strerror) + + +class PermissionError(OSError): pass -class ObjectNotFound(Error): +class ObjectNotFound(OSError): pass @@ -199,7 +209,7 @@ class ObjectExists(Error): pass -class IOError(Error): +class IOError(OSError): pass @@ -299,7 +309,7 @@ cdef make_ex(ret, msg): """ ret = abs(ret) if ret in errno_to_exception: - return errno_to_exception[ret](msg) + return errno_to_exception[ret](ret, msg) else: return Error(msg + (": error code %d" % ret)) diff --git a/src/test/pybind/test_rados.py b/src/test/pybind/test_rados.py index 50b09053cdd00..a4e1efd852ee2 100644 --- a/src/test/pybind/test_rados.py +++ b/src/test/pybind/test_rados.py @@ -11,7 +11,7 @@ import sys # Are we running Python 2.x -_python2 = sys.hexversion < 0x03000000 +_python2 = sys.version_info[0] < 3 def test_rados_init_error(): assert_raises(Error, Rados, conffile='', rados_id='admin',