viff

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 diff
     1.1 --- a/viff/runtime.py	Tue Sep 16 16:11:10 2008 +0200
     1.2 +++ b/viff/runtime.py	Tue Sep 16 16:07:10 2008 +0200
     1.3 @@ -1073,6 +1073,18 @@
     1.4          result.addCallback(shamir.recombine)
     1.5          return result
     1.6  
     1.7 +def make_runtime_class(runtime_class=Runtime, mixins=None):
     1.8 +    """Creates a new runtime class with *runtime_class* as a base
     1.9 +    class mixing in the *mixins*.
    1.10 +    """
    1.11 +    if mixins is None:
    1.12 +        return runtime_class
    1.13 +    else:
    1.14 +        # We must include at least one new-style class in bases. We
    1.15 +        # include it last to avoid overriding __init__ from the other
    1.16 +        # base classes.
    1.17 +        bases = (runtime_class,) + tuple(mixins) + (object,)
    1.18 +        return type("ExtendedRuntime", bases, {})
    1.19  
    1.20  def create_runtime(id, players, threshold, options=None, runtime_class=Runtime):
    1.21      """Create a :class:`Runtime` and connect to the other players.