intro helpers.sanitize_filename() to make sure we do not run, use it where it is appropriate

This commit is contained in:
Nikos Kouremenos 2006-03-21 13:55:22 +00:00
parent 7418be2323
commit b3bf080e6f
1 changed files with 13 additions and 0 deletions

View File

@ -695,3 +695,16 @@ def get_os_info():
if uname_output is not None:
return uname_output[0] # only first line
return 'N/A'
def sanitize_filename(filename):
'''makes sure the filename we try to write does not contain
unacceptable characters'''
filename = filename.replace('/', '_')
if os.name == 'nt':
filename = filename.replace('?', '').replace(':', '').replace('!', '')\
.replace('"', "'")
# 48 is the limit; 44 is used to account for the extenstion.
if len(filename) > 44:
filename = filename[0:44]
return filename