Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_on_connection_close_ok(self):
"""make sure _on_connection_close_ok terminates connection"""
method_frame = mock.Mock()
method_frame.method = mock.Mock(spec=spec.Connection.CloseOk)
self.connection._terminate_stream = mock.Mock()
self.connection._on_connection_close_ok(method_frame)
#Check
self.connection._terminate_stream.assert_called_once_with(None)
def begin(self, channel):
# Simulate Connection.Blocked
channel.connection._on_connection_blocked(
channel.connection,
pika.frame.Method(0,
spec.Connection.Blocked(
'Testing blocked connection timeout')))
async def send_tune_ok(self):
# TODO: for now, do not want a heartbeat
tunk = pika.spec.Connection.TuneOk(frame_max=self.MAX_DATA_SIZE)
frame_value = pika.frame.Method(0, tunk)
await self.sock.sendall(frame_value.marshal())
return
def _send_connection_close(self, reply_code, reply_text):
"""Send a Connection.Close method frame.
:param int reply_code: The reason for the close
:param str reply_text: The text reason for the close
"""
self._rpc(0, spec.Connection.Close(reply_code, reply_text, 0, 0),
self._on_connection_closed, [spec.Connection.CloseOk])
def _add_connection_start_callback(self):
"""Add a callback for when a Connection.Start frame is received from
the broker.
"""
self.callbacks.add(0, spec.Connection.Start, self._on_connection_start)
def add_on_connection_unblocked_callback(self, callback):
"""RabbitMQ AMQP extension - Add a callback to be notified when the
connection gets unblocked (`Connection.Unblocked` frame is received from
RabbitMQ) letting publishers know it's ok to start publishing again.
:param callable callback: Callback to call on
`Connection.Unblocked`, having the signature
`callback(connection, pika.frame.Method)`, where the method frame's
`method` member is of type `pika.spec.Connection.Unblocked`
"""
validators.require_callback(callback)
self.callbacks.add(
0,
spec.Connection.Unblocked,
functools.partial(callback, self),
one_shot=False)
data.encode_short_string(pieces, self.cluster_id)
flag_pieces = list()
while True:
remainder = flags >> 16
partial_flags = flags & 0xFFFE
if remainder != 0:
partial_flags |= 1
flag_pieces.append(struct.pack('>H', partial_flags))
flags = remainder
if not flags:
break
return flag_pieces + pieces
methods = {
0x000A000A: Connection.Start,
0x000A000B: Connection.StartOk,
0x000A0014: Connection.Secure,
0x000A0015: Connection.SecureOk,
0x000A001E: Connection.Tune,
0x000A001F: Connection.TuneOk,
0x000A0028: Connection.Open,
0x000A0029: Connection.OpenOk,
0x000A0032: Connection.Close,
0x000A0033: Connection.CloseOk,
0x000A003C: Connection.Blocked,
0x000A003D: Connection.Unblocked,
0x0014000A: Channel.Open,
0x0014000B: Channel.OpenOk,
0x00140014: Channel.Flow,
0x00140015: Channel.FlowOk,
0x00140028: Channel.Close,
0x00140029: Channel.CloseOk,
flag_pieces.append(struct.pack('>H', partial_flags))
flags = remainder
if not flags:
break
return flag_pieces + pieces
methods = {
0x000A000A: Connection.Start,
0x000A000B: Connection.StartOk,
0x000A0014: Connection.Secure,
0x000A0015: Connection.SecureOk,
0x000A001E: Connection.Tune,
0x000A001F: Connection.TuneOk,
0x000A0028: Connection.Open,
0x000A0029: Connection.OpenOk,
0x000A0032: Connection.Close,
0x000A0033: Connection.CloseOk,
0x000A003C: Connection.Blocked,
0x000A003D: Connection.Unblocked,
0x0014000A: Channel.Open,
0x0014000B: Channel.OpenOk,
0x00140014: Channel.Flow,
0x00140015: Channel.FlowOk,
0x00140028: Channel.Close,
0x00140029: Channel.CloseOk,
0x001E000A: Access.Request,
0x001E000B: Access.RequestOk,
0x0028000A: Exchange.Declare,
0x0028000B: Exchange.DeclareOk,
0x00280014: Exchange.Delete,
0x00280015: Exchange.DeleteOk,
0x0028001E: Exchange.Bind,
def _add_connection_tune_callback(self):
"""Add a callback for when a Connection.Tune frame is received."""
self.callbacks.add(0, spec.Connection.Tune, self._on_connection_tune)
def _send_connection_close(self, reply_code, reply_text):
"""Send a Connection.Close method frame.
:param int reply_code: The reason for the close
:param str reply_text: The text reason for the close
"""
self._rpc(0, spec.Connection.Close(reply_code, reply_text, 0, 0),
self._on_connection_close_ok, [spec.Connection.CloseOk])