code: 
  
  
  
  
  
  
  import os
  import warnings
  from pathlib import Path
  from typing import Optional, Union
  
  from .dynamic_module_utils import custom_object_save
  from .tokenization_utils_base import PreTrainedTokenizerBase
  from .utils import PushToHubMixin, copy_func, direct_transformers_import, logging
  
  
  lowerCamelCase										=  logging.get_logger(__name__)
  
  # Dynamically import the Transformers module to grab the attribute classes of the processor form their names.
  lowerCamelCase										=  direct_transformers_import(Path(__file__).parent)
  
  
  lowerCamelCase										=  {
      '''AutoTokenizer''': '''PreTrainedTokenizerBase''',
      '''AutoFeatureExtractor''': '''FeatureExtractionMixin''',
      '''AutoImageProcessor''': '''ImageProcessingMixin''',
  }
  
  class 					snake_case_							(       lowercase_      ):
  
  
  
  
  
  
  
     """simple docstring"""
  
  
  
     __lowerCAmelCase      =						["""feature_extractor""", """tokenizer"""]
     # Names need to be attr_class for attr in attributes
     __lowerCAmelCase      =						None
     __lowerCAmelCase      =						None
     __lowerCAmelCase      =						None
  
     def __init__(    self:	List[str]   ,       *snake_case__:	str   ,       **snake_case__:	Union[str, Any]	)  ->		Optional[Any]:
  
  
         """simple docstring"""
  
  
  
         for key in kwargs:
             if key not in self.attributes:
                 raise TypeError(f'''Unexpected keyword argument {key}.'''	)
         for arg, attribute_name in zip(snake_case__   ,       self.attributes	):
             if attribute_name in kwargs:
                 raise TypeError(f'''Got multiple values for argument {attribute_name}.'''	)
             else:
                 _lowercase     =	arg
  
         if len(snake_case__	) != len(self.attributes	):
             raise ValueError(
                 f'''This processor requires {len(self.attributes	)} arguments: {", ".join(self.attributes	)}. Got '''
                 f'''{len(snake_case__	)} arguments instead.'''	)
  
         # Check each arg is of the proper class (this will also catch a user initializing in the wrong order)
         for attribute_name, arg in kwargs.items():
             _lowercase     =	getattr(self   ,       f'''{attribute_name}_class'''	)
             # Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
             _lowercase     =	AUTO_TO_BASE_CLASS_MAPPING.get(snake_case__   ,       snake_case__	)
             if isinstance(snake_case__   ,       snake_case__	):
                 _lowercase     =	tuple(getattr(snake_case__   ,       snake_case__	) for n in class_name if n is not None	)
             else:
                 _lowercase     =	getattr(snake_case__   ,       snake_case__	)
  
             if not isinstance(snake_case__   ,       snake_case__	):
                 raise ValueError(
                     f'''Received a {type(snake_case__	).__name__} for argument {attribute_name}, but a {class_name} was expected.'''	)
  
             setattr(self   ,       snake_case__   ,       snake_case__	)
  
     def __repr__(    self:	List[Any]	)  ->		Union[str, Any]:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	[f'''- {name}: {repr(getattr(self   ,       snake_case__	)	)}''' for name in self.attributes]
         _lowercase     =	'\n'.join(snake_case__	)
         return f'''{self.__class__.__name__}:\n{attributes_repr}'''
  
     def 			SCREAMING_SNAKE_CASE__				(    self:	Optional[Any]   ,       snake_case__:	Any   ,       snake_case__:	bool = False   ,       **snake_case__:	Union[str, Any]	)  ->		List[Any]:
  
  
         """simple docstring"""
  
  
  
         os.makedirs(snake_case__   ,       exist_ok=snake_case__	)
  
         if push_to_hub:
             _lowercase     =	kwargs.pop('commit_message'   ,       snake_case__	)
             _lowercase     =	kwargs.pop('repo_id'   ,       save_directory.split(os.path.sep	)[-1]	)
             _lowercase     =	self._create_repo(snake_case__   ,       **snake_case__	)
             _lowercase     =	self._get_files_timestamps(snake_case__	)
         # If we have a custom config, we copy the file defining it in the folder and set the attributes so it can be
         # loaded from the Hub.
         if self._auto_class is not None:
             _lowercase     =	[getattr(self   ,       snake_case__	) for attribute_name in self.attributes]
             _lowercase     =	[(a.init_kwargs if isinstance(snake_case__   ,       snake_case__	) else a) for a in attrs]
             custom_object_save(self   ,       snake_case__   ,       config=snake_case__	)
  
         for attribute_name in self.attributes:
             _lowercase     =	getattr(self   ,       snake_case__	)
             # Include the processor class in the attribute config so this processor can then be reloaded with the
             # `AutoProcessor` API.
             if hasattr(snake_case__   ,       '_set_processor_class'	):
                 attribute._set_processor_class(self.__class__.__name__	)
             attribute.save_pretrained(snake_case__	)
  
         if self._auto_class is not None:
             # We added an attribute to the init_kwargs of the tokenizers, which needs to be cleaned up.
             for attribute_name in self.attributes:
                 _lowercase     =	getattr(self   ,       snake_case__	)
                 if isinstance(snake_case__   ,       snake_case__	):
                     del attribute.init_kwargs["auto_map"]
  
         if push_to_hub:
             self._upload_modified_files(
                 snake_case__   ,       snake_case__   ,       snake_case__   ,       commit_message=snake_case__   ,       token=kwargs.get('use_auth_token'	)   ,       )
  
     @classmethod
     def 			SCREAMING_SNAKE_CASE__				(    cls:	str   ,       snake_case__:	Union[str, os.PathLike]   ,       snake_case__:	Optional[Union[str, os.PathLike]] = None   ,       snake_case__:	bool = False   ,       snake_case__:	bool = False   ,       snake_case__:	Optional[Union[str, bool]] = None   ,       snake_case__:	str = "main"   ,       **snake_case__:	Optional[int]   ,       )  ->		List[Any]:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	cache_dir
         _lowercase     =	force_download
         _lowercase     =	local_files_only
         _lowercase     =	revision
  
         _lowercase     =	kwargs.pop('use_auth_token'   ,       snake_case__	)
         if use_auth_token is not None:
             warnings.warn(
                 'The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers.'   ,       snake_case__	)
             if token is not None:
                 raise ValueError(
                     '`token` and `use_auth_token` are both specified. Please set only the argument `token`.'	)
             _lowercase     =	use_auth_token
  
         if token is not None:
             # change to `token` in a follow-up PR
             _lowercase     =	token
  
         _lowercase     =	cls._get_arguments_from_pretrained(snake_case__   ,       **snake_case__	)
         return cls(*snake_case__	)
  
     @classmethod
     def 			SCREAMING_SNAKE_CASE__				(    cls:	int   ,       snake_case__:	int="AutoProcessor"	)  ->		str:
  
  
         """simple docstring"""
  
  
  
         if not isinstance(snake_case__   ,       snake_case__	):
             _lowercase     =	auto_class.__name__
  
         import transformers.models.auto as auto_module
  
         if not hasattr(snake_case__   ,       snake_case__	):
             raise ValueError(f'''{auto_class} is not a valid auto class.'''	)
  
         _lowercase     =	auto_class
  
     @classmethod
     def 			SCREAMING_SNAKE_CASE__				(    cls:	List[Any]   ,       snake_case__:	int   ,       **snake_case__:	int	)  ->		str:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	[]
         for attribute_name in cls.attributes:
             _lowercase     =	getattr(cls   ,       f'''{attribute_name}_class'''	)
             if isinstance(snake_case__   ,       snake_case__	):
                 _lowercase     =	tuple(getattr(snake_case__   ,       snake_case__	) if n is not None else None for n in class_name	)
                 _lowercase     =	kwargs.get('use_fast'   ,       snake_case__	)
                 if use_fast and classes[1] is not None:
                     _lowercase     =	classes[1]
                 else:
                     _lowercase     =	classes[0]
             else:
                 _lowercase     =	getattr(snake_case__   ,       snake_case__	)
  
             args.append(attribute_class.from_pretrained(snake_case__   ,       **snake_case__	)	)
         return args
  
     @property
     def 			SCREAMING_SNAKE_CASE__				(    self:	Dict	)  ->		str:
  
  
         """simple docstring"""
  
  
  
         _lowercase     =	getattr(self   ,       self.attributes[0]	)
         return getattr(snake_case__   ,       'model_input_names'   ,       snake_case__	)
  
  
  
  
  
  
  lowerCamelCase										=  copy_func(ProcessorMixin.push_to_hub)
  if ProcessorMixin.push_to_hub.__doc__ is not None:
     lowerCamelCase										=  ProcessorMixin.push_to_hub.__doc__.format(
         object='''processor''', object_class='''AutoProcessor''', object_files='''processor files'''
     )
  
