Retrieve all output from stdout until timeout (3 sec by default). If ``output``
        is None, ``stdout`` returns all of the stdout outputted by the process, else
        it returns ``self``.

        :param output: optional output to be expected from stdout, raises \
                       :class:`check50.Failure` if no match
        :type output: str
        :param str_output: what will be displayed as expected output, a human \
                           readable form of ``output``
        :type str_output: str
        :param regex: flag indicating whether ``output`` should be treated as a regex
        :type regex: bool
        :param timeout: maximum number of seconds to wait for ``output``
        :type timeout: int / float
        :raises check50.Mismatch: if ``output`` is specified and nothing that the \
                                  process outputs matches it
        :raises check50.Failure: if process times out or if it outputs invalid UTF-8 text.

        Example usage::

            check50.run("./hello").stdout("[Hh]ello, world!?", "hello, world").exit()

            output = check50.run("./hello").stdout()
            if not re.match("[Hh]ello, world!?", output):
                raise check50.Mismatch("hello, world", output)

def stdout(self, output=None, str_output=None, regex=True, timeout=3):
        """
        Retrieve all output from stdout until timeout (3 sec by default). If ``output``
        is None, ``stdout`` returns all of the stdout outputted by the process, else
        it returns ``self``.

        :param output: optional output to be expected from stdout, raises \
                       :class:`check50.Failure` if no match
        :type output: str
        :param str_output: what will be displayed as expected output, a human \
                           readable form of ``output``
        :type str_output: str
        :param regex: flag indicating whether ``output`` should be treated as a regex
        :type regex: bool
        :param timeout: maximum number of seconds to wait for ``output``
        :type timeout: int / float
        :raises check50.Mismatch: if ``output`` is specified and nothing that the \
                                  process outputs matches it
        :raises check50.Failure: if process times out or if it outputs invalid UTF-8 text.

        Example usage::

            check50.run("./hello").stdout("[Hh]ello, world!?", "hello, world").exit()

            output = check50.run("./hello").stdout()
            if not re.match("[Hh]ello, world!?", output):
                raise check50.Mismatch("hello, world", output)
        """
        if output is None:
            self._wait(timeout)
            return self.process.before.replace("\r\n", "\n").lstrip("\n")

        try:
            output = output.read()
        except AttributeError:
            pass

        expect = self.process.expect if regex else self.process.expect_exact

        if str_output is None:
            str_output = output

        if output == EOF:
            log(_("checking for EOF..."))
        else:
            output = output.replace("\n", "\r\n")
            log(_("checking for output \"{}\"...").format(str_output))

        try:
            expect(output, timeout=timeout)
        except EOF:
            result = self.process.before + self.process.buffer
            if self.process.after != EOF:
                result += self.process.after
            raise Mismatch(str_output, result.replace("\r\n", "\n"))
        except TIMEOUT:
            raise Failure(_("did not find \"{}\"").format(_raw(str_output)))
        except UnicodeDecodeError:
            raise Failure(_("output not valid ASCII text"))
        except Exception:
            raise Failure(_("check50 could not verify output"))

        # If we expected EOF and we still got output, report an error.
        if output == EOF and self.process.before:
            raise Mismatch(EOF, self.process.before.replace("\r\n", "\n"))

        return self