示例#1
0
    def consume(self, message_type):
        """ Consume the data in this stream by yielding `message_type` messages,
        or raising if the stream was closed with an error.
        """
        while True:
            item = self.queue.get()
            if isinstance(item, GrpcError):
                raise item
            elif item is STREAM_END:
                break

            compressed, message_data = item
            if compressed:
                message_data = decompress(message_data)

            message = message_type()
            message.ParseFromString(message_data)

            yield message
示例#2
0
    def test_unsupported_algorithm(self):
        payload = b"\x00" * 1000

        with pytest.raises(UnsupportedEncoding):
            decompress(payload)  # not correctly encoded
示例#3
0
    def test_fallback_algorithm(self):
        payload = b"\x00" * 1000

        assert decompress(gzip.compress(payload)) == payload
示例#4
0
    def test_preferred_algorithm(self):
        payload = b"\x00" * 1000

        assert decompress(zlib.compress(payload)) == payload