


'''simple docstring'''



__UpperCAmelCase      :Tuple			    =       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"




def      _a     (						_lowercase :     bytes  ):





     '''simple docstring'''






     if not isinstance(_lowercase      , _lowercase  ):
          __UpperCAmelCase     :			Dict  							=      F'a bytes-like object is required, not \'{data.__class__.__name__}\''
          raise TypeError(_lowercase  )

     __UpperCAmelCase     :			Optional[Any]  							=      ''''''.join(bin(_lowercase  )[2:].zfill(8  ) for byte in data  )

     __UpperCAmelCase     :			Union[str, Any]  							=      len(_lowercase  ) % 6 != 0

     if padding_needed:
          # The padding that will be added later
          __UpperCAmelCase     :			List[Any]  							=      b'''=''' * ((6 - len(_lowercase  ) % 6) // 2)

          # Append binary_stream with arbitrary binary digits (0's by default) to make its
          # length a multiple of 6.
          binary_stream += "0" * (6 - len(_lowercase  ) % 6)
     else:
          __UpperCAmelCase     :			Tuple  							=      b''''''

     # Encode every 6 binary digits to their corresponding Base64 character
     return (
         "".join(
             B64_CHARSET[int(binary_stream[index : index + 6]      , 2  )]
             for index in range(0      , len(_lowercase  )      , 6  )  ).encode()
         + padding
     )




def      _a     (						_lowercase :     str  ):





     '''simple docstring'''






     if not isinstance(_lowercase      , _lowercase  ) and not isinstance(_lowercase      , _lowercase  ):
          __UpperCAmelCase     :			str  							=      (
              '''argument should be a bytes-like object or ASCII string, '''
              F'not \'{encoded_data.__class__.__name__}\''
          )
          raise TypeError(_lowercase  )

     # In case encoded_data is a bytes-like object, make sure it contains only
     # ASCII characters so we convert it to a string object
     if isinstance(_lowercase      , _lowercase  ):
          try:
               __UpperCAmelCase     :			Tuple  							=      encoded_data.decode('''utf-8'''  )
          except UnicodeDecodeError:
               raise ValueError('''base64 encoded data should only contain ASCII characters'''  )

     __UpperCAmelCase     :			List[Any]  							=      encoded_data.count('''='''  )

     # Check if the encoded string contains non base64 characters
     if padding:
          assert all(
              char in B64_CHARSET for char in encoded_data[:-padding]  ), "Invalid base64 character(s) found."
     else:
          assert all(
              char in B64_CHARSET for char in encoded_data  ), "Invalid base64 character(s) found."

     # Check the padding
     assert len(_lowercase  ) % 4 == 0 and padding < 3, "Incorrect padding"

     if padding:
          # Remove padding if there is one
          __UpperCAmelCase     :			str  							=      encoded_data[:-padding]

          __UpperCAmelCase     :			str  							=      ''''''.join(
              bin(B64_CHARSET.index(_lowercase  )  )[2:].zfill(6  ) for char in encoded_data  )[: -padding * 2]
     else:
          __UpperCAmelCase     :			Tuple  							=      ''''''.join(
              bin(B64_CHARSET.index(_lowercase  )  )[2:].zfill(6  ) for char in encoded_data  )

     __UpperCAmelCase     :			Optional[int]  							=      [
         int(binary_stream[index : index + 8]      , 2  )
         for index in range(0      , len(_lowercase  )      , 8  )
     ]

     return bytes(_lowercase  )


if __name__ == "__main__":
      import doctest

      doctest.testmod()




'''simple docstring'''



import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bert import BertTokenizer


__UpperCAmelCase      :Dict			    =       logging.get_logger(__name__)

__UpperCAmelCase      :str			    =       {"vocab_file": "vocab.txt", "tokenizer_file": "tokenizer.json"}

__UpperCAmelCase      :Optional[int]			    =       {
    "vocab_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/vocab.txt",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/vocab.txt",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt"
        ),
        "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt",
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt"
        ),
        "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt",
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json"
        ),
        "bert-base-multilingual-cased": (
            "https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-cased": (
            "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json"
        ),
    },
}

__UpperCAmelCase      :Union[str, Any]			    =       {
    "bert-base-uncased": 5_1_2,
    "bert-large-uncased": 5_1_2,
    "bert-base-cased": 5_1_2,
    "bert-large-cased": 5_1_2,
    "bert-base-multilingual-uncased": 5_1_2,
    "bert-base-multilingual-cased": 5_1_2,
    "bert-base-chinese": 5_1_2,
    "bert-base-german-cased": 5_1_2,
    "bert-large-uncased-whole-word-masking": 5_1_2,
    "bert-large-cased-whole-word-masking": 5_1_2,
    "bert-large-uncased-whole-word-masking-finetuned-squad": 5_1_2,
    "bert-large-cased-whole-word-masking-finetuned-squad": 5_1_2,
    "bert-base-cased-finetuned-mrpc": 5_1_2,
    "bert-base-german-dbmdz-cased": 5_1_2,
    "bert-base-german-dbmdz-uncased": 5_1_2,
    "TurkuNLP/bert-base-finnish-cased-v1": 5_1_2,
    "TurkuNLP/bert-base-finnish-uncased-v1": 5_1_2,
    "wietsedv/bert-base-dutch-cased": 5_1_2,
}

