diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 88845012e48..44e89181cb6 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -61,8 +61,8 @@ except NameError: def _strerror(err): try: - return strerror(err) - except (ValueError, OverflowError): + return os.strerror(err) + except (ValueError, OverflowError, NameError): if err in errorcode: return errorcode[err] return "Unknown error %s" %err diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py index 4db29ca14ea..785b2116f6f 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -6,6 +6,7 @@ import socket import threading import sys import time +import errno from test import support from test.support import TESTFN, run_unittest, unlink @@ -315,6 +316,14 @@ class DispatcherTests(unittest.TestCase): # test cheap inheritance with the underlying socket self.assertEqual(d.family, socket.AF_INET) + def test_strerror(self): + # refers to bug #8573 + err = asyncore._strerror(errno.EPERM) + if hasattr(os, 'strerror'): + self.assertEqual(err, os.strerror(errno.EPERM)) + err = asyncore._strerror(-1) + self.assertTrue("unknown error" in err.lower()) + class dispatcherwithsend_noread(asyncore.dispatcher_with_send): def readable(self):