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

Skip to content

Commit e6f8a89

Browse files
committed
Debug output is now printed to sys.stderr .
Closes bug #980938.
1 parent cd77dd6 commit e6f8a89

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Lib/smtplib.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import base64
4848
import hmac
4949
from email.base64MIME import encode as encode_base64
50+
from sys import stderr
5051

5152
__all__ = ["SMTPException","SMTPServerDisconnected","SMTPResponseException",
5253
"SMTPSenderRefused","SMTPRecipientsRefused","SMTPDataError",
@@ -282,17 +283,17 @@ def connect(self, host='localhost', port = 0):
282283
except ValueError:
283284
raise socket.error, "nonnumeric port"
284285
if not port: port = SMTP_PORT
285-
if self.debuglevel > 0: print 'connect:', (host, port)
286+
if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
286287
msg = "getaddrinfo returns an empty list"
287288
self.sock = None
288289
for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
289290
af, socktype, proto, canonname, sa = res
290291
try:
291292
self.sock = socket.socket(af, socktype, proto)
292-
if self.debuglevel > 0: print 'connect:', (host, port)
293+
if self.debuglevel > 0: print>>stderr, 'connect:', (host, port)
293294
self.sock.connect(sa)
294295
except socket.error, msg:
295-
if self.debuglevel > 0: print 'connect fail:', (host, port)
296+
if self.debuglevel > 0: print>>stderr, 'connect fail:', (host, port)
296297
if self.sock:
297298
self.sock.close()
298299
self.sock = None
@@ -301,12 +302,12 @@ def connect(self, host='localhost', port = 0):
301302
if not self.sock:
302303
raise socket.error, msg
303304
(code, msg) = self.getreply()
304-
if self.debuglevel > 0: print "connect:", msg
305+
if self.debuglevel > 0: print>>stderr, "connect:", msg
305306
return (code, msg)
306307

307308
def send(self, str):
308309
"""Send `str' to the server."""
309-
if self.debuglevel > 0: print 'send:', repr(str)
310+
if self.debuglevel > 0: print>>stderr, 'send:', repr(str)
310311
if self.sock:
311312
try:
312313
self.sock.sendall(str)
@@ -345,7 +346,7 @@ def getreply(self):
345346
if line == '':
346347
self.close()
347348
raise SMTPServerDisconnected("Connection unexpectedly closed")
348-
if self.debuglevel > 0: print 'reply:', repr(line)
349+
if self.debuglevel > 0: print>>stderr, 'reply:', repr(line)
349350
resp.append(line[4:].strip())
350351
code=line[:3]
351352
# Check that the error code is syntactically correct.
@@ -361,7 +362,7 @@ def getreply(self):
361362

362363
errmsg = "\n".join(resp)
363364
if self.debuglevel > 0:
364-
print 'reply: retcode (%s); Msg: %s' % (errcode,errmsg)
365+
print>>stderr, 'reply: retcode (%s); Msg: %s' % (errcode,errmsg)
365366
return errcode, errmsg
366367

367368
def docmd(self, cmd, args=""):
@@ -474,7 +475,7 @@ def data(self,msg):
474475
"""
475476
self.putcmd("data")
476477
(code,repl)=self.getreply()
477-
if self.debuglevel >0 : print "data:", (code,repl)
478+
if self.debuglevel >0 : print>>stderr, "data:", (code,repl)
478479
if code != 354:
479480
raise SMTPDataError(code,repl)
480481
else:
@@ -484,7 +485,7 @@ def data(self,msg):
484485
q = q + "." + CRLF
485486
self.send(q)
486487
(code,msg)=self.getreply()
487-
if self.debuglevel >0 : print "data:", (code,msg)
488+
if self.debuglevel >0 : print>>stderr, "data:", (code,msg)
488489
return (code,msg)
489490

490491
def verify(self, address):

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Extension modules
2929
Library
3030
-------
3131

32+
- Bug #980938: smtplib now prints debug output to sys.stderr.
33+
3234
- Bug #930024: posixpath.realpath() now handles infinite loops in symlinks by
3335
returning the last point in the path that was not part of any loop. Thanks
3436
AM Kuchling.

0 commit comments

Comments
 (0)