Given a stream, wrap it in a `StreamWrapper` instance and return the wrapped stream.

    :param stream: A stream instance to wrap
    :returns: A new, wrapped stream
    :rtype: :class:`StreamWrapper`

def get_wrapped_stream(stream):
    """
    Given a stream, wrap it in a `StreamWrapper` instance and return the wrapped stream.

    :param stream: A stream instance to wrap
    :returns: A new, wrapped stream
    :rtype: :class:`StreamWrapper`
    """

    if stream is None:
        raise TypeError("must provide a stream to wrap")
    encoding = getattr(stream, "encoding", None)
    encoding = get_output_encoding(encoding)
    return StreamWrapper(stream, encoding, "replace", line_buffering=True)