From 5d804ae1c6e6b35966f0886a4b27602f4f7e1aee Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 24 Apr 2011 21:05:09 +0200 Subject: fixes char replacement --- module/Utils.py | 9 +++++++++ module/plugins/Plugin.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/module/Utils.py b/module/Utils.py index 3d344a147..fee1dee0f 100644 --- a/module/Utils.py +++ b/module/Utils.py @@ -21,6 +21,13 @@ def decode(string): except: return string +def removeChars(string, repl): + """ removes all chars in repl from string""" + if type(string) == str: + return string.translate(None, repl) + elif type(string) == unicode: + return string.translate(dict([(ord(s), None) for s in repl])) + def save_join(*args): """ joins a path, encoding aware """ paths = [] @@ -104,3 +111,5 @@ def parseFileSize(string): #returns bytes if __name__ == "__main__": print freeSpace(".") + + print replace("ab'cdgdsf''ds'", "'ghd") diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 5607b8331..482bb0e45 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -38,7 +38,7 @@ if os.name != "nt": from itertools import islice -from module.utils import save_join, decode +from module.utils import save_join, decode, removeChars def chunks(iterable, size): it = iter(iterable) @@ -351,7 +351,7 @@ class Plugin(object): name = self.pyfile.name if os_name == 'nt': #delete illegal characters - name = name.translate(None, '/\\?%*:|"<>') + name = removeChars(name, '/\\?%*:|"<>') filename = save_join(location, name) try: -- cgit v1.2.3