<s> from xierpa3 . toolbox . transformer import TX <EOL> from xierpa3 . attributes . attribute import Attribute <EOL> def asValue ( value ) : <EOL> if isinstance ( value , Value ) : <EOL> return value . value <EOL> return TX . px ( value ) <EOL> class Value ( Attribute ) : <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT:%s>' % self . value <EOL> class Named ( Value ) : <EOL> u"""<STR_LIT>""" <EOL> def __init__ ( self , value , name = None ) : <EOL> self . value = value <EOL> self . name = name <EOL> class Selection ( Value ) : <EOL> u"""<STR_LIT>""" <EOL> def __init__ ( self , param , values ) : <EOL> self . param = param <EOL> self . values = values <EOL> def selectFromParams ( self , params ) : <EOL> key = params . get ( self . param ) <EOL> if key is not None : <EOL> return self . values . get ( key ) or self . values . get ( '<STR_LIT:default>' ) <EOL> return None <EOL> class Z ( Value ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> class BaseCalculator ( Value ) : <EOL> u"""<STR_LIT>""" <EOL> def rawValue ( self ) : <EOL> return self . _value <EOL> def __add__ ( self , value ) : <EOL> if isinstance ( value , self . __class__ ) : <EOL> value = value . rawValue ( ) <EOL> if TX . isNumber ( value ) : <EOL> return self . __class__ ( self . rawValue ( ) + value ) <EOL> return None <EOL> def __sub__ ( self , value ) : <EOL> if isinstance ( value , self . __class__ ) : <EOL> value = value . rawValue ( ) <EOL> if TX . isNumber ( value ) : <EOL> return self . __class__ ( self . rawValue ( ) - value ) <EOL> return None <EOL> def __mul__ ( self , value ) : <EOL> if isinstance ( value , self . __class__ ) : <EOL> value = value . rawValue ( ) <EOL> if TX . isNumber ( value ) : <EOL> return self . __class__ ( self . rawValue ( ) * value ) <EOL> return None <EOL> def __div__ ( self , value ) : <EOL> if isinstance ( value , self . __class__ ) : <EOL> value = value . rawValue ( ) <EOL> if TX . isNumber ( value ) : <EOL> return self . __class__ ( self . rawValue ( ) / value ) <EOL> return None <EOL> class Px ( BaseCalculator ) : <EOL> u"""<STR_LIT>""" <EOL> def __init__ ( self , value ) : <EOL> self . _value = value <EOL> def _get_value ( self ) : <EOL> if TX . isFloat ( self . _value ) : <EOL> return '<STR_LIT>' % self . _value <EOL> if TX . isInt ( self . _value ) : <EOL> return '<STR_LIT>' % self . _value <EOL> return self . _value <EOL> value = property ( _get_value ) <EOL> class Perc ( BaseCalculator ) : <EOL> u"""<STR_LIT>""" <EOL> def __init__ ( self , value ) : <EOL> self . _value = value <EOL> def _get_value ( self ) : <EOL> if TX . isFloat ( self . _value ) : <EOL> return '<STR_LIT>' % self . _value <EOL> if TX . isInt ( self . _value ) : <EOL> return '<STR_LIT>' % self . _value <EOL> return self . _value <EOL> value = property ( _get_value ) <EOL> class Em ( BaseCalculator ) : <EOL> def __init__ ( self , value ) : <EOL> self . _value = value <EOL> def _get_value ( self ) : <EOL> if TX . isFloat ( self . _value ) : <EOL> return '<STR_LIT>' % self . _value <EOL> if TX . isInt ( self . _value ) : <EOL> return '<STR_LIT>' % self . _value <EOL> return self . _value <EOL> value = property ( _get_value ) </s>
