def find_iter_window(bitstream, pattern, max_pos=None):
    """
    >>> pattern = list(bytes2bit_strings("B"))
    >>> bitstream = bytes2bit_strings("AAABCCC")
    >>> find_iter_window(bitstream, pattern)
    24
    >>> "".join(list(bitstream2string(bitstream)))
    'CCC'

    >>> find_iter_window(bytes2bit_strings("HELLO!"), list(bytes2bit_strings("LO")))
    24

    >>> find_iter_window(bytes2bit_strings("HELLO!"), list(bytes2bit_strings("LO")), max_pos=16)
    Traceback (most recent call last):
    ...
    MaxPosArraived: 17

    >>> find_iter_window(bytes2bit_strings("HELLO!"), list(bytes2bit_strings("X")))
    Traceback (most recent call last):
    ...
    PatternNotFound: 40
    """
    assert isinstance(bitstream, (collections.Iterable, types.GeneratorType))
    assert isinstance(pattern, (list, tuple))

    window_size = len(pattern)
    pos = -1
    for pos, data in enumerate(iter_window(bitstream, window_size)):
#         print pos, data, pattern
        if data == pattern:
            return pos
        if max_pos is not None and pos > max_pos:
            raise MaxPosArraived(pos)
    raise PatternNotFound(pos)
>>> pattern = list(bytes2bit_strings("B"))
    >>> bitstream = bytes2bit_strings("AAABCCC")
    >>> find_iter_window(bitstream, pattern)
    24
    >>> "".join(list(bitstream2string(bitstream)))
    'CCC'

    >>> find_iter_window(bytes2bit_strings("HELLO!"), list(bytes2bit_strings("LO")))
    24

    >>> find_iter_window(bytes2bit_strings("HELLO!"), list(bytes2bit_strings("LO")), max_pos=16)
    Traceback (most recent call last):
    ...
    MaxPosArraived: 17

    >>> find_iter_window(bytes2bit_strings("HELLO!"), list(bytes2bit_strings("X")))
    Traceback (most recent call last):
    ...
    PatternNotFound: 40