def file_or_filename(input):
    """Open a filename for reading with `smart_open`, or seek to the beginning if `input` is an already open file.

    Parameters
    ----------
    input : str or file-like
        Filename or file-like object.

    Returns
    -------
    file-like object
        An open file, positioned at the beginning.

    """
    if isinstance(input, str):
        # input was a filename: open as file
        return open(input, 'rb')
    else:
        # input already a file-like object; just reset to the beginning
        input.seek(0)
        return input