<s> from comparable import ComparableMixin <EOL> class IncompatibleTypesError ( Exception ) : <EOL> pass <EOL> class InvalidValueError ( Exception ) : <EOL> pass <EOL> class ColorValue ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . colordef = kwargs . pop ( '<STR_LIT>' ) <EOL> def get_kwargs ( self ) : <EOL> kwargs = { } <EOL> kwargs [ '<STR_LIT>' ] = self . get_colordef ( ) <EOL> return kwargs <EOL> def clone ( self ) : <EOL> kwargs = self . get_kwargs ( ) <EOL> return self . __class__ ( ** kwargs ) <EOL> def check_compatibility ( self , other ) : <EOL> if self . get_color_id ( ) != other . get_color_id ( ) : <EOL> raise IncompatibleTypesError <EOL> def get_colordef ( self ) : <EOL> return self . colordef <EOL> def get_color_id ( self ) : <EOL> return self . colordef . get_color_id ( ) <EOL> def is_uncolored ( self ) : <EOL> return self . get_color_id ( ) == <NUM_LIT:0> <EOL> class AdditiveColorValue ( ColorValue , ComparableMixin ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( AdditiveColorValue , self ) . __init__ ( ** kwargs ) <EOL> self . value = int ( kwargs . pop ( '<STR_LIT:value>' ) ) <EOL> if not isinstance ( self . value , int ) : <EOL> raise InvalidValueError ( '<STR_LIT>' % self . value . __class__ ) <EOL> def get_kwargs ( self ) : <EOL> kwargs = super ( AdditiveColorValue , self ) . get_kwargs ( ) <EOL> kwargs [ '<STR_LIT:value>' ] = self . get_value ( ) <EOL> return kwargs <EOL> def get_value ( self ) : <EOL> return self . value <EOL> def get_satoshi ( self ) : <EOL> return self . get_colordef ( ) . __class__ . color_to_satoshi ( self ) <EOL> def __add__ ( self , other ) : <EOL> if isinstance ( other , int ) and other == <NUM_LIT:0> : <EOL> return self <EOL> self . check_compatibility ( other ) <EOL> kwargs = self . get_kwargs ( ) <EOL> kwargs [ '<STR_LIT:value>' ] = self . get_value ( ) + other . get_value ( ) <EOL> return self . __class__ ( ** kwargs ) <EOL> def __neg__ ( self ) : <EOL> kwargs = self . get_kwargs ( ) <EOL> kwargs [ '<STR_LIT:value>' ] = - self . get_value ( ) <EOL> return self . __class__ ( ** kwargs ) <EOL> def __radd__ ( self , other ) : <EOL> return self + other <EOL> def __sub__ ( self , other ) : <EOL> if isinstance ( other , int ) and other == <NUM_LIT:0> : <EOL> return self <EOL> self . check_compatibility ( other ) <EOL> kwargs = self . get_kwargs ( ) <EOL> kwargs [ '<STR_LIT:value>' ] = self . get_value ( ) - other . get_value ( ) <EOL> return self . __class__ ( ** kwargs ) <EOL> def __iadd__ ( self , other ) : <EOL> self . check_compatibility ( other ) <EOL> self . value += other . value <EOL> return self <EOL> def __eq__ ( self , other ) : <EOL> if self . get_colordef ( ) != other . get_colordef ( ) : <EOL> return False <EOL> else : <EOL> return self . get_value ( ) == other . get_value ( ) <EOL> def __lt__ ( self , other ) : <EOL> self . check_compatibility ( other ) <EOL> return self . get_value ( ) < other . get_value ( ) <EOL> def __gt__ ( self , other ) : <EOL> if isinstance ( other , int ) and other == <NUM_LIT:0> : <EOL> return self . get_value ( ) > <NUM_LIT:0> <EOL> return other < self <EOL> @ classmethod <EOL> def sum ( cls , items ) : <EOL> return reduce ( lambda x , y : x + y , items ) <EOL> class SimpleColorValue ( AdditiveColorValue ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( SimpleColorValue , self ) . __init__ ( ** kwargs ) <EOL> if kwargs . get ( '<STR_LIT:label>' ) : <EOL> self . label = kwargs . pop ( '<STR_LIT:label>' ) <EOL> else : <EOL> self . label = '<STR_LIT>' <EOL> def get_kwargs ( self ) : <EOL> kwargs = super ( SimpleColorValue , self ) . get_kwargs ( ) <EOL> kwargs [ '<STR_LIT:label>' ] = self . get_label ( ) <EOL> return kwargs <EOL> def get_label ( self ) : <EOL> return self . label <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . get_label ( ) or self . get_colordef ( ) , self . value ) </s>
