summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2010-05-06 18:24:02 (GMT)
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2010-05-06 18:24:02 (GMT)
commit902b57b6f6693bd1b5bb9161ad52d8109177aee0 (patch)
treea924aac70593b5e8bcc68d06765866ae0da36115
parent1222669b440e163885be8661cf81c3d46a73b337 (diff)
downloadcpython-902b57b6f6693bd1b5bb9161ad52d8109177aee0.zip
cpython-902b57b6f6693bd1b5bb9161ad52d8109177aee0.tar.gz
cpython-902b57b6f6693bd1b5bb9161ad52d8109177aee0.tar.bz2
Merged revisions 80875 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r80875 | giampaolo.rodola | 2010-05-06 19:57:06 +0200 (gio, 06 mag 2010) | 1 line Fix asyncore issues 8573 and 8483: _strerror might throw ValueError; asyncore.__getattr__ cheap inheritance caused confusing error messages when accessing undefined class attributes; added an alias for __str__ which now is used as a fallback for __repr__ ........
-rw-r--r--Lib/asyncore.py16
-rw-r--r--Lib/test/test_asyncore.py12
-rw-r--r--Misc/NEWS6
3 files changed, 29 insertions, 5 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py
index 4f1153b..07d5311 100644
--- a/Lib/asyncore.py
+++ b/Lib/asyncore.py
@@ -61,10 +61,12 @@ except NameError:
socket_map = {}
def _strerror(err):
- res = os.strerror(err)
- if res == 'Unknown error':
- res = errorcode[err]
- return res
+ try:
+ return strerror(err)
+ except (ValueError, OverflowError):
+ if err in errorcode:
+ return errorcode[err]
+ return "Unknown error %s" %err
class ExitNow(Exception):
pass
@@ -391,7 +393,11 @@ class dispatcher:
# cheap inheritance, used to pass all other attribute
# references to the underlying socket object.
def __getattr__(self, attr):
- return getattr(self.socket, attr)
+ try:
+ return getattr(self.socket, attr)
+ except AttributeError:
+ raise AttributeError("%s instance has no attribute '%s'"
+ %(self.__class__.__name__, attr))
# log and log_info may be overridden to provide more sophisticated
# logging and warning methods. In general, log is for 'hit' logging
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index ce835aa..670ee43 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -301,6 +301,18 @@ class DispatcherTests(unittest.TestCase):
'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
+ try:
+ d.foo
+ except AttributeError, err:
+ self.assertTrue('dispatcher instance' in str(err))
+ else:
+ self.fail("exception not raised")
+ # test cheap inheritance with the underlying socket
+ self.assertEqual(d.family, socket.AF_INET)
class dispatcherwithsend_noread(asyncore.dispatcher_with_send):
diff --git a/Misc/NEWS b/Misc/NEWS
index 7bafbbe..8e33eb9 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,12 @@ Core and Builtins
Library
-------
+- Issue #8573: asyncore _strerror() function might throw ValueError.
+
+- Issue #8483: asyncore.dispatcher's __getattr__ method produced confusing
+ error messages when accessing undefined class attributes because of the cheap
+ inheritance with the underlying socket object.
+
- Issue #4265: shutil.copyfile() was leaking file descriptors when disk fills.
Patch by Tres Seaver.