"""simple docstring"""




from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_clip import CLIPTokenizer


__lowerCamelCase									=	logging.get_logger(__name__)

__lowerCamelCase									=	{"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

__lowerCamelCase									=	{
    """vocab_file""": {
        """openai/clip-vit-base-patch32""": """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """openai/clip-vit-base-patch32""": """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """openai/clip-vit-base-patch32""": (
            """https://huggingface.co/openai/clip-vit-base-patch32/resolve/main/tokenizer.json"""
        ),
    },
}

__lowerCamelCase									=	{
    """openai/clip-vit-base-patch32""": 77,
}
class      UpperCamelCase__(      __A			):
						lowerCAmelCase__	:    Dict    				=		VOCAB_FILES_NAMES
						lowerCAmelCase__	:    str    				=		PRETRAINED_VOCAB_FILES_MAP
						lowerCAmelCase__	:    List[Any]    				=		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						lowerCAmelCase__	:    str    				=		['''input_ids''', '''attention_mask''']
						lowerCAmelCase__	:    Optional[Any]    				=		CLIPTokenizer





						def __init__(							self		,__UpperCAmelCase=None		,__UpperCAmelCase=None		,__UpperCAmelCase=None		,__UpperCAmelCase="<|endoftext|>"		,__UpperCAmelCase="<|startoftext|>"		,__UpperCAmelCase="<|endoftext|>"		,__UpperCAmelCase="<|endoftext|>"		,**__UpperCAmelCase		,)       ->					int:
													super().__init__(
													    __UpperCAmelCase		,__UpperCAmelCase		,tokenizer_file=__UpperCAmelCase		,unk_token=__UpperCAmelCase		,bos_token=__UpperCAmelCase		,eos_token=__UpperCAmelCase		,pad_token=__UpperCAmelCase		,**__UpperCAmelCase		,)

													if not isinstance(self.backend_tokenizer.pre_tokenizer		,pre_tokenizers.Sequence  ):
																				raise ValueError(
																				    'The `backend_tokenizer` provided does not match the expected format. The CLIP tokenizer has been'
																				    ' heavily modified from transformers version 4.17.0. You need to convert the tokenizer you are using'
																				    ' to be compatible with this version.The easiest way to do so is'
																				    ' `CLIPTokenizerFast.from_pretrained("path_to_local_folder_or_hub_repo, from_slow=True)`. If you want'
																				    ' to use your existing tokenizer, you will have to revert to a version prior to 4.17.0 of'
																				    ' transformers.'  )

													self._wrap_decode_method_backend_tokenizer()





						def 					snake_case__						(							self  )       ->					str:
													A__						  =				self.backend_tokenizer.decode

													def new_decode_method(*__UpperCAmelCase		,**__UpperCAmelCase  ):
																				A__						  =				orig_decode_method(*__UpperCAmelCase		,**__UpperCAmelCase  )
																				A__						  =				text.replace(self.backend_tokenizer.model.end_of_word_suffix		,' '  ).strip()
																				return text

													A__						  =				new_decode_method





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase = None  )       ->					str:
													A__						  =				[self.bos_token_id]
													A__						  =				[self.eos_token_id]

													if token_ids_a is None:
																				return bos_token + token_ids_a + eos_token
													return bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase = None  )       ->					int:
													A__						  =				[self.bos_token_id]
													A__						  =				[self.eos_token_id]

													if token_ids_a is None:
																				return len(bos_token + token_ids_a + eos_token  ) * [0]
													return len(bos_token + token_ids_a + eos_token + eos_token + token_ids_a + eos_token  ) * [0]





						def 					snake_case__						(							self		,__UpperCAmelCase		,__UpperCAmelCase = None  )       ->					List[str]:
													A__						  =				self._tokenizer.model.save(__UpperCAmelCase		,name=__UpperCAmelCase  )
													return tuple(__UpperCAmelCase  )













"""simple docstring"""





class   _lowercase			:


      def __init__(     self					:						Optional[Any]				, a					:						Union[str, Any]    ):





            """simple docstring"""







            __snake_case   :     Union[str, Any]	      =data
            __snake_case   :     Optional[Any]	      =None
            __snake_case   :     Any	      =None







      def __str__(     self					:						Any    ):





            """simple docstring"""







            return f'''{self.data}'''



