






import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin




class       snake_case__ (				lowerCamelCase__):

       '''simple docstring'''
       lowerCamelCase				:					int								=			"""MCTCTFeatureExtractor"""
       lowerCamelCase				:					Any								=			"""AutoTokenizer"""



       def __init__(				self      ,    a__      ,    a__     )			->   Optional[Any]:






            '''simple docstring'''





            super().__init__(snake_case__      ,    snake_case__     )
            __snake_case      :Optional[int] 							=    self.feature_extractor
            __snake_case      :Tuple 							=    False



       def __call__(				self      ,    *a__      ,    **a__     )			->   Optional[int]:






            '''simple docstring'''





            if self._in_target_context_manager:
                 return self.current_processor(*snake_case__      ,    **snake_case__     )

            if "raw_speech" in kwargs:
                 warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""     )
                 __snake_case      :Tuple 							=    kwargs.pop("""raw_speech"""     )
            else:
                 __snake_case      :int 							=    kwargs.pop("""audio"""      ,    snake_case__     )
            __snake_case      :int 							=    kwargs.pop("""sampling_rate"""      ,    snake_case__     )
            __snake_case      :Tuple 							=    kwargs.pop("""text"""      ,    snake_case__     )
            if len(snake_case__     ) > 0:
                 __snake_case      :Dict 							=    args[0]
                 __snake_case      :Union[str, Any] 							=    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:
                 __snake_case      :Tuple 							=    self.feature_extractor(snake_case__      ,    *snake_case__      ,    sampling_rate=snake_case__      ,    **snake_case__     )
            if text is not None:
                 __snake_case      :Optional[Any] 							=    self.tokenizer(snake_case__      ,    **snake_case__     )

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



       def        __lowercase    (				self      ,    *a__      ,    **a__     )			->   int:






            '''simple docstring'''





            return self.tokenizer.batch_decode(*snake_case__      ,    **snake_case__     )



       def        __lowercase    (				self      ,    *a__      ,    **a__     )			->   Tuple:






            '''simple docstring'''





            if self._in_target_context_manager:
                 return self.current_processor.pad(*snake_case__      ,    **snake_case__     )

            __snake_case      :Optional[Any] 							=    kwargs.pop("""input_features"""      ,    snake_case__     )
            __snake_case      :List[Any] 							=    kwargs.pop("""labels"""      ,    snake_case__     )
            if len(snake_case__     ) > 0:
                 __snake_case      :Any 							=    args[0]
                 __snake_case      :Optional[int] 							=    args[1:]

            if input_features is not None:
                 __snake_case      :int 							=    self.feature_extractor.pad(snake_case__      ,    *snake_case__      ,    **snake_case__     )
            if labels is not None:
                 __snake_case      :int 							=    self.tokenizer.pad(snake_case__      ,    **snake_case__     )

            if labels is None:
                 return input_features
            elif input_features is None:
                 return labels
            else:
                 __snake_case      :Optional[int] 							=    labels["""input_ids"""]
                 return input_features



       def        __lowercase    (				self      ,    *a__      ,    **a__     )			->   List[str]:






            '''simple docstring'''





            return self.tokenizer.decode(*snake_case__      ,    **snake_case__     )



       @contextmanager
       def        __lowercase    (				self     )			->   Optional[int]:






            '''simple docstring'''





            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."""     )
            __snake_case      :Dict 							=    True
            __snake_case      :Dict 							=    self.tokenizer
            yield
            __snake_case      :List[str] 							=    self.feature_extractor
            __snake_case      :List[Any] 							=    False









import pytest
import requests

from datasets.utils.file_utils import http_head

from .utils import OfflineSimulationMode, RequestWouldHangIndefinitelyError, offline





@pytest.mark.integration
def  __magic_name__  (				)				-> Union[str, Any]:

							"""simple docstring"""



							with offline(OfflineSimulationMode.CONNECTION_TIMES_OUT				):
														with pytest.raises(lowercase				):
																					requests.request("""GET"""				,       """https://huggingface.co"""				)
														with pytest.raises(requests.exceptions.ConnectTimeout				):
																					requests.request("""GET"""				,       """https://huggingface.co"""				,       timeout=1.0				)





@pytest.mark.integration
def  __magic_name__  (				)				-> Union[str, Any]:

							"""simple docstring"""



							with offline(OfflineSimulationMode.CONNECTION_FAILS				):
														with pytest.raises(requests.exceptions.ConnectionError				):
																					requests.request("""GET"""				,       """https://huggingface.co"""				)





def  __magic_name__  (				)				-> Dict:

							"""simple docstring"""



							with offline(OfflineSimulationMode.HF_DATASETS_OFFLINE_SET_TO_1				):
														with pytest.raises(lowercase				):
																					http_head("""https://huggingface.co"""				)