def safe_filename(name: str) -> str:
    """Make string safe for use as a filename"""
    keepcharacters = (' ', '.', '_')
    return "".join(c for c in name if c.isalnum() or c in keepcharacters).rstrip()