summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/Utils.py49
-rw-r--r--module/plugins/Plugin.py14
-rw-r--r--module/plugins/hooks/ExtractArchive.py2
-rw-r--r--module/web/pyload_app.py14
4 files changed, 35 insertions, 44 deletions
diff --git a/module/Utils.py b/module/Utils.py
index f626eef10..1f4f8c047 100644
--- a/module/Utils.py
+++ b/module/Utils.py
@@ -32,6 +32,7 @@ def remove_chars(string, 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':
@@ -39,39 +40,27 @@ def save_path(name):
else:
return remove_chars(name, '/\\"')
+
def save_join(*args):
""" joins a path, encoding aware """
- paths = []
- for i, path in enumerate(args):
- # remove : for win comp, but not for first segment
- if i:
- path = path.replace(":", "")
-
- paths.append(unicode(path))
- return join(*paths)
-
-def fs_encode(string):
- """ Encodes string with utf-8 if locale support seems to be missing
-
- :param string: string to decode
- :return:
- """
- try:
- if sys.getfilesystemencoding() == 'ANSI_X3.4-1968':
+ return fs_encode(join(*[unicode(x) for x in args]))
+
+
+# File System Encoding functions:
+# Use fs_encode before accesing files on disk, it will encode the string properly
+
+if sys.getfilesystemencoding() == 'ANSI_X3.4-1968':
+ def fs_encode(string):
+ try:
string = string.encode('utf-8')
- finally:
- return string
+ finally:
+ return string
-def fs_decode(string):
- """ Decodes with filesystem encoding
+ fs_decode = decode #decode utf8
+
+else:
+ fs_encode = fs_decode = lambda x: x # do nothing
- :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)
@@ -158,6 +147,7 @@ def parseFileSize(string, unit=None): #returns bytes
return traffic
+
def lock(func):
def new(*args):
#print "Handler: %s args: %s" % (func,args[1:])
@@ -188,9 +178,10 @@ def fixup(m):
text = unichr(name2codepoint[name])
except KeyError:
pass
-
+
return text # leave as is
+
def html_unescape(text):
"""Removes HTML or XML character references and entities from a text string"""
return re.sub("&#?\w+;", fixup, text)
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index e2aadb38e..f7587d3f2 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -532,16 +532,16 @@ class Plugin(Base):
:param read_size: amount of bytes to read from files larger then max_size
:return: dictionary key of the first rule that matched
"""
- fs_name = fs_encode(self.lastDownload)
- if not exists(fs_name): return None
+ lastDownload = fs_encode(self.lastDownload)
+ if not exists(lastDownload): return None
- size = stat(fs_name)
+ size = stat(lastDownload)
size = size.st_size
if api_size and api_size <= size: return None
elif size > max_size and not read_size: return None
self.log.debug("Download Check triggered")
- f = open(fs_name, "rb")
+ f = open(lastDownload, "rb")
content = f.read(read_size if read_size else -1)
f.close()
#produces encoding errors, better log to other file in the future?
@@ -550,13 +550,13 @@ class Plugin(Base):
if type(rule) in (str, unicode):
if rule in content:
if delete:
- remove(fs_name)
+ remove(lastDownload)
return name
elif hasattr(rule, "search"):
m = rule.search(content)
if m:
if delete:
- remove(fs_name)
+ remove(lastDownload)
self.lastCheck = m
return name
@@ -586,7 +586,7 @@ class Plugin(Base):
raise SkipDownload(pyfile.pluginname)
download_folder = self.config['general']['download_folder']
- location = fs_encode(save_join(download_folder, pack.folder, self.pyfile.name))
+ location = save_join(download_folder, pack.folder, self.pyfile.name)
if starting and self.core.config['download']['skip_existing'] and exists(location):
size = os.stat(location).st_size
diff --git a/module/plugins/hooks/ExtractArchive.py b/module/plugins/hooks/ExtractArchive.py
index 359bfca76..82e9c1d36 100644
--- a/module/plugins/hooks/ExtractArchive.py
+++ b/module/plugins/hooks/ExtractArchive.py
@@ -165,7 +165,7 @@ class ExtractArchive(Hook):
for plugin in self.plugins:
targets = plugin.getTargets(files_ids)
- if targets: self.logDebug("Targets: %s" % targets)
+ if targets: self.logDebug("Targets for %s: %s" % (plugin.__name__, targets))
for target, fid in targets:
if target in extracted:
self.logDebug(basename(target), "skipped")
diff --git a/module/web/pyload_app.py b/module/web/pyload_app.py
index c64619c57..067eea9d3 100644
--- a/module/web/pyload_app.py
+++ b/module/web/pyload_app.py
@@ -36,7 +36,7 @@ from utils import render_to_response, parse_permissions, parse_userdata, \
from filters import relpath, unquotepath
-from module.utils import formatSize, fs_decode
+from module.utils import formatSize, save_join
# Helper
@@ -187,7 +187,7 @@ def collector():
@route("/downloads")
@login_required('DOWNLOAD')
def downloads():
- root = fs_decode(PYLOAD.getConfigValue("general", "download_folder"))
+ root = PYLOAD.getConfigValue("general", "download_folder")
if not isdir(root):
return base([_('Download directory not found.')])
@@ -196,19 +196,19 @@ def downloads():
'files': []
}
- items = [fs_decode(x) for x in listdir(root)]
+ items = listdir(root)
for item in sorted(items):
- if isdir(join(root, item)):
+ if isdir(save_join(root, item)):
folder = {
'name': item,
'path': item,
'files': []
}
- files = [fs_decode(x) for x in listdir(join(root, item))]
+ files = listdir(save_join(root, item))
for file in sorted(files):
try:
- if isfile(join(root, item, file)):
+ if isfile(save_join(root, item, file)):
folder['files'].append(file)
except:
pass
@@ -223,7 +223,7 @@ def downloads():
@route("/downloads/get/:path#.+#")
@login_required("DOWNLOAD")
def get_download(path):
- path = unquote(path)
+ path = unquote(path).decode("utf8")
#@TODO some files can not be downloaded
root = PYLOAD.getConfigValue("general", "download_folder")