MCPcopy Index your code
hub / github.com/prometheus/client_python / _compress_payload

Function _compress_payload

prometheus_client/exposition.py:760–779  ·  view source on GitHub ↗
(data: bytes, compression: CompressionType)

Source from the content-addressed store, hash-verified

758
759
760def _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
782def _escape_grouping_key(k, v):

Callers 1

_use_gatewayFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected