code: def flush(self):
          
          if not self._buffer:
              return
  
          data = ''.join(self._buffer)
  
          try:
              # (We try to encode ourself, because that way we can replace
              # characters that don't exist in the character set, avoiding
              # UnicodeEncodeError crashes. E.g. u'\xb7' does not appear in 'ascii'.)
              # My Arch Linux installation of july 2015 reported 'ANSI_X3.4-1968'
              # for sys.stdout.encoding in xterm.
              if self.write_binary:
                  if hasattr(self.stdout, 'buffer'):
                      out = self.stdout.buffer  # Py3.
                  else:
                      out = self.stdout
                  out.write(data.encode(self.stdout.encoding or 'utf-8', 'replace'))
              else:
                  self.stdout.write(data)
  
              self.stdout.flush()
          except IOError as e:
              if e.args and e.args[0] == errno.EINTR:
                  # Interrupted system call. Can happpen in case of a window
                  # resize signal. (Just ignore. The resize handler will render
                  # again anyway.)
                  pass
              elif e.args and e.args[0] == 0:
                  # This can happen when there is a lot of output and the user
                  # sends a KeyboardInterrupt by pressing Control-C. E.g. in
                  # a Python REPL when we execute "while True: print('test')".
                  # (The `ptpython` REPL uses this `Output` class instead of
                  # `stdout` directly -- in order to be network transparent.)
                  # So, just ignore.
                  pass
              else:
                  raise
  
          self._buffer = []
docs: Write to output stream and flush.