summaryrefslogtreecommitdiffstats
path: root/module/plugins/Plugin.py
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-04-30 19:16:47 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2011-04-30 19:16:47 +0200
commit6272b848234d63ce193abc6996b2eec9b2af5cb7 (patch)
tree1f5f963c07fb4d5c3d4a454c40afd4b3025c8b78 /module/plugins/Plugin.py
parentUploadStation & BitshareCom: #295 (diff)
downloadpyload-6272b848234d63ce193abc6996b2eec9b2af5cb7.tar.xz
closed #290, #291, #292
Diffstat (limited to 'module/plugins/Plugin.py')
-rw-r--r--module/plugins/Plugin.py40
1 files changed, 29 insertions, 11 deletions
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 482bb0e45..a8009f6d4 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -28,8 +28,7 @@ from os import makedirs
from os import chmod
from os import stat
from os import name as os_name
-from os.path import exists
-from os.path import join
+from os.path import exists, join, dirname
if os.name != "nt":
from os import chown
@@ -294,20 +293,16 @@ class Plugin(object):
return result
- def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, no_post_encode=False, raw_cookies={}, utf8=False):
+ def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, utf8=False):
""" returns the content loaded """
if self.pyfile.abort: raise Abort
- if raw_cookies: self.log.warning("Deprecated argument raw cookies: %s" % raw_cookies)
- if no_post_encode: self.log.warning("Deprecated argument no_post_encode: %s" % no_post_encode)
-
res = self.req.load(url, get, post, ref, cookies, just_header)
if utf8:
#@TODO parse header and decode automatically when needed
res = decode(res)
-
if self.core.debug:
from inspect import currentframe
frame = currentframe()
@@ -324,10 +319,31 @@ class Plugin(object):
f.write(tmp)
f.close()
-
+
+
+ if just_header:
+ #parse header
+ header = {"code" : self.req.code}
+ for line in res.splitlines():
+ line = line.strip()
+ if not line or ":" not in line: continue
+
+ key, none, value = line.partition(":")
+ key = key.lower().strip()
+ value = value.strip()
+
+ if header.has_key(key):
+ if type(header[key]) == list:
+ header[key].append(value)
+ else:
+ header[key] = [header[key],value]
+ else:
+ header[key] = value
+ res = header
+
return res
- def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=True):
+ def download(self, url, get={}, post={}, ref=True, cookies=True, disposition=False):
""" downloads the url content to disk """
self.pyfile.setStatus("downloading")
@@ -352,6 +368,8 @@ class Plugin(object):
if os_name == 'nt':
#delete illegal characters
name = removeChars(name, '/\\?%*:|"<>')
+ else:
+ name = removeChars(name, '/\\"')
filename = save_join(location, name)
try:
@@ -359,10 +377,10 @@ class Plugin(object):
finally:
self.pyfile.size = self.req.size
- if newname and newname != filename:
+ 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 = newname
+ filename = save_join(location, newname)
if self.core.config["permission"]["change_file"]:
chmod(filename, int(self.core.config["permission"]["file"],8))