Oops, put remove_path_badchars where it belongs alphabetically.

master
voussoir 2017-12-07 21:37:55 -08:00
parent f39717c216
commit 13803dc7f7
1 changed files with 15 additions and 15 deletions

View File

@ -299,21 +299,6 @@ def recursive_dict_keys(d):
keys.update(subkeys) keys.update(subkeys)
return keys return keys
def remove_path_badchars(filepath, allowed=''):
'''
Remove the bad characters seen in constants.FILENAME_BADCHARS, except
those which you explicitly permit.
'file*name' -> 'filename'
('D:\\file*name', allowed=':\\') -> 'D:\\filename'
'''
badchars = remove_characters(constants.FILENAME_BADCHARS, allowed)
filepath = remove_characters(filepath, badchars)
filepath = filepath.replace('/', os.sep)
filepath = filepath.replace('\\', os.sep)
return filepath
def remove_characters(text, characters): def remove_characters(text, characters):
translator = {ord(c): None for c in characters} translator = {ord(c): None for c in characters}
text = text.translate(translator) text = text.translate(translator)
@ -329,6 +314,21 @@ def remove_control_characters(text):
''' '''
return ''.join(c for c in text if unicodedata.category(c)[0] != 'C') return ''.join(c for c in text if unicodedata.category(c)[0] != 'C')
def remove_path_badchars(filepath, allowed=''):
'''
Remove the bad characters seen in constants.FILENAME_BADCHARS, except
those which you explicitly permit.
'file*name' -> 'filename'
('D:\\file*name', allowed=':\\') -> 'D:\\filename'
'''
badchars = remove_characters(constants.FILENAME_BADCHARS, allowed)
filepath = remove_characters(filepath, badchars)
filepath = filepath.replace('/', os.sep)
filepath = filepath.replace('\\', os.sep)
return filepath
def seconds_to_hms(seconds): def seconds_to_hms(seconds):
''' '''
Convert integer number of seconds to an hh:mm:ss string. Convert integer number of seconds to an hh:mm:ss string.