<commit_before>#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .TProtocol import TProtocolBase
from thrift.Thrift import TApplicationException, TMessageType
from .TBinaryProtocol import TBinaryProtocol
from .TSimpleJSONProtocol import TSimpleJSONProtocol
from .TCompactProtocol import TCompactProtocol
from thrift.transport.THeaderTransport import THeaderTransport

class THeaderProtocol(TProtocolBase):

    """Pass through header protocol (transport can set)"""
    T_BINARY_PROTOCOL = 0
    T_JSON_PROTOCOL = 1
    T_COMPACT_PROTOCOL = 2

    __proto = None
    __proto_id = None

    def get_protocol_id(self):
        return self.__proto_id

    def reset_protocol(self):
        if self.__proto_id == self.trans.get_protocol_id():
            return

        proto_id = self.trans.get_protocol_id()

        if proto_id == self.T_BINARY_PROTOCOL:
            self.__proto = TBinaryProtocol(self.trans, self.strictRead, True)
        elif proto_id == self.T_COMPACT_PROTOCOL:
            self.__proto = TCompactProtocol(self.trans)
        else:
            raise TApplicationException(TProtocolException.INVALID_PROTOCOL,
                                        "Unknown protocol requested")
        self.__proto_id = proto_id

    def __init__(self, trans, strictRead=False, client_types=None):
        """Create a THeaderProtocol instance

        @param transport(TTransport) The underlying transport.
        @param strictRead(bool) Turn on strictRead if using TBinaryProtocol
        @param client_types([THeaderTransport.HEADERS_CLIENT_TYPE, ...])
                   List of client types to support.  Defaults to
                   HEADERS_CLIENT_TYPE only.
        """

        htrans = THeaderTransport(trans, client_types)<commit_msg>Use THeaderTransport in BaseThriftClient<commit_after>#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from .TProtocol import TProtocolBase
from thrift.Thrift import TApplicationException, TMessageType
from .TBinaryProtocol import TBinaryProtocolAccelerated
from .TSimpleJSONProtocol import TSimpleJSONProtocol
from .TCompactProtocol import TCompactProtocol
from thrift.transport.THeaderTransport import THeaderTransport

class THeaderProtocol(TProtocolBase):

    """Pass through header protocol (transport can set)"""
    T_BINARY_PROTOCOL = 0
    T_JSON_PROTOCOL = 1
    T_COMPACT_PROTOCOL = 2

    __proto = None
    __proto_id = None

    def get_protocol_id(self):
        return self.__proto_id

    def reset_protocol(self):
        if self.__proto_id == self.trans.get_protocol_id():
            return

        proto_id = self.trans.get_protocol_id()

        if proto_id == self.T_BINARY_PROTOCOL:
            self.__proto = TBinaryProtocolAccelerated(self.trans,
                    self.strictRead, True)
        elif proto_id == self.T_COMPACT_PROTOCOL:
            self.__proto = TCompactProtocol(self.trans)
        else:
            raise TApplicationException(TProtocolException.INVALID_PROTOCOL,
                                        "Unknown protocol requested")
        self.__proto_id = proto_id

    def __init__(self, trans, strictRead=False, client_types=None):
        """Create a THeaderProtocol instance

        @param transport(TTransport) The underlying transport.
        @param strictRead(bool) Turn on strictRead if using TBinaryProtocol
        @param client_types([THeaderTransport.HEADERS_CLIENT_TYPE, ...])
                   List of client types to support.  Defaults to
                   HEADERS_CLIENT_TYPE only.
        """

        htrans = THeaderTransport(trans, client_types)
{'fraction_non_alphanumeric': 0.05977956286194657, 'fraction_numerical': 0.0026153558752101624, 'mean_word_length': 3.3957307060755335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3094418', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1363, 'n_words': 486}