def iter_bytes(stream, max_bytes=None):
    """Wrap a stream in an iterator that yields individual bytes, not lines.

    :param stream:
        A stream opened in binary mode.
    :param int max_bytes:
        The maximum number of bytes to read.

    .. versionadded:: 0.2.1
    """
    n_read = 0
    while max_bytes is None or n_read < max_bytes:
        this_byte = stream.read(1)
        if this_byte == b'':
            return
        yield this_byte
        n_read += 1
