[BitTorrent] FIXED: Re: Problem with zurllib and Python 2.4 [patch]

Jonathan Lennox lennox at cnr.cs.columbia.edu
Wed Dec 8 17:01:31 EST 2004


On Wednesday, December 8 2004, "Jonathan Lennox" wrote to "BitTorrent at yahoogroups.com" saying:

> I'm not able to run the Python BitTorrent client (version 3.4.2) with Python
> 2.4.  It's not able to fetch .torrent files, or connect to the tracker.

I've fixed the code; a patch is attached below.

The problem is that in Python 2.4, the return value for http_open() added
two additional members, 'code' and 'msg'.  The new urllib2 handler
HTTPErrorProcessor gets upset if at least the first of these doesn't exist.

This patch adds code to copy the 'code' and 'msg' fields, if they exist,
from the value returned by HTTPHandler.http_open() to the value returned by
HTTPContentEncodingHandler.http_open().  Tested with both Python 2.3 and
2.4.

The patch also changes the test() function to avoid hitting the original
author's website, instead hitting websites which can almost certainly handle
any additional load this causes.

--- /usr/local/lib/python2.4/site-packages/BitTorrent/zurllib.py	Wed Dec  8 11:17:40 2004
+++ zurllib.py	Wed Dec  8 16:52:20 2004
@@ -35,7 +35,14 @@
         if DEBUG: 
              pprint.pprint(headers.dict)
         url = fp.url
-        return addinfourldecompress(fp, headers, url)
+        resp = addinfourldecompress(fp, headers, url)
+        # As of Python 2.4 http_open response also has 'code' and 'msg'
+        # members, and HTTPErrorProcessor breaks if they don't exist.
+        if 'code' in dir(fp):
+           resp.code = fp.code
+        if 'msg' in dir(fp):
+           resp.msg = fp.msg
+        return resp
 
 
 class addinfourldecompress(addinfourl):
@@ -125,13 +132,13 @@
             print "no iscompressed function!  this shouldn't happen"
 
     print "Trying to GET a compressed document...\n"
-    fp = urlopen('http://a.scarywater.net/hng/index.shtml')
+    fp = urlopen('http://slashdot.org/')
     print fp.read()
     printcomp(fp)
     fp.close()
 
-    print "Trying to GET an unknown document...\n"
-    fp = urlopen('http://www.otaku.org/')
+    print "Trying to GET an uncompressed document...\n"
+    fp = urlopen('http://google.com/')
     print fp.read()
     printcomp(fp)
     fp.close()


-- 
Jonathan Lennox
lennox at cs.columbia.edu


------------------------ Yahoo! Groups Sponsor --------------------~--> 
$4.98 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/Q7_YsB/neXJAA/yQLSAA/dkFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/BitTorrent/

<*> To unsubscribe from this group, send an email to:
    BitTorrent-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the BitTorrent mailing list