#NEWLINE# def main( JSONinput ) : #NEWLINE# #INDENT# query = json . loads ( JSONinput ) #NEWLINE# p = SQLAPIcall ( query ) #NEWLINE# result = p . execute ( ) #NEWLINE# if ( ( query [ 'method' ] == 'data' ) and ( 'format' in query ) and ( query [ 'format' ] == 'json' ) ) : #NEWLINE# #INDENT# jresp = json . loads ( result ) #NEWLINE# resp = jsonify ( jresp ) #NEWLINE# if ( jresp [ 'status' ] == 'error' ) : #NEWLINE# #INDENT# resp . status_code = ( jresp [ 'code' ] if ( 'code' in jresp ) else 500 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# resp = Response ( result ) #NEWLINE# #UNINDENT# if ( query [ 'method' ] == 'return_tsv' ) : #NEWLINE# #INDENT# resp . headers [ 'Content-Type' ] = 'text; charset=utf-8' #NEWLINE# resp . headers [ 'Content-Disposition' ] = 'filename=Bookworm-data.txt' #NEWLINE# resp . headers [ 'Pragma' ] = 'no-cache' #NEWLINE# resp . headers [ 'Expires' ] = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( query [ 'method' ] in [ 'return_json' , 'return_pickle' ] ) : #NEWLINE# #INDENT# resp . headers [ 'Content-Type' ] = 'text/html' #NEWLINE# #UNINDENT# #UNINDENT# resp . headers [ 'Access-Control-Allow-Origin' ] = '*' #NEWLINE# resp . headers [ 'Access-Control-Allow-Methods' ] = 'GET, POST, PUT, OPTIONS' #NEWLINE# resp . headers [ 'Access-Control-Allow-Headers' ] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token' #NEWLINE# return resp