diff options
| author | Giampaolo RodolĂ <g.rodola@gmail.com> | 2010-05-06 17:57:06 (GMT) |
|---|---|---|
| committer | Giampaolo RodolĂ <g.rodola@gmail.com> | 2010-05-06 17:57:06 (GMT) |
| commit | f7454fa98dfe5d2c3d59437aade27b5daa6208c5 (patch) | |
| tree | d87578596420ca2799f21eb387d0cbb9f0db4de5 /Lib/asyncore.py | |
| parent | a8ac944924281a2604c1a3329465705fe30bab68 (diff) | |
| download | cpython-f7454fa98dfe5d2c3d59437aade27b5daa6208c5.zip cpython-f7454fa98dfe5d2c3d59437aade27b5daa6208c5.tar.gz cpython-f7454fa98dfe5d2c3d59437aade27b5daa6208c5.tar.bz2 | |
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__
Diffstat (limited to 'Lib/asyncore.py')
| -rw-r--r-- | Lib/asyncore.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 6d6ca33..5aec688 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -50,6 +50,7 @@ import select import socket import sys import time +import warnings import os from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ @@ -61,10 +62,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 @@ -265,6 +268,8 @@ class dispatcher: 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 +401,15 @@ 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: + 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 |
