def handle_read(self): """We got some output from a remote shell, this is one of the state machine""" if self.state == STATE_DEAD: return global nr_handle_read nr_handle_read += 1 new_data = buffered_dispatcher.handle_read(self) if self.debug: self.print_debug('==> ' + new_data) if self.handle_read_fast_case(self.read_buffer): return lf_pos = new_data.find('\n') if lf_pos >= 0: # Optimization: we knew there were no '\n' in the previous read # buffer, so we searched only in the new_data and we offset the # found index by the length of the previous buffer lf_pos += len(self.read_buffer) - len(new_data) elif self.state is STATE_NOT_STARTED and \ options.password is not None and \ 'password:'******'\n') self.read_buffer = '' return while lf_pos >= 0: # For each line in the buffer line = self.read_buffer[:lf_pos + 1] if callbacks.process(line): pass elif self.state in (STATE_IDLE, STATE_RUNNING): self.print_lines(line) elif self.state is STATE_NOT_STARTED: self.read_in_state_not_started += line if 'The authenticity of host' in line: msg = line.strip('\n') + ' Closing connection.' self.disconnect() elif 'REMOTE HOST IDENTIFICATION HAS CHANGED' in line: msg = 'Remote host identification has changed.' else: msg = None if msg: self.print_lines(msg + ' Consider manually connecting or ' + 'using ssh-keyscan.') # Go to the next line in the buffer self.read_buffer = self.read_buffer[lf_pos + 1:] if self.handle_read_fast_case(self.read_buffer): return lf_pos = self.read_buffer.find('\n') if self.state is STATE_NOT_STARTED and not self.init_string_sent: self.dispatch_write(self.init_string) self.init_string_sent = True
def print_unfinished_line(self): """The unfinished line stayed long enough in the buffer to be printed""" if self.state is STATE_RUNNING: if not callbacks.process(self.read_buffer): self.print_lines(self.read_buffer) self.read_buffer = b''
def print_unfinished_line(self): """The unfinished line stayed long enough in the buffer to be printed""" if self.state is STATE_RUNNING: if not callbacks.process(self.read_buffer): self.print_lines(self.read_buffer) self.read_buffer = ''