#NEWLINE# def _executeQuery( self , command , args = None ) : #NEWLINE# #INDENT# 'execute the provided command on the database.\n\n        args are specified as a dictionary.  error checking on the\n        results is performed here and the returned value is a list of\n        lists with each list representing a row of the returned table.\n        ' #NEWLINE# try : #NEWLINE# #INDENT# argument_string = '&' . join ( [ ( '%s=%s' % ( x , args [ x ] ) ) for x in args ] ) #NEWLINE# command_string = '&' . join ( [ command , argument_string ] ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# command_string = command #NEWLINE# #UNINDENT# query = ( '%s?cmd=%s' % ( self . url , command_string ) ) #NEWLINE# if ( len ( query ) > 2048 ) : #NEWLINE# #INDENT# if ( 'gene_list' in args ) : #NEWLINE# #INDENT# genes = args [ 'gene_list' ] . split ( ',' ) #NEWLINE# if ( len ( genes ) < 2 ) : #NEWLINE# #INDENT# raise ValueError ( 'Request too long' ) #NEWLINE# #UNINDENT# args [ 'gene_list' ] = ',' . join ( genes [ ( len ( genes ) / 2 ) : ] ) #NEWLINE# query1 = self . _executeQuery ( command , args ) #NEWLINE# warnings = self . last_warnings #NEWLINE# args [ 'gene_list' ] = ',' . join ( genes [ : ( len ( genes ) / 2 ) ] ) #NEWLINE# query2 = self . _executeQuery ( command , args ) #NEWLINE# self . last_warnings = ( warnings + self . last_warnings ) #NEWLINE# return ( query1 + query2 ) #NEWLINE# #UNINDENT# #UNINDENT# data = urllib2 . urlopen ( query ) #NEWLINE# line = data . readline ( ) #NEWLINE# self . last_query = query #NEWLINE# self . last_status = line #NEWLINE# self . last_warnings = [ ] #NEWLINE# self . last_header = [ self . last_status ] #NEWLINE# return_table = [ ] #NEWLINE# while re . match ( '^#' , line ) : #NEWLINE# #INDENT# if re . match ( '^# Warning: (.+)' , line ) : #NEWLINE# #INDENT# self . last_warnings . append ( re . match ( '^# Warning: (.+)' , line ) . groups ( 1 ) [ 0 ] ) #NEWLINE# self . last_header . append ( line ) #NEWLINE# line = data . readline ( ) #NEWLINE# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if re . match ( '^#' , line ) : #NEWLINE# #INDENT# self . last_header . append ( line ) #NEWLINE# line = data . readline ( ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if re . match ( '^Error: (.+)' , line ) : #NEWLINE# #INDENT# self . last_header . append ( line ) #NEWLINE# raise CDGSError ( re . match ( '^Error: (.+)' , line ) . groups ( 1 ) [ 0 ] , query ) #NEWLINE# #UNINDENT# line = line . strip ( ) #NEWLINE# headers = line . split ( '\t' ) #NEWLINE# for line in data : #NEWLINE# #INDENT# if re . match ( '^# Warning: (.+)' , line ) : #NEWLINE# #INDENT# self . last_warnings . append ( re . match ( '^# Warning: (.+)' , line ) . groups ( 1 ) [ 0 ] ) #NEWLINE# self . last_header . append ( line ) #NEWLINE# line = data . readline ( ) #NEWLINE# continue #NEWLINE# #UNINDENT# line = line . strip ( ) #NEWLINE# return_table . append ( odict ( zip ( headers , line . split ( '\t' ) ) ) ) #NEWLINE# #UNINDENT# return return_table