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):
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
def connection(self):
"""The underlying connection object.
@ -552,10 +559,8 @@ class BrokerConnection(object):
depend on the interface of this object.
"""
if self._closed:
return
if not self._connection or not \
self.transport.verify_connection(self._connection):
if not self._closed:
if not self.connected:
self._connection = self._establish_connection()
self._closed = False
return self._connection