diff options
| author | 2010-12-25 20:20:33 +0100 | |
|---|---|---|
| committer | 2010-12-25 20:20:33 +0100 | |
| commit | 805cb9d007e61edf2a211467b65b868bf35b49f1 (patch) | |
| tree | 01d4df81dc689b5ed676dfee1024d263ec9507d7 | |
| parent | cleanup stuff (diff) | |
| download | pyload-805cb9d007e61edf2a211467b65b868bf35b49f1.tar.xz | |
great fixes http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0134872dea10970c-pi
| -rw-r--r-- | module/ThreadManager.py | 3 | ||||
| -rw-r--r-- | module/network/Browser.py | 10 | ||||
| -rw-r--r-- | module/network/HTTPBase.py | 27 | ||||
| -rw-r--r-- | module/network/HTTPDownload.py | 5 | ||||
| -rw-r--r-- | module/network/helper.py | 4 | ||||
| -rw-r--r-- | module/plugins/Plugin.py | 3 | 
6 files changed, 34 insertions, 18 deletions
| diff --git a/module/ThreadManager.py b/module/ThreadManager.py index 5e36738d3..0a2ce674b 100644 --- a/module/ThreadManager.py +++ b/module/ThreadManager.py @@ -147,6 +147,7 @@ class ThreadManager:          sleep(1)          ip = self.getIP()          self.core.hookManager.afterReconnecting(ip) +        self.closeAllConnecions()          self.log.info(_("Reconnected, new IP: %s") % ip) @@ -229,7 +230,7 @@ class ThreadManager:                  thread = PluginThread.DecrypterThread(self, job)      def closeAllConnecions(self): -        """closes all connections, when a reconnect has made """ +        """closes all connections, when a reconnect was 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 23fe4993c..066b0e3ec 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -23,7 +23,7 @@ class Browser(object):          self.http = HTTPBase(interface=interface, proxies=proxies)          self.setCookieJar(cookieJar)          self.proxies = proxies -        self.abort = property(lambda: False, lambda val: self.abortDownloads()) +        self.abort = property(lambda: False, lambda val: self.abortDownloads() if val else None)          self.downloadConnections = [] @@ -84,12 +84,14 @@ class Browser(object):      def _removeConnection(self, *args, **kwargs):          i = self.downloadConnections.index(args[-1]) +        self.downloadConnections[i].download.clean()          del self.downloadConnections[i]      def abortDownloads(self):          for d in self.downloadConnections: +            d.download.setAbort(True)              d.abort = True -     +      @property      def speed(self):          speed = 0 @@ -149,7 +151,9 @@ class Browser(object):      def clean(self):          """ cleanup """ -        self.http.clean() +        if hasattr(self, "http"): +            self.http.clean() +            del self.http  if __name__ == "__main__":      browser = Browser()#proxies={"socks5": "localhost:5000"}) diff --git a/module/network/HTTPBase.py b/module/network/HTTPBase.py index ca3737bff..f5cd7afcc 100644 --- a/module/network/HTTPBase.py +++ b/module/network/HTTPBase.py @@ -279,9 +279,17 @@ class HTTPBase():              self.handler.setSocksProxy(socks.PROXY_TYPE_SOCKS4, proxies["socks4"])          self.cookieJar = CookieJar() + +        self.opener = None          self.debug = DEBUG -     + +    def getOpener(self, cookies=True): +        if not self.opener: +            self.opener = self.createOpener(cookies) + +        return self.opener +      def createOpener(self, cookies=True):          opener = OpenerDirector()          opener.add_handler(self.handler) @@ -312,14 +320,10 @@ class HTTPBase():              if isinstance(post, dict):                  post = urlencode(post)              req.add_data(post) -         -        #req.add_header("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5") -        #req.add_header("Accept-Language", "en-US,en")          if referer:              req.add_header("Referer", referer) -        #req.add_header("Accept-Encoding", "gzip, deflate")          for key, val in customHeaders.iteritems():              req.add_header(key, val) @@ -327,7 +331,7 @@ class HTTPBase():      def getResponse(self, url, get={}, post={}, referer=None, cookies=True, customHeaders={}):          req = self.createRequest(url, get, post, referer, customHeaders) -        opener = self.createOpener(cookies) +        opener = self.getOpener(cookies)          if self.debug:              print "[HTTP] ----" @@ -354,7 +358,7 @@ class HTTPBase():          resp = opener.open(req)          resp.getcode = lambda: resp.code -         +          if self.debug:              print "[HTTP] ----"              print "[HTTP] got response" @@ -375,12 +379,17 @@ class HTTPBase():      def closeAll(self):          """ closes all connections """ -        self.handler.close_all() +        if hasattr(self, "handler"): +            self.handler.close_all()      def clean(self):          """ cleanup """          self.closeAll() - +        if hasattr(self, "opener"): +            del self.opener +        if hasattr(self, "handler"): +            del self.handler +          if __name__ == "__main__":      base = HTTPBase()      resp = base.getResponse("http://python.org/") diff --git a/module/network/HTTPDownload.py b/module/network/HTTPDownload.py index 117ecd0c6..bce698e1e 100644 --- a/module/network/HTTPDownload.py +++ b/module/network/HTTPDownload.py @@ -173,7 +173,7 @@ class HTTPDownload():      def _chunkDone(self):          self.chunksDone += 1 -        print self.chunksDone, "/", len(self.chunks) +        #print self.chunksDone, "/", len(self.chunks)          if self.chunksDone == len(self.chunks):              self._copyChunks() @@ -306,7 +306,8 @@ class HTTPDownload():      def clean(self):          """ cleanup """ -        pass +        for c in self.chunks: +            c.clean()  if __name__ == "__main__":      import sys diff --git a/module/network/helper.py b/module/network/helper.py index dac0185ce..5ce21a8dd 100644 --- a/module/network/helper.py +++ b/module/network/helper.py @@ -72,7 +72,7 @@ class Deferred():          if not self.prgr.has_key(chain):              return          for f in self.prgr[chain]: -            callInThread(f, *args, **kwargs) +            f(*args, **kwargs)  #decorator  def threaded(f): @@ -92,7 +92,7 @@ def waitFor(d):          def wait(self):              self.d.addCallback(self.callb)              self.d.addErrback(self.errb) -            while self.waiting: +            while self.waiting and not self.d.abort:                  sleep(0.5)              if self.err:                  #try: diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index c9ca7e999..ac66d6243 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -334,7 +334,8 @@ class Plugin(object):          self.pyfile.download = d          d.addProgress("percent", self.pyfile.progress.setValue)          waitFor(d) -        d.clean() + +        if d.abort: raise Abort          self.pyfile.download = None          newname = basename(filename) | 
