| 758 | |
| 759 | |
| 760 | def _compress_payload(data: bytes, compression: CompressionType) -> Tuple[bytes, List[Tuple[str, str]]]: |
| 761 | headers = [('Content-Type', CONTENT_TYPE_PLAIN_0_0_4)] |
| 762 | if compression is None: |
| 763 | return data, headers |
| 764 | |
| 765 | encoding = compression.lower() |
| 766 | if encoding == 'gzip': |
| 767 | headers.append(('Content-Encoding', 'gzip')) |
| 768 | return gzip.compress(data), headers |
| 769 | if encoding == 'snappy': |
| 770 | if not SNAPPY_AVAILABLE: |
| 771 | raise RuntimeError('Snappy compression requires the python-snappy package to be installed.') |
| 772 | headers.append(('Content-Encoding', 'snappy')) |
| 773 | compressor = snappy.StreamCompressor() |
| 774 | compressed = compressor.compress(data) |
| 775 | flush = getattr(compressor, 'flush', None) |
| 776 | if callable(flush): |
| 777 | compressed += flush() |
| 778 | return compressed, headers |
| 779 | raise ValueError(f"Unsupported compression type: {compression}") |
| 780 | |
| 781 | |
| 782 | def _escape_grouping_key(k, v): |