<s> from combi . _python_toolbox import exceptions <EOL> from combi . _python_toolbox import cute_iter_tools <EOL> from combi . _python_toolbox import nifty_collections <EOL> from combi . _python_toolbox import caching <EOL> from combi . _python_toolbox . third_party import sortedcontainers <EOL> from . . selection_space import SelectionSpace <EOL> class Variation ( nifty_collections . CuteEnum ) : <EOL> '''<STR_LIT>''' <EOL> RAPPLIED = '<STR_LIT>' <EOL> RECURRENT = '<STR_LIT>' <EOL> PARTIAL = '<STR_LIT>' <EOL> COMBINATION = '<STR_LIT>' <EOL> DAPPLIED = '<STR_LIT>' <EOL> FIXED = '<STR_LIT>' <EOL> DEGREED = '<STR_LIT>' <EOL> SLICED = '<STR_LIT>' <EOL> TYPED = '<STR_LIT>' <EOL> __order__ = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class UnallowedVariationSelectionException ( exceptions . CuteException ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , variation_clash ) : <EOL> self . variation_clash = variation_clash <EOL> assert variation_clash in variation_clashes <EOL> super ( UnallowedVariationSelectionException , self ) . __init__ ( <EOL> "<STR_LIT>" % ( <EOL> '<STR_LIT>' . join ( <EOL> '<STR_LIT>' % ( <EOL> '<STR_LIT>' if included else '<STR_LIT>' , <EOL> variation . value <EOL> ) for variation , included in variation_clash . items ( ) <EOL> ) <EOL> ) <EOL> ) <EOL> variation_clashes = ( <EOL> { Variation . DAPPLIED : True , Variation . COMBINATION : True , } , <EOL> { Variation . DEGREED : True , Variation . COMBINATION : True , } , <EOL> { Variation . DEGREED : True , Variation . PARTIAL : True , } , <EOL> { Variation . DEGREED : True , Variation . RECURRENT : True , } , <EOL> { Variation . COMBINATION : True , Variation . FIXED : True , } , <EOL> { Variation . RAPPLIED : False , Variation . RECURRENT : True , } , <EOL> ) <EOL> '''<STR_LIT>''' <EOL> class VariationSelectionSpace ( SelectionSpace ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self ) : <EOL> SelectionSpace . __init__ ( self , Variation ) <EOL> @ caching . cache ( ) <EOL> def __getitem__ ( self , i ) : <EOL> return VariationSelection ( SelectionSpace . __getitem__ ( self , i ) ) <EOL> def index ( self , variation_selection ) : <EOL> return super ( VariationSelectionSpace , self ) . index ( <EOL> variation_selection . variations <EOL> ) <EOL> @ caching . cache ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' <EOL> @ caching . CachedProperty <EOL> def allowed_variation_selections ( self ) : <EOL> '''<STR_LIT>''' <EOL> return tuple ( variation_selection for variation_selection in self if <EOL> variation_selection . is_allowed ) <EOL> @ caching . CachedProperty <EOL> def unallowed_variation_selections ( self ) : <EOL> '''<STR_LIT>''' <EOL> return tuple ( variation_selection for variation_selection in self if <EOL> not variation_selection . is_allowed ) <EOL> variation_selection_space = VariationSelectionSpace ( ) <EOL> class VariationSelectionType ( type ) : <EOL> __call__ = lambda cls , variations : cls . _create_from_sorted_set ( <EOL> sortedcontainers . SortedSet ( variations ) ) <EOL> class VariationSelection ( object ) : <EOL> '''<STR_LIT>''' <EOL> __metaclass__ = VariationSelectionType <EOL> @ classmethod <EOL> @ caching . cache ( ) <EOL> def _create_from_sorted_set ( cls , variations ) : <EOL> '''<STR_LIT>''' <EOL> variation_selection = super ( VariationSelection , cls ) . __new__ ( cls ) <EOL> variation_selection . __init__ ( variations ) <EOL> return variation_selection <EOL> def __init__ ( self , variations ) : <EOL> self . variations = variations <EOL> assert cute_iter_tools . is_sorted ( self . variations ) <EOL> self . is_rapplied = Variation . RAPPLIED in self . variations <EOL> self . is_recurrent = Variation . RECURRENT in self . variations <EOL> self . is_partial = Variation . PARTIAL in self . variations <EOL> self . is_combination = Variation . COMBINATION in self . variations <EOL> self . is_dapplied = Variation . DAPPLIED in self . variations <EOL> self . is_fixed = Variation . FIXED in self . variations <EOL> self . is_degreed = Variation . DEGREED in self . variations <EOL> self . is_sliced = Variation . SLICED in self . variations <EOL> self . is_typed = Variation . TYPED in self . variations <EOL> self . is_pure = not self . variations <EOL> @ caching . cache ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> type ( self ) . __name__ , <EOL> self . number , <EOL> '<STR_LIT:U+002CU+0020>' . join ( variation . value for variation in self . variations ) <EOL> or '<STR_LIT>' <EOL> ) <EOL> @ caching . CachedProperty <EOL> def is_allowed ( self ) : <EOL> '''<STR_LIT>''' <EOL> _variations_set = set ( self . variations ) <EOL> for variation_clash in variation_clashes : <EOL> for variation , included in variation_clash . items ( ) : <EOL> if ( variation in _variations_set ) != included : <EOL> break <EOL> else : <EOL> return False <EOL> else : <EOL> return True <EOL> number = caching . CachedProperty ( <EOL> variation_selection_space . index , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> _reduced = caching . CachedProperty ( lambda self : ( type ( self ) , self . number ) ) <EOL> _hash = caching . CachedProperty ( lambda self : hash ( self . _reduced ) ) <EOL> __eq__ = lambda self , other : isinstance ( other , VariationSelection ) and self . _reduced == other . _reduced <EOL> __hash__ = lambda self : self . _hash </s>
