def dataReceived(self, data):
        """
        Parse the given data from a terminal server, dispatching to event
        handlers defined by C{self.terminal}.
        """
        toWrite = []
        for b in iterbytes(data):
            if self.state == b'data':
                if b == b'\x1b':
                    if toWrite:
                        self.terminal.write(b''.join(toWrite))
                        del toWrite[:]
                    self.state = b'escaped'
                elif b == b'\x14':
                    if toWrite:
                        self.terminal.write(b''.join(toWrite))
                        del toWrite[:]
                    self.terminal.shiftOut()
                elif b == b'\x15':
                    if toWrite:
                        self.terminal.write(b''.join(toWrite))
                        del toWrite[:]
                    self.terminal.shiftIn()
                elif b == b'\x08':
                    if toWrite:
                        self.terminal.write(b''.join(toWrite))
                        del toWrite[:]
                    self.terminal.cursorBackward()
                else:
                    toWrite.append(b)
            elif self.state == b'escaped':
                fName = self._shorts.get(b)
                if fName is not None:
                    self.state = b'data'
                    getattr(self.terminal, fName.decode("ascii"))()
                else:
                    state = self._longs.get(b)
                    if state is not None:
                        self.state = state
                    else:
                        self.terminal.unhandledControlSequence(b'\x1b' + b)
                        self.state = b'data'
            elif self.state == b'bracket-escape':
                if self._escBuf is None:
                    self._escBuf = []
                if b.isalpha() or b == b'~':
                    self._handleControlSequence(b''.join(self._escBuf), b)
                    del self._escBuf
                    self.state = b'data'
                else:
                    self._escBuf.append(b)
            elif self.state == b'select-g0':
                self.terminal.selectCharacterSet(self._charsets.get(b, b), G0)
                self.state = b'data'
            elif self.state == b'select-g1':
                self.terminal.selectCharacterSet(self._charsets.get(b, b), G1)
                self.state = b'data'
            elif self.state == b'select-height-width':
                self._handleHeightWidth(b)
                self.state = b'data'
            else:
                raise ValueError("Illegal state")
        if toWrite:
            self.terminal.write(b''.join(toWrite))

        Parse the given data from a terminal server, dispatching to event
        handlers defined by C{self.terminal}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/insults/insults.py