summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Greenan <kmgreen2@gmail.com>2015-03-11 08:55:53 -0700
committerTushar Gohad <tushar.gohad@intel.com>2015-03-11 15:45:27 -0700
commiteecc70d55a9112b5c1906f3ac220f8ca0cd0d182 (patch)
treee01ea4f138147bcee4b117acddfd875893207c5d
parent06e68bb656ad96758f9944e125a1ecd12a117089 (diff)
downloadpyeclib-eecc70d55a9112b5c1906f3ac220f8ca0cd0d182.tar.gz
Replace ECPyECLibException with ECDriverErrorv1.0.1
-rw-r--r--pyeclib/core.py39
1 files changed, 14 insertions, 25 deletions
diff --git a/pyeclib/core.py b/pyeclib/core.py
index 6a777cc..c0935c5 100644
--- a/pyeclib/core.py
+++ b/pyeclib/core.py
@@ -21,7 +21,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-from ec_iface import PyECLib_FRAGHDRCHKSUM_Types
+from ec_iface import PyECLib_FRAGHDRCHKSUM_Types, ECDriverError
import math
import pyeclib_c
from pyeclib_c import error as PyECLibError
@@ -29,17 +29,6 @@ import sys
pyver = float('%s.%s' % sys.version_info[:2])
-
-# Generic ECPyECLibException
-class ECPyECLibException(Exception):
-
- def __init__(self, error_str):
- self.error_str = error_str
-
- def __str__(self):
- return self.error_str
-
-
class ECPyECLibDriver(object):
def __init__(self, k, m, ec_type,
@@ -88,10 +77,10 @@ class ECPyECLibDriver(object):
def decode(self, fragment_payloads, ranges=None, force_metadata_checks=False):
fragment_len = self._validate_and_return_fragment_size(fragment_payloads)
if fragment_len < 0:
- raise ECPyECLibException("Invalid fragment payload in ECPyECLibDriver.decode")
+ raise ECDriverError("Invalid fragment payload in ECPyECLibDriver.decode")
if len(fragment_payloads) < self.k:
- raise ECPyECLibException("Not enough fragments given in ECPyECLibDriver.decode")
+ raise ECDriverError("Not enough fragments given in ECPyECLibDriver.decode")
try:
ret = pyeclib_c.decode(self.handle, fragment_payloads, fragment_len, ranges, force_metadata_checks)
@@ -100,14 +89,14 @@ class ECPyECLibDriver(object):
# Was there an error decoding
if ret is None:
- raise ECPyECLibException("Error decoding from fragments in ECPyECLibDriver.decode")
+ raise ECDriverError("Error decoding from fragments in ECPyECLibDriver.decode")
return ret
def reconstruct(self, fragment_payloads, indexes_to_reconstruct):
fragment_len = self._validate_and_return_fragment_size(fragment_payloads)
if fragment_len < 0:
- raise ECPyECLibException("Invalid fragment payload in ECPyECLibDriver.reconstruct")
+ raise ECDriverError("Invalid fragment payload in ECPyECLibDriver.reconstruct")
reconstructed_data = []
_fragment_payloads = fragment_payloads[:]
@@ -205,12 +194,12 @@ class ECStripingDriver(object):
"""Stripe an arbitrary-sized string into k fragments
:param k: the number of data fragments to stripe
:param m: the number of parity fragments to stripe
- :raises: ECPyECLibException if there is an error during encoding
+ :raises: ECDriverError if there is an error during encoding
"""
self.k = k
if m != 0:
- raise ECPyECLibException("This driver only supports m=0")
+ raise ECDriverError("This driver only supports m=0")
self.m = m
@@ -218,7 +207,7 @@ class ECStripingDriver(object):
"""Stripe an arbitrary-sized string into k fragments
:param data_bytes: the buffer to encode
:returns: a list of k buffers (data only)
- :raises: ECPyECLibException if there is an error during encoding
+ :raises: ECDriverError if there is an error during encoding
"""
# Main fragment size
fragment_size = math.ceil(len(data_bytes) / float(self.k))
@@ -244,16 +233,16 @@ class ECStripingDriver(object):
:param force_metadata_checks (unsupported): this driver does not support
fragment metadata
:returns: a string containing the original data
- :raises: ECPyECLibException if there is an error during decoding
+ :raises: ECDriverError if there is an error during decoding
"""
if ranges is not None:
- raise ECPyECLibException(
+ raise ECDriverError(
"Decode does not support range requests in the striping driver.")
if force_metadata_checks is not False:
- raise ECPyECLibException(
+ raise ECDriverError(
"Decode does not support metadata integrity checks in the striping driver.")
if len(fragment_payloads) != self.k:
- raise ECPyECLibException(
+ raise ECDriverError(
"Decode requires %d fragments, %d fragments were given" %
(len(fragment_payloads), self.k))
@@ -272,10 +261,10 @@ class ECStripingDriver(object):
:param available_fragment_payloads: available fragments (in order)
:param missing_fragment_indexes: indexes of missing fragments
:returns: a string containing the original data
- :raises: ECPyECLibException if there is an error during reconstruction
+ :raises: ECDriverError if there is an error during reconstruction
"""
if len(available_fragment_payloads) != self.k:
- raise ECPyECLibException(
+ raise ECDriverError(
"Reconstruction requires %d fragments, %d fragments given" %
(len(available_fragment_payloads), self.k))