aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cryptography/utils.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/cryptography/utils.py b/cryptography/utils.py
index 55187c3b..636776f4 100644
--- a/cryptography/utils.py
+++ b/cryptography/utils.py
@@ -13,6 +13,7 @@
from __future__ import absolute_import, division, print_function
+import inspect
import sys
@@ -26,6 +27,26 @@ def register_interface(iface):
return register_decorator
+class InterfaceNotImplemented(Exception):
+ pass
+
+
+def verify_interface(iface, klass):
+ for method in iface.__abstractmethods__:
+ if not hasattr(klass, method):
+ raise InterfaceNotImplemented(
+ "{0} is missing a {1!r} method".format(klass, method)
+ )
+ spec = getattr(iface, method).__func__
+ actual = getattr(klass, method)
+ if inspect.getargspec(spec) != inspect.getargspec(actual):
+ raise InterfaceNotImplemented(
+ "{0}.{1}'s signature differs from the expected".format(
+ klass, method
+ )
+ )
+
+
def bit_length(x):
if sys.version_info >= (2, 7):
return x.bit_length()