#NEWLINE# def parse_values( values , outfile ) : #NEWLINE# #INDENT# '\n    Given a file handle and the raw values from a MySQL INSERT\n    statement, write the equivalent CSV to the file\n    ' #NEWLINE# latest_row = [ ] #NEWLINE# reader = csv . reader ( [ values ] , delimiter = ',' , doublequote = False , escapechar = '\\' , quotechar = "'" , strict = True ) #NEWLINE# writer = csv . writer ( outfile , quoting = csv . QUOTE_MINIMAL ) #NEWLINE# for reader_row in reader : #NEWLINE# #INDENT# for column in reader_row : #NEWLINE# #INDENT# if ( ( len ( column ) == 0 ) or ( column == 'NULL' ) ) : #NEWLINE# #INDENT# latest_row . append ( chr ( 0 ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( column [ 0 ] == '(' ) : #NEWLINE# #INDENT# new_row = False #NEWLINE# if ( len ( latest_row ) > 0 ) : #NEWLINE# #INDENT# if ( latest_row [ ( - 1 ) ] [ ( - 1 ) ] == ')' ) : #NEWLINE# #INDENT# latest_row [ ( - 1 ) ] = latest_row [ ( - 1 ) ] [ : ( - 1 ) ] #NEWLINE# new_row = True #NEWLINE# #UNINDENT# #UNINDENT# if new_row : #NEWLINE# #INDENT# writer . writerow ( latest_row ) #NEWLINE# latest_row = [ ] #NEWLINE# #UNINDENT# if ( len ( latest_row ) == 0 ) : #NEWLINE# #INDENT# column = column [ 1 : ] #NEWLINE# #UNINDENT# #UNINDENT# latest_row . append ( column ) #NEWLINE# #UNINDENT# if ( latest_row [ ( - 1 ) ] [ ( - 2 ) : ] == ');' ) : #NEWLINE# #INDENT# latest_row [ ( - 1 ) ] = latest_row [ ( - 1 ) ] [ : ( - 2 ) ] #NEWLINE# writer . writerow ( latest_row )