

'''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


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

UpperCamelCase_    						=       {
    """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"""
        ),
    },
}

UpperCamelCase_    						=       {
    """unc-nlp/lxmert-base-uncased""": 512,
}

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





class 		__SCREAMING_SNAKE_CASE							(			lowercase__      ):
				lowerCamelCase_		       =    VOCAB_FILES_NAMES
				lowerCamelCase_		       =    PRETRAINED_VOCAB_FILES_MAP
				lowerCamelCase_		       =    PRETRAINED_INIT_CONFIGURATION
				lowerCamelCase_		       =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				lowerCamelCase_		       =    LxmertTokenizer







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

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

										lowercase :							int    		=do_lower_case







				def  lowerCamelCase_	(       self     :		List[Any]		,					UpperCAmelCase__     :		Any		,					UpperCAmelCase__     :		int=None   ):
										'''simple docstring'''
										lowercase :							Union[str, 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  lowerCamelCase_	(       self     :		Dict		,					UpperCAmelCase__     :		List[int]		,					UpperCAmelCase__     :		Optional[List[int]] = None   ):
										'''simple docstring'''
										lowercase :							List[Any]    		=[self.sep_token_id]
										lowercase :							List[str]    		=[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     :		str		,					UpperCAmelCase__     :		str		,					UpperCAmelCase__     :		Optional[str] = None   ):
										'''simple docstring'''
										lowercase :							List[Any]    		=self._tokenizer.model.save(UpperCAmelCase__		,					name=UpperCAmelCase__   )
										return tuple(UpperCAmelCase__   )









from importlib import import_module

from .logging import get_logger


_lowerCAmelCase:						str   				=       get_logger(__name__)




class       lowercase_					:





				def __init__(				self       ,  lowercase_       ,  lowercase_=None)  -> Tuple:
											a__      =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_))
											a__      =module._original_module if isinstance(lowercase_       ,  _PatchedModuleObj) else module







class       lowercase_					:
				snake_case	    =[]





				def __init__(				self       ,  lowercase_       ,  lowercase_       ,  lowercase_       ,  lowercase_=None)  -> List[str]:
											a__      =obj
											a__      =target
											a__      =new
											a__      =target.split('.')[0]
											a__      ={}
											a__      =attrs or []





				def __enter__(				self)  -> Optional[int]:
											*a__    ,     a__      =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:
																									a__      =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__():
																									a__      =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)
																									):
																																a__      =obj_attr
																																# patch at top level
																																setattr(self.obj       ,  lowercase_       ,  _PatchedModuleObj(lowercase_       ,  attrs=self.attrs))
																																a__      =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))
																																							a__      =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:
																									a__      =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:
																																a__      =getattr(self.obj       ,  lowercase_)
																																setattr(self.obj       ,  lowercase_       ,  self.new)
											elif target_attr in globals()["__builtins__"]:  # if it'a s builtin like "open"
																		a__      =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       ,  *lowercase_)  -> str:
											for attr in list(self.original):
																		setattr(self.obj       ,  lowercase_       ,  self.original.pop(lowercase_))





				def 						__UpperCamelCase    (				self)  -> Any:
											self.__enter__()
											self._active_patches.append(self)





				def 						__UpperCamelCase    (				self)  -> Union[str, Any]:
											try:
																		self._active_patches.remove(self)
											except ValueError:
																		# If the patch hasn't been started this will fail
																		return None

											return self.__exit__()

