Esempio n. 1
0
    def flush_queue_to_buffer(self):
        """ Write the bytes from any messages in the queue to the buffer.
        """
        while True:
            try:
                message = self.queue.get_nowait()
            except Empty:
                break

            # any error should be raised immediately
            if isinstance(message, GrpcError):
                raise message

            # add the bytes from the message to the buffer
            if message and message != STREAM_END:
                body = message.SerializeToString()
                compressed, body = compress(body, self.encoding)

                data = (struct.pack("?", compressed) +
                        struct.pack(">I", len(body)) + body)
                self.buffer.write(data)
Esempio n. 2
0
    def test_unsupported_algorithm(self):
        payload = b"\x00" * 1000

        with pytest.raises(UnsupportedEncoding):
            compress(payload, "bogus")
Esempio n. 3
0
 def test_gzip(self):
     payload = b"\x00" * 1000
     assert compress(payload, "gzip") == (True, gzip.compress(payload))
Esempio n. 4
0
 def test_deflate(self):
     payload = b"\x00" * 1000
     assert compress(payload, "deflate") == (True, zlib.compress(payload))
Esempio n. 5
0
 def test_identity(self):
     payload = b"\x00" * 1000
     assert compress(payload, "identity") == (False, payload)