diff options
author | Stefano <l.stickell@yahoo.it> | 2014-07-09 12:07:43 +0200 |
---|---|---|
committer | Stefano <l.stickell@yahoo.it> | 2014-07-09 12:07:43 +0200 |
commit | 378a0aa5fddb1adc10d0ae789ad95e98dfc2f0f3 (patch) | |
tree | 44508d0c9949342abcd15682a0019b9122c6b048 /module/utils.py | |
parent | Update Account.py (diff) | |
download | pyload-378a0aa5fddb1adc10d0ae789ad95e98dfc2f0f3.tar.xz |
Improved filename sanitation.
Fixes #656
Diffstat (limited to 'module/utils.py')
-rw-r--r-- | module/utils.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/module/utils.py b/module/utils.py index a65a08801..6abee5eab 100644 --- a/module/utils.py +++ b/module/utils.py @@ -10,6 +10,7 @@ from os.path import join from string import maketrans from htmlentitydefs import name2codepoint + def chmod(*args): try: os.chmod(*args) @@ -27,18 +28,24 @@ def decode(string): def remove_chars(string, repl): """ removes all chars in repl from string""" - if type(string) == str: - return string.translate(maketrans("", ""), repl) - elif type(string) == unicode: - return string.translate(dict([(ord(s), None) for s in repl])) + if type(repl) == unicode: + for badc in list(repl): + string = string.replace(badc, "") + return string + else: + if type(string) == str: + return string.translate(maketrans("", ""), repl) + elif type(string) == unicode: + return string.translate(dict([(ord(s), None) for s in repl])) def save_path(name): #remove some chars if os.name == 'nt': - return remove_chars(name, '/\\?%*:|"<>') + return remove_chars(name, u'\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31\32' + u'\33\34\35\36\37/\\?%*:|"<>') else: - return remove_chars(name, '/\\"') + return remove_chars(name, u'\0/\\"') def save_join(*args): @@ -61,6 +68,7 @@ if sys.getfilesystemencoding().startswith('ANSI'): else: fs_encode = fs_decode = lambda x: x # do nothing + def get_console_encoding(enc): if os.name == "nt": if enc == "cp65001": # aka UTF-8 @@ -71,6 +79,7 @@ def get_console_encoding(enc): return enc + def compare_time(start, end): start = map(int, start) end = map(int, end) |