class   _lowercase			:


      def __init__(     self					:						Optional[int]    ):





            """simple docstring"""







            __snake_case   :     Any	      =None
            __snake_case   :     int	      =None


      def __iter__(     self					:						int    ):





            """simple docstring"""







            __snake_case   :     List[str]	      =self.head
            while node:
                  yield node.data
                  __snake_case   :     str	      =node.next


      def __str__(     self					:						Optional[int]    ):





            """simple docstring"""







            return "->".join([str(a    ) for item in self]    )


      def __len__(     self					:						str    ):





            """simple docstring"""







            return sum(1 for _ in self    )


      def _UpperCamelCase    (     self					:						int				, a					:						List[Any]    ):





            """simple docstring"""







            self.insert_at_nth(0				, a    )


      def _UpperCamelCase    (     self					:						str				, a					:						Optional[int]    ):





            """simple docstring"""







            self.insert_at_nth(len(self    )				, a    )


      def _UpperCamelCase    (     self					:						Optional[Any]				, a					:						int				, a					:						Tuple    ):





            """simple docstring"""







            __snake_case   :     List[str]	      =len(self    )

            if not 0 <= index <= length:
                  raise IndexError('''list index out of range'''    )
            __snake_case   :     List[Any]	      =Node(a    )
            if self.head is None:
                  __snake_case   :     Dict	      =new_node
            elif index == 0:
                  __snake_case   :     Union[str, Any]	      =new_node
                  __snake_case   :     Any	      =self.head
                  __snake_case   :     List[Any]	      =new_node
            elif index == length:
                  __snake_case   :     int	      =new_node
                  __snake_case   :     Optional[Any]	      =self.tail
                  __snake_case   :     Optional[Any]	      =new_node
            else:
                  __snake_case   :     Any	      =self.head
                  for _ in range(0				, a    ):
                        __snake_case   :     Optional[Any]	      =temp.next
                  __snake_case   :     Optional[Any]	      =new_node
                  __snake_case   :     Union[str, Any]	      =temp.previous
                  __snake_case   :     List[Any]	      =temp
                  __snake_case   :     str	      =new_node


      def _UpperCamelCase    (     self					:						List[str]    ):





            """simple docstring"""







            return self.delete_at_nth(0    )


      def _UpperCamelCase    (     self					:						List[Any]    ):





            """simple docstring"""







            return self.delete_at_nth(len(self    ) - 1    )


      def _UpperCamelCase    (     self					:						Optional[int]				, a					:						int    ):





            """simple docstring"""







            __snake_case   :     Tuple	      =len(self    )

            if not 0 <= index <= length - 1:
                  raise IndexError('''list index out of range'''    )
            __snake_case   :     str	      =self.head  # default first node
            if length == 1:
                  __snake_case   :     List[Any]	      =None
            elif index == 0:
                  __snake_case   :     List[Any]	      =self.head.next
                  __snake_case   :     Optional[int]	      =None
            elif index == length - 1:
                  __snake_case   :     str	      =self.tail
                  __snake_case   :     Union[str, Any]	      =self.tail.previous
                  __snake_case   :     Optional[Any]	      =None
            else:
                  __snake_case   :     Optional[int]	      =self.head
                  for _ in range(0				, a    ):
                        __snake_case   :     List[Any]	      =temp.next
                  __snake_case   :     Union[str, Any]	      =temp
                  __snake_case   :     Optional[int]	      =temp.previous
                  __snake_case   :     int	      =temp.next
            return delete_node.data


      def _UpperCamelCase    (     self					:						List[Any]				, a					:						Any    ):





            """simple docstring"""







            __snake_case   :     Optional[int]	      =self.head

            while current.data != data:  # Find the position to delete
                  if current.next:
                        __snake_case   :     Dict	      =current.next
                  else:  # We have reached the end an no value matches
                        raise ValueError('''No data matching given value'''    )

            if current == self.head:
                  self.delete_head()

            elif current == self.tail:
                  self.delete_tail()

            else:  # Before: 1 <--> 2(current) <--> 3
                  __snake_case   :     Tuple	      =current.next  # 1 --> 3
                  __snake_case   :     Optional[Any]	      =current.previous  # 1 <--> 3
            return data







      def _UpperCamelCase    (     self					:						int    ):





            """simple docstring"""







            return len(self    ) == 0



def      __lowercase       (     )       ->       None:
      __snake_case   :     List[str]	      =DoublyLinkedList()
      assert linked_list.is_empty() is True
      assert str(a			) == ""

      try:
            linked_list.delete_head()
            raise AssertionError  # This should not happen.
      except IndexError:
            assert True  # This should happen.

      try:
            linked_list.delete_tail()
            raise AssertionError  # This should not happen.
      except IndexError:
            assert True  # This should happen.

      for i in range(10			):
            assert len(a			) == i
            linked_list.insert_at_nth(a							,		i + 1			)
      assert str(a			) == "->".join(str(a			) for i in range(1							,		11			)			)

      linked_list.insert_at_head(0			)
      linked_list.insert_at_tail(11			)
      assert str(a			) == "->".join(str(a			) for i in range(0							,		12			)			)

      assert linked_list.delete_head() == 0
      assert linked_list.delete_at_nth(9			) == 10
      assert linked_list.delete_tail() == 11
      assert len(a			) == 9
      assert str(a			) == "->".join(str(a			) for i in range(1							,		10			)			)


if __name__ == "__main__":
    from doctest import testmod

    testmod()


