From 9d47e5e4170bf9ddc3e642362027f7eb741380ca Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 26 Jun 2017 19:13:58 -0400 Subject: [PATCH] pybind: restore original API for backwards compatibility Fixes: http://tracker.ceph.com/issues/20421 Signed-off-by: Jason Dillaman --- src/pybind/rados/rados.pyx | 15 ++++++++++----- src/pybind/rbd/rbd.pyx | 15 +++++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 9e8430e246eb..132da45ad908 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -312,13 +312,18 @@ class InvalidArgumentError(Error): class OSError(Error): """ `OSError` class, derived from `Error` """ - def __init__(self, errno, strerror): + def __init__(self, message, errno=None): + super(OSError, self).__init__(message) self.errno = errno - self.strerror = strerror def __str__(self): - return '[Errno {0}] {1}'.format(self.errno, self.strerror) + msg = super(OSError, self).__str__() + if self.errno is None: + return msg + return '[errno {0}] {1}'.format(self.errno, msg) + def __reduce__(self): + return (self.__class__, (self.message, self.errno)) class InterruptedOrTimeoutError(OSError): """ `InterruptedOrTimeoutError` class, derived from `OSError` """ @@ -432,9 +437,9 @@ cdef make_ex(ret, msg): """ ret = abs(ret) if ret in errno_to_exception: - return errno_to_exception[ret](ret, msg) + return errno_to_exception[ret](msg, errno=ret) else: - return Error(ret, msg + (": error code %d" % ret)) + return OSError(msg, errno=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 8de6b3cab844..f0f52f3cf1b1 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -388,15 +388,18 @@ class Error(Exception): class OSError(Error): """ `OSError` class, derived from `Error` """ - def __init__(self, errno, strerror): + def __init__(self, message, errno=None): + super(OSError, self).__init__(message) self.errno = errno - self.strerror = strerror def __str__(self): - return '[Errno {0}] {1}'.format(self.errno, self.strerror) + msg = super(OSError, self).__str__() + if self.errno is None: + return msg + return '[errno {0}] {1}'.format(self.errno, msg) def __reduce__(self): - return (self.__class__, (self.errno, self.strerror)) + return (self.__class__, (self.message, self.errno)) class PermissionError(OSError): pass @@ -490,9 +493,9 @@ cdef make_ex(ret, msg): """ ret = abs(ret) if ret in errno_to_exception: - return errno_to_exception[ret](ret, msg) + return errno_to_exception[ret](msg, errno=ret) else: - return Error(ret, msg + (": error code %d" % ret)) + return OSError(msg, errno=ret) cdef rados_ioctx_t convert_ioctx(rados.Ioctx ioctx) except? NULL: -- 2.47.3