doc string cleanup
This commit is contained in:
@@ -290,7 +290,7 @@ class FanoutPublisher(Publisher):
|
|||||||
|
|
||||||
|
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
"""Connection instance object."""
|
"""Connection object."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.consumers = []
|
self.consumers = []
|
||||||
@@ -503,7 +503,18 @@ ConnectionPool = Pool(
|
|||||||
|
|
||||||
|
|
||||||
class ConnectionContext(object):
|
class ConnectionContext(object):
|
||||||
|
"""The class that is actually returned to the caller of
|
||||||
|
create_connection(). This is a essentially a wrapper around
|
||||||
|
Connection that supports 'with' and can return a new Connection or
|
||||||
|
one from a pool. It will also catch when an instance of this class
|
||||||
|
is to be deleted so that we can return Connections to the pool on
|
||||||
|
exceptions and so forth without making the caller be responsible for
|
||||||
|
catching all exceptions and making sure to return a connection to
|
||||||
|
the pool.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, pooled=True):
|
def __init__(self, pooled=True):
|
||||||
|
"""Create a new connection, or get one from the pool"""
|
||||||
self.connection = None
|
self.connection = None
|
||||||
if pooled:
|
if pooled:
|
||||||
self.connection = ConnectionPool.get()
|
self.connection = ConnectionPool.get()
|
||||||
@@ -512,9 +523,13 @@ class ConnectionContext(object):
|
|||||||
self.pooled = pooled
|
self.pooled = pooled
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
"""with ConnectionContext() should return self"""
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def _done(self):
|
def _done(self):
|
||||||
|
"""If the connection came from a pool, clean it up and put it back.
|
||||||
|
If it did not come from a pool, close it.
|
||||||
|
"""
|
||||||
if self.connection:
|
if self.connection:
|
||||||
if self.pooled:
|
if self.pooled:
|
||||||
# Reset the connection so it's ready for the next caller
|
# Reset the connection so it's ready for the next caller
|
||||||
@@ -533,19 +548,19 @@ class ConnectionContext(object):
|
|||||||
self.connection = None
|
self.connection = None
|
||||||
|
|
||||||
def __exit__(self, t, v, tb):
|
def __exit__(self, t, v, tb):
|
||||||
"""end if 'with' statement. We're done here."""
|
"""end of 'with' statement. We're done here."""
|
||||||
self._done()
|
self._done()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""Put Connection back into the pool if this ConnectionContext
|
"""Caller is done with this connection. Make sure we cleaned up."""
|
||||||
is being deleted
|
|
||||||
"""
|
|
||||||
self._done()
|
self._done()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
"""Caller is done with this connection."""
|
||||||
self._done()
|
self._done()
|
||||||
|
|
||||||
def __getattr__(self, key):
|
def __getattr__(self, key):
|
||||||
|
"""Proxy all other calls to the Connection instance"""
|
||||||
if self.connection:
|
if self.connection:
|
||||||
return getattr(self.connection, key)
|
return getattr(self.connection, key)
|
||||||
else:
|
else:
|
||||||
@@ -637,6 +652,7 @@ def _pack_context(msg, context):
|
|||||||
|
|
||||||
|
|
||||||
class RpcContext(context.RequestContext):
|
class RpcContext(context.RequestContext):
|
||||||
|
"""Context that supports replying to a rpc.call"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
msg_id = kwargs.pop('msg_id', None)
|
msg_id = kwargs.pop('msg_id', None)
|
||||||
self.msg_id = msg_id
|
self.msg_id = msg_id
|
||||||
@@ -656,7 +672,7 @@ class MulticallWaiter(object):
|
|||||||
|
|
||||||
def done(self):
|
def done(self):
|
||||||
self._done = True
|
self._done = True
|
||||||
self._connection = None
|
self._connection.close()
|
||||||
|
|
||||||
def __call__(self, data):
|
def __call__(self, data):
|
||||||
"""The consume() callback will call this. Store the result."""
|
"""The consume() callback will call this. Store the result."""
|
||||||
@@ -666,6 +682,7 @@ class MulticallWaiter(object):
|
|||||||
self._result = data['result']
|
self._result = data['result']
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
|
"""Return a result until we get a 'None' response from consumer"""
|
||||||
if self._done:
|
if self._done:
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user