#NEWLINE# def upload_zmodem( self , filename ) : #NEWLINE# #INDENT# 'Call external ZMODEM program to upload a file.\n        Return an ExitStatus object that should indicate success or failure.\n        ' #NEWLINE# sockfd = self . sock . fileno ( ) #NEWLINE# ( pread , pwrite ) = os . pipe ( ) #NEWLINE# pid = os . fork ( ) #NEWLINE# if ( pid == 0 ) : #NEWLINE# #INDENT# os . dup2 ( sockfd , 0 ) #NEWLINE# os . dup2 ( wpid , 1 ) #NEWLINE# os . dup2 ( pwrite , 2 ) #NEWLINE# os . close ( pread ) #NEWLINE# os . close ( pwrite ) #NEWLINE# for fd in xrange ( 3 , 64 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . close ( fd ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# os . write ( 0 , 'rz -e -q -s +30\r' ) #NEWLINE# os . execlp ( 'sz' , 'sz' , '-e' , '-q' , '-y' , '-L' , '128' , filename ) #NEWLINE# os . _exit ( 1 ) #NEWLINE# #UNINDENT# os . close ( pwrite ) #NEWLINE# while True : #NEWLINE# #INDENT# ( wpid , es ) = os . waitpid ( pid , 0 ) #NEWLINE# if ( wpid == pid ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# errout = os . read ( pread , 4096 ) #NEWLINE# es = ExitStatus ( 'sz {}' . format ( filename ) , es ) #NEWLINE# es . output = errout #NEWLINE# return es