Merge pull request #11 from bninja/cxn-str

fix cxn str to work w/ pika.BlockingConnection
This commit is contained in:
andrew 2016-05-27 10:12:50 -07:00
commit 5b1d3b6503
2 changed files with 16 additions and 2 deletions

View File

@ -231,9 +231,22 @@ class Pool(object):
if not Connection.is_connection_invalidated(ex):
raise
@property
def cxn_params(self):
if isinstance(self.cxn, pika.BaseConnection):
return self.cxn.params
if isinstance(self.cxn, pika.BlockingConnection):
return self.cxn._impl.params
@property
def cxn_str(self):
params = self.cxn_params
if params:
return '{0}:{1}/{2}'.format(params.host, params.port, params.virtual_host)
def __str__(self):
return ', '.join('{0}={1}'.format(k, v) for k, v in [
('cxn', '{0}:{1}/{2}'.format(self.cxn.params.host, self.cxn.params.port, self.cxn.params.virtual_host)),
('cxn', self.cxn_str),
('channel', '{0}'.format(int(self.channel) if self.channel is not None else self.channel)),
])
@ -358,7 +371,7 @@ class QueuedPool(Pool):
def __str__(self):
return ', '.join('{0}={1}'.format(k, v) for k, v in [
('cxn', '{0}:{1}/{2}'.format(self.cxn.params.host, self.cxn.params.port, self.cxn.params.virtual_host)),
('cxn', self.cxn_str),
('channel', '{0}'.format(int(self.channel) if self.channel is not None else self.channel)),
('created_at', '{0}'.format(datetime.fromtimestamp(self.created_at).isoformat())),
('released_at', '{0}'.format(datetime.fromtimestamp(self.released_at).isoformat())),

View File

@ -139,6 +139,7 @@ def test_use_it():
delivery_mode=2,
)
)
assert 'cxn=localhost:5672//' in str(cxn.fairy)
class TestQueuedPool(object):