From ee1cd74e805176e06d4a91f3f82c0eb474df1875 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Tue, 10 Jan 2017 06:05:25 +0100 Subject: [PATCH] memoryviews --- coolamqp/attaches/consumer.py | 4 +++- coolamqp/framing/field_table.py | 2 ++ tests/test_clustering/test_a.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/coolamqp/attaches/consumer.py b/coolamqp/attaches/consumer.py index 6043072..ef275e9 100644 --- a/coolamqp/attaches/consumer.py +++ b/coolamqp/attaches/consumer.py @@ -62,7 +62,9 @@ class Consumer(Channeler): SECOND declaration, ie. it will retry ad infinitum :type fail_on_first_time_resource_locked: bool :param fucking_memoryviews: if you set that to True, bodies of your ReceivedMessages will be iterables - of memoryviews, instead of bytes. Fast as fuck :/ + of memoryviews, instead of bytes. + AT LEAST YOU WILL BE FAST AS FUUUUCK + :type fucking_memoryviews: bool """ super(Consumer, self).__init__() diff --git a/coolamqp/framing/field_table.py b/coolamqp/framing/field_table.py index db25625..ffc5888 100644 --- a/coolamqp/framing/field_table.py +++ b/coolamqp/framing/field_table.py @@ -89,6 +89,8 @@ def enframe_field_value(buf, fv): def deframe_field_value(buf, offset): # -> (value, type), bytes_consumed start_offset = offset field_type = buf[offset] + if six.PY3: + field_type = bytes([field_type]) #todo slow offset += 1 if field_type not in FIELD_TYPES.keys(): diff --git a/tests/test_clustering/test_a.py b/tests/test_clustering/test_a.py index f152f09..19d15cf 100644 --- a/tests/test_clustering/test_a.py +++ b/tests/test_clustering/test_a.py @@ -63,4 +63,20 @@ class TestA(unittest.TestCase): self.assertTrue(P['q']) + def test_send_recv_nonzerolen_fuckingmemoryviews(self): + + P = {'q': False} + + def ok(e): + self.assertIsInstance(e, ReceivedMessage) + self.assertIsInstance(e.body[0], memoryview) + P['q'] = True + + con, fut = self.c.consume(Queue(u'hello', exclusive=True), on_message=ok, no_ack=True, fucking_memoryviews=True) + fut.result() + self.c.publish(Message(b'hello'), routing_key=u'hello', tx=True).result() + + time.sleep(1) + + self.assertTrue(P['q']) -- GitLab