r107 - in /debtorrent/trunk/DebTorrent/BT1: AptListener.py HTTPDownloader.py makemetafile.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Thu Jun 14 06:16:26 UTC 2007


Author: camrdale-guest
Date: Thu Jun 14 06:16:25 2007
New Revision: 107

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=107
Log:
Fix some small bugs in HTTP downloading, making torrent files, and getting paths from APT.

Modified:
    debtorrent/trunk/DebTorrent/BT1/AptListener.py
    debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py
    debtorrent/trunk/DebTorrent/BT1/makemetafile.py

Modified: debtorrent/trunk/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/AptListener.py?rev=107&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/AptListener.py Thu Jun 14 06:16:25 2007
@@ -471,6 +471,7 @@
         """
         
         # TODO: Add caching and cache-checking before downloading
+        # TODO: Make this threaded so it doesn't block while waiting for the download
         try:
             ungzip = True
             if path[-1].endswith('.gz'):
@@ -747,7 +748,7 @@
         try:
             (scheme, netloc, path, pars, query, fragment) = urlparse(path)
             if self.uq_broken == 1:
-                path = path.replace('+',' ')
+                #path = path.replace('+',' ') What is this!
                 query = query.replace('+',' ')
             path = unquote(path)[1:]
             for s in query.split('&'):

Modified: debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py?rev=107&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/HTTPDownloader.py Thu Jun 14 06:16:25 2007
@@ -16,9 +16,10 @@
 from DebTorrent.CurrentRateMeasure import Measure
 from random import randint
 from urlparse import urlparse
-from httplib import HTTPConnection
+from httplib import HTTPConnection, BadStatusLine
 from urllib import quote
 from threading import Thread
+from traceback import print_exc
 from DebTorrent.__init__ import product_name,version_short
 try:
     True
@@ -146,7 +147,7 @@
         self.request_size = 0
         self.endflag = False
         self.error = None
-        self.retry_period = 30
+        self.retry_period = 10
         self._retry_period = None
         self.errorcount = 0
         self.goodseed = False
@@ -239,16 +240,27 @@
                 print 'HTTPDownloader: sending request'
                 print 'GET', self.url, self.headers
             self.connection.request('GET',self.url, None, self.headers)
-            r = self.connection.getresponse()
+            
+            # Check for closed persistent connection due to server timeout
+            try:
+                r = self.connection.getresponse()
+            except BadStatusLine:
+                # Reopen the connection to get a new socket
+                self.connection.close()
+                self.connection.connect()
+                self.connection.request('GET',self.url, None, self.headers)
+                r = self.connection.getresponse()
+                
             if DEBUG:
                 print 'HTTPDownloader: got response'
                 print r.status, r.reason, r.getheaders()
             self.connection_status = r.status
             self.received_data = r.read()
         except Exception, e:
-            self.error = 'error accessing http seed: '+str(e)
             if DEBUG:
                 print 'error accessing http seed: '+str(e)
+                print_exc()
+            self.error = 'error accessing http seed: '+str(e)
             try:
                 self.connection.close()
             except:
@@ -290,12 +302,6 @@
         
         """
         
-        if self.connection_status == 503:   # seed is busy
-            try:
-                self.retry_period = max(int(self.received_data),5)
-            except:
-                pass
-            return False
         if self.connection_status not in [200, 206]:
             self.errorcount += 1
             return False

Modified: debtorrent/trunk/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/makemetafile.py?rev=107&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/makemetafile.py Thu Jun 14 06:16:25 2007
@@ -193,6 +193,8 @@
             f = piece_data.split('\n')
         except:
             return {}
+    else:
+        return {}
 
     p = [None, [], []]
     read_data = False




More information about the Debtorrent-commits mailing list