


import importlib
import shutil
import threading
import warnings
from typing import List

import fsspec
import fsspec.asyn

from . import compression
from .hffilesystem import HfFileSystem


_A			=						importlib.util.find_spec('s3fs') is not None

if _has_safs:
   from .safilesystem import SaFileSystem  # noqa: F401

_A			=						[
    compression.BzaFileSystem,
    compression.GzipFileSystem,
    compression.LzaFileSystem,
    compression.XzFileSystem,
    compression.ZstdFileSystem,
]

# Register custom filesystems
for fs_class in COMPRESSION_FILESYSTEMS + [HfFileSystem]:
   if fs_class.protocol in fsspec.registry and fsspec.registry[fs_class.protocol] is not fs_class:
      warnings.warn(f"""A filesystem protocol was already set for {fs_class.protocol} and will be overwritten.""")
   fsspec.register_implementation(fs_class.protocol, fs_class, clobber=True)

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : str    ):
     if "://" in dataset_path:
          __UpperCamelCase   							=dataset_path.split('://'    )[1]
     return dataset_path

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : fsspec.AbstractFileSystem    ):
     if fs is not None and fs.protocol != "file":
          return True
     else:
          return False

def 						_UpperCAmelCase    (      SCREAMING_SNAKE_CASE__      : fsspec.AbstractFileSystem      ,					SCREAMING_SNAKE_CASE__      : str      ,					SCREAMING_SNAKE_CASE__      : str    ):
     __UpperCamelCase   							=not is_remote_filesystem(SCREAMING_SNAKE_CASE__    )
     if is_local:
          # LocalFileSystem.mv does copy + rm, it is more efficient to simply move a local directory
          shutil.move(fs._strip_protocol(SCREAMING_SNAKE_CASE__    )      ,					fs._strip_protocol(SCREAMING_SNAKE_CASE__    )    )
     else:
          fs.mv(SCREAMING_SNAKE_CASE__      ,					SCREAMING_SNAKE_CASE__      ,					recursive=SCREAMING_SNAKE_CASE__    )





def 						_UpperCAmelCase    (      ):
     if hasattr(fsspec.asyn      ,					'reset_lock'    ):
          # for future fsspec>2022.05.0
          fsspec.asyn.reset_lock()
     else:
          __UpperCamelCase   							=None
          __UpperCamelCase   							=None
          __UpperCamelCase   							=threading.Lock()









import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin






class    UpperCAmelCase__	( A_		):



    """simple docstring"""






    UpperCAmelCase__						:		Optional[int]              =  "MCTCTFeatureExtractor"
    UpperCAmelCase__						:		str              =  "AutoTokenizer"






    def __init__(      self ,       A_ ,       A_   )  ->	Dict:
         super().__init__(A_ ,       A_   )
         __UpperCamelCase   							=self.feature_extractor
         __UpperCamelCase   							=False






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

         if "raw_speech" in kwargs:
              warnings.warn('Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.'   )
              __UpperCamelCase   							=kwargs.pop('raw_speech'   )
         else:
              __UpperCamelCase   							=kwargs.pop('audio' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('sampling_rate' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('text' ,       A_   )
         if len(A_   ) > 0:
              __UpperCamelCase   							=args[0]
              __UpperCamelCase   							=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:
              __UpperCamelCase   							=self.feature_extractor(A_ ,       *A_ ,       sampling_rate=A_ ,       **A_   )
         if text is not None:
              __UpperCamelCase   							=self.tokenizer(A_ ,       **A_   )

         if text is None:
              return inputs
         elif audio is None:
              return encodings
         else:
              __UpperCamelCase   							=encodings['input_ids']
              return inputs






    def _a (      self ,       *A_ ,       **A_   )  ->	str:
         return self.tokenizer.batch_decode(*A_ ,       **A_   )






    def _a (      self ,       *A_ ,       **A_   )  ->	List[Any]:
         # For backward compatibility
         if self._in_target_context_manager:
              return self.current_processor.pad(*A_ ,       **A_   )

         __UpperCamelCase   							=kwargs.pop('input_features' ,       A_   )
         __UpperCamelCase   							=kwargs.pop('labels' ,       A_   )
         if len(A_   ) > 0:
              __UpperCamelCase   							=args[0]
              __UpperCamelCase   							=args[1:]

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

         if labels is None:
              return input_features
         elif input_features is None:
              return labels
         else:
              __UpperCamelCase   							=labels['input_ids']
              return input_features






    def _a (      self ,       *A_ ,       **A_   )  ->	Optional[int]:
         return self.tokenizer.decode(*A_ ,       **A_   )






    @contextmanager
    def _a (      self   )  ->	str:
         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.'   )
         __UpperCamelCase   							=True
         __UpperCamelCase   							=self.tokenizer
         yield
         __UpperCamelCase   							=self.feature_extractor
         __UpperCamelCase   							=False





