diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-12-25 11:38:11 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-12-25 11:38:11 +0100 |
commit | e70ba609af6793e26857d88e496860114ccac103 (patch) | |
tree | ae2ab2892e88b640b8ff6d7ed02417431f6efdcc /module | |
parent | catch socket exceptions (diff) | |
download | pyload-e70ba609af6793e26857d88e496860114ccac103.tar.xz |
cleanup stuff
Diffstat (limited to 'module')
-rw-r--r-- | module/PluginThread.py | 2 | ||||
-rw-r--r-- | module/PyFile.py | 4 | ||||
-rw-r--r-- | module/ThreadManager.py | 6 | ||||
-rw-r--r-- | module/network/Browser.py | 9 | ||||
-rw-r--r-- | module/network/HTTPBase.py | 35 | ||||
-rw-r--r-- | module/network/HTTPDownload.py | 4 | ||||
-rw-r--r-- | module/plugins/Plugin.py | 2 |
7 files changed, 43 insertions, 19 deletions
diff --git a/module/PluginThread.py b/module/PluginThread.py index eca00324a..20bef84df 100644 --- a/module/PluginThread.py +++ b/module/PluginThread.py @@ -110,7 +110,7 @@ class PluginThread(Thread): def clean(self, pyfile): """ set thread unactive and clean pyfile """ - #pyfile.plugin.req.clean() + pyfile.plugin.req.clean() self.active = False pyfile.release() diff --git a/module/PyFile.py b/module/PyFile.py index e7c7c2c2b..c198ce459 100644 --- a/module/PyFile.py +++ b/module/PyFile.py @@ -119,8 +119,12 @@ class PyFile(): def release(self): """sync and remove from cache""" self.sync() + if hasattr(self, "plugin"): del self.plugin + if hasattr(self, "download"): + del self.download + self.m.releaseLink(self.id) def delete(self): diff --git a/module/ThreadManager.py b/module/ThreadManager.py index bb693d695..5e36738d3 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -227,3 +227,9 @@ class ThreadManager: else: thread = PluginThread.DecrypterThread(self, job) + + def closeAllConnecions(self): + """closes all connections, when a reconnect has made """ + for pyfile in self.core.files.cache.itervalues(): + if pyfile.plugin and pyfile.plugin.req: + pyfile.plugin.req.http.closeAll() diff --git a/module/network/Browser.py b/module/network/Browser.py index 512a437ed..23fe4993c 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -131,11 +131,6 @@ class Browser(object): d.addCallback(self._removeConnection, d) return d - #compatibility wrapper - def clean(self): - self.log.warning("Browser: deprecated call 'clean'") - print_stack() - def load(self, url, get={}, post={}, ref=True, cookies=True, just_header=False, no_post_encode=False, raw_cookies={}): self.log.warning("Browser: deprecated call 'load'") print_stack() @@ -152,6 +147,10 @@ class Browser(object): return filename + def clean(self): + """ cleanup """ + self.http.clean() + if __name__ == "__main__": browser = Browser()#proxies={"socks5": "localhost:5000"}) ip = "http://www.whatismyip.com/automation/n09230945.asp" diff --git a/module/network/HTTPBase.py b/module/network/HTTPBase.py index 7627c8499..ca3737bff 100644 --- a/module/network/HTTPBase.py +++ b/module/network/HTTPBase.py @@ -34,6 +34,7 @@ from httplib import HTTPResponse from httplib import responses as HTTPStatusCodes from httplib import ResponseNotReady from httplib import BadStatusLine +from httplib import CannotSendRequest from CookieJar import CookieJar from CookieRedirectHandler import CookieRedirectHandler @@ -180,19 +181,17 @@ class PyLoadHTTPHandler(HTTPHandler): def _start_connection(self, h, req): data = "" - try: - if req.has_data(): - data = req.get_data() - h.putrequest('POST', req.get_selector(), skip_accept_encoding=1) - if not req.headers.has_key('Content-type'): - h.putheader('Content-type', - 'application/x-www-form-urlencoded') - if not req.headers.has_key('Content-length'): - h.putheader('Content-length', '%d' % len(data)) - else: - h.putrequest('GET', req.get_selector(), skip_accept_encoding=1) - except socket.error, err: - raise URLError(err) + + if req.has_data(): + data = req.get_data() + h.putrequest('POST', req.get_selector(), skip_accept_encoding=1) + if not req.headers.has_key('Content-type'): + h.putheader('Content-type', + 'application/x-www-form-urlencoded') + if not req.headers.has_key('Content-length'): + h.putheader('Content-length', '%d' % len(data)) + else: + h.putrequest('GET', req.get_selector(), skip_accept_encoding=1) for args in self.parent.addheaders: h.putheader(*args) @@ -216,6 +215,8 @@ class PyLoadHTTPHandler(HTTPHandler): r = None except BadStatusLine: r = None + except CannotSendRequest: + r = None else: try: r = h.getresponse() except ResponseNotReady: r = None @@ -372,6 +373,14 @@ class HTTPBase(): pass return resp + def closeAll(self): + """ closes all connections """ + self.handler.close_all() + + def clean(self): + """ cleanup """ + self.closeAll() + if __name__ == "__main__": base = HTTPBase() resp = base.getResponse("http://python.org/") diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index b81008cc5..117ecd0c6 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -304,6 +304,10 @@ class HTTPDownload(): else: raise Exception("no chunks") + def clean(self): + """ cleanup """ + pass + if __name__ == "__main__": import sys from Bucket import Bucket diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 95e937d1c..c9ca7e999 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -334,6 +334,8 @@ class Plugin(object): self.pyfile.download = d d.addProgress("percent", self.pyfile.progress.setValue) waitFor(d) + d.clean() + self.pyfile.download = None newname = basename(filename) |