#NEWLINE# def lineReceived( self , line ) : #NEWLINE# #INDENT# '\n        ' #NEWLINE# log . msg ( ( 'CMD: %s' % ( line , ) ) ) #NEWLINE# self . lexer = shlex . shlex ( instream = line , punctuation_chars = True ) #NEWLINE# tokens = [ ] #NEWLINE# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# tok = self . lexer . get_token ( ) #NEWLINE# if ( tok == self . lexer . eof ) : #NEWLINE# #INDENT# if len ( tokens ) : #NEWLINE# #INDENT# self . cmdpending . append ( tokens ) #NEWLINE# tokens = [ ] #NEWLINE# #UNINDENT# break #NEWLINE# #UNINDENT# if ( ( tok == ';' ) or ( tok == '&&' ) or ( tok == '||' ) ) : #NEWLINE# #INDENT# self . cmdpending . append ( tokens ) #NEWLINE# tokens = [ ] #NEWLINE# #UNINDENT# if ( tok == ';' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( tok == '&&' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( tok == '||' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( tok == '$?' ) : #NEWLINE# #INDENT# tok = '0' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tok [ 0 ] == '$' ) : #NEWLINE# #INDENT# env_rex = re . compile ( '^\\$([_a-zA-Z0-9]+)$' ) #NEWLINE# env_search = env_rex . search ( tok ) #NEWLINE# if ( env_search != None ) : #NEWLINE# #INDENT# env_match = env_search . group ( 1 ) #NEWLINE# if ( env_match in list ( self . environ . keys ( ) ) ) : #NEWLINE# #INDENT# tok = self . environ [ env_match ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# env_rex = re . compile ( '^\\${([_a-zA-Z0-9]+)}$' ) #NEWLINE# env_search = env_rex . search ( tok ) #NEWLINE# if ( env_search != None ) : #NEWLINE# #INDENT# env_match = env_search . group ( 1 ) #NEWLINE# if ( env_match in list ( self . environ . keys ( ) ) ) : #NEWLINE# #INDENT# tok = self . environ [ env_match ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# tokens . append ( tok ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# self . protocol . terminal . write ( 'bash: syntax error: unexpected end of file\n' ) #NEWLINE# log . msg ( 'exception: {}' . format ( e ) ) #NEWLINE# self . cmdpending = [ ] #NEWLINE# self . showPrompt ( ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# if len ( self . cmdpending ) : #NEWLINE# #INDENT# self . runCommand ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . showPrompt ( )