

'''simple docstring'''






import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


__SCREAMING_SNAKE_CASE     =						get_logger(__name__)






class 			lowerCAmelCase__     (					enum.Enum						):




     """simple docstring"""





     __UpperCamelCase									= "all_checks"
     __UpperCamelCase									= "basic_checks"
     __UpperCamelCase									= "no_checks"






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass



def 			__a		(       lowerCAmelCase__ :    Dict     ,  lowerCAmelCase__ :    Union[str, Any]     ,  lowerCAmelCase__ :    Optional[Any]=None      ):
     if expected_checksums is None:
          logger.info('''Unable to verify checksums.'''      )
          return
     if len(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      ) > 0:
          raise ExpectedMoreDownloadedFiles(str(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      )      )
     if len(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      ) > 0:
          raise UnexpectedDownloadedFile(str(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      )      )
     a__   :      List[Any]     =						[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
     a__   :      Optional[Any]     =						''' for ''' + verification_name if verification_name is not None else ''''''
     if len(lowerCamelCase__      ) > 0:
          raise NonMatchingChecksumError(
              F'Checksums didn\'t match{for_verification_name}:\n'
              F'{bad_urls}\n'
              '''Set `verification_mode=\'no_checks\'` to skip checksums verification and ignore this error'''      )
     logger.info('''All the checksums matched successfully''' + for_verification_name      )






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass






class 			lowerCAmelCase__     (					snake_case_						):




     """simple docstring"""





     pass



def 			__a		(       lowerCAmelCase__ :    Optional[int]     ,  lowerCAmelCase__ :    int      ):
     if expected_splits is None:
          logger.info('''Unable to verify splits sizes.'''      )
          return
     if len(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      ) > 0:
          raise ExpectedMoreSplits(str(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      )      )
     if len(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      ) > 0:
          raise UnexpectedSplits(str(set(lowerCamelCase__      ) - set(lowerCamelCase__      )      )      )
     a__   :      Dict     =						[
         {'''expected''': expected_splits[name], '''recorded''': recorded_splits[name]}
         for name in expected_splits
         if expected_splits[name].num_examples != recorded_splits[name].num_examples
     ]
     if len(lowerCamelCase__      ) > 0:
          raise NonMatchingSplitsSizesError(str(lowerCamelCase__      )      )
     logger.info('''All the splits matched successfully.'''      )



def 			__a		(       lowerCAmelCase__ :    str     ,  lowerCAmelCase__ :    Optional[Any] = True      ):
     if record_checksum:
          a__   :      List[Any]     =						shaaaa()
          with open(lowerCamelCase__     ,  '''rb'''      ) as f:
               for chunk in iter(lambda: f.read(1 << 20      )     ,  b''''''      ):
                    m.update(lowerCamelCase__      )
               a__   :      str     =						m.hexdigest()
     else:
          a__   :      List[str]     =						None
     return {"num_bytes": os.path.getsize(lowerCamelCase__      ), "checksum": checksum}



def 			__a		(       lowerCAmelCase__ :    Optional[Any]      ):
     if dataset_size and config.IN_MEMORY_MAX_SIZE:
          return dataset_size < config.IN_MEMORY_MAX_SIZE
     else:
          return False


import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin




class        _SCREAMING_SNAKE_CASE	( snake_case_		):
	lowerCAmelCase__   =					'MCTCTFeatureExtractor'
	lowerCAmelCase__   =					'AutoTokenizer'



	def __init__(       self		,    lowercase		,    lowercase					)							->			str:
					super().__init__(lowercase		,    lowercase					)
					lowerCamelCase_         =     self.feature_extractor
					lowerCamelCase_         =     False



	def __call__(       self		,    *lowercase		,    **lowercase					)							->			List[str]:
					# For backward compatibility
					if self._in_target_context_manager:
									return self.current_processor(*lowercase		,    **lowercase					)

					if "raw_speech" in kwargs:
									warnings.warn("Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."					)
									lowerCamelCase_         =     kwargs.pop("raw_speech"					)
					else:
									lowerCamelCase_         =     kwargs.pop("audio"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("sampling_rate"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("text"		,    lowercase					)
					if len(lowercase					) > 0:
									lowerCamelCase_         =     args[0]
									lowerCamelCase_         =     args[1:]

					if audio is None and text is None:
									raise ValueError("You need to specify either an `audio` or `text` input to process."					)

					if audio is not None:
									lowerCamelCase_         =     self.feature_extractor(lowercase		,    *lowercase		,    sampling_rate=lowercase		,    **lowercase					)
					if text is not None:
									lowerCamelCase_         =     self.tokenizer(lowercase		,    **lowercase					)

					if text is None:
									return inputs
					elif audio is None:
									return encodings
					else:
									lowerCamelCase_         =     encodings["input_ids"]
									return inputs



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			Optional[Any]:
					return self.tokenizer.batch_decode(*lowercase		,    **lowercase					)



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			Optional[Any]:
					# For backward compatibility
					if self._in_target_context_manager:
									return self.current_processor.pad(*lowercase		,    **lowercase					)

					lowerCamelCase_         =     kwargs.pop("input_features"		,    lowercase					)
					lowerCamelCase_         =     kwargs.pop("labels"		,    lowercase					)
					if len(lowercase					) > 0:
									lowerCamelCase_         =     args[0]
									lowerCamelCase_         =     args[1:]

					if input_features is not None:
									lowerCamelCase_         =     self.feature_extractor.pad(lowercase		,    *lowercase		,    **lowercase					)
					if labels is not None:
									lowerCamelCase_         =     self.tokenizer.pad(lowercase		,    **lowercase					)

					if labels is None:
									return input_features
					elif input_features is None:
									return labels
					else:
									lowerCamelCase_         =     labels["input_ids"]
									return input_features



	def        SCREAMING_SNAKE_CASE_(       self		,    *lowercase		,    **lowercase					)							->			List[str]:
					return self.tokenizer.decode(*lowercase		,    **lowercase					)



	@contextmanager
	def        SCREAMING_SNAKE_CASE_(       self					)							->			Optional[int]:
					warnings.warn(
					    "`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your "
					    "labels by using the argument `text` of the regular `__call__` method (either in the same call as "
					    "your audio inputs, or in a separate call."					)
					lowerCamelCase_         =     True
					lowerCamelCase_         =     self.tokenizer
					yield
					lowerCamelCase_         =     self.feature_extractor
					lowerCamelCase_         =     False


