Example #1
0
 def test_partial_streams(self):
     s = stream.Stream(stream.HeaderByteStream(2), stream.JSONParser())
     data = b'\x00\x1b{"id": 1, "name": "Daniel"}\x00\x12{"color": "green"}'
     result = s.receive(data[0:10])
     assert result == []
     result = s.receive(data[10:])
     assert result == [{'id': 1, 'name': "Daniel"}, {'color': "green"}]
Example #2
0
 def test_partial_frames(self):
     s = stream.HeaderByteStream(2)
     data = b'\x00\x03ABC\x00\x0212'
     result = s.receive(data[0:4])
     assert result == []
     result = s.receive(data[4:7])
     assert result == [b'ABC']
     result = s.receive(data[7:])
     assert result == [b'12']
Example #3
0
    def __init__(self, writer, future_factory, implementation_class):
        self.stream = stream.Stream(stream.HeaderByteStream(2),
                                    stream.JSONParser())
        self.id_pool = pool.MessageIdPool()
        self.pending_requests = {}  # (int) --> Future
        self._writer = writer
        self.future_factory = future_factory

        self.implementation = implementation_class(self.make_outbound_request)
Example #4
0
 def test_single_frame(self):
     s = stream.HeaderByteStream(2)
     data = b'\x00\x03ABC'
     result = s.receive(data)
     assert result == [b'ABC']
Example #5
0
 def test_multiple_objects(self):
     s = stream.Stream(stream.HeaderByteStream(2), stream.JSONParser())
     result = s.receive(
         b'\x00\x1b{"id": 1, "name": "Daniel"}\x00\x09{"id": 2}')
     assert result == [{'id': 1, 'name': "Daniel"}, {'id': 2}]
Example #6
0
 def test_multiple_frames(self):
     s = stream.HeaderByteStream(2)
     result = s.receive(b'\x00\x02AB\x00\x041234')
     assert result == [b'AB', b'1234']