diff --git a/coolamqp/attaches/publisher.py b/coolamqp/attaches/publisher.py index b5fa4df53b7a34d03023e7dc696f0aacb30ce0c8..b8e3136c6fa5e8dfae6894931b46442505010fc0 100644 --- a/coolamqp/attaches/publisher.py +++ b/coolamqp/attaches/publisher.py @@ -115,18 +115,11 @@ class Publisher(Channeler, Synchronized): # Break down large bodies bodies = [] - if six.PY3: # memoryview - buffer = memoryview - - body = buffer(message.body) + body = memoryview(message.body) max_body_size = self.connection.frame_max - AMQPBodyFrame.FRAME_SIZE_WITHOUT_PAYLOAD while len(body) > 0: - 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) + bodies.append(body[:max_body_size]) + body = body[max_body_size:] self.connection.send([ diff --git a/coolamqp/framing/compilation/compile_definitions.py b/coolamqp/framing/compilation/compile_definitions.py index ec0022e019e19b7d7dddef07abb0773b4b16a95c..76558ac5b42fd6631eabe70424a39136a511810b 100644 --- a/coolamqp/framing/compilation/compile_definitions.py +++ b/coolamqp/framing/compilation/compile_definitions.py @@ -40,6 +40,15 @@ See coolamqp.uplink.framing.compilation for the tool AMQP is copyright (c) 2016 OASIS CoolAMQP is copyright (c) 2016 DMS Serwis s.c. + + +########################################### +# IMPORTANT NOTE +# Type of field may depend on the origin of packet. +# strings will be memoryviews if we received the packet +# while they may be bytes if we created it +# +# this has some use - speed :D """ import struct, collections, warnings, logging, six @@ -415,6 +424,7 @@ Field = collections.namedtuple('Field', ('name', 'type', 'basic_type', 'reserved ''') line(get_from_buffer(method.fields, '', 2, remark=(method.name == 'deliver'))) + line(" return %s(%s)", full_class_name, u', '.join(format_field_name(field.name) for field in method.fields if not field.reserved)) diff --git a/coolamqp/framing/definitions.py b/coolamqp/framing/definitions.py index 83251c5b6541bb2b74b99ee088a19f4f696e7c08..55b348e4deb5f46de016821baa469db1d5587492 100644 --- a/coolamqp/framing/definitions.py +++ b/coolamqp/framing/definitions.py @@ -8,6 +8,15 @@ See coolamqp.uplink.framing.compilation for the tool AMQP is copyright (c) 2016 OASIS CoolAMQP is copyright (c) 2016 DMS Serwis s.c. + + +########################################### +# IMPORTANT NOTE +# Type of field may depend on the origin of packet. +# strings will be memoryviews if we received the packet +# while they may be bytes if we created it +# +# this has some use - speed :D """ import struct, collections, warnings, logging, six @@ -2369,7 +2378,7 @@ class BasicContentPropertyList(AMQPContentPropertyList): pfl = 2 while ord(buf[offset + pfl - 1]) & 1: pfl += 2 - zpf = BasicContentPropertyList.zero_property_flags(buf[offset:offset+pfl]) + zpf = BasicContentPropertyList.zero_property_flags(buf[offset:offset+pfl]).tobytes() if zpf in BasicContentPropertyList.PARTICULAR_CLASSES: return BasicContentPropertyList.PARTICULAR_CLASSES[zpf].from_buffer(buf, offset) else: diff --git a/coolamqp/framing/field_table.py b/coolamqp/framing/field_table.py index b53faa44c86b51039fb799b337a2694a2c29379c..db2562578a2f24f8f21bbd5fbf5f5c89ca29af6f 100644 --- a/coolamqp/framing/field_table.py +++ b/coolamqp/framing/field_table.py @@ -8,6 +8,8 @@ An array is of form [field-value1, field-value2, ...] A table is of form ( (name1::bytes, fv1), (name2::bytes, fv2), ...) + +NOTE: it's not buffers, it's memoryview all along """ from __future__ import absolute_import, division, print_function import struct @@ -31,7 +33,7 @@ def deframe_decimal(buf, offset): def deframe_shortstr(buf, offset): # -> value, bytes_eaten ln, = struct.unpack_from('!B', buf, offset) - return buf[offset+1:offset+1+ln], 1+ln + return buf[offset+1:offset+1+ln].tobytes(), 1+ln def enframe_shortstr(buf, value): @@ -41,7 +43,7 @@ def enframe_shortstr(buf, value): def deframe_longstr(buf, offset): # -> value, bytes_eaten ln, = struct.unpack_from('!I', buf, offset) - return buf[offset+4:offset+4+ln], 4 + ln + return buf[offset+4:offset+4+ln].tobytes(), 4 + ln def enframe_longstr(buf, value): diff --git a/coolamqp/uplink/connection/recv_framer.py b/coolamqp/uplink/connection/recv_framer.py index 7caf9d64168061f743c22bd9df758924fdcdb5da..4e809557bd6ac5fa0df2a9e8d99f2c7dab7a0dad 100644 --- a/coolamqp/uplink/connection/recv_framer.py +++ b/coolamqp/uplink/connection/recv_framer.py @@ -55,9 +55,7 @@ class ReceivingFramer(object): :param data: received data """ self.total_data_len += len(data) - if six.PY3: - buffer = memoryview - self.chunks.append(buffer(data)) + self.chunks.append(memoryview(data)) while self._statemachine(): pass @@ -67,14 +65,11 @@ class ReceivingFramer(object): if up_to >= len(self.chunks[0]): q = self.chunks.popleft() else: - 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) + q = self.chunks[0][:up_to] + self.chunks[0] = self.chunks[0][up_to:] self.total_data_len -= len(q) + print(repr(q)) return q def _statemachine(self): @@ -91,7 +86,7 @@ class ReceivingFramer(object): elif (self.frame_type == FRAME_HEARTBEAT) and (self.total_data_len >= AMQPHeartbeatFrame.LENGTH-1): data = b'' while len(data) < AMQPHeartbeatFrame.LENGTH-1: - data = data + six.binary_type(self._extract(AMQPHeartbeatFrame.LENGTH-1 - len(data))) + data = data + self._extract(AMQPHeartbeatFrame.LENGTH-1 - len(data)).tobytes() if data != AMQPHeartbeatFrame.DATA[1:]: # Invalid heartbeat frame! @@ -106,9 +101,9 @@ class ReceivingFramer(object): elif (self.frame_type != FRAME_HEARTBEAT) and (self.frame_type is not None) and (self.frame_size is None) and (self.total_data_len > 6): hdr = b'' while len(hdr) < 6: - hdr = hdr + six.binary_type(self._extract(6 - len(hdr))) + hdr = hdr + self._extract(6 - len(hdr)).tobytes() - self.frame_channel, self.frame_size = struct.unpack('!HI', hdr) + self.frame_channel, self.frame_size = struct.unpack('!HI',hdr) return True diff --git a/coolamqp/uplink/handshake.py b/coolamqp/uplink/handshake.py index 18edb52b54751c4f08f43783b7f138b712d4aea6..adcb938b9c415b20f52eed8c0153e216eea9a4b8 100644 --- a/coolamqp/uplink/handshake.py +++ b/coolamqp/uplink/handshake.py @@ -66,8 +66,8 @@ class Handshaker(object): def on_connection_start(self, payload): - sasl_mechanisms = payload.mechanisms.split(b' ') - locale_supported = payload.locales.split(b' ') + sasl_mechanisms = payload.mechanisms.tobytes().split(b' ') + locale_supported = payload.locales.tobytes().split(b' ') # Select a mechanism if b'PLAIN' not in sasl_mechanisms: diff --git a/coolamqp/uplink/listener/socket.py b/coolamqp/uplink/listener/socket.py index 8fcc0bc77f8ead4cb642e2cc81471a51adceec30..9684243ab9ceeae7d4a35a20ed7f43f7219f055d 100644 --- a/coolamqp/uplink/listener/socket.py +++ b/coolamqp/uplink/listener/socket.py @@ -126,10 +126,7 @@ class BaseSocket(object): if sent < len(self.data_to_send[0]): # Not everything could be 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) + self.data_to_send[0] = 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 bb1f6e55e70c176f94a7f99fab52df754976cfdb..295771cc557da05e6a24b2bc56aa86141be848dc 100644 --- a/tests/test_framing/test_definitions/test_frames.py +++ b/tests/test_framing/test_definitions/test_frames.py @@ -8,9 +8,6 @@ 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): @@ -18,7 +15,7 @@ class TestShitSerializesRight(unittest.TestCase): b'\x00\x00\x00\x00\x00\x00\x00\x0A' + \ b'\xC0\x00\x0Atext/plain\x04utf8' - hf = AMQPHeaderFrame.unserialize(0, buffer(s)) + hf = AMQPHeaderFrame.unserialize(0, memoryview(s)) self.assertEquals(hf.class_id, 60) self.assertEquals(hf.weight, 0) diff --git a/tests/test_framing/test_field_table.py b/tests/test_framing/test_field_table.py index 1ffecd2fa3dbae43013d0ca3c2a5d6a5c63f9e89..af5082fa8b0607d873017fa3a5847b69995971dd 100644 --- a/tests/test_framing/test_field_table.py +++ b/tests/test_framing/test_field_table.py @@ -28,7 +28,7 @@ class TestFramingTables(unittest.TestCase): self.assertEquals(buf, struct.pack('!I', 10) + b'\x05fields\x02yo') - tab, delta = deframe_table(buffer(buf), 0) + tab, delta = deframe_table(memoryview(buf), 0) self.assertEquals(len(tab), 1) self.assertEquals(delta, 14) @@ -43,7 +43,7 @@ class TestFramingTables(unittest.TestCase): buf = buf.getvalue() self.assertEquals(b's\x02yo', buf) - fv, delta = deframe_field_value(buffer(buf), 0) + fv, delta = deframe_field_value(memoryview(buf), 0) self.assertEquals(fv, (b'yo', b's')) self.assertEquals(delta, 4)