diff --git a/.codeclimate.yml b/.codeclimate.yml index 249d03d1eebe265a1a2e3ea2019fc67abcaadf9d..5c6e916b0e52a4cc22177dd925b536243506da9d 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -16,6 +16,7 @@ engines: exclude_paths: - examples/** - tests/** +- coolamqp/framing/definitions.py ratings: paths: - coolamqp/** diff --git a/coolamqp/attaches/publisher.py b/coolamqp/attaches/publisher.py index 5266e2ec09a820145265cffffce133d62f9ff28c..b5fa4df53b7a34d03023e7dc696f0aacb30ce0c8 100644 --- a/coolamqp/attaches/publisher.py +++ b/coolamqp/attaches/publisher.py @@ -13,6 +13,7 @@ from __future__ import absolute_import, division, print_function import collections import logging import struct +import six import warnings from coolamqp.framing.definitions import ChannelOpenOk, BasicPublish, Basic, BasicAck @@ -114,11 +115,19 @@ class Publisher(Channeler, Synchronized): # Break down large bodies bodies = [] + if six.PY3: # memoryview + buffer = memoryview + body = buffer(message.body) max_body_size = self.connection.frame_max - AMQPBodyFrame.FRAME_SIZE_WITHOUT_PAYLOAD while len(body) > 0: - bodies.append(buffer(body, 0, max_body_size)) - body = buffer(body, max_body_size) + if six.PY3: + bodies.append(body[:max_body_size]) + body = body[max_body_size:] + else: + bodies.append(buffer(body, 0, max_body_size)) + body = buffer(body, max_body_size) + self.connection.send([ AMQPMethodFrame(self.channel_id, BasicPublish(exchange_name, routing_key, False, False)), diff --git a/coolamqp/uplink/connection/recv_framer.py b/coolamqp/uplink/connection/recv_framer.py index 1075f52066130fc8c87982e2ef54a0d048546047..7caf9d64168061f743c22bd9df758924fdcdb5da 100644 --- a/coolamqp/uplink/connection/recv_framer.py +++ b/coolamqp/uplink/connection/recv_framer.py @@ -55,6 +55,8 @@ class ReceivingFramer(object): :param data: received data """ self.total_data_len += len(data) + if six.PY3: + buffer = memoryview self.chunks.append(buffer(data)) while self._statemachine(): @@ -65,8 +67,12 @@ class ReceivingFramer(object): if up_to >= len(self.chunks[0]): q = self.chunks.popleft() else: - q = buffer(self.chunks[0], 0, up_to) - self.chunks[0] = buffer(self.chunks[0], up_to) + if six.PY3: + q = self.chunks[0][:up_to] + self.chunks[0] = self.chunks[0][up_to:] + else: + q = buffer(self.chunks[0], 0, up_to) + self.chunks[0] = buffer(self.chunks[0], up_to) self.total_data_len -= len(q) return q diff --git a/coolamqp/uplink/listener/socket.py b/coolamqp/uplink/listener/socket.py index e2fd2a8b83e90556cb4c84e49111dca827f828e3..8fcc0bc77f8ead4cb642e2cc81471a51adceec30 100644 --- a/coolamqp/uplink/listener/socket.py +++ b/coolamqp/uplink/listener/socket.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function import collections import socket +import six class SocketFailed(IOError): @@ -125,7 +126,10 @@ class BaseSocket(object): if sent < len(self.data_to_send[0]): # Not everything could be sent - self.data_to_send[0] = buffer(self.data_to_send[0], sent) + if six.PY3: + self.data_to_send[0] = self.data_to_send[0][sent:] + else: + self.data_to_send[0] = buffer(self.data_to_send[0], sent) return False else: # Looks like everything has been sent diff --git a/tests/test_framing/test_definitions/test_frames.py b/tests/test_framing/test_definitions/test_frames.py index 8f57d0aed68b88028561099b546b5f23adfd5281..bb1f6e55e70c176f94a7f99fab52df754976cfdb 100644 --- a/tests/test_framing/test_definitions/test_frames.py +++ b/tests/test_framing/test_definitions/test_frames.py @@ -3,10 +3,14 @@ from __future__ import absolute_import, division, print_function import unittest import io import struct +import six from coolamqp.framing.frames import AMQPHeaderFrame from coolamqp.framing.definitions import BasicContentPropertyList, FRAME_HEADER, FRAME_END, ConnectionStartOk +if six.PY3: + buffer = memoryview + class TestShitSerializesRight(unittest.TestCase): def test_unser_header_frame(self): diff --git a/tests/test_framing/test_field_table.py b/tests/test_framing/test_field_table.py index 0f3f7ccbb82889b6f48322f10bda69aaa916a499..1ffecd2fa3dbae43013d0ca3c2a5d6a5c63f9e89 100644 --- a/tests/test_framing/test_field_table.py +++ b/tests/test_framing/test_field_table.py @@ -3,11 +3,15 @@ from __future__ import absolute_import, division, print_function import unittest import struct import io +import six from coolamqp.framing.field_table import enframe_table, deframe_table, frame_table_size, \ enframe_field_value, deframe_field_value, frame_field_value_size +if six.PY3: + buffer = memoryview + class TestFramingTables(unittest.TestCase): def test_frame_unframe_table(self):