#NEWLINE# def _AcceptResponses( self , expected_header , info_cb , timeout_ms = None ) : #NEWLINE# #INDENT# "Accepts responses until the expected header or a FAIL.\n\n    Args:\n      expected_header: OKAY or DATA\n      info_cb: Optional callback for text sent from the bootloader.\n      timeout_ms: Timeout in milliseconds to wait for each response.\n\n    Raises:\n      FastbootStateMismatch: Fastboot responded with the wrong packet type.\n      FastbootRemoteFailure: Fastboot reported failure.\n      FastbootInvalidResponse: Fastboot responded with an unknown packet type.\n\n    Returns:\n      OKAY packet's message.\n    " #NEWLINE# while True : #NEWLINE# #INDENT# response = self . usb . BulkRead ( 64 , timeout_ms = timeout_ms ) #NEWLINE# header = response [ : 4 ] #NEWLINE# remaining = response [ 4 : ] #NEWLINE# if ( header == 'INFO' ) : #NEWLINE# #INDENT# info_cb ( FastbootMessage ( remaining , header ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( header in self . FINAL_HEADERS ) : #NEWLINE# #INDENT# if ( header != expected_header ) : #NEWLINE# #INDENT# raise FastbootStateMismatch ( 'Expected %s, got %s' , expected_header , header ) #NEWLINE# #UNINDENT# if ( info_cb == 'OKAY' ) : #NEWLINE# #INDENT# info_cb ( FastbootMessage ( remaining , header ) ) #NEWLINE# #UNINDENT# return remaining #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( header == 'FAIL' ) : #NEWLINE# #INDENT# info_cb ( FastbootMessage ( remaining , header ) ) #NEWLINE# raise FastbootRemoteFailure ( 'FAIL: %s' , remaining ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise FastbootInvalidResponse ( 'Got unknown header %s and response %s' , header , remaining )