changeset 920:53fde6bf9230

Added make_runtime_class function to viff.runtime. This is convenience function for dynamically mixing new runtime classes.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Tue, 16 Sep 2008 16:07:10 +0200
parents 6d14c1d7c92d
children dab7f77c5fc8
files viff/runtime.py
diffstat 1 files changed, 12 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/runtime.py	Tue Sep 16 16:11:10 2008 +0200
+++ b/viff/runtime.py	Tue Sep 16 16:07:10 2008 +0200
@@ -1073,6 +1073,18 @@
         result.addCallback(shamir.recombine)
         return result
 
+def make_runtime_class(runtime_class=Runtime, mixins=None):
+    """Creates a new runtime class with *runtime_class* as a base
+    class mixing in the *mixins*.
+    """
+    if mixins is None:
+        return runtime_class
+    else:
+        # We must include at least one new-style class in bases. We
+        # include it last to avoid overriding __init__ from the other
+        # base classes.
+        bases = (runtime_class,) + tuple(mixins) + (object,)
+        return type("ExtendedRuntime", bases, {})
 
 def create_runtime(id, players, threshold, options=None, runtime_class=Runtime):
     """Create a :class:`Runtime` and connect to the other players.