From d49ac7f4ceec36ad627d716ab83194c3c4b974be Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 17 Nov 2008 02:35:00 +0000 Subject: Stop dropping a byte every time a download fails. also start working on making other exceptions propagete from woder threads. git-svn-id: file:///home/or/svnrepo/updater/trunk@17309 55e972cd-5a19-0410-ae62-a4d7a52db4cd --- lib/thandy/download.py | 10 ++++++++-- lib/thandy/util.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/thandy/download.py b/lib/thandy/download.py index 8a9f083..2f98b30 100644 --- a/lib/thandy/download.py +++ b/lib/thandy/download.py @@ -40,6 +40,9 @@ class DownloadManager: for t in self.threads: t.setDaemon(True) + #DOCDOC + self._raiseMe = None + def start(self): """Start all of this download manager's worker threads.""" for t in self.threads: @@ -80,6 +83,9 @@ class DownloadManager: self.done.wait() self.done.release() + if self._raiseMe: + raise self._raiseMe + try: while True: item = self.resultQueue.get(block=False) @@ -233,7 +239,7 @@ class DownloadJob: gotRange = f_in.info().get("Content-Range") expectLength = f_in.info().get("Content-Length", "???") if gotRange: - if gotRange.startswith("bytes %s-"%(have_length+1)): + if gotRange.startswith("bytes %s-"%have_length): logging.info("Resuming download from %s"%url) f_out = open(self._tmpPath, 'a') else: @@ -344,7 +350,7 @@ def getConnection(url, useTor, have_length=None): is_http = urltype in ["http", "https"] if have_length is not None and is_http: - headers['Range'] = "bytes=%s-"%(have_length+1) + headers['Range'] = "bytes=%s-"%have_length req = urllib2.Request(url, headers=headers) diff --git a/lib/thandy/util.py b/lib/thandy/util.py index c1f1326..00efb59 100644 --- a/lib/thandy/util.py +++ b/lib/thandy/util.py @@ -10,6 +10,11 @@ try: except ImportError: import simplejson as json +try: + import _winreg +except ImportError: + _winreg = None + import thandy.formats import thandy.keys import thandy.master_keys @@ -100,3 +105,4 @@ def randChooseWeighted(lst): return i return lst[-1][1] + -- cgit v1.2.3