Merged revisions 70873,70904,70934,71490,71553,71579 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r70873 | josiah.carlson | 2009-03-31 15:32:34 -0400 (Tue, 31 Mar 2009) | 2 lines

  This resolves issue 1161031.  Tests pass.
........
  r70904 | josiah.carlson | 2009-03-31 17:49:36 -0400 (Tue, 31 Mar 2009) | 3 lines

  Made handle_expt_event() be called last, so that we don't accidentally read
  after closing the socket.
........
  r70934 | josiah.carlson | 2009-03-31 21:28:11 -0400 (Tue, 31 Mar 2009) | 2 lines

  Fix for failing asyncore tests.
........
  r71490 | r.david.murray | 2009-04-11 13:52:56 -0400 (Sat, 11 Apr 2009) | 4 lines

  Make test_asyncore tests match code changes introduced by the
  fix to Issue1161031, refactoring the test to simplify it in
  the process.
........
  r71553 | r.david.murray | 2009-04-12 21:06:46 -0400 (Sun, 12 Apr 2009) | 3 lines

  Adjust test_asyncore to account for intentional asyncore behavior change
  introduced by r70934 that was causing a test failure when run under -O.
........
  r71579 | r.david.murray | 2009-04-13 12:56:32 -0400 (Mon, 13 Apr 2009) | 2 lines

  Add missing NEWS item for issue1161031 fix.
........
This commit is contained in:
R. David Murray 2009-04-15 23:00:41 +00:00
parent 0ec635138f
commit 7cd8f2bea3
4 changed files with 59 additions and 70 deletions

View file

@ -69,10 +69,12 @@ def _strerror(err):
class ExitNow(Exception):
pass
_reraised_exceptions = (ExitNow, KeyboardInterrupt, SystemExit)
def read(obj):
try:
obj.handle_read_event()
except (ExitNow, KeyboardInterrupt, SystemExit):
except _reraised_exceptions:
raise
except:
obj.handle_error()
@ -80,7 +82,7 @@ def read(obj):
def write(obj):
try:
obj.handle_write_event()
except (ExitNow, KeyboardInterrupt, SystemExit):
except _reraised_exceptions:
raise
except:
obj.handle_error()
@ -88,22 +90,22 @@ def write(obj):
def _exception(obj):
try:
obj.handle_expt_event()
except (ExitNow, KeyboardInterrupt, SystemExit):
except _reraised_exceptions:
raise
except:
obj.handle_error()
def readwrite(obj, flags):
try:
if flags & (select.POLLIN | select.POLLPRI):
if flags & select.POLLIN:
obj.handle_read_event()
if flags & select.POLLOUT:
obj.handle_write_event()
if flags & (select.POLLERR | select.POLLNVAL):
obj.handle_expt_event()
if flags & select.POLLHUP:
if flags & (select.POLLHUP | select.POLLERR | select.POLLNVAL):
obj.handle_close()
except (ExitNow, KeyboardInterrupt, SystemExit):
if flags & select.POLLPRI:
obj.handle_expt_event()
except _reraised_exceptions:
raise
except:
obj.handle_error()
@ -211,6 +213,7 @@ class dispatcher:
accepting = False
closing = False
addr = None
ignore_log_types = frozenset(['warning'])
def __init__(self, sock=None, map=None):
if map is None:
@ -398,7 +401,7 @@ class dispatcher:
sys.stderr.write('log: %s\n' % str(message))
def log_info(self, message, type='info'):
if __debug__ or type != 'info':
if type not in self.ignore_log_types:
print '%s: %s' % (type, message)
def handle_read_event(self):
@ -432,22 +435,17 @@ class dispatcher:
self.handle_write()
def handle_expt_event(self):
# if the handle_expt is the same default worthless method,
# we'll not even bother calling it, we'll instead generate
# a useful error
x = True
try:
y1 = self.__class__.handle_expt.im_func
y2 = dispatcher.handle_expt.im_func
x = y1 is y2
except AttributeError:
pass
if x:
err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
msg = _strerror(err)
raise socket.error(err, msg)
# handle_expt_event() is called if there might be an error on the
# socket, or if there is OOB data
# check for the error condition first
err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
if err != 0:
# we can get here when select.select() says that there is an
# exceptional condition on the socket
# since there is an error, we'll go ahead and close the socket
# like we would in a subclassed handle_read() that received no
# data
self.handle_close()
else:
self.handle_expt()
@ -472,7 +470,7 @@ class dispatcher:
self.handle_close()
def handle_expt(self):
self.log_info('unhandled exception', 'warning')
self.log_info('unhandled incoming priority event', 'warning')
def handle_read(self):
self.log_info('unhandled read event', 'warning')
@ -553,7 +551,7 @@ def close_all(map=None, ignore_all=False):
pass
elif not ignore_all:
raise
except (ExitNow, KeyboardInterrupt, SystemExit):
except _reraised_exceptions:
raise
except:
if not ignore_all: