mirror of
https://github.com/python/cpython.git
synced 2025-08-15 22:30:42 +00:00
Fix Issue 6706: return None on connect() in case of EWOULDBLOCK/ECONNABORTED error.
This commit is contained in:
parent
abacccc50c
commit
19e9fefc66
4 changed files with 70 additions and 37 deletions
31
Lib/smtpd.py
31
Lib/smtpd.py
|
@ -35,7 +35,6 @@ given then 8025 is used. If remotehost is not given then `localhost' is used,
|
|||
and if remoteport is not given, then 25 is used.
|
||||
"""
|
||||
|
||||
|
||||
# Overview:
|
||||
#
|
||||
# This file implements the minimal SMTP protocol as defined in RFC 821. It
|
||||
|
@ -96,7 +95,6 @@ EMPTYSTRING = ''
|
|||
COMMASPACE = ', '
|
||||
|
||||
|
||||
|
||||
def usage(code, msg=''):
|
||||
print >> sys.stderr, __doc__ % globals()
|
||||
if msg:
|
||||
|
@ -104,7 +102,6 @@ def usage(code, msg=''):
|
|||
sys.exit(code)
|
||||
|
||||
|
||||
|
||||
class SMTPChannel(asynchat.async_chat):
|
||||
COMMAND = 0
|
||||
DATA = 1
|
||||
|
@ -276,7 +273,6 @@ class SMTPChannel(asynchat.async_chat):
|
|||
self.push('354 End data with <CR><LF>.<CR><LF>')
|
||||
|
||||
|
||||
|
||||
class SMTPServer(asyncore.dispatcher):
|
||||
def __init__(self, localaddr, remoteaddr):
|
||||
self._localaddr = localaddr
|
||||
|
@ -299,22 +295,11 @@ class SMTPServer(asyncore.dispatcher):
|
|||
localaddr, remoteaddr)
|
||||
|
||||
def handle_accept(self):
|
||||
try:
|
||||
conn, addr = self.accept()
|
||||
except TypeError:
|
||||
# sometimes accept() might return None
|
||||
return
|
||||
except socket.error, err:
|
||||
# ECONNABORTED might be thrown
|
||||
if err[0] != errno.ECONNABORTED:
|
||||
raise
|
||||
return
|
||||
else:
|
||||
# sometimes addr == None instead of (ip, port)
|
||||
if addr == None:
|
||||
return
|
||||
print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
|
||||
channel = SMTPChannel(self, conn, addr)
|
||||
pair = self.accept()
|
||||
if pair is not None:
|
||||
conn, addr = pair
|
||||
print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr)
|
||||
channel = SMTPChannel(self, conn, addr)
|
||||
|
||||
# API for "doing something useful with the message"
|
||||
def process_message(self, peer, mailfrom, rcpttos, data):
|
||||
|
@ -342,7 +327,6 @@ class SMTPServer(asyncore.dispatcher):
|
|||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
class DebuggingServer(SMTPServer):
|
||||
# Do something with the gathered message
|
||||
def process_message(self, peer, mailfrom, rcpttos, data):
|
||||
|
@ -358,7 +342,6 @@ class DebuggingServer(SMTPServer):
|
|||
print '------------ END MESSAGE ------------'
|
||||
|
||||
|
||||
|
||||
class PureProxy(SMTPServer):
|
||||
def process_message(self, peer, mailfrom, rcpttos, data):
|
||||
lines = data.split('\n')
|
||||
|
@ -399,7 +382,6 @@ class PureProxy(SMTPServer):
|
|||
return refused
|
||||
|
||||
|
||||
|
||||
class MailmanProxy(PureProxy):
|
||||
def process_message(self, peer, mailfrom, rcpttos, data):
|
||||
from cStringIO import StringIO
|
||||
|
@ -478,13 +460,11 @@ class MailmanProxy(PureProxy):
|
|||
msg.Enqueue(mlist, torequest=1)
|
||||
|
||||
|
||||
|
||||
class Options:
|
||||
setuid = 1
|
||||
classname = 'PureProxy'
|
||||
|
||||
|
||||
|
||||
def parseargs():
|
||||
global DEBUGSTREAM
|
||||
try:
|
||||
|
@ -541,7 +521,6 @@ def parseargs():
|
|||
return options
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
options = parseargs()
|
||||
# Become nobody
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue