diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-04-30 19:16:47 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-04-30 19:16:47 +0200 |
commit | 6272b848234d63ce193abc6996b2eec9b2af5cb7 (patch) | |
tree | 1f5f963c07fb4d5c3d4a454c40afd4b3025c8b78 /module | |
parent | UploadStation & BitshareCom: #295 (diff) | |
download | pyload-6272b848234d63ce193abc6996b2eec9b2af5cb7.tar.xz |
Diffstat (limited to 'module')
-rw-r--r-- | module/network/Browser.py | 13 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 7 | ||||
-rw-r--r-- | module/network/HTTPRequest.py | 1 | ||||
-rw-r--r-- | module/network/RequestFactory.py | 11 | ||||
-rw-r--r-- | module/plugins/Plugin.py | 40 | ||||
-rw-r--r-- | module/plugins/hoster/BasePlugin.py | 3 |
6 files changed, 49 insertions, 26 deletions
diff --git a/module/network/Browser.py b/module/network/Browser.py index 0bf5cf3cf..9020a6de1 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -1,7 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -from os.path import join from logging import getLogger from HTTPRequest import HTTPRequest @@ -74,7 +73,7 @@ class Browser(object): self._size = self.dl.size self.dl.abort = True - def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None, disposition=True): + def httpDownload(self, url, filename, get={}, post={}, ref=True, cookies=True, chunks=1, resume=False, progressNotify=None, disposition=False): """ this can also download ftp """ self._size = 0 self.dl = HTTPDownload(url, filename, get, post, self.lastEffectiveURL if ref else None, @@ -87,15 +86,9 @@ class Browser(object): return name - - def download(self, url, file_name, folder, get={}, post={}, ref=True, cookies=True, no_post_encode=False): - self.log.warning("Browser: deprecated call 'download'") - - return self.httpDownload(url, join(folder, file_name), get, post, ref, cookies) - - def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False): + def load(self, *args, **kwargs): """ retrieves page """ - return self.http.load(url, get, post, ref, cookies, just_header) + return self.http.load(*args, **kwargs) def putHeader(self, name, value): diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index b20f565ea..9d0395c6f 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -18,7 +18,7 @@ """ from os import remove, fsync -from os.path import dirname, join +from os.path import dirname from time import sleep, time from shutil import move @@ -28,11 +28,12 @@ from HTTPChunk import ChunkInfo, HTTPChunk from HTTPRequest import BadHeader from module.plugins.Plugin import Abort +from module.utils import save_join class HTTPDownload(): """ loads a url http + ftp """ def __init__(self, url, filename, get={}, post={}, referer=None, cj=None, bucket=None, - interface=None, proxies={}, progressNotify=None, disposition=True): + interface=None, proxies={}, progressNotify=None, disposition=False): self.url = url self.filename = filename #complete file destination, not only name self.get = get @@ -110,7 +111,7 @@ class HTTPDownload(): fo.close() if self.nameDisposition and self.disposition: - self.filename = join(dirname(self.filename), self.nameDisposition) + self.filename = save_join(dirname(self.filename), self.nameDisposition) move(init, self.filename) self.info.remove() #remove info file diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index 50c09afe2..fa088391a 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -159,6 +159,7 @@ class HTTPRequest(): self.c.setopt(pycurl.NOBODY, 1) self.c.perform() rep = self.header + else: self.c.perform() rep = self.getResponse() diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py index 90a48fe3c..e91b9ea41 100644 --- a/module/network/RequestFactory.py +++ b/module/network/RequestFactory.py @@ -54,6 +54,10 @@ class RequestFactory(): self.lock.release() return req + def getHTTPRequest(self): + """ returns a http request, dont forget to close it ! """ + return HTTPRequest(None, self.iface(), self.getProxies()) + def getURL(self, url, get={}, post={}, multipart=False): h = HTTPRequest(None, self.iface(), self.getProxies()) rep = h.load(url, get, post, multipart=multipart) @@ -76,7 +80,7 @@ class RequestFactory(): type = "http" setting = self.core.config["proxy"]["type"].lower() if setting == "socks4": type = "socks4" - if setting == "socks5": type = "socks5" + elif setting == "socks5": type = "socks5" username = None if self.core.config["proxy"]["username"] and self.core.config["proxy"]["username"].lower() != "none": @@ -103,4 +107,7 @@ class RequestFactory(): # needs pyreq in global namespace def getURL(*args, **kwargs): - return pyreq.getURL(*args, **kwargs)
\ No newline at end of file + return pyreq.getURL(*args, **kwargs) + +def getRequest(*args, **kwargs): + return pyreq.getHTTPRequest()
\ No newline at end of file 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)) diff --git a/module/plugins/hoster/BasePlugin.py b/module/plugins/hoster/BasePlugin.py index 0248ca624..50652010c 100644 --- a/module/plugins/hoster/BasePlugin.py +++ b/module/plugins/hoster/BasePlugin.py @@ -32,6 +32,9 @@ class BasePlugin(Hoster): # # return + + self.load("http://pyload.org", just_header=True) + if pyfile.url.startswith("http"): pyfile.name = re.findall("([^/=]+)", pyfile.url)[-1] |