Exemplo n.º 1
0
 def handle_read(self):
     # we cant parse full buffer in one call because if many data in buffer then we will be run this cycle by buffer while buffer became empty
     # but in case Basic.Ack we need to write response immediatly after get frame,
     # so we read data, but don't remove it from socket buffer for getting read events again and then all data in app buffer is parser
     #  remove data from socket buffer
     payload_size, frame, self.buffer_in.frame_bytes = amqp_spec.decode_frame(self.buffer_in.frame_bytes)
     if not frame:
         self.buffer_in.frame_bytes = self.socket.recv(4096, socket.MSG_PEEK)
         if not self.buffer_in.frame_bytes:
             self.stop()
         payload_size, frame, self.buffer_in.frame_bytes = amqp_spec.decode_frame(self.buffer_in.frame_bytes)
     if frame:
         self.buffer_in.parsed_data_size += (payload_size + 8)
         log.debug('IN {}: {}'.format(self.socket.fileno(), frame))
         if self.expected_response_frames and not issubclass(type(frame), tuple(self.expected_response_frames)):
             log.error('Unexpected frame type: %s', str(frame))
             self.stop()
         else:
             self.expected_response_frames = []
         response = self.method_handler(frame)
         _, next_frame, _ = amqp_spec.decode_frame(self.buffer_in.frame_bytes)
         if not next_frame:
             # "frame" was last frame in buffer_in so remove already parsed data, do second read without flag
             self.socket.recv(self.buffer_in.parsed_data_size)
             self.buffer_in.clear()
         if response:
             # TODO why this try here?
             try:
                 self.app_gen.send(response)
             except StopIteration:
                 pass
Exemplo n.º 2
0
 def test_connection_startok(self):
     start_ok = amqp_spec.Connection.StartOk(
         client_properties={'tratata': 121}, mechanisms='PLAIN', credential=['user', 'password'], locale='en_US',  channel_number=123)
     assert amqp_spec.decode_frame(start_ok.encoded) == (len(start_ok) - 8, start_ok, b'')
Exemplo n.º 3
0
 def test_connection_secure(self):
     secure = amqp_spec.Connection.Secure(challenge='tratatata', channel_number=124)
     assert amqp_spec.decode_frame(secure.encoded) == (len(secure) - 8, secure, b'')
Exemplo n.º 4
0
 def test_connection_start(self):
     s = amqp_spec.Connection.Start(version_major=3, version_minor=2, server_properties={'tratata': 121}, mechanisms='PLAIN', locale='en_US', channel_number=123)
     assert amqp_spec.decode_frame(s.encoded) == (len(s) - 8, s, b'')
Exemplo n.º 5
0
 def test_content(self):
     content = amqp_spec.Content('sdgsgagasgd')
     assert amqp_spec.decode_frame(content.encoded) == (len(content) - 8, content, b'')
     content = amqp_spec.Content(b'sdgsgagasgd')
     assert amqp_spec.decode_frame(content.encoded) == (len(content) - 8, content, b'')
Exemplo n.º 6
0
 def test_content_header(self):
     c_header = amqp_spec.Header(class_id=40, weight=15, body_size=1536136,
                                 header_properties={'content­encoding': 'identity', 'user­id': 'tratata', 'delivery­mode': 111}, channel_number=14)
     assert amqp_spec.decode_frame(c_header.encoded) == (len(c_header) - 8, c_header, b'')
Exemplo n.º 7
0
 def test_heartbeat(self):
     heartbeat = amqp_spec.Heartbeat()
     assert amqp_spec.decode_frame(heartbeat.encoded) == (len(heartbeat) - 8, heartbeat, b'')
Exemplo n.º 8
0
 def test_protocol_header(self):
     p_header = amqp_spec.ProtocolHeader('A', 'M', 'Q', 'P', 0, 0, 9, 1)
     assert amqp_spec.decode_frame(p_header.encoded) == (len(p_header) - 8, p_header, b'')