summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-06-15 18:53:49 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-06-15 18:53:49 +0200
commit8d8e5738073d1726ace7d19589b9c6529b8b30ad (patch)
tree8e3fdd1c3cdbb2cbe42d5fbcfa4837801c563fb3
parenthtml_unescape function, little plugin improvements (diff)
downloadpyload-8d8e5738073d1726ace7d19589b9c6529b8b30ad.tar.xz
fixes some encoding issues
-rw-r--r--module/Utils.py23
-rw-r--r--module/plugins/Plugin.py6
-rw-r--r--module/plugins/hooks/MergeFiles.py10
3 files changed, 31 insertions, 8 deletions
diff --git a/module/Utils.py b/module/Utils.py
index cdf76c144..45fa81d52 100644
--- a/module/Utils.py
+++ b/module/Utils.py
@@ -43,10 +43,31 @@ def save_join(*args):
path = decode(path)
- tmp = path.encode(sys.getfilesystemencoding(), "replace")
+ tmp = fs_encode(path)
paths.append(tmp)
return join(*paths)
+def fs_encode(string):
+ """ Encodes with filesystem encoding
+
+ :param string: string to decode
+ :return:
+ """
+ try:
+ return string.encode(sys.getfilesystemencoding(), "replace")
+ except:
+ return string
+
+def fs_decode(string):
+ """ Decodes with filesystem encoding
+
+ :param string: string to decode
+ :return:
+ """
+ try:
+ return string.decode(sys.getfilesystemencoding(), "replace")
+ except:
+ return string
def compare_time(start, end):
start = map(int, start)
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 0b47187e3..0c98845c4 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -37,7 +37,7 @@ if os.name != "nt":
from itertools import islice
-from module.utils import save_join, removeChars
+from module.utils import save_join, fs_encode, removeChars
def chunks(iterable, size):
it = iter(iterable)
@@ -435,7 +435,7 @@ class Plugin(object):
else:
name = removeChars(name, '/\\"')
- filename = save_join(location, name)
+ filename = join(location, fs_encode(name))
try:
newname = self.req.httpDownload(url, filename, get=get, post=post, ref=ref, cookies=cookies,
chunks=self.getChunkCount(), resume=self.resumeDownload,
@@ -446,7 +446,7 @@ class Plugin(object):
if disposition and newname and newname != name: #triple check, just to be sure
self.log.info("%(name)s saved as %(newname)s" % {"name": name, "newname": newname})
self.pyfile.name = newname
- filename = save_join(location, newname)
+ filename = join(location, fs_encode(newname))
if self.core.config["permission"]["change_file"]:
chmod(filename, int(self.core.config["permission"]["file"], 8))
diff --git a/module/plugins/hooks/MergeFiles.py b/module/plugins/hooks/MergeFiles.py
index 9062cb14c..b4c98df08 100644
--- a/module/plugins/hooks/MergeFiles.py
+++ b/module/plugins/hooks/MergeFiles.py
@@ -17,13 +17,15 @@
@author: and9000
"""
-from module.plugins.Hook import Hook
-
import os
import re
import sys
import traceback
+from os.path import join
+from module.utils import save_join, fs_encode
+from module.plugins.Hook import Hook
+
BUFFER_SIZE = 4096
class MergeFiles(Hook):
@@ -55,11 +57,11 @@ class MergeFiles(Hook):
download_folder = self.core.config['general']['download_folder']
if self.core.config['general']['folder_per_package']:
- download_folder = os.path.join(download_folder, pack.folder.decode(sys.getfilesystemencoding()))
+ download_folder = save_join(download_folder, pack.folder)
for name, file_list in files.iteritems():
self.core.log.info("Starting merging of %s" % name)
- final_file = open(os.path.join(download_folder, name), "wb")
+ final_file = open(join(download_folder, fs_encode(name)), "wb")
for splitted_file in file_list:
self.core.log.debug("Merging part %s" % splitted_file)