Index: Lib/asyncore.py =================================================================== --- Lib/asyncore.py (revisione 80760) +++ Lib/asyncore.py (copia locale) @@ -50,6 +50,7 @@ import socket import sys import time +import warnings import os from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ @@ -265,6 +266,8 @@ 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: @@ -396,7 +399,15 @@ # cheap inheritance, used to pass all other attribute # references to the underlying socket object. def __getattr__(self, attr): - return getattr(self.socket, attr) + try: + retattr = getattr(self.socket, attr) + except AttributeError: + raise AttributeError("%s instance has no attribute '%s'" + %(self.__class__.__name__, attr)) + else: + warnings.warn("cheap inheritance is deprecated", 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 Index: Lib/test/test_asyncore.py =================================================================== --- Lib/test/test_asyncore.py (revisione 80760) +++ Lib/test/test_asyncore.py (copia locale) @@ -5,6 +5,7 @@ import socket import sys import time +import warnings from test import test_support from test.test_support import TESTFN, run_unittest, unlink @@ -305,6 +306,22 @@ 'warning: unhandled accept event'] self.assertEquals(lines, expected) + def test_issue_8594(self): + d = asyncore.dispatcher(socket.socket()) + # make sure the error message no longer refers to the socket + # object but the dispatcher instance instead + self.assertRaisesRegexp(AttributeError, 'dispatcher instance', + getattr, d, 'foo') + # The cheap inheritance with the underlying socket is supposed + # to still work but a DeprecationWarning is expected. + # Note: this test is supposed to be removed in next major Python + # version. + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + family = d.family + self.assertEqual(family, socket.AF_INET) + self.assertTrue(len(w) == 1) + self.assertTrue(issubclass(w[0].category, DeprecationWarning)) class dispatcherwithsend_noread(asyncore.dispatcher_with_send):