def is_iterator(obj):
    """Returns True if and only if the given object is an iterator
    object.

    """
    has_next_attr = hasattr(obj, '__next__') or hasattr(obj, 'next')
    return iter(obj) is obj and has_next_attr
