<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(self, buf, newline=True):
 """ Writes buffer to output stream. `buf` Data buffer to write. `newline` Append newline character to buffer before writing. """


        buf = buf or ''

        if newline:
            buf += os.linesep

        try:
            self._output.write(buf)

            if hasattr(self._output, 'flush'):
                self._output.flush()

        except IOError as exc:
            if exc.errno != errno.EPIPE:  # silence EPIPE errors
                raise