style_context: 
  
  
  
  
  
  
  from __future__ import annotations
  def        UpperCAmelCase      (   _lowercase,      _lowercase      ):
  
  
      '''simple docstring'''
  
  
  
      _lowercase     =	[None] * (len(_lowercase      ) + len(_lowercase      ))
  
      _lowercase     =	0  # pointer to current index for left Half
      _lowercase     =	0  # pointer to current index for the right Half
      _lowercase     =	0  # pointer to current index for the sorted array Half
  
      while pointera < len(_lowercase      ) and pointera < len(_lowercase      ):
          if left_half[pointera] < right_half[pointera]:
              _lowercase     =	left_half[pointera]
              pointera += 1
              index += 1
          else:
              _lowercase     =	right_half[pointera]
              pointera += 1
              index += 1
      while pointera < len(_lowercase      ):
          _lowercase     =	left_half[pointera]
          pointera += 1
          index += 1
  
      while pointera < len(_lowercase      ):
          _lowercase     =	right_half[pointera]
          pointera += 1
          index += 1
  
      return sorted_array
  def        UpperCAmelCase      (   _lowercase      ):
  
  
      '''simple docstring'''
  
  
  
      if len(_lowercase      ) <= 1:
          return array
      # the actual formula to calculate the middle element = left + (right - left) // 2
      # this avoids integer overflow in case of large N
      _lowercase     =	0 + (len(_lowercase      ) - 0) // 2
  
      # Split the array into halves till the array length becomes equal to One
      # merge the arrays of single length returned by mergeSort function and
      # pass them into the merge arrays function which merges the array
      _lowercase     =	array[:middle]
      _lowercase     =	array[middle:]
  
      return merge(merge_sort(_lowercase      ),      merge_sort(_lowercase      )      )
  
  
  if __name__ == "__main__":
     import doctest
  
     doctest.testmod()
  