def read_and_reset(inner):
    """Decorator that resets a file-like object back to the original
    position after the function has been called."""

    def wrapper(infile, *args, **kwargs):
        current_position = infile.tell()
        rval = inner(infile, *args, **kwargs)
        infile.seek(current_position)
        return rval

    return wrapper