
'''simple docstring'''







import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from .tokenization_lxmert import LxmertTokenizer


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

__lowerCAmelCase         =    {
    """vocab_file""": {
        """unc-nlp/lxmert-base-uncased""": """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/vocab.txt""",
    },
    """tokenizer_file""": {
        """unc-nlp/lxmert-base-uncased""": (
            """https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

__lowerCAmelCase         =    {
    """unc-nlp/lxmert-base-uncased""": 5_1_2,
}

__lowerCAmelCase         =    {
    """unc-nlp/lxmert-base-uncased""": {"""do_lower_case""": True},
}







class UpperCAmelCase__	( __lowerCamelCase	):





  """simple docstring"""

  __UpperCAmelCase				:				List[Any]   =					VOCAB_FILES_NAMES
  __UpperCAmelCase				:				Dict   =					PRETRAINED_VOCAB_FILES_MAP
  __UpperCAmelCase				:				Union[str, Any]   =					PRETRAINED_INIT_CONFIGURATION
  __UpperCAmelCase				:				Dict   =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  __UpperCAmelCase				:				Optional[Any]   =					LxmertTokenizer


  def __init__(		self      :     Union[str, Any]							,_a      :     str=None							,_a      :     Optional[Any]=None							,_a      :     List[str]=True							,_a      :     Dict="[UNK]"							,_a      :     int="[SEP]"							,_a      :     Optional[int]="[PAD]"							,_a      :     Tuple="[CLS]"							,_a      :     List[str]="[MASK]"							,_a      :     Optional[int]=True							,_a      :     List[str]=None							,**_a      :     Any							,):


     '''simple docstring'''






     super().__init__(
         __lowercase							,tokenizer_file=__lowercase							,do_lower_case=__lowercase							,unk_token=__lowercase							,sep_token=__lowercase							,pad_token=__lowercase							,cls_token=__lowercase							,mask_token=__lowercase							,tokenize_chinese_chars=__lowercase							,strip_accents=__lowercase							,**__lowercase							,)

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

     _a				:	Dict			=   do_lower_case


  def   __lowercase		(		self      :     List[str]							,_a      :     Optional[Any]							,_a      :     Optional[Any]=None       ):


     '''simple docstring'''






     _a				:	Optional[Any]			=   [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   __lowercase		(		self      :     Optional[Any]							,_a      :     List[int]							,_a      :     Optional[List[int]] = None       ):


     '''simple docstring'''






     _a				:	Optional[int]			=   [self.sep_token_id]
     _a				:	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   __lowercase		(		self      :     Dict							,_a      :     str							,_a      :     Optional[str] = None       ):


     '''simple docstring'''






     _a				:	Any			=   self._tokenizer.model.save(__lowercase							,name=__lowercase       )
     return tuple(__lowercase       )








from importlib import import_module

from .logging import get_logger


A__								=						get_logger(__name__)


class       a							:



		def __init__(     self     :Optional[int]   ,__lowercase     :List[str]   ,__lowercase     :Any=None  ):
						snake_case__	:      List[str]     		=	attrs or []
						if module is not None:
										for key in module.__dict__:
														if key in attrs or not key.startswith('''__'''  ):
																		setattr(self   ,__lowercase   ,getattr(__lowercase   ,__lowercase  )  )
						snake_case__	:      Optional[Any]     		=	module._original_module if isinstance(__lowercase   ,_PatchedModuleObj  ) else module


class       a							:
		__lowerCAmelCase	:    Any											=					[]



		def __init__(     self     :List[str]   ,__lowercase     :Optional[Any]   ,__lowercase     :str   ,__lowercase     :Dict   ,__lowercase     :Any=None  ):
						snake_case__	:      Dict     		=	obj
						snake_case__	:      Dict     		=	target
						snake_case__	:      List[str]     		=	new
						snake_case__	:      int     		=	target.split('''.'''  )[0]
						snake_case__	:      List[str]     		=	{}
						snake_case__	:      Any     		=	attrs or []



		def __enter__(     self     :Tuple  ):
						*snake_case__		, snake_case__	:      str     		=	self.target.split('''.'''  )

						# Patch modules:
						# it's used to patch attributes of submodules like "os.path.join";
						# in this case we need to patch "os" and "os.path"

						for i in range(len(__lowercase  )  ):
										try:
														snake_case__	:      Any     		=	import_module('''.'''.join(submodules[: i + 1]  )  )
										except ModuleNotFoundError:
														continue
										# We iterate over all the globals in self.obj in case we find "os" or "os.path"
										for attr in self.obj.__dir__():
														snake_case__	:      Optional[int]     		=	getattr(self.obj   ,__lowercase  )
														# We don't check for the name of the global, but rather if its value *is* "os" or "os.path".
														# This allows to patch renamed modules like "from os import path as ospath".
														if obj_attr is submodule or (
														    (isinstance(__lowercase   ,_PatchedModuleObj  ) and obj_attr._original_module is submodule)
														):
																		snake_case__	:      List[Any]     		=	obj_attr
																		# patch at top level
																		setattr(self.obj   ,__lowercase   ,_PatchedModuleObj(__lowercase   ,attrs=self.attrs  )  )
																		snake_case__	:      List[Any]     		=	getattr(self.obj   ,__lowercase  )
																		# construct lower levels patches
																		for key in submodules[i + 1 :]:
																						setattr(__lowercase   ,__lowercase   ,_PatchedModuleObj(getattr(__lowercase   ,__lowercase   ,__lowercase  )   ,attrs=self.attrs  )  )
																						snake_case__	:      List[Any]     		=	getattr(__lowercase   ,__lowercase  )
																		# finally set the target attribute
																		setattr(__lowercase   ,__lowercase   ,self.new  )

        # Patch attribute itself:
        # it's used for builtins like "open",
        # and also to patch "os.path.join" we may also need to patch "join"
        # itself if it was imported as "from os.path import join".

						if submodules:  # if it's an attribute of a submodule like "os.path.join"
										try:
														snake_case__	:      int     		=	getattr(import_module('''.'''.join(__lowercase  )  )   ,__lowercase  )
										except (AttributeError, ModuleNotFoundError):
														return
										# We iterate over all the globals in self.obj in case we find "os.path.join"
										for attr in self.obj.__dir__():
														# We don't check for the name of the global, but rather if its value *is* "os.path.join".
														# This allows to patch renamed attributes like "from os.path import join as pjoin".
														if getattr(self.obj   ,__lowercase  ) is attr_value:
																		snake_case__	:      str     		=	getattr(self.obj   ,__lowercase  )
																		setattr(self.obj   ,__lowercase   ,self.new  )
						elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
										snake_case__	:      str     		=	globals()['''__builtins__'''][target_attr]
										setattr(self.obj   ,__lowercase   ,self.new  )
						else:
										raise RuntimeError(F"""Tried to patch attribute {target_attr} instead of a submodule."""  )



		def __exit__(     self     :Tuple   ,*__lowercase     :Optional[int]  ):
						for attr in list(self.original  ):
										setattr(self.obj   ,__lowercase   ,self.original.pop(__lowercase  )  )



		def 	__lowerCamelCase			(     self     :Tuple  ):
						self.__enter__()
						self._active_patches.append(self  )






		def 	__lowerCamelCase			(     self     :Dict  ):
						try:
										self._active_patches.remove(self  )
						except ValueError:
										# If the patch hasn't been started this will fail
										return None

						return self.__exit__()

