#NEWLINE# def prepare( self ) : #NEWLINE# #INDENT# '\n        This uploads the protocol functions nessecary to do binary\n        chunked transfer\n        ' #NEWLINE# log . info ( 'Preparing esp for transfer.' ) #NEWLINE# for func in LUA_FUNCTIONS : #NEWLINE# #INDENT# detected = self . __exchange ( 'print({0})' . format ( func ) ) #NEWLINE# if ( detected . find ( 'function:' ) == ( - 1 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# log . info ( 'Preparation already done. Not adding functions again.' ) #NEWLINE# return True #NEWLINE# #UNINDENT# functions = ( ( RECV_LUA + '\n' ) + SEND_LUA ) #NEWLINE# data = functions . format ( baud = self . _port . baudrate ) #NEWLINE# lines = data . replace ( '\r' , '' ) . split ( '\n' ) #NEWLINE# for line in lines : #NEWLINE# #INDENT# line = line . strip ( ) . replace ( ', ' , ',' ) . replace ( ' = ' , '=' ) #NEWLINE# if ( len ( line ) == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# resp = self . __exchange ( line ) #NEWLINE# if ( ( 'unexpected' in resp ) or ( 'stdin' in resp ) or ( len ( resp ) > ( len ( functions ) + 10 ) ) ) : #NEWLINE# #INDENT# log . error ( 'error when preparing "%s"' , resp ) #NEWLINE# return False #NEWLINE# #UNINDENT# #UNINDENT# return True