'attempt to get a chunk of data to write to our child process\'s
stdin, then write it.  the return value answers the questions "are we
done writing forever?"'

def write(self):

    try:
        chunk = self.get_chunk()
        if (chunk is None):
            raise DoneReadingForever
    except DoneReadingForever:
        self.log.debug('done    reading')
        if self.tty_in:
            try:
                char = termios.tcgetattr(self.stream)[6][termios.VEOF]
            except:
                char = chr(4).encode()
            os.write(self.stream, char)
            os.write(self.stream, char)
        return True
    except NotYetReadyToRead:
        self.log.debug('received    no    data')
        return False
    if (IS_PY3 and hasattr(chunk, 'encode')):
        chunk = chunk.encode(self.encoding)
    for proc_chunk in self.stream_bufferer.process(chunk):
        self.log.debug('got    chunk    size    %d:    %r', len(proc_chunk), proc_chunk[:30])
        self.log.debug('writing    chunk    to    process')
        try:
            os.write(self.stream, proc_chunk)
        except OSError:
            self.log.debug('OSError    writing    stdin    chunk')
            return True
