[Python-checkins] r80879 - in python/branches/release31-maint: Lib/asyncore.py Lib/test/test_asyncore.py Misc/NEWS

giampaolo.rodola python-checkins at python.org
Thu May 6 20:37:34 CEST 2010


Author: giampaolo.rodola
Date: Thu May  6 20:37:34 2010
New Revision: 80879

Log:
Merged revisions 80876 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r80876 | giampaolo.rodola | 2010-05-06 20:06:30 +0200 (gio, 06 mag 2010) | 9 lines
  
  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__
  ........
................


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/asyncore.py
   python/branches/release31-maint/Lib/test/test_asyncore.py
   python/branches/release31-maint/Misc/NEWS

Modified: python/branches/release31-maint/Lib/asyncore.py
==============================================================================
--- python/branches/release31-maint/Lib/asyncore.py	(original)
+++ python/branches/release31-maint/Lib/asyncore.py	Thu May  6 20:37:34 2010
@@ -60,10 +60,12 @@
     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
@@ -395,7 +397,11 @@
     # 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

Modified: python/branches/release31-maint/Lib/test/test_asyncore.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_asyncore.py	(original)
+++ python/branches/release31-maint/Lib/test/test_asyncore.py	Thu May  6 20:37:34 2010
@@ -302,6 +302,18 @@
                     '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 as 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):

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Thu May  6 20:37:34 2010
@@ -40,6 +40,12 @@
 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 #7472: Fixed typo in email.encoders module; messages using ISO-2022
   character sets will now consistently use a Content-Transfer-Encoding of
   7bit rather than sometimes being marked as 8bit.


More information about the Python-checkins mailing list