Print debug on stderr.

This commit is contained in:
Bastian Kleineidam 2012-10-10 12:27:25 +02:00
parent 0c20ef5de4
commit a0610310b4

View file

@ -70,6 +70,7 @@ Req-sent-unread-response _CS_REQ_SENT <response_class>
"""
import errno
import sys
import mimetools
from array import array
import os
@ -369,7 +370,7 @@ class HTTPResponse:
if len(line) > _MAXLINE:
raise LineTooLong("header line")
if self.debuglevel > 0:
print "reply:", repr(line)
print >>sys.stderr, "reply:", repr(line)
if not line:
# Presumably, the server closed the connection before
# sending a valid response.
@ -421,7 +422,7 @@ class HTTPResponse:
if not skip:
break
if self.debuglevel > 0:
print "header:", skip
print >>sys.stderr, "header:", skip
self.status = status
self.reason = reason.strip()
@ -444,7 +445,7 @@ class HTTPResponse:
self.msg = HTTPMessage(self.fp, 0)
if self.debuglevel > 0:
for hdr in self.msg.headers:
print "header:", hdr,
print >>sys.stderr, "header:", hdr,
# don't let the msg keep an fp
self.msg.fp = None
@ -798,11 +799,11 @@ class HTTPConnection:
# 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(data)
print >>sys.stderr, "send:", repr(data)
try:
blocksize=8192
if hasattr(data,'read') and not isinstance(data, array):
if self.debuglevel > 0: print "sendIng a read()able"
if self.debuglevel > 0: print >>sys.stderr, "sendIng a read()able"
datablock=data.read(blocksize)
while datablock:
self.sock.sendall(datablock)
@ -1004,7 +1005,7 @@ class HTTPConnection:
thelen = str(os.fstat(body.fileno()).st_size)
except (AttributeError, OSError):
# Don't send a length if this failed
if self.debuglevel > 0: print "Cannot stat!!"
if self.debuglevel > 0: print >>sys.stderr, "Cannot stat!!"
if thelen is not None:
self.putheader('Content-Length', thelen)