<s> import re <EOL> def parse_output ( actual_out = "<STR_LIT>" , horizontal = False , mearge_header = True ) : <EOL> """<STR_LIT>""" <EOL> if horizontal : <EOL> data = actual_out . split ( '<STR_LIT:\n>' ) <EOL> heading = data . pop ( <NUM_LIT:0> ) <EOL> header_line1 = data . pop ( <NUM_LIT:0> ) <EOL> header_line2 = data . pop ( <NUM_LIT:0> ) <EOL> row_data = data [ - <NUM_LIT:3> ] <EOL> index = - <NUM_LIT:4> <EOL> while not row_data : <EOL> row_data = data [ index ] <EOL> index = index - <NUM_LIT:1> <EOL> no_of_rows = row_data . split ( '<STR_LIT::>' ) [ <NUM_LIT:1> ] <EOL> if mearge_header : <EOL> return ( heading , get_merged_header ( header_line1 , header_line2 ) , no_of_rows ) <EOL> else : <EOL> return ( heading , header_line1 + header_line2 , no_of_rows ) <EOL> else : <EOL> data = actual_out . split ( '<STR_LIT:\n>' ) <EOL> heading = data . pop ( <NUM_LIT:0> ) <EOL> header = data . pop ( <NUM_LIT:0> ) <EOL> params = [ item . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] . strip ( ) for item in data if item . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] . strip ( ) ] <EOL> for i , item in enumerate ( params ) : <EOL> if "<STR_LIT>" in item : <EOL> params [ i ] = item [ <NUM_LIT:4> : ] <EOL> if '<STR_LIT>' in params : <EOL> params . remove ( '<STR_LIT>' ) <EOL> return ( heading , header , params ) <EOL> def get_separate_output ( in_str = '<STR_LIT>' , mid_str = '<STR_LIT>' ) : <EOL> _regex = re . compile ( "<STR_LIT>" + mid_str + "<STR_LIT>" ) <EOL> out_pattern , outstr = re . findall ( _regex , in_str ) , re . split ( _regex , in_str ) <EOL> output_list = [ ] <EOL> for i , item in enumerate ( out_pattern ) : <EOL> output_list . append ( ( item + outstr [ i + <NUM_LIT:1> ] ) ) <EOL> return output_list <EOL> def get_merged_header ( h1 , h2 ) : <EOL> h1 = filter ( None , h1 . split ( '<STR_LIT:U+0020>' ) ) <EOL> h2 = filter ( None , h2 . split ( '<STR_LIT:U+0020>' ) ) <EOL> header = [ ] <EOL> if len ( h1 ) == len ( h2 ) : <EOL> for i in range ( len ( h1 ) ) : <EOL> if h2 [ i ] == '<STR_LIT:.>' : <EOL> header . append ( h1 [ i ] ) <EOL> continue <EOL> header . append ( h1 [ i ] + '<STR_LIT:U+0020>' + h2 [ i ] ) <EOL> return header </s>
