<s> """<STR_LIT>""" <EOL> import collections as col <EOL> import six <EOL> class MultiView ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , model ) : <EOL> res = [ str ( model [ key ] ) for key in model ] <EOL> return "<STR_LIT:\n>" . join ( res ) <EOL> class BasicKeyValueView ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , model ) : <EOL> res = "<STR_LIT>" <EOL> for key in model : <EOL> res += "<STR_LIT>" . format ( key = key , value = model [ key ] ) <EOL> return res <EOL> class KeyValueView ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> indent_str = '<STR_LIT:U+0020>' , <EOL> key_sep = '<STR_LIT>' , <EOL> dict_sep = '<STR_LIT>' , <EOL> list_sep = '<STR_LIT>' , <EOL> anon_dict = '<STR_LIT>' , <EOL> before_dict = None , <EOL> before_list = None ) : <EOL> self . indent_str = indent_str <EOL> self . key_sep = key_sep <EOL> self . dict_sep = dict_sep <EOL> self . list_sep = list_sep <EOL> self . anon_dict = anon_dict <EOL> self . before_dict = before_dict <EOL> self . before_list = before_list <EOL> def __call__ ( self , model ) : <EOL> def serialize ( root , rootkey , indent ) : <EOL> res = [ ] <EOL> if rootkey is not None : <EOL> res . append ( ( self . indent_str * indent ) + rootkey ) <EOL> if isinstance ( root , col . Mapping ) : <EOL> if rootkey is None and indent > <NUM_LIT:0> : <EOL> res . append ( ( self . indent_str * indent ) + self . anon_dict ) <EOL> elif rootkey is not None : <EOL> res [ <NUM_LIT:0> ] += self . dict_sep <EOL> if self . before_dict is not None : <EOL> res . insert ( <NUM_LIT:0> , self . before_dict ) <EOL> for key in root : <EOL> res . extend ( serialize ( root [ key ] , key , indent + <NUM_LIT:1> ) ) <EOL> elif ( isinstance ( root , col . Sequence ) and <EOL> not isinstance ( root , six . string_types ) ) : <EOL> if rootkey is not None : <EOL> res [ <NUM_LIT:0> ] += self . list_sep <EOL> if self . before_list is not None : <EOL> res . insert ( <NUM_LIT:0> , self . before_list ) <EOL> for val in root : <EOL> res . extend ( serialize ( val , None , indent + <NUM_LIT:1> ) ) <EOL> else : <EOL> str_root = str ( root ) <EOL> if '<STR_LIT:\n>' in str_root : <EOL> if rootkey is not None : <EOL> res [ <NUM_LIT:0> ] += self . dict_sep <EOL> list_root = [ ( self . indent_str * ( indent + <NUM_LIT:1> ) ) + line <EOL> for line in str_root . split ( '<STR_LIT:\n>' ) ] <EOL> res . extend ( list_root ) <EOL> else : <EOL> try : <EOL> res [ <NUM_LIT:0> ] += self . key_sep + str_root <EOL> except IndexError : <EOL> res = [ ( self . indent_str * indent ) + str_root ] <EOL> return res <EOL> return "<STR_LIT:\n>" . join ( serialize ( model , None , - <NUM_LIT:1> ) ) <EOL> class TableView ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , column_names , column_values , table_prop_name ) : <EOL> self . table_prop_name = table_prop_name <EOL> self . column_names = column_names <EOL> self . column_values = column_values <EOL> self . column_width = ( <NUM_LIT> - len ( column_names ) + <NUM_LIT:1> ) / len ( column_names ) <EOL> column_headers = "<STR_LIT:|>" . join ( <EOL> "<STR_LIT>" + str ( n ) + "<STR_LIT>" + str ( self . column_width ) + "<STR_LIT:}>" <EOL> for n in range ( len ( column_names ) ) <EOL> ) <EOL> test_fmt = column_headers . format ( ch = column_names ) <EOL> if len ( test_fmt ) < <NUM_LIT> : <EOL> column_headers += '<STR_LIT:U+0020>' * ( <NUM_LIT> - len ( test_fmt ) ) <EOL> vert_divider = '<STR_LIT:->' * <NUM_LIT> <EOL> self . header_fmt_str = column_headers + "<STR_LIT:\n>" + vert_divider + "<STR_LIT:\n>" <EOL> self . row_fmt_str = "<STR_LIT:|>" . join ( <EOL> "<STR_LIT>" + str ( n ) + "<STR_LIT>" + str ( self . column_width ) + "<STR_LIT:}>" <EOL> for n in range ( len ( column_values ) ) <EOL> ) <EOL> def __call__ ( self , model ) : <EOL> res = self . header_fmt_str . format ( ch = self . column_names ) <EOL> for raw_row in model [ self . table_prop_name ] : <EOL> row = [ str ( raw_row [ prop_name ] ) for prop_name in self . column_values ] <EOL> res += '<STR_LIT>' . format ( self . row_fmt_str . format ( cv = row ) ) <EOL> return res </s>
