def filename_segment(value):
    """Check that the string is valid for use as part of a filename."""
    for character in value:
        if not character.isalnum() and character not in '-_. ':
            raise ValueError(f"invalid value: '{value}'")
    return value