import re


def safe_file_name(file_name):
    """Returns a file name with all path separator and directory traversal replaced with underscores."""
    return re.sub('_+', '_', file_name.replace('\\', '_').replace('../', '_').replace('/', '_').replace('~', '_'))