diff options
-rw-r--r-- | Lib/asyncore.py | 4 | ||||
-rw-r--r-- | Lib/test/test_asyncore.py | 9 |
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py index ac0b755..c2ec259 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -63,8 +63,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 b2c0198..27a585d 100644 --- a/Lib/test/test_asyncore.py +++ b/Lib/test/test_asyncore.py @@ -6,6 +6,7 @@ import socket import sys import time import warnings +import errno from test import support from test.support import TESTFN, run_unittest, unlink @@ -324,6 +325,14 @@ class DispatcherTests(unittest.TestCase): self.assertTrue(len(w) == 1) self.assertTrue(issubclass(w[0].category, DeprecationWarning)) + 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): |