<s> """<STR_LIT>""" <EOL> import warnings <EOL> from openmdao . components . exec_comp import ExecComp <EOL> class ConstraintComp ( ExecComp ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr , out = '<STR_LIT>' ) : <EOL> warnings . simplefilter ( '<STR_LIT>' , DeprecationWarning ) <EOL> warnings . warn ( "<STR_LIT>" , <EOL> DeprecationWarning , stacklevel = <NUM_LIT:2> ) <EOL> warnings . simplefilter ( '<STR_LIT:ignore>' , DeprecationWarning ) <EOL> newexpr = _combined_expr ( expr ) <EOL> super ( ConstraintComp , self ) . __init__ ( "<STR_LIT>" % ( out , newexpr ) ) <EOL> def _combined_expr ( expr ) : <EOL> """<STR_LIT>""" <EOL> lhs , op , rhs = _parse_constraint ( expr ) <EOL> first , second = ( rhs , lhs ) if op . startswith ( '<STR_LIT:>>' ) else ( lhs , rhs ) <EOL> try : <EOL> if float ( first ) == <NUM_LIT:0> : <EOL> return "<STR_LIT>" % second <EOL> except Exception : <EOL> pass <EOL> try : <EOL> if float ( second ) == <NUM_LIT:0.> : <EOL> return first <EOL> except Exception : <EOL> pass <EOL> return '<STR_LIT>' % ( first , second ) <EOL> def _parse_constraint ( expr_string ) : <EOL> """<STR_LIT>""" <EOL> for comparator in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:>>' , '<STR_LIT:<>' , '<STR_LIT:=>' ] : <EOL> parts = expr_string . split ( comparator ) <EOL> if len ( parts ) == <NUM_LIT:2> : <EOL> if comparator == '<STR_LIT>' : <EOL> break <EOL> return ( parts [ <NUM_LIT:0> ] . strip ( ) , comparator , parts [ <NUM_LIT:1> ] . strip ( ) ) <EOL> msg = "<STR_LIT>" <EOL> raise ValueError ( msg ) </s>
