Adds BrokerConnection.connected

This method returns True if the connection object has actually
established a connection, and is not closed.
This commit is contained in:
Ask Solem 2011-09-08 20:18:03 +01:00
parent 81dd557f46
commit 412a1b15d4
1 changed files with 12 additions and 7 deletions

View File

@ -543,6 +543,13 @@ class BrokerConnection(object):
def __exit__(self, *args): def __exit__(self, *args):
self.release() self.release()
@property
def connected(self):
"""Returns true if the connection has been established."""
return (not self._closed and
self._connection is not None and
self.transport.verify_connection(self._connection))
@property @property
def connection(self): def connection(self):
"""The underlying connection object. """The underlying connection object.
@ -552,13 +559,11 @@ class BrokerConnection(object):
depend on the interface of this object. depend on the interface of this object.
""" """
if self._closed: if not self._closed:
return if not self.connected:
if not self._connection or not \ self._connection = self._establish_connection()
self.transport.verify_connection(self._connection): self._closed = False
self._connection = self._establish_connection() return self._connection
self._closed = False
return self._connection
@property @property
def default_channel(self): def default_channel(self):