Skip to content
Snippets Groups Projects
Commit d2ae61f5 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

memoryview madness

parent 1057fe53
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ engines:
exclude_paths:
- examples/**
- tests/**
- coolamqp/framing/definitions.py
ratings:
paths:
- coolamqp/**
......@@ -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)),
......
......@@ -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
......
......@@ -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
......
......@@ -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):
......
......@@ -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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment