<s> """<STR_LIT>""" <EOL> import click <EOL> from SoftLayer import utils <EOL> class Column ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , path , mask = None ) : <EOL> self . name = name <EOL> self . path = path <EOL> self . mask = mask <EOL> if self . mask is None and isinstance ( path , ( tuple , list ) ) : <EOL> self . mask = '<STR_LIT:.>' . join ( path ) <EOL> class ColumnFormatter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . columns = [ ] <EOL> self . column_funcs = [ ] <EOL> self . mask_parts = set ( ) <EOL> def add_column ( self , column ) : <EOL> """<STR_LIT>""" <EOL> self . columns . append ( column . name ) <EOL> self . column_funcs . append ( column . path ) <EOL> if column . mask is not None : <EOL> self . mask_parts . add ( column . mask ) <EOL> def row ( self , data ) : <EOL> """<STR_LIT>""" <EOL> for column in self . column_funcs : <EOL> if callable ( column ) : <EOL> yield column ( data ) <EOL> else : <EOL> yield utils . lookup ( data , * column ) <EOL> def mask ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT:U+002C>' . join ( self . mask_parts ) <EOL> def get_formatter ( columns ) : <EOL> """<STR_LIT>""" <EOL> column_map = dict ( ( column . name , column ) for column in columns ) <EOL> def validate ( ctx , param , value ) : <EOL> """<STR_LIT>""" <EOL> if value == '<STR_LIT>' : <EOL> raise click . BadParameter ( '<STR_LIT>' ) <EOL> formatter = ColumnFormatter ( ) <EOL> for column in [ col . strip ( ) for col in value . split ( '<STR_LIT:U+002C>' ) ] : <EOL> if column in column_map : <EOL> formatter . add_column ( column_map [ column ] ) <EOL> else : <EOL> formatter . add_column ( Column ( column , column . split ( '<STR_LIT:.>' ) ) ) <EOL> return formatter <EOL> return validate </s>
