#NEWLINE# def set_state( self , state ) : #NEWLINE# #INDENT# ' Switches state of the TDS session.\n\n        It also does state transitions checks.\n        :param state: New state, one of TDS_PENDING/TDS_READING/TDS_IDLE/TDS_DEAD/TDS_QUERING\n        ' #NEWLINE# prior_state = self . state #NEWLINE# if ( state == prior_state ) : #NEWLINE# #INDENT# return state #NEWLINE# #UNINDENT# if ( state == TDS_PENDING ) : #NEWLINE# #INDENT# if ( prior_state in ( TDS_READING , TDS_QUERYING ) ) : #NEWLINE# #INDENT# self . state = TDS_PENDING #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise InterfaceError ( 'logic error: cannot chage query state from {0} to {1}' . format ( state_names [ prior_state ] , state_names [ state ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( state == TDS_READING ) : #NEWLINE# #INDENT# if ( self . state != TDS_PENDING ) : #NEWLINE# #INDENT# raise InterfaceError ( 'logic error: cannot change query state from {0} to {1}' . format ( state_names [ prior_state ] , state_names [ state ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . state = state #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( state == TDS_IDLE ) : #NEWLINE# #INDENT# if ( prior_state == TDS_DEAD ) : #NEWLINE# #INDENT# raise InterfaceError ( 'logic error: cannot change query state from {0} to {1}' . format ( state_names [ prior_state ] , state_names [ state ] ) ) #NEWLINE# #UNINDENT# self . state = state #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( state == TDS_DEAD ) : #NEWLINE# #INDENT# self . state = state #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( state == TDS_QUERYING ) : #NEWLINE# #INDENT# if ( self . state == TDS_DEAD ) : #NEWLINE# #INDENT# raise InterfaceError ( 'logic error: cannot change query state from {0} to {1}' . format ( state_names [ prior_state ] , state_names [ state ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . state != TDS_IDLE ) : #NEWLINE# #INDENT# raise InterfaceError ( 'logic error: cannot change query state from {0} to {1}' . format ( state_names [ prior_state ] , state_names [ state ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . rows_affected = TDS_NO_COUNT #NEWLINE# self . internal_sp_called = 0 #NEWLINE# self . state = state #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# assert False #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return self . state