Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df5f6b5

Browse files
committed
Fix several failing tests in test_urllib2net.
The HTTPResponse object is being passed to BufferedReader, but it wasn't designed to be used that way. These changes extend the hacks that have already been made in urllib2 to get the tests to pass. The hacks need to be removed and proper support for use with the io library. That's a project for another day.
1 parent 6a10e02 commit df5f6b5

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/httplib.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,20 @@ def close(self):
499499
self.fp.close()
500500
self.fp = None
501501

502+
# These implementations are for the benefit of io.BufferedReader.
503+
504+
# XXX This class should probably be revised to act more like
505+
# the "raw stream" that BufferedReader expects.
506+
507+
@property
508+
def closed(self):
509+
return self.isclosed()
510+
511+
def flush(self):
512+
self.fp.flush()
513+
514+
# End of "raw stream" methods
515+
502516
def isclosed(self):
503517
# NOTE: it is possible that we will not ever call self.close(). This
504518
# case occurs when will_close is TRUE, length is None, and we

Lib/urllib2.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,10 @@ def do_open(self, http_class, req):
10721072
# Pick apart the HTTPResponse object to get the addinfourl
10731073
# object initialized properly.
10741074

1075+
# XXX Should an HTTPResponse object really be passed to
1076+
# BufferedReader? If so, we should change httplib to support
1077+
# this use directly.
1078+
10751079
# Add some fake methods to the reader to satisfy BufferedReader.
10761080
r.readable = lambda: True
10771081
r.writable = r.seekable = lambda: False
@@ -1283,7 +1287,6 @@ def ftp_open(self, req):
12831287

12841288
def connect_ftp(self, user, passwd, host, port, dirs, timeout):
12851289
fw = ftpwrapper(user, passwd, host, port, dirs, timeout)
1286-
## fw.ftp.set_debuglevel(1)
12871290
return fw
12881291

12891292
class CacheFTPHandler(FTPHandler):

0 commit comments

Comments
 (0)