from types import GeneratorType


def is_iterator(obj):
    """Detect if the object provided implements the iterator protocol.

    (i.e. like a generator).

    This will return False for objects which are iterable,
    but not iterators themselves.
    """
    if isinstance(obj, GeneratorType):
        return True
    elif not hasattr(obj, '__iter__'):
        return False
    else:
        # Types which implement the protocol must return themselves when
        # invoking 'iter' upon them.
        return iter(obj) is obj