def _convert_a_header_to_a_h2_header(self, hdr_name, hdr_value, is_sensitive, should_index):  # noqa: E501
        # type: (str, str, Callable[[str, str], bool], Callable[[str], bool]) -> Tuple[HPackHeaders, int]  # noqa: E501
        """ _convert_a_header_to_a_h2_header builds a HPackHeaders from a header
        name and a value. It returns a HPackIndexedHdr whenever possible. If not,  # noqa: E501
        it returns a HPackLitHdrFldWithoutIndexing or a
        HPackLitHdrFldWithIncrIndexing, based on the should_index callback.
        HPackLitHdrFldWithoutIndexing is forced if the is_sensitive callback
        returns True and its never_index bit is set.
        """

        # If both name and value are already indexed
        idx = self.get_idx_by_name_and_value(hdr_name, hdr_value)
        if idx is not None:
            return HPackIndexedHdr(index=idx), len(self[idx])

        # The value is not indexed for this headers

        hdr_value = self._optimize_header_length_and_packetify(hdr_value)

        # Searching if the header name is indexed
        idx = self.get_idx_by_name(hdr_name)
        if idx is not None:
            if is_sensitive(
                hdr_name,
                hdr_value.getfieldval('data').origin()
            ):
                return HPackLitHdrFldWithoutIndexing(
                    never_index=1,
                    index=idx,
                    hdr_value=hdr_value
                ), len(
                    HPackHdrEntry(
                        self[idx].name(),
                        hdr_value.getfieldval('data').origin()
                    )
                )
            if should_index(hdr_name):
                return HPackLitHdrFldWithIncrIndexing(
                    index=idx,
                    hdr_value=hdr_value
                ), len(
                    HPackHdrEntry(
                        self[idx].name(),
                        hdr_value.getfieldval('data').origin()
                    )
                )
            return HPackLitHdrFldWithoutIndexing(
                index=idx,
                hdr_value=hdr_value
            ), len(
                HPackHdrEntry(
                    self[idx].name(),
                    hdr_value.getfieldval('data').origin()
                )
            )

        hdr_name = self._optimize_header_length_and_packetify(hdr_name)

        if is_sensitive(
            hdr_name.getfieldval('data').origin(),
            hdr_value.getfieldval('data').origin()
        ):
            return HPackLitHdrFldWithoutIndexing(
                never_index=1,
                index=0,
                hdr_name=hdr_name,
                hdr_value=hdr_value
            ), len(
                HPackHdrEntry(
                    hdr_name.getfieldval('data').origin(),
                    hdr_value.getfieldval('data').origin()
                )
            )
        if should_index(hdr_name.getfieldval('data').origin()):
            return HPackLitHdrFldWithIncrIndexing(
                index=0,
                hdr_name=hdr_name,
                hdr_value=hdr_value
            ), len(
                HPackHdrEntry(
                    hdr_name.getfieldval('data').origin(),
                    hdr_value.getfieldval('data').origin()
                )
            )
        return HPackLitHdrFldWithoutIndexing(
            index=0,
            hdr_name=hdr_name,
            hdr_value=hdr_value
        ), len(
            HPackHdrEntry(
                hdr_name.getfieldval('data').origin(),
                hdr_value.getfieldval('data').origin()
            )
        )
def _convert_a_header_to_a_h2_header ( self , hdr_name , hdr_value , is_sensitive , should_index ) : idx = self . get_idx_by_name_and_value ( hdr_name , hdr_value ) if idx is not None : return HPackIndexedHdr ( index = idx ) , len ( self [ idx ] ) hdr_value = self . _optimize_header_length_and_packetify ( hdr_value ) idx = self . get_idx_by_name ( hdr_name ) if idx is not None : if is_sensitive ( hdr_name , hdr_value . getfieldval ( 'data' ) . origin ( ) ) : return HPackLitHdrFldWithoutIndexing ( never_index = 1 , index = idx , hdr_value = hdr_value ) , len ( HPackHdrEntry ( self [ idx ] . name ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) ) if should_index ( hdr_name ) : return HPackLitHdrFldWithIncrIndexing ( index = idx , hdr_value = hdr_value ) , len ( HPackHdrEntry ( self [ idx ] . name ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) ) return HPackLitHdrFldWithoutIndexing ( index = idx , hdr_value = hdr_value ) , len ( HPackHdrEntry ( self [ idx ] . name ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) ) hdr_name = self . _optimize_header_length_and_packetify ( hdr_name ) if is_sensitive ( hdr_name . getfieldval ( 'data' ) . origin ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) : return HPackLitHdrFldWithoutIndexing ( never_index = 1 , index = 0 , hdr_name = hdr_name , hdr_value = hdr_value ) , len ( HPackHdrEntry ( hdr_name . getfieldval ( 'data' ) . origin ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) ) if should_index ( hdr_name . getfieldval ( 'data' ) . origin ( ) ) : return HPackLitHdrFldWithIncrIndexing ( index = 0 , hdr_name = hdr_name , hdr_value = hdr_value ) , len ( HPackHdrEntry ( hdr_name . getfieldval ( 'data' ) . origin ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) ) return HPackLitHdrFldWithoutIndexing ( index = 0 , hdr_name = hdr_name , hdr_value = hdr_value ) , len ( HPackHdrEntry ( hdr_name . getfieldval ( 'data' ) . origin ( ) , hdr_value . getfieldval ( 'data' ) . origin ( ) ) )
_convert_a_header_to_a_h2_header builds a HPackHeaders from a header
        name and a value. It returns a HPackIndexedHdr whenever possible. If not,  # noqa: E501
        it returns a HPackLitHdrFldWithoutIndexing or a
        HPackLitHdrFldWithIncrIndexing, based on the should_index callback.
        HPackLitHdrFldWithoutIndexing is forced if the is_sensitive callback
        returns True and its never_index bit is set.