<s> from __future__ import ( absolute_import , division , generators , nested_scopes , print_function , <EOL> unicode_literals , with_statement ) <EOL> import copy <EOL> from pants . option . ranked_value import RankedValue <EOL> class OptionValueContainer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _value_map = { } <EOL> def get_rank ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . _value_map . get ( key ) . rank <EOL> def is_flagged ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . get_rank ( key ) == RankedValue . FLAG <EOL> def is_default ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . get_rank ( key ) in ( RankedValue . NONE , RankedValue . HARDCODED ) <EOL> def update ( self , attrs ) : <EOL> """<STR_LIT>""" <EOL> for k , v in attrs . items ( ) : <EOL> self . _set ( k , v ) <EOL> def get ( self , key , default = None ) : <EOL> if key in self . _value_map : <EOL> return self . _get_underlying_value ( key ) <EOL> else : <EOL> return default <EOL> def _get_underlying_value ( self , key ) : <EOL> if key not in self . _value_map : <EOL> raise AttributeError ( key ) <EOL> val = self . _value_map [ key ] <EOL> if isinstance ( val , RankedValue ) : <EOL> return val . value <EOL> else : <EOL> return val <EOL> def _set ( self , key , value ) : <EOL> if key in self . _value_map : <EOL> existing_value = self . _value_map [ key ] <EOL> existing_rank = existing_value . rank <EOL> else : <EOL> existing_rank = RankedValue . NONE <EOL> if isinstance ( value , RankedValue ) : <EOL> new_rank = value . rank <EOL> else : <EOL> raise AttributeError ( '<STR_LIT>' . format ( value ) ) <EOL> if new_rank >= existing_rank : <EOL> self . _value_map [ key ] = value <EOL> def __getitem__ ( self , key ) : <EOL> return getattr ( self , key ) <EOL> def __setattr__ ( self , key , value ) : <EOL> if key == '<STR_LIT>' : <EOL> return super ( OptionValueContainer , self ) . __setattr__ ( key , value ) <EOL> self . _set ( key , value ) <EOL> def __getattr__ ( self , key ) : <EOL> if key == '<STR_LIT>' : <EOL> raise AttributeError ( key ) <EOL> return self . _get_underlying_value ( key ) <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> for name in sorted ( self . _value_map . keys ( ) ) : <EOL> yield name <EOL> def __copy__ ( self ) : <EOL> """<STR_LIT>""" <EOL> ret = type ( self ) ( ) <EOL> ret . _value_map = copy . copy ( self . _value_map ) <EOL> return ret </s>
