<s> from colordef import ColorDefinition , UNCOLORED_MARKER <EOL> from txspec import InvalidColorIdError <EOL> class ColorMap ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , metastore ) : <EOL> self . metastore = metastore <EOL> self . colordefs = { } <EOL> def find_color_desc ( self , color_id ) : <EOL> if color_id == <NUM_LIT:0> : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return self . metastore . find_color_desc ( color_id ) <EOL> def resolve_color_desc ( self , color_desc , auto_add = True ) : <EOL> if color_desc == "<STR_LIT>" : <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return self . metastore . resolve_color_desc ( color_desc , auto_add ) <EOL> def get_color_def ( self , color_id_or_desc ) : <EOL> """<STR_LIT>""" <EOL> if color_id_or_desc == <NUM_LIT:0> or color_id_or_desc == '<STR_LIT>' : <EOL> return UNCOLORED_MARKER <EOL> color_id = color_id_or_desc <EOL> color_desc = None <EOL> if not isinstance ( color_id , ( int , long ) ) : <EOL> color_desc = color_id_or_desc <EOL> color_id = self . resolve_color_desc ( color_id_or_desc ) <EOL> if color_id in self . colordefs : <EOL> return self . colordefs [ color_id ] <EOL> if not color_desc : <EOL> color_desc = self . find_color_desc ( color_id ) <EOL> if not color_desc : <EOL> raise InvalidColorIdError ( "<STR_LIT>" % color_id ) <EOL> cd = ColorDefinition . from_color_desc ( <EOL> color_id , color_desc ) <EOL> self . colordefs [ color_id ] = cd <EOL> return cd </s>
