def open_file_for_reading(filename):
    """Open file or file-like stream  *filename* for reading.

    *filename* may be a string and then it is opened but if it is a
    file-like object (such as an open :class:`file` or
    :class:`StringIO.StringIO` --- really anything with ``next()``,
    ``read()``, ``readlines()``, ``readline``, ``close`` methods) then
    the object is just passed through (the stream is attempted to be
    reset to the beginning with ``fseek(0)``).
    """
    if (hasattr(filename, 'next') or hasattr(filename, '__next__')
        ) and hasattr(filename, 'read') and hasattr(filename, 'readline'
        ) and hasattr(filename, 'readlines') and hasattr(filename, 'close'):
        try:
            filename.fseek(0)
        except AttributeError:
            pass
        return filename
    try:
        f = open(filename, 'r')
    except:
        raise IOError('Cannot find file %s' % filename)
    return f