__UpperCAmelCase      :str			    =       {
    "bert-base-uncased": {"do_lower_case": True},
    "bert-large-uncased": {"do_lower_case": True},
    "bert-base-cased": {"do_lower_case": False},
    "bert-large-cased": {"do_lower_case": False},
    "bert-base-multilingual-uncased": {"do_lower_case": True},
    "bert-base-multilingual-cased": {"do_lower_case": False},
    "bert-base-chinese": {"do_lower_case": False},
    "bert-base-german-cased": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking-finetuned-squad": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking-finetuned-squad": {"do_lower_case": False},
    "bert-base-cased-finetuned-mrpc": {"do_lower_case": False},
    "bert-base-german-dbmdz-cased": {"do_lower_case": False},
    "bert-base-german-dbmdz-uncased": {"do_lower_case": True},
    "TurkuNLP/bert-base-finnish-cased-v1": {"do_lower_case": False},
    "TurkuNLP/bert-base-finnish-uncased-v1": {"do_lower_case": True},
    "wietsedv/bert-base-dutch-cased": {"do_lower_case": False},
}



class      a    (		_a	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE	:			List[Any]							       =       PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE	:			Tuple							       =       PRETRAINED_INIT_CONFIGURATION
     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE	:			Optional[Any]							       =       BertTokenizer

     def __init__(    self					:		Optional[int]							,			snake_case					:		Union[str, Any]=None							,			snake_case					:		str=None							,			snake_case					:		Any=True							,			snake_case					:		Tuple="[UNK]"							,			snake_case					:		int="[SEP]"							,			snake_case					:		Optional[Any]="[PAD]"							,			snake_case					:		int="[CLS]"							,			snake_case					:		Optional[Any]="[MASK]"							,			snake_case					:		Union[str, Any]=True							,			snake_case					:		List[Any]=None							,			**snake_case					:		int							,			)						->							str:
          super().__init__(
              snake_case							,			tokenizer_file=snake_case							,			do_lower_case=snake_case							,			unk_token=snake_case							,			sep_token=snake_case							,			pad_token=snake_case							,			cls_token=snake_case							,			mask_token=snake_case							,			tokenize_chinese_chars=snake_case							,			strip_accents=snake_case							,			**snake_case							,			)

          __UpperCAmelCase     :			List[str]  							=      json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
          if (
              normalizer_state.get('''lowercase'''							,			snake_case      ) != do_lower_case
              or normalizer_state.get('''strip_accents'''							,			snake_case      ) != strip_accents
              or normalizer_state.get('''handle_chinese_chars'''							,			snake_case      ) != tokenize_chinese_chars
          ):
               __UpperCAmelCase     :			List[Any]  							=      getattr(snake_case							,			normalizer_state.pop('''type'''      )      )
               __UpperCAmelCase     :			List[Any]  							=      do_lower_case
               __UpperCAmelCase     :			List[Any]  							=      strip_accents
               __UpperCAmelCase     :			str  							=      tokenize_chinese_chars
               __UpperCAmelCase     :			List[str]  							=      normalizer_class(**snake_case      )

          __UpperCAmelCase     :			Optional[int]  							=      do_lower_case

     def 			lowerCamelCase__			(    self					:		List[Any]							,			snake_case					:		Tuple							,			snake_case					:		List[str]=None      )						->							str:
          __UpperCAmelCase     :			Optional[int]  							=      [self.cls_token_id] + token_ids_a + [self.sep_token_id]

          if token_ids_a:
               output += token_ids_a + [self.sep_token_id]

          return output

     def 			lowerCamelCase__			(    self					:		str							,			snake_case					:		List[int]							,			snake_case					:		Optional[List[int]] = None      )						->							List[int]:
          __UpperCAmelCase     :			List[str]  							=      [self.sep_token_id]
          __UpperCAmelCase     :			Tuple  							=      [self.cls_token_id]
          if token_ids_a is None:
               return len(cls + token_ids_a + sep      ) * [0]
          return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]






     def 			lowerCamelCase__			(    self					:		List[Any]							,			snake_case					:		str							,			snake_case					:		Optional[str] = None      )						->							Tuple[str]:
          __UpperCAmelCase     :			Optional[int]  							=      self._tokenizer.model.save(snake_case							,			name=snake_case      )
          return tuple(snake_case      )