summaryrefslogtreecommitdiff
path: root/Lib/asyncore.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/asyncore.py')
-rw-r--r--Lib/asyncore.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 00464a9427..5d7bddaf84 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -50,10 +50,12 @@ import select
import socket
import sys
import time
+import warnings
+
import os
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
- ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, \
- EAGAIN, errorcode
+ ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
+ errorcode
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
EBADF))
@@ -270,6 +272,8 @@ class dispatcher:
status.append(repr(self.addr))
return '<%s at %#x>' % (' '.join(status), id(self))
+ __str__ = __repr__
+
def add_channel(self, map=None):
#self.log_info('adding channel %s' % self)
if map is None:
@@ -367,7 +371,7 @@ class dispatcher:
except socket.error as why:
if why.args[0] == EWOULDBLOCK:
return 0
- elif why.args[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED):
+ elif why.args[0] in _DISCONNECTED:
self.handle_close()
return 0
else:
@@ -385,7 +389,7 @@ class dispatcher:
return data
except socket.error as why:
# winsock sometimes throws ENOTCONN
- if why.args[0] in [ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED]:
+ if why.args[0] in _DISCONNECTED:
self.handle_close()
return b''
else:
@@ -405,10 +409,15 @@ class dispatcher:
# references to the underlying socket object.
def __getattr__(self, attr):
try:
- return getattr(self.socket, attr)
+ retattr = getattr(self.socket, attr)
except AttributeError:
raise AttributeError("%s instance has no attribute '%s'"
%(self.__class__.__name__, attr))
+ else:
+ msg = "%(me)s.%(attr)s is deprecated; use %(me)s.socket.%(attr)s " \
+ "instead" % {'me' : self.__class__.__name__, 'attr' : attr}
+ warnings.warn(msg, DeprecationWarning, stacklevel=2)
+ return retattr
# log and log_info may be overridden to provide more sophisticated
# logging and warning methods. In general, log is for 'hit' logging
@@ -502,7 +511,13 @@ class dispatcher:
self.log_info('unhandled connect event', 'warning')
def handle_accept(self):
- self.log_info('unhandled accept event', 'warning')
+ pair = self.accept()
+ if pair is not None:
+ self.handle_accepted(*pair)
+
+ def handle_accepted(self, sock, addr):
+ sock.close()
+ self.log_info('unhandled accepted event', 'warning')
def handle_close(self):
self.log_info('unhandled close event', 'warning')