Skip to content

Commit

Permalink
read_frame python3 compatible for large payloads (#248)
Browse files Browse the repository at this point in the history
read_frame is using str.join to concatenate the payload if the received
frame is bigger than SIGNED_INT_MAX.

That's fine with python2, however in python3 documentation is stated

str.joinReturn a string which is the concatenation of the strings in the
iterable iterable. A TypeError will be raised if there are any
non-string values in iterable, including bytes objects. The separator
between elements is the string providing this method.

So we have to use the byte object join() method

Signed-off-by: aojeagarcia <aojeagarcia@suse.com>
  • Loading branch information
aojea authored and auvipy committed Jan 25, 2019
1 parent 734305d commit e45ea3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion amqp/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def read_frame(self, unpack=unpack):
if size > SIGNED_INT_MAX:
part1 = read(SIGNED_INT_MAX)
part2 = read(size - SIGNED_INT_MAX)
payload = ''.join([part1, part2])
payload = b''.join([part1, part2])
else:
payload = read(size)
read_frame_buffer += payload
Expand Down
11 changes: 11 additions & 0 deletions t/unit/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from amqp.platform import pack
from amqp.transport import _AbstractTransport

SIGNED_INT_MAX = 0x7FFFFFFF


class DummyException(Exception):
pass
Expand Down Expand Up @@ -319,6 +321,15 @@ def on_read1(size, *args):
with pytest.raises(UnexpectedFrame):
self.t.read_frame()

def test_read_frame__long(self):
self.t._read = Mock()
self.t._read.side_effect = [pack('>BHI', 1, 1, SIGNED_INT_MAX + 16),
b'read1', b'read2', b'\xce']
frame_type, channel, payload = self.t.read_frame()
assert frame_type == 1
assert channel == 1
assert payload == b'read1read2'

def transport_read_EOF(self):
for host, ssl in (('localhost:5672', False),
('localhost:5671', True),):
Expand Down

0 comments on commit e45ea3e

Please sign in to comment.