def write_file(self, path, destination='<STR_LIT>', verify='<STR_LIT:none>'):
filename = os.path.basename(path)<EOL>if not destination:<EOL><INDENT>destination = filename<EOL><DEDENT>log.info('<STR_LIT>', path, destination)<EOL>self.__writeln("<STR_LIT>")<EOL>res = self.__expect('<STR_LIT>')<EOL>if not res.endswith('<STR_LIT>'):<EOL><INDENT>log.error('<STR_LIT>', res)<EOL>raise CommunicationTimeout('<STR_LIT>', res)<EOL><DEDENT>log.debug('<STR_LIT>', destination)<EOL>self.__write(destination + '<STR_LIT:\x00>', True)<EOL>if not self.__got_ack():<EOL><INDENT>log.error('<STR_LIT>')<EOL>raise NoAckException('<STR_LIT>')<EOL><DEDENT>content = from_file(path)<EOL>log.debug('<STR_LIT>', len(content), filename)<EOL>pos = <NUM_LIT:0><EOL>chunk_size = <NUM_LIT><EOL>while pos < len(content):<EOL><INDENT>rest = len(content) - pos<EOL>if rest > chunk_size:<EOL><INDENT>rest = chunk_size<EOL><DEDENT>data = content[pos:pos+rest]<EOL>if not self.__write_chunk(data):<EOL><INDENT>resp = self.__expect()<EOL>log.error('<STR_LIT>', resp, hexify(resp))<EOL>raise BadResponseException('<STR_LIT>', ACK, resp)<EOL><DEDENT>pos += chunk_size<EOL><DEDENT>log.debug('<STR_LIT>')<EOL>self.__write_chunk('<STR_LIT>')<EOL>if verify != '<STR_LIT:none>':<EOL><INDENT>self.verify_file(path, destination, verify)<EOL><DEDENT>
sends a file to the device using the transfer protocol