code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
''' Abandon all message publications and acks in the current transaction. Caller can specify a callback to use when the transaction has been aborted. ''' # Could call select() but spec 1.9.2.5 says to raise an exception if not self.enabled: raise self....
def rollback(self, cb=None)
Abandon all message publications and acks in the current transaction. Caller can specify a callback to use when the transaction has been aborted.
9.576322
5.751054
1.665142
''' True if transport is synchronous or the connection has been forced into synchronous mode, False otherwise. ''' if self._transport is None: if self._close_info and len(self._close_info['reply_text']) > 0: raise ConnectionClosed("connection is closed...
def synchronous(self)
True if transport is synchronous or the connection has been forced into synchronous mode, False otherwise.
4.454195
2.943401
1.513282
''' Connect to a host and port. ''' # Clear the connect state immediately since we're no longer connected # at this point. self._connected = False # Only after the socket has connected do we clear this state; closed # must be False so that writes can be b...
def connect(self, host, port)
Connect to a host and port.
9.94875
9.838934
1.011161
''' Disconnect from the current host, but do not update the closed state. After the transport is disconnected, the closed state will be True if this is called after a protocol shutdown, or False if the disconnect was in error. TODO: do we really need closed vs. connected...
def disconnect(self)
Disconnect from the current host, but do not update the closed state. After the transport is disconnected, the closed state will be True if this is called after a protocol shutdown, or False if the disconnect was in error. TODO: do we really need closed vs. connected states? this only a...
8.125326
1.765702
4.601753
msg = 'unknown cause' self.logger.warning('transport to %s closed : %s' % (self._host, kwargs.get('msg', msg))) self._close_info = { 'reply_code': kwargs.get('reply_code', 0), 'reply_text': kwargs.get('msg', msg), 'class_id...
def transport_closed(self, **kwargs)
Called by Transports when they close unexpectedly, not as a result of Connection.disconnect(). TODO: document args
4.175374
4.115197
1.014623
'''Return the next possible channel id. Is a circular enumeration.''' self._channel_counter += 1 if self._channel_counter >= self._channel_max: self._channel_counter = 1 return self._channel_counter
def _next_channel_id(self)
Return the next possible channel id. Is a circular enumeration.
5.421177
2.502099
2.166652
if channel_id is None: # adjust for channel 0 if len(self._channels) - 1 >= self._channel_max: raise Connection.TooManyChannels( "%d channels already open, max %d", len(self._channels) - 1, self._channel...
def channel(self, channel_id=None, synchronous=False)
Fetch a Channel object identified by the numeric channel_id, or create that object if it doesn't already exist. If channel_id is not None but no channel exists for that id, will raise InvalidChannel. If there are already too many channels open, will raise TooManyChannels. If synchrono...
3.724746
3.681823
1.011658
''' Close this connection. ''' self._close_info = { 'reply_code': reply_code, 'reply_text': reply_text, 'class_id': class_id, 'method_id': method_id } if disconnect: self._closed = True self.disconnec...
def close(self, reply_code=0, reply_text='', class_id=0, method_id=0, disconnect=False)
Close this connection.
2.937835
2.871547
1.023084
''' Read frames from the transport and process them. Some transports may choose to do this in the background, in several threads, and so on. ''' # It's possible in a concurrent environment that our transport handle # has gone away, so handle that cleanly. # TODO: ...
def read_frames(self)
Read frames from the transport and process them. Some transports may choose to do this in the background, in several threads, and so on.
7.02347
6.380361
1.100795
''' Callback when protocol has been initialized on channel 0 and we're ready to send out frames to set up any channels that have been created. ''' # In the rare case (a bug) where this is called but send_frame thinks # they should be buffered, don't clobber. ...
def _flush_buffered_frames(self)
Callback when protocol has been initialized on channel 0 and we're ready to send out frames to set up any channels that have been created.
11.112757
4.243769
2.618606
''' Send a single frame. If there is no transport or we're not connected yet, append to the output buffer, else send immediately to the socket. This is called from within the MethodFrames. ''' if self._closed: if self._close_info and len(self._close_info['repl...
def send_frame(self, frame)
Send a single frame. If there is no transport or we're not connected yet, append to the output buffer, else send immediately to the socket. This is called from within the MethodFrames.
3.413217
2.480149
1.376214
''' Override the default dispatch since we don't need the rest of the stack. ''' if frame.type() == HeartbeatFrame.type(): self.send_heartbeat() elif frame.type() == MethodFrame.type(): if frame.class_id == 10: cb = self._method_ma...
def dispatch(self, frame)
Override the default dispatch since we don't need the rest of the stack.
3.522742
2.986824
1.179427
''' Send a heartbeat if needed. Tracks last heartbeat send time. ''' # Note that this does not take into account the time that we last # sent a frame. Hearbeats are so small the effect should be quite # limited. Also note that we're looking for something near to our ...
def send_heartbeat(self)
Send a heartbeat if needed. Tracks last heartbeat send time.
9.007919
7.490956
1.202506
'''Send the start_ok message.''' args = Writer() args.write_table(self.connection._properties) args.write_shortstr(self.connection._login_method) args.write_longstr(self.connection._login_response) args.write_shortstr(self.connection._locale) self.send_frame(Metho...
def _send_start_ok(self)
Send the start_ok message.
5.078632
5.11046
0.993772
''' Cleanup local data. ''' self._declare_cb = None self._delete_cb = None super(ExchangeClass, self)._cleanup()
def _cleanup(self)
Cleanup local data.
16.081564
9.383814
1.713756
nowait = nowait and self.allow_nowait() and not cb args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(exchange).\ write_shortstr(type).\ write_bits(passive, durable, False, False, nowait).\ write_table(argume...
def declare(self, exchange, type, passive=False, durable=False, nowait=True, arguments=None, ticket=None, cb=None)
Declare the exchange. exchange - The name of the exchange to declare type - One of
3.850659
4.91465
0.783506
''' Delete an exchange. ''' nowait = nowait and self.allow_nowait() and not cb args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(exchange).\ write_bits(if_unused, nowait) self.send_frame(MethodFrame(self.chan...
def delete(self, exchange, if_unused=False, nowait=True, ticket=None, cb=None)
Delete an exchange.
4.920982
4.776014
1.030353
'''Connect assuming a host and port tuple. :param tuple: A tuple containing host and port for a connection. :param klass: A implementation of socket.socket. :raises socket.gaierror: If no address can be resolved. :raises socket.error: If no connection can be made. ''' ...
def connect(self, (host, port), klass=socket.socket)
Connect assuming a host and port tuple. :param tuple: A tuple containing host and port for a connection. :param klass: A implementation of socket.socket. :raises socket.gaierror: If no address can be resolved. :raises socket.error: If no connection can be made.
3.329957
2.498748
1.33265
''' Read from the transport. If timeout>0, will only block for `timeout` seconds. ''' e = None if not hasattr(self, '_sock'): return None try: # Note that we ignore both None and 0, i.e. we either block with a # timeout or bloc...
def read(self, timeout=None)
Read from the transport. If timeout>0, will only block for `timeout` seconds.
4.59308
4.192784
1.095473
''' Buffer unused bytes from the input stream. ''' if not hasattr(self, '_sock'): return None # data will always be a byte array if len(self._buffer): self._buffer.extend(data) else: self._buffer = bytearray(data)
def buffer(self, data)
Buffer unused bytes from the input stream.
5.427904
4.427286
1.226012
''' Write some bytes to the transport. ''' if not hasattr(self, '_sock'): return None try: self._sock.sendall(data) if self.connection.debug > 1: self.connection.logger.debug( 'sent %d bytes to %s' % (len(d...
def write(self, data)
Write some bytes to the transport.
6.109616
5.854407
1.043593
''' Cleanup all the local data. ''' self._pending_consumers = None self._consumer_cb = None self._get_cb = None self._recover_cb = None self._cancel_cb = None self._return_listener = None super(BasicClass, self)._cleanup()
def _cleanup(self)
Cleanup all the local data.
8.455869
6.037729
1.400505
''' Set a callback for basic.return listening. Will be called with a single Message argument. The return_info attribute of the Message will have the following properties: 'channel': Channel instance 'reply_code': reply code (int) 'reply_text':...
def set_return_listener(self, cb)
Set a callback for basic.return listening. Will be called with a single Message argument. The return_info attribute of the Message will have the following properties: 'channel': Channel instance 'reply_code': reply code (int) 'reply_text': reply text ...
6.471955
1.668473
3.878968
''' Set QoS on this channel. ''' args = Writer() args.write_long(prefetch_size).\ write_short(prefetch_count).\ write_bit(is_global) self.send_frame(MethodFrame(self.channel_id, 60, 10, args)) self.channel.add_synchronous_cb(self._recv_qos...
def qos(self, prefetch_size=0, prefetch_count=0, is_global=False)
Set QoS on this channel.
6.420998
5.957142
1.077865
''' Start a queue consumer. If `cb` is supplied, will be called when broker confirms that consumer is registered. ''' nowait = nowait and self.allow_nowait() and not cb if nowait and consumer_tag == '': consumer_tag = self._generate_consumer_tag() ar...
def consume(self, queue, consumer, consumer_tag='', no_local=False, no_ack=True, exclusive=False, nowait=True, ticket=None, cb=None)
Start a queue consumer. If `cb` is supplied, will be called when broker confirms that consumer is registered.
4.454838
3.559598
1.2515
''' Cancel a consumer. Can choose to delete based on a consumer tag or the function which is consuming. If deleting by function, take care to only use a consumer once per channel. ''' if consumer: tag = self._lookup_consumer_tag_by_consumer(consumer) ...
def cancel(self, consumer_tag='', nowait=True, consumer=None, cb=None)
Cancel a consumer. Can choose to delete based on a consumer tag or the function which is consuming. If deleting by function, take care to only use a consumer once per channel.
5.592693
3.313572
1.687814
'''Look up consumer tag given its consumer function NOTE: this protected method may be called by derived classes :param callable consumer: consumer function :returns: matching consumer tag or None :rtype: str or None ''' for (tag, func) in self._consumer_cb.ite...
def _lookup_consumer_tag_by_consumer(self, consumer)
Look up consumer tag given its consumer function NOTE: this protected method may be called by derived classes :param callable consumer: consumer function :returns: matching consumer tag or None :rtype: str or None
6.581962
2.488221
2.645248
'''Purge consumer entry from this basic instance NOTE: this protected method may be called by derived classes :param str consumer_tag: ''' try: del self._consumer_cb[consumer_tag] except KeyError: self.logger.warning( 'no callback...
def _purge_consumer_by_tag(self, consumer_tag)
Purge consumer entry from this basic instance NOTE: this protected method may be called by derived classes :param str consumer_tag:
5.890861
2.983911
1.974208
''' publish a message. ''' args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(exchange).\ write_shortstr(routing_key).\ write_bits(mandatory, immediate) self.send_frame(MethodFrame(self.channel_id, 60, 40,...
def publish(self, msg, exchange, routing_key, mandatory=False, immediate=False, ticket=None)
publish a message.
4.218167
4.13621
1.019814
''' Return a failed message. Not named "return" because python interpreter can't deal with that. ''' args = Writer() args.write_short(reply_code).\ write_shortstr(reply_text).\ write_shortstr(exchange).\ write_shortstr(routing_key) ...
def return_msg(self, reply_code, reply_text, exchange, routing_key)
Return a failed message. Not named "return" because python interpreter can't deal with that.
5.573202
2.801154
1.98961
''' Handle basic.return method. If we have a complete message, will call the user's return listener callabck (if any). If there are not enough frames, will re-queue current frames and raise a FrameUnderflow NOTE: if the channel was in confirmation mode when the message was ...
def _recv_return(self, method_frame)
Handle basic.return method. If we have a complete message, will call the user's return listener callabck (if any). If there are not enough frames, will re-queue current frames and raise a FrameUnderflow NOTE: if the channel was in confirmation mode when the message was published, then t...
11.839987
2.580518
4.588222
''' Ask to fetch a single message from a queue. If a consumer is supplied, the consumer will be called with either a Message argument, or None if there is no message in queue. If a synchronous transport, Message or None is returned. ''' args = Writer() ar...
def get(self, queue, consumer=None, no_ack=True, ticket=None)
Ask to fetch a single message from a queue. If a consumer is supplied, the consumer will be called with either a Message argument, or None if there is no message in queue. If a synchronous transport, Message or None is returned.
6.921235
3.50443
1.974996
''' Handle either get_ok or get_empty. This is a hack because the synchronous callback stack is expecting one method to satisfy the expectation. To keep that loop as tight as possible, work within those constraints. Use of get is not recommended anyway. ''' if met...
def _recv_get_response(self, method_frame)
Handle either get_ok or get_empty. This is a hack because the synchronous callback stack is expecting one method to satisfy the expectation. To keep that loop as tight as possible, work within those constraints. Use of get is not recommended anyway.
9.405009
1.62799
5.77707
''' Acknowledge delivery of a message. If multiple=True, acknowledge up-to and including delivery_tag. ''' args = Writer() args.write_longlong(delivery_tag).\ write_bit(multiple) self.send_frame(MethodFrame(self.channel_id, 60, 80, args))
def ack(self, delivery_tag, multiple=False)
Acknowledge delivery of a message. If multiple=True, acknowledge up-to and including delivery_tag.
6.036528
4.19162
1.440142
''' Reject a message. ''' args = Writer() args.write_longlong(delivery_tag).\ write_bit(requeue) self.send_frame(MethodFrame(self.channel_id, 60, 90, args))
def reject(self, delivery_tag, requeue=False)
Reject a message.
6.304851
6.374498
0.989074
''' Redeliver all unacknowledged messages on this channel. This method is deprecated in favour of the synchronous recover/recover-ok ''' args = Writer() args.write_bit(requeue) self.send_frame(MethodFrame(self.channel_id, 60, 100, args))
def recover_async(self, requeue=False)
Redeliver all unacknowledged messages on this channel. This method is deprecated in favour of the synchronous recover/recover-ok
7.102159
4.064595
1.747323
''' Ask server to redeliver all unacknowledged messages. ''' args = Writer() args.write_bit(requeue) # The XML spec is incorrect; this method is always synchronous # http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-January/010738.html self._reco...
def recover(self, requeue=False, cb=None)
Ask server to redeliver all unacknowledged messages.
6.629932
6.200655
1.069231
''' Support method to read a Message from the current frame buffer. Will return a Message, or re-queue current frames and raise a FrameUnderflow. Takes an optional argument on whether to read the consumer tag so it can be used for both deliver and get-ok. ''' head...
def _read_msg(self, method_frame, with_consumer_tag=False, with_message_count=False)
Support method to read a Message from the current frame buffer. Will return a Message, or re-queue current frames and raise a FrameUnderflow. Takes an optional argument on whether to read the consumer tag so it can be used for both deliver and get-ok.
2.931603
1.779614
1.647325
''' Support method to read a returned (basic.return) Message from the current frame buffer. Will return a Message with return_info, or re-queue current frames and raise a FrameUnderflow. :returns: Message with the return_info attribute set, where return_info is a dict ...
def _read_returned_msg(self, method_frame)
Support method to read a returned (basic.return) Message from the current frame buffer. Will return a Message with return_info, or re-queue current frames and raise a FrameUnderflow. :returns: Message with the return_info attribute set, where return_info is a dict with the following p...
4.395488
1.731553
2.538466
''' Support method to reap header frame and body from current frame buffer. Used in processing of basic.return, basic.deliver, and basic.get_ok. Will return a pair (<header frame>, <body>), or re-queue current frames and raise a FrameUnderflow. :returns: pair (<header fr...
def _reap_msg_frames(self, method_frame)
Support method to reap header frame and body from current frame buffer. Used in processing of basic.return, basic.deliver, and basic.get_ok. Will return a pair (<header frame>, <body>), or re-queue current frames and raise a FrameUnderflow. :returns: pair (<header frame>, <body>) ...
5.355059
2.828643
1.893155
''' Publish a message. Caller can supply an optional callback which will be fired when the transaction is committed. Tries very hard to avoid closed and inactive channels, but a ChannelError or ConnectionError may still be raised. ''' user_cb = kwargs.pop('cb', No...
def publish(self, *args, **kwargs)
Publish a message. Caller can supply an optional callback which will be fired when the transaction is committed. Tries very hard to avoid closed and inactive channels, but a ChannelError or ConnectionError may still be raised.
5.327984
3.782934
1.408426
''' If there are any message in the queue, process one of them. ''' if len(self._queue): args, kwargs = self._queue.popleft() self.publish(*args, **kwargs)
def _process_queue(self)
If there are any message in the queue, process one of them.
5.9488
3.154197
1.885995
''' Fetch a channel from the pool. Will return a new one if necessary. If a channel in the free pool is closed, will remove it. Will return None if we hit the cap. Will clean up any channels that were published to but closed due to error. ''' while len(self._free_...
def _get_channel(self)
Fetch a channel from the pool. Will return a new one if necessary. If a channel in the free pool is closed, will remove it. Will return None if we hit the cap. Will clean up any channels that were published to but closed due to error.
6.921582
2.964341
2.334948
''' A generator which will create frames from a buffer given a max frame size. ''' size = frame_max - 8 # 8 bytes overhead for frame header and footer offset = 0 while True: payload = buf[offset:(offset + size)] if len(payload) == 0: ...
def create_frames(self, channel_id, buf, frame_max)
A generator which will create frames from a buffer given a max frame size.
4.740733
3.407645
1.391205
''' Write the frame into an existing buffer. ''' writer = Writer(buf) writer.write_octet(self.type()).\ write_short(self.channel_id).\ write_long(len(self._payload)).\ write(self._payload).\ write_octet(0xce)
def write_frame(self, buf)
Write the frame into an existing buffer.
6.803553
5.580836
1.219092
''' Connect assuming a host and port tuple. Implemented as non-blocking, and will close the transport if there's an error ''' self._host = "%s:%s" % (host, port) self._sock = EventSocket( read_cb=self._sock_read_cb, close_cb=self._sock_close_cb, ...
def connect(self, (host, port))
Connect assuming a host and port tuple. Implemented as non-blocking, and will close the transport if there's an error
3.873752
2.814014
1.376593
''' Read from the transport. If no data is available, should return None. The timeout is ignored as this returns only data that has already been buffered locally. ''' # NOTE: copying over this comment from Connection, because there is # knowledge captured here, ev...
def read(self, timeout=None)
Read from the transport. If no data is available, should return None. The timeout is ignored as this returns only data that has already been buffered locally.
11.479639
8.837406
1.298983
''' Disconnect from the transport. Typically socket.close(). This call is welcome to raise exceptions, which the Connection will catch. The transport is encouraged to allow for any pending writes to complete before closing the socket. ''' if not hasattr(self, '_s...
def disconnect(self)
Disconnect from the transport. Typically socket.close(). This call is welcome to raise exceptions, which the Connection will catch. The transport is encouraged to allow for any pending writes to complete before closing the socket.
11.234509
3.233162
3.474774
''' Parse a header frame for a channel given a Reader payload. ''' class_id = payload.read_short() weight = payload.read_short() size = payload.read_longlong() properties = {} # The AMQP spec is overly-complex when it comes to handling header # fr...
def parse(self, channel_id, payload)
Parse a header frame for a channel given a Reader payload.
6.437378
5.790168
1.111778
''' Write the frame into an existing buffer. ''' writer = Writer(buf) writer.write_octet(self.type()) writer.write_short(self.channel_id) # Track the position where we're going to write the total length # of the frame arguments. stream_args_len_po...
def write_frame(self, buf)
Write the frame into an existing buffer.
3.483538
3.390383
1.027476
''' Read one or more frames from an IO stream. Buffer must support file object interface. After reading, caller will need to check if there are bytes remaining in the stream. If there are, then that implies that there is one or more incomplete frames and more data needs...
def read_frames(cls, reader)
Read one or more frames from an IO stream. Buffer must support file object interface. After reading, caller will need to check if there are bytes remaining in the stream. If there are, then that implies that there is one or more incomplete frames and more data needs to be read. The po...
5.247185
1.868489
2.808251
''' Read a single frame from a Reader. Will return None if there is an incomplete frame in the stream. Raise MissingFooter if there's a problem reading the footer byte. ''' frame_type = reader.read_octet() channel_id = reader.read_short() size = reader.r...
def _read_frame(cls, reader)
Read a single frame from a Reader. Will return None if there is an incomplete frame in the stream. Raise MissingFooter if there's a problem reading the footer byte.
4.667657
3.28526
1.420788
''' Unbind an exchange from another. ''' nowait = nowait and self.allow_nowait() and not cb args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(exchange).\ write_shortstr(source).\ write_shortstr(routing_ke...
def unbind(self, exchange, source, routing_key='', nowait=True, arguments={}, ticket=None, cb=None)
Unbind an exchange from another.
3.804767
3.579444
1.062949
''' Cleanup all the local data. ''' self._ack_listener = None self._nack_listener = None self._broker_cancel_cb_map = None super(RabbitBasicClass, self)._cleanup()
def _cleanup(self)
Cleanup all the local data.
14.503791
9.34201
1.552534
''' Publish a message. Will return the id of the message if publisher confirmations are enabled, else will return 0. ''' if self.channel.confirm._enabled: self._msg_id += 1 super(RabbitBasicClass, self).publish(*args, **kwargs) return self._msg_id
def publish(self, *args, **kwargs)
Publish a message. Will return the id of the message if publisher confirmations are enabled, else will return 0.
8.646436
4.089672
2.114213
'''Receive an ack from the broker.''' if self._ack_listener: delivery_tag = method_frame.args.read_longlong() multiple = method_frame.args.read_bit() if multiple: while self._last_ack_id < delivery_tag: self._last_ack_id += 1 ...
def _recv_ack(self, method_frame)
Receive an ack from the broker.
2.940122
2.977216
0.987541
'''Send a nack to the broker.''' args = Writer() args.write_longlong(delivery_tag).\ write_bits(multiple, requeue) self.send_frame(MethodFrame(self.channel_id, 60, 120, args))
def nack(self, delivery_tag, multiple=False, requeue=False)
Send a nack to the broker.
6.550632
6.646092
0.985637
'''Receive a nack from the broker.''' if self._nack_listener: delivery_tag = method_frame.args.read_longlong() multiple, requeue = method_frame.args.read_bits(2) if multiple: while self._last_ack_id < delivery_tag: self._last_ack_id...
def _recv_nack(self, method_frame)
Receive a nack from the broker.
2.966125
2.965705
1.000142
'''Start a queue consumer. Accepts the following optional arg in addition to those of `BasicClass.consume()`: :param cancel_cb: a callable to be called when the broker cancels the consumer; e.g., when the consumer's queue is deleted. See www.rabbitmq.com/consumer-ca...
def consume(self, queue, consumer, consumer_tag='', no_local=False, no_ack=True, exclusive=False, nowait=True, ticket=None, cb=None, cancel_cb=None)
Start a queue consumer. Accepts the following optional arg in addition to those of `BasicClass.consume()`: :param cancel_cb: a callable to be called when the broker cancels the consumer; e.g., when the consumer's queue is deleted. See www.rabbitmq.com/consumer-cancel.html. ...
4.049529
2.131214
1.900105
''' Cancel a consumer. Can choose to delete based on a consumer tag or the function which is consuming. If deleting by function, take care to only use a consumer once per channel. ''' # Remove the consumer's broker-cancel callback entry if consumer: t...
def cancel(self, consumer_tag='', nowait=True, consumer=None, cb=None)
Cancel a consumer. Can choose to delete based on a consumer tag or the function which is consuming. If deleting by function, take care to only use a consumer once per channel.
6.652439
3.604068
1.845814
'''Handle Basic.Cancel from broker :param MethodFrame method_frame: Basic.Cancel method frame from broker ''' self.logger.warning("consumer cancelled by broker: %r", method_frame) consumer_tag = method_frame.args.read_shortstr() # NOTE: per RabbitMQ spec, no-wait is al...
def _recv_cancel(self, method_frame)
Handle Basic.Cancel from broker :param MethodFrame method_frame: Basic.Cancel method frame from broker
5.987456
5.332416
1.122841
''' Set this channel to use publisher confirmations. ''' nowait = nowait and self.allow_nowait() and not cb if not self._enabled: self._enabled = True self.channel.basic._msg_id = 0 self.channel.basic._last_ack_id = 0 args = Writer...
def select(self, nowait=True, cb=None)
Set this channel to use publisher confirmations.
6.145918
5.268094
1.16663
''' Close this channel. Routes to channel.close. ''' # In the off chance that we call this twice. A good example is if # there's an error in close listeners and so we're still inside a # single call to process_frames, which will try to close this channel # if the...
def close(self, reply_code=0, reply_text='', class_id=0, method_id=0)
Close this channel. Routes to channel.close.
9.634088
8.100328
1.189345
''' Helper for publishing a message using transactions. If 'cb' keyword arg is supplied, will be called when the transaction is committed. ''' cb = kwargs.pop('cb', None) self.tx.select() self.basic.publish(*args, **kwargs) self.tx.commit(cb=cb)
def publish_synchronous(self, *args, **kwargs)
Helper for publishing a message using transactions. If 'cb' keyword arg is supplied, will be called when the transaction is committed.
6.565114
2.620167
2.505609
''' Dispatch a method. ''' klass = self._class_map.get(method_frame.class_id) if klass: klass.dispatch(method_frame) else: raise Channel.InvalidClass( "class %d is not supported on channel %d", method_frame.class_id,...
def dispatch(self, method_frame)
Dispatch a method.
4.075304
3.867203
1.053812
''' Process the input buffer. ''' while len(self._frame_buffer): # It would make sense to call next_frame, but it's # technically faster to repeat the code here. frame = self._frame_buffer.popleft() if self._emergency_close_pending: ...
def process_frames(self)
Process the input buffer.
7.766389
7.483155
1.03785
''' Queue a frame for sending. Will send immediately if there are no pending synchronous transactions on this connection. ''' if self.closed: if self.close_info and len(self.close_info['reply_text']) > 0: raise ChannelClosed( "chan...
def send_frame(self, frame)
Queue a frame for sending. Will send immediately if there are no pending synchronous transactions on this connection.
7.94731
6.613481
1.201683
''' Add an expectation of a callback to release a synchronous transaction. ''' if self.connection.synchronous or self._synchronous: wrapper = SyncWrapper(cb) self._pending_events.append(wrapper) while wrapper._read: # Don't check that t...
def add_synchronous_cb(self, cb)
Add an expectation of a callback to release a synchronous transaction.
6.417976
5.471066
1.173076
''' If the callback is the current expected callback, will clear it off the stack. Else will raise in exception if there's an expectation but this doesn't satisfy it. ''' if len(self._pending_events): ev = self._pending_events[0] # We can't have ...
def clear_synchronous_cb(self, cb)
If the callback is the current expected callback, will clear it off the stack. Else will raise in exception if there's an expectation but this doesn't satisfy it.
9.271934
6.033352
1.53678
''' Send pending frames that are in the event queue. ''' while len(self._pending_events) and \ isinstance(self._pending_events[0], Frame): self._connection.send_frame(self._pending_events.popleft())
def _flush_pending_events(self)
Send pending frames that are in the event queue.
4.965882
2.846639
1.744472
''' "Private" callback from the ChannelClass when a channel is closed. Only called after broker initiated close, or we receive a close_ok. Caller has the option to send a final frame, to be used to bypass any synchronous or otherwise-pending frames so that the channel can be ...
def _closed_cb(self, final_frame=None)
"Private" callback from the ChannelClass when a channel is closed. Only called after broker initiated close, or we receive a close_ok. Caller has the option to send a final frame, to be used to bypass any synchronous or otherwise-pending frames so that the channel can be cleanly closed.
9.828916
4.255165
2.309879
''' Connect using a host,port tuple ''' super(GeventTransport, self).connect((host, port), klass=socket.socket)
def connect(self, (host, port))
Connect using a host,port tuple
13.090016
8.631221
1.516589
''' Read from the transport. If no data is available, should return None. If timeout>0, will only block for `timeout` seconds. ''' # If currently locked, another greenlet is trying to read, so yield # control and then return none. Required if a Connection is configured ...
def read(self, timeout=None)
Read from the transport. If no data is available, should return None. If timeout>0, will only block for `timeout` seconds.
9.107909
7.422815
1.227016
''' Buffer unused bytes from the input stream. ''' self._read_lock.acquire() try: return super(GeventTransport, self).buffer(data) finally: self._read_lock.release()
def buffer(self, data)
Buffer unused bytes from the input stream.
4.921143
3.799305
1.295274
''' Write some bytes to the transport. ''' # MUST use a lock here else gevent could raise an exception if 2 # greenlets try to write at the same time. I was hoping that # sendall() would do that blocking for me, but I guess not. May # require an eventsocket-like b...
def write(self, data)
Write some bytes to the transport.
9.686846
8.898329
1.088614
''' Process a set of channels by calling Channel.process_frames() on each. Some transports may choose to do this in unique ways, such as through a pool of threads. The default implementation will simply iterate over them and call process_frames() on each. ''' ...
def process_channels(self, channels)
Process a set of channels by calling Channel.process_frames() on each. Some transports may choose to do this in unique ways, such as through a pool of threads. The default implementation will simply iterate over them and call process_frames() on each.
8.295458
1.978615
4.192558
''' Dispatch a method for this protocol. ''' method = self.dispatch_map.get(method_frame.method_id) if method: callback = self.channel.clear_synchronous_cb(method) callback(method_frame) else: raise self.InvalidMethod( "...
def dispatch(self, method_frame)
Dispatch a method for this protocol.
4.859916
4.203024
1.15629
''' Simple seek. Follows standard interface. ''' if whence == 0: self._pos = self._start_pos + offset elif whence == 1: self._pos += offset else: self._pos = (self._end_pos - 1) + offset
def seek(self, offset, whence=0)
Simple seek. Follows standard interface.
3.78429
2.621255
1.443694
''' Raise BufferUnderflow if there's not enough bytes to satisfy the request. ''' if self._pos + n > self._end_pos: raise self.BufferUnderflow()
def _check_underflow(self, n)
Raise BufferUnderflow if there's not enough bytes to satisfy the request.
6.738605
3.320427
2.029439
''' Get a copy of the buffer that this is reading from. Returns a buffer object ''' return buffer(self._input, self._start_pos, (self._end_pos - self._start_pos))
def buffer(self)
Get a copy of the buffer that this is reading from. Returns a buffer object
9.470531
3.974603
2.382761
self._check_underflow(n) rval = self._input[self._pos:self._pos + n] self._pos += n return rval
def read(self, n)
Read n bytes. Will raise BufferUnderflow if there's not enough bytes in the buffer.
4.141732
3.838335
1.079044
# Perform a faster check on underflow if self._pos >= self._end_pos: raise self.BufferUnderflow() result = ord(self._input[self._pos]) & 1 self._pos += 1 return result
def read_bit(self)
Read a single boolean value, returns 0 or 1. Convience for single bit fields. Will raise BufferUnderflow if there's not enough bytes in the buffer.
6.330437
5.71573
1.107546
''' Read several bits packed into the same field. Will return as a list. The bit field itself is little-endian, though the order of the returned array looks big-endian for ease of decomposition. Reader('\x02').read_bits(2) -> [False,True] Reader('\x08').read_bits(2) -> ...
def read_bits(self, num)
Read several bits packed into the same field. Will return as a list. The bit field itself is little-endian, though the order of the returned array looks big-endian for ease of decomposition. Reader('\x02').read_bits(2) -> [False,True] Reader('\x08').read_bits(2) -> [False,Tr...
6.207512
2.000917
3.102333
# Technically should look at unpacker.size, but skipping that is way # faster and this method is the most-called of the readers if self._pos >= self._end_pos: raise self.BufferUnderflow() rval = unpacker(self._input, self._pos)[0] self._pos += size re...
def read_octet(self, unpacker=Struct('B').unpack_from, size=Struct('B').size)
Read one byte, return as an integer Will raise BufferUnderflow if there's not enough bytes in the buffer. Will raise struct.error if the data is malformed
8.13466
8.173656
0.995229
self._check_underflow(size) rval = unpacker(self._input, self._pos)[0] self._pos += size return rval
def read_short(self, unpacker=Struct('>H').unpack_from, size=Struct('>H').size)
Read an unsigned 16-bit integer Will raise BufferUnderflow if there's not enough bytes in the buffer. Will raise struct.error if the data is malformed
4.284645
4.878577
0.878257
# Only need to check underflow on the table once tlen = self.read_long() self._check_underflow(tlen) end_pos = self._pos + tlen result = {} while self._pos < end_pos: name = self._field_shortstr() result[name] = self._read_field() ...
def read_table(self)
Read an AMQP table, and return as a Python dictionary. Will raise BufferUnderflow if there's not enough bytes in the buffer. Will raise UnicodeDecodeError if the text is mal-formed. Will raise struct.error if the data is malformed
5.874676
5.226996
1.12391
''' Read a single byte for field type, then read the value. ''' ftype = self._input[self._pos] self._pos += 1 reader = self.field_type_map.get(ftype) if reader: return reader(self) raise Reader.FieldError('Unknown field type %s', ftype)
def _read_field(self)
Read a single byte for field type, then read the value.
6.133451
3.671945
1.670355
''' Open the channel for communication. ''' args = Writer() args.write_shortstr('') self.send_frame(MethodFrame(self.channel_id, 20, 10, args)) self.channel.add_synchronous_cb(self._recv_open_ok)
def open(self)
Open the channel for communication.
9.17525
7.276706
1.260907
''' Send a flow control command. ''' args = Writer() args.write_bit(active) self.send_frame(MethodFrame(self.channel_id, 20, 20, args)) self.channel.add_synchronous_cb(self._recv_flow_ok)
def _send_flow(self, active)
Send a flow control command.
7.453441
5.917195
1.259624
''' Receive a flow control command from the broker ''' self.channel._active = method_frame.args.read_bit() args = Writer() args.write_bit(self.channel.active) self.send_frame(MethodFrame(self.channel_id, 20, 21, args)) if self._flow_control_cb is not Non...
def _recv_flow(self, method_frame)
Receive a flow control command from the broker
6.258631
5.307616
1.179179
''' Receive a flow control ack from the broker. ''' self.channel._active = method_frame.args.read_bit() if self._flow_control_cb is not None: self._flow_control_cb()
def _recv_flow_ok(self, method_frame)
Receive a flow control ack from the broker.
9.443575
6.917616
1.365149
''' Close this channel. Caller has the option of specifying the reason for closure and the class and method ids of the current frame in which an error occurred. If in the event of an exception, the channel will be marked as immediately closed. If channel is already closed, cal...
def close(self, reply_code=0, reply_text='', class_id=0, method_id=0)
Close this channel. Caller has the option of specifying the reason for closure and the class and method ids of the current frame in which an error occurred. If in the event of an exception, the channel will be marked as immediately closed. If channel is already closed, call is ignored...
4.908768
3.377535
1.453358
''' Receive a close command from the broker. ''' self.channel._close_info = { 'reply_code': method_frame.args.read_short(), 'reply_text': method_frame.args.read_shortstr(), 'class_id': method_frame.args.read_short(), 'method_id': method_fra...
def _recv_close(self, method_frame)
Receive a close command from the broker.
3.412823
2.976516
1.146583
''' Receive a close ack from the broker. ''' self.channel._closed = True self.channel._closed_cb()
def _recv_close_ok(self, method_frame)
Receive a close ack from the broker.
10.431999
5.806342
1.796656
''' Cleanup all the local data. ''' self._declare_cb = None self._bind_cb = None self._unbind_cb = None self._delete_cb = None self._purge_cb = None super(QueueClass, self)._cleanup()
def _cleanup(self)
Cleanup all the local data.
6.60109
4.518812
1.460802
''' bind to a queue. ''' nowait = nowait and self.allow_nowait() and not cb args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(queue).\ write_shortstr(exchange).\ write_shortstr(routing_key).\ ...
def bind(self, queue, exchange, routing_key='', nowait=True, arguments={}, ticket=None, cb=None)
bind to a queue.
3.787053
3.704706
1.022228
''' Unbind a queue from an exchange. This is always synchronous. ''' args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(queue).\ write_shortstr(exchange).\ write_shortstr(routing_key).\ write_table(arg...
def unbind(self, queue, exchange, routing_key='', arguments={}, ticket=None, cb=None)
Unbind a queue from an exchange. This is always synchronous.
4.163915
3.501419
1.189208
''' Purge all messages in a queue. ''' nowait = nowait and self.allow_nowait() and not cb args = Writer() args.write_short(ticket or self.default_ticket).\ write_shortstr(queue).\ write_bit(nowait) self.send_frame(MethodFrame(self.channel_...
def purge(self, queue, nowait=True, ticket=None, cb=None)
Purge all messages in a queue.
5.403135
5.431325
0.99481
''' Write multiple bits in a single byte field. The bits will be written in little-endian order, but should be supplied in big endian order. Will raise ValueError when more than 8 arguments are supplied. write_bits(True, False) => 0x02 ''' # Would be nice to make...
def write_bits(self, *args)
Write multiple bits in a single byte field. The bits will be written in little-endian order, but should be supplied in big endian order. Will raise ValueError when more than 8 arguments are supplied. write_bits(True, False) => 0x02
6.64763
3.016879
2.203479
''' Write a single bit. Convenience method for single bit args. ''' self._output_buffer.append(pack(True if b else False)) return self
def write_bit(self, b, pack=Struct('B').pack)
Write a single bit. Convenience method for single bit args.
11.708279
4.494821
2.604838