summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2017-05-02 16:20:28 -0700
committerTim Burke <tim.burke@gmail.com>2017-05-02 16:20:28 -0700
commit607500d3c5957449720d17228954221784201d97 (patch)
tree630c766c5f7beed2ad6b32e2c35f00d2a8511fca
parentea1b479a816650242999f4c19401d201f6160047 (diff)
downloadpyeclib-607500d3c5957449720d17228954221784201d97.tar.gz
Simplify required-method check
Change-Id: I527ab490d707871cc9c08345e3213ec2da7c0c43
-rw-r--r--pyeclib/ec_iface.py39
1 files changed, 17 insertions, 22 deletions
diff --git a/pyeclib/ec_iface.py b/pyeclib/ec_iface.py
index 59bf1fb..6639e32 100644
--- a/pyeclib/ec_iface.py
+++ b/pyeclib/ec_iface.py
@@ -215,30 +215,25 @@ class ECDriver(object):
#
# Verify that the imported library implements the required functions
#
- required_methods = {
- 'decode': 0,
- 'encode': 0,
- 'reconstruct': 0,
- 'fragments_needed': 0,
- 'min_parity_fragments_needed': 0,
- 'get_metadata': 0,
- 'verify_stripe_metadata': 0,
- 'get_segment_info': 0
- }
-
- for attr in dir(self.ec_lib_reference):
- if hasattr(getattr(self.ec_lib_reference, attr), "__call__"):
- required_methods[attr] = 1
-
- not_implemented_str = ""
- for (method, is_implemented) in required_methods.items():
- if is_implemented == 0:
- not_implemented_str += method + " "
-
- if len(not_implemented_str) > 0:
+ required_methods = [
+ 'decode',
+ 'encode',
+ 'reconstruct',
+ 'fragments_needed',
+ 'min_parity_fragments_needed',
+ 'get_metadata',
+ 'verify_stripe_metadata',
+ 'get_segment_info',
+ ]
+
+ missing_methods = ' '.join(
+ method for method in required_methods
+ if not callable(getattr(self.ec_lib_reference, method, None)))
+
+ if missing_methods:
raise ECDriverError(
"The following required methods are not implemented "
- "in %s: %s" % (self.library_import_str, not_implemented_str))
+ "in %s: %s" % (self.library_import_str, missing_methods))
def __repr__(self):
return '%s(ec_type=%r, k=%r, m=%r)' % (