Ejemplo 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)
Ejemplo n.º 2
0
    def test_unsupported_algorithm(self):
        payload = b"\x00" * 1000

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