Commit 11debaa9 authored by Julien Muchembled's avatar Julien Muchembled

Add more information in __repr__ of connections

parent 6b410098
......@@ -280,14 +280,21 @@ class BaseConnection(object):
self.connector = None
self.aborted = False
def _getReprInfo(self):
return [
('uuid', uuid_str(self.getUUID())),
('address', self.addr and '%s:%d' % self.addr or '?'),
('handler', self.getHandler()),
], ['closed'] if self.isClosed() else []
def __repr__(self):
address = self.addr and '%s:%d' % self.addr or '?'
return '<%s(uuid=%s, address=%s, closed=%s, handler=%s) at %x>' % (
r, flags = self._getReprInfo()
r = map('%s=%s'.__mod__, r)
r += flags
return '<%s(%s) at %x>' % (
', '.join(r),
......@@ -388,6 +395,16 @@ class Connection(BaseConnection):
self._on_close = None
self._parser_state = ParserState()
def _getReprInfo(self):
r, flags = super(Connection, self)._getReprInfo()
if self._queue:
r.append(('len(queue)', len(self._queue)))
if self._on_close is not None:
r.append(('on_close', getattr(self._on_close, '__name__', '?')))
flags.extend(x for x in ('aborted', 'connecting', 'client', 'server')
if getattr(self, x))
return r, flags
def setOnClose(self, callback):
self._on_close = callback
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment