<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import division <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> from suds . sudsobject import asdict <EOL> def _underscore_key ( string ) : <EOL> """<STR_LIT>""" <EOL> return string . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) <EOL> def to_string ( item , convert_bool = True ) : <EOL> """<STR_LIT>""" <EOL> str_val = unicode ( item ) . encode ( '<STR_LIT:utf-8>' , '<STR_LIT:replace>' ) <EOL> if convert_bool : <EOL> if str_val == u'<STR_LIT:True>' or str_val == u'<STR_LIT:true>' : <EOL> return True <EOL> elif str_val == u'<STR_LIT:False>' or str_val == u'<STR_LIT:false>' : <EOL> return False <EOL> return str_val <EOL> def recursive_asdict ( obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , dict ) : <EOL> return obj <EOL> out = { } <EOL> for key , val in asdict ( obj ) . iteritems ( ) : <EOL> if hasattr ( val , '<STR_LIT>' ) : <EOL> out [ _underscore_key ( key ) ] = recursive_asdict ( val ) <EOL> elif isinstance ( val , list ) : <EOL> out [ _underscore_key ( key ) ] = [ ] <EOL> for item in val : <EOL> if hasattr ( item , '<STR_LIT>' ) : <EOL> out [ _underscore_key ( key ) ] . append ( recursive_asdict ( item ) ) <EOL> else : <EOL> out [ _underscore_key ( key ) ] . append ( to_string ( item ) ) <EOL> else : <EOL> out [ _underscore_key ( key ) ] = to_string ( val ) <EOL> return out <EOL> def format_pql_response ( raw_list ) : <EOL> """<STR_LIT>""" <EOL> column_keys = raw_list . pop ( <NUM_LIT:0> ) <EOL> data_list = [ ] <EOL> for result in raw_list : <EOL> data = { } <EOL> for col_name , val in zip ( column_keys , result ) : <EOL> data [ col_name ] = str ( val ) <EOL> data_list . append ( data ) <EOL> return data_list <EOL> def format_report_list ( raw_list ) : <EOL> """<STR_LIT>""" <EOL> column_keys = raw_list . pop ( <NUM_LIT:0> ) <EOL> data_list = [ ] <EOL> for result in raw_list : <EOL> data = { } <EOL> for col_name , val in zip ( column_keys , result ) : <EOL> val = val . encode ( '<STR_LIT:utf-8>' ) <EOL> data [ col_name ] = str ( val ) <EOL> data_list . append ( data ) <EOL> return data_list <EOL> def sanitize_report_response ( response ) : <EOL> """<STR_LIT>""" <EOL> clean_response = { } <EOL> for _key , _val in response . items ( ) : <EOL> clean_key = _key . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] <EOL> clean_key = clean_key . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] <EOL> clean_response [ clean_key ] = _val <EOL> return clean_response </s>
