modified filename escaping to a "smarter" one
This commit is contained in:
parent
fe4d68e196
commit
42cb53fcfa
2 changed files with 18 additions and 8 deletions
|
@ -194,10 +194,20 @@ def timeconvert(timestr):
|
|||
def sanitize_filename(s):
|
||||
"""Sanitizes a string so it could be used as part of a filename."""
|
||||
def replace_insane(char):
|
||||
if char in u' .\\/|?*<>:"' or ord(char) < 32:
|
||||
return '_'
|
||||
if char == '?' or ord(char) < 32 or ord(char) == 127:
|
||||
return ''
|
||||
elif char == '"':
|
||||
return '\''
|
||||
elif char == ':':
|
||||
return ' -'
|
||||
elif char in '\\/|*<>':
|
||||
return '-'
|
||||
return char
|
||||
return u''.join(map(replace_insane, s)).strip('_')
|
||||
|
||||
result = u''.join(map(replace_insane, s))
|
||||
while '--' in result:
|
||||
result = result.replace('--', '-')
|
||||
return result.strip('-')
|
||||
|
||||
def orderedSet(iterable):
|
||||
""" Remove all duplicates from the input iterable """
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue