def make_filename(string):
"""
Turn a string into something that can be safely used as a file or directory
name.
:param string: The string to convert.
:return: The sanitised string.
:raises ValueError: If string is None.
"""
if string is None:
raise ValueError('String cannot be None')
safe = [' ', '.', '_', '-', '\'']
joined = ''.join([c for c in unidecode.unidecode(string)
if c.isalnum() or c in safe]).strip()
if not joined:
raise ValueError('Filename would be empty')
return joined
评论列表
文章目录