(self, shell_output)
Write shell output to console.
Write shell output to console.
Write shell output to console .
def _show_output(self, shell_output):
        """Write shell output to console."""
        # detect sentinel for start of new command
        if shell_output and self._detect_encoding(shell_output):
            # detect sentinel for start of new command
            # wait for at least one LF
            if not shell_output[0]:
                if b'\n' not in shell_output:
                    return
            # can't do a comprehension as it will crash if the deque is accessed by the thread
            lines = deque()
            while shell_output:
                lines.append(shell_output.popleft())
            # push back last char if not aligned to encoding
            if self._encoding == 'utf-16le' and lines[-1] != b'\0':
                shell_output.appendleft(lines.pop())
            # detect echo
            while not lines[0]:
                lines.popleft()
                while lines:
                    reply = lines.popleft()
                    if self._encoding == 'utf-16le':
                        reply += lines.popleft()
                    try:
                        cmd = self._last_command.popleft()
                    except IndexError:
                        cmd = b''
                    if self._enc(cmd) != reply:
                        lines.appendleft(reply)
                        if reply not in (self._enc(u'\r'), self._enc(u'\n')):
                            # two CRs, for some reason
                            lines.appendleft(self._enc(u'\r'))
                        break
            outstr = b''.join(lines)
            # accept CRLF or LF in output
            outstr = outstr.replace(self._enc(u'\r\n'), self._enc(u'\r'))
            # remove BELs (dosemu uses these a lot)
            outstr = outstr.replace(self._enc(u'\x07'), b'')
            outstr = outstr.decode(self._encoding, errors='replace')
            outstr = self._codepage.unicode_to_bytes(outstr, errors='replace')
            logging.debug('SHELL output: %r', outstr)
            self._console.write(outstr)
def _show_output ( self , shell_output ) : # detect sentinel for start of new command if shell_output and self . _detect_encoding ( shell_output ) : # detect sentinel for start of new command # wait for at least one LF if not shell_output [ 0 ] : if b'\n' not in shell_output : return # can't do a comprehension as it will crash if the deque is accessed by the thread lines = deque ( ) while shell_output : lines . append ( shell_output . popleft ( ) ) # push back last char if not aligned to encoding if self . _encoding == 'utf-16le' and lines [ - 1 ] != b'\0' : shell_output . appendleft ( lines . pop ( ) ) # detect echo while not lines [ 0 ] : lines . popleft ( ) while lines : reply = lines . popleft ( ) if self . _encoding == 'utf-16le' : reply += lines . popleft ( ) try : cmd = self . _last_command . popleft ( ) except IndexError : cmd = b'' if self . _enc ( cmd ) != reply : lines . appendleft ( reply ) if reply not in ( self . _enc ( u'\r' ) , self . _enc ( u'\n' ) ) : # two CRs, for some reason lines . appendleft ( self . _enc ( u'\r' ) ) break outstr = b'' . join ( lines ) # accept CRLF or LF in output outstr = outstr . replace ( self . _enc ( u'\r\n' ) , self . _enc ( u'\r' ) ) # remove BELs (dosemu uses these a lot) outstr = outstr . replace ( self . _enc ( u'\x07' ) , b'' ) outstr = outstr . decode ( self . _encoding , errors = 'replace' ) outstr = self . _codepage . unicode_to_bytes ( outstr , errors = 'replace' ) logging . debug ( 'SHELL output: %r' , outstr ) self . _console . write ( outstr )