Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eee80ee

Browse files
committed
Patch #470744: Simplify __repr__ error handling.
1 parent 61c5edf commit eee80ee

1 file changed

Lines changed: 4 additions & 16 deletions

File tree

Lib/asyncore.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
import select
5151
import socket
5252
import sys
53-
import types
5453

5554
import os
5655
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \
@@ -208,28 +207,17 @@ def __init__ (self, sock=None, map=None):
208207
self.addr = sock.getpeername()
209208

210209
def __repr__ (self):
211-
try:
212210
status = [self.__class__.__module__+"."+self.__class__.__name__]
213211
if self.accepting and self.addr:
214212
status.append ('listening')
215213
elif self.connected:
216214
status.append ('connected')
217-
if self.addr:
218-
if type(self.addr) == types.TupleType:
215+
if self.addr is not None:
216+
try:
219217
status.append ('%s:%d' % self.addr)
220-
else:
221-
status.append (self.addr)
218+
except TypeError:
219+
status.append (repr(self.addr))
222220
return '<%s at %#x>' % (' '.join (status), id (self))
223-
except:
224-
pass
225-
226-
try:
227-
ar = repr (self.addr)
228-
except AttributeError:
229-
ar = 'no self.addr!'
230-
231-
return '<__repr__() failed for %s instance at %x (addr=%s)>' % \
232-
(self.__class__.__name__, id (self), ar)
233221

234222
def add_channel (self, map=None):
235223
#self.log_info ('adding channel %s' % self)

0 commit comments

Comments
 (0)