[Python-checkins] CVS: python/dist/src/Lib httplib.py,1.21,1.22
Jeremy Hylton
python-dev@python.org
Mon, 18 Sep 2000 15:50:41 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv22353/Lib
Modified Files:
httplib.py
Log Message:
Do not close socket when a Content-Length is 0. This make the
interface consistent: The client is responsible for closing the
socket, regardless of the amount of data received.
Restore suport for set_debuglevel call.
Index: httplib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/httplib.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -r1.21 -r1.22
*** httplib.py 2000/09/14 20:34:27 1.21
--- httplib.py 2000/09/18 22:50:38 1.22
***************
*** 88,93 ****
class HTTPResponse:
! def __init__(self, sock):
self.fp = sock.makefile('rb', 0)
self.msg = None
--- 88,94 ----
class HTTPResponse:
! def __init__(self, sock, debuglevel=0):
self.fp = sock.makefile('rb', 0)
+ self.debuglevel = debuglevel
self.msg = None
***************
*** 109,112 ****
--- 110,115 ----
line = self.fp.readline()
+ if self.debuglevel > 0:
+ print "reply:", repr(line)
try:
[version, status, reason] = string.split(line, None, 2)
***************
*** 133,136 ****
--- 136,142 ----
self.msg = mimetools.Message(self.fp, 0)
+ if self.debuglevel > 0:
+ for hdr in self.msg.headers:
+ print "header:", hdr,
# don't let the msg keep an fp
***************
*** 188,196 ****
self.will_close = 1
- # if there is no body, then close NOW. read() may never be called, thus
- # we will never mark self as closed.
- if self.length == 0:
- self.close()
-
def close(self):
if self.fp:
--- 194,197 ----
***************
*** 274,283 ****
s = self.fp.read(amt)
- # close our "file" if we know we should
- ### I'm not sure about the len(s) < amt part; we should be safe because
- ### we shouldn't be using non-blocking sockets
- if self.length == 0 or len(s) < amt:
- self.close()
-
return s
--- 275,278 ----
***************
*** 319,322 ****
--- 314,318 ----
default_port = HTTP_PORT
auto_open = 1
+ debuglevel = 0
def __init__(self, host, port=None):
***************
*** 338,344 ****
--- 334,345 ----
self.port = port
+ def set_debuglevel(self, level):
+ self.debuglevel = level
+
def connect(self):
"""Connect to the host and port specified in __init__."""
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ if self.debuglevel > 0:
+ print "connect: (%s, %s)" % (self.host, self.port)
self.sock.connect((self.host, self.port))
***************
*** 366,369 ****
--- 367,372 ----
# NOTE: we DO propagate the error, though, because we cannot simply
# ignore the error... the caller will know if they can retry.
+ if self.debuglevel > 0:
+ print "send:", repr(str)
try:
self.sock.send(str)
***************
*** 525,529 ****
raise ResponseNotReady()
! response = self.response_class(self.sock)
response.begin()
--- 528,535 ----
raise ResponseNotReady()
! if self.debuglevel > 0:
! response = self.response_class(self.sock, self.debuglevel)
! else:
! response = self.response_class(self.sock)
response.begin()
***************
*** 648,653 ****
def set_debuglevel(self, debuglevel):
! "The class no longer supports the debuglevel."
! pass
def getfile(self):
--- 654,658 ----
def set_debuglevel(self, debuglevel):
! self._conn.set_debuglevel(debuglevel)
def getfile(self):