Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/grpc/_compression.py
7764 views
# Copyright 2019 The gRPC authors.1#2# Licensed under the Apache License, Version 2.0 (the "License");3# you may not use this file except in compliance with the License.4# You may obtain a copy of the License at5#6# http://www.apache.org/licenses/LICENSE-2.07#8# Unless required by applicable law or agreed to in writing, software9# distributed under the License is distributed on an "AS IS" BASIS,10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11# See the License for the specific language governing permissions and12# limitations under the License.1314from grpc._cython import cygrpc1516NoCompression = cygrpc.CompressionAlgorithm.none17Deflate = cygrpc.CompressionAlgorithm.deflate18Gzip = cygrpc.CompressionAlgorithm.gzip1920_METADATA_STRING_MAPPING = {21NoCompression: 'identity',22Deflate: 'deflate',23Gzip: 'gzip',24}252627def _compression_algorithm_to_metadata_value(compression):28return _METADATA_STRING_MAPPING[compression]293031def compression_algorithm_to_metadata(compression):32return (cygrpc.GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY,33_compression_algorithm_to_metadata_value(compression))343536def create_channel_option(compression):37return ((cygrpc.GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM,38int(compression)),) if compression else ()394041def augment_metadata(metadata, compression):42if not metadata and not compression:43return None44base_metadata = tuple(metadata) if metadata else ()45compression_metadata = (46compression_algorithm_to_metadata(compression),) if compression else ()47return base_metadata + compression_metadata484950__all__ = (51"NoCompression",52"Deflate",53"Gzip",54)555657