From 272da80bc4cff5557ab365b40073939046b1a785 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Tue, 10 Jan 2017 06:22:02 +0100 Subject: [PATCH] py3 --- coolamqp/framing/definitions.py | 4 +++- coolamqp/framing/field_table.py | 8 ++++---- coolamqp/objects.py | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/coolamqp/framing/definitions.py b/coolamqp/framing/definitions.py index 8a9e7d8..d76defe 100644 --- a/coolamqp/framing/definitions.py +++ b/coolamqp/framing/definitions.py @@ -10,13 +10,15 @@ 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 +# Remember to call .tobytes() if you need so! +########################################################### """ import struct, collections, warnings, logging, six diff --git a/coolamqp/framing/field_table.py b/coolamqp/framing/field_table.py index ffc5888..f25aae3 100644 --- a/coolamqp/framing/field_table.py +++ b/coolamqp/framing/field_table.py @@ -33,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].tobytes(), 1+ln + return buf[offset+1:offset+1+ln], 1+ln def enframe_shortstr(buf, value): @@ -43,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].tobytes(), 4 + ln + return buf[offset+4:offset+4+ln], 4 + ln def enframe_longstr(buf, value): @@ -90,7 +90,7 @@ 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 + field_type = chr(field_type) offset += 1 if field_type not in FIELD_TYPES.keys(): @@ -161,7 +161,7 @@ def deframe_table(buf, start_offset): # -> (table, bytes_consumed) offset += ln fv, delta = deframe_field_value(buf, offset) offset += delta - fields.append((field_name, fv)) + fields.append((field_name.tobytes(), fv)) if offset > (start_offset+table_length+4): raise ValueError('Table turned out longer than expected! Found %s bytes expected %s', diff --git a/coolamqp/objects.py b/coolamqp/objects.py index e9cd9c6..b476f5f 100644 --- a/coolamqp/objects.py +++ b/coolamqp/objects.py @@ -36,6 +36,7 @@ class Message(object): :param body: stream of octets :type body: str (py2) or bytes (py3) or ... a list of memoryviews, if you find the right option. It's disabled by default. + check coolamqp.attaches.consumer.Consumer() for details :param properties: AMQP properties to be sent along. default is 'no properties at all' You can pass a dict - it will be passed to MessageProperties, -- GitLab