
import os
from typing import Optional

import fsspec
from fsspec.archive import AbstractArchiveFileSystem
from fsspec.utils import DEFAULT_BLOCK_SIZE





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					=''''''
				_lowercase					=(
				    None  # protocol passed in prefix to the url. ex: "gzip", for gzip://file.txt::http://foo.bar/file.txt.gz
				)
				_lowercase					=None  # compression type in fsspec. ex: "gzip"
				_lowercase					=None  # extension of the filename to strip. ex: "".gz" to get file.txt from file.txt.gz




				def __init__(					self				,				_UpperCamelCase = ""				,				_UpperCamelCase = None				,				_UpperCamelCase = None				,				**_UpperCamelCase     )				->      List[Any]:
							super().__init__(self				,				**_UpperCamelCase     )
							# always open as "rb" since fsspec can then use the TextIOWrapper to make it work for "r" mode
							lowerCAmelCase_						=	fsspec.open(
							    _UpperCamelCase				,				mode="rb"				,				protocol=_UpperCamelCase				,				compression=self.compression				,				client_kwargs={
							        "requote_redirect_url": False,  # see https://github.com/huggingface/datasets/pull/5459
							        "trust_env": True,  # Enable reading proxy env variables.
							        **(target_options or {}).pop("client_kwargs"				,				{}     ),  # To avoid issues if it was already passed.
							    }				,				**(target_options or {})				,				)
							lowerCAmelCase_						=	os.path.basename(self.file.path.split("::"     )[0]     )
							lowerCAmelCase_						=	(
							    self.compressed_name[: self.compressed_name.rindex("."     )]
							    if "." in self.compressed_name
							    else self.compressed_name
							)
							lowerCAmelCase_						=	None




				@classmethod
				def      __a						(					cls				,				_UpperCamelCase     )				->      int:
							# compressed file paths are always relative to the archive root
							return super()._strip_protocol(_UpperCamelCase     ).lstrip("/"     )




				def      __a						(					self     )				->      Optional[Any]:
							if self.dir_cache is None:
										lowerCAmelCase_						=	{**self.file.fs.info(self.file.path     ), "name": self.uncompressed_name}
										lowerCAmelCase_						=	{f["name"]: f}




				def      __a						(					self				,				_UpperCamelCase     )				->      List[str]:
							return self.file.open().read()




				def      __a						(					self				,				_UpperCamelCase				,				_UpperCamelCase = "rb"				,				_UpperCamelCase=None				,				_UpperCamelCase=True				,				_UpperCamelCase=None				,				**_UpperCamelCase				,				)				->      Optional[int]:
							lowerCAmelCase_						=	self._strip_protocol(_UpperCamelCase     )
							if mode != "rb":
										raise ValueError(f"""Tried to read with mode {mode} on file {self.file.path} opened with mode 'rb'"""     )
							return self.file.open()





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					='''bz2'''
				_lowercase					='''bz2'''
				_lowercase					='''.bz2'''





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					='''gzip'''
				_lowercase					='''gzip'''
				_lowercase					='''.gz'''





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					='''lz4'''
				_lowercase					='''lz4'''
				_lowercase					='''.lz4'''





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					='''xz'''
				_lowercase					='''xz'''
				_lowercase					='''.xz'''





class 	_lowerCAmelCase					(	__a       ):
				_lowercase					='''zstd'''
				_lowercase					='''zstd'''
				_lowercase					='''.zst'''




				def __init__(					self				,				_UpperCamelCase				,				_UpperCamelCase = "rb"				,				_UpperCamelCase = None				,				_UpperCamelCase = None				,				_UpperCamelCase = DEFAULT_BLOCK_SIZE				,				**_UpperCamelCase				,				)				->      Any:
							super().__init__(
							    fo=_UpperCamelCase				,				mode=_UpperCamelCase				,				target_protocol=_UpperCamelCase				,				target_options=_UpperCamelCase				,				block_size=_UpperCamelCase				,				**_UpperCamelCase				,				)
							# We need to wrap the zstd decompressor to avoid this error in fsspec==2021.7.0 and zstandard==0.15.2:
							#
							# File "/Users/user/.virtualenvs/hf-datasets/lib/python3.7/site-packages/fsspec/core.py", line 145, in open
							#     out.close = close
							# AttributeError: 'zstd.ZstdDecompressionReader' object attribute 'close' is read-only
							#
							# see https://github.com/intake/filesystem_spec/issues/725
							lowerCAmelCase_						=	self.file.__enter__





							class 	_lowerCAmelCase					:




											def __init__(					self				,				_UpperCamelCase     )				->      Tuple:
														lowerCAmelCase_						=	file_




											def __enter__(					self     )				->      List[str]:
														self._file.__enter__()
														return self




											def __exit__(					self				,				*_UpperCamelCase				,				**_UpperCamelCase     )				->      Optional[int]:
														self._file.__exit__(*_UpperCamelCase				,				**_UpperCamelCase     )




											def __iter__(					self     )				->      str:
														return iter(self._file     )




											def      __a						(					self     )				->      Any:
														return next(self._file     )




											def __getattr__(					self				,				_UpperCamelCase     )				->      Any:
														return getattr(self._file				,				_UpperCamelCase     )

							def fixed_enter(*_UpperCamelCase				,				**_UpperCamelCase     ):
										return WrappedFile(_enter(*_UpperCamelCase				,				**_UpperCamelCase     )     )

							lowerCAmelCase_						=	fixed_enter





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_speech_available,
    is_tf_available,
    is_torch_available,
)


_A   =     {
    "configuration_speech_to_text": ["SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP", "Speech2TextConfig"],
    "processing_speech_to_text": ["Speech2TextProcessor"],
}

try:
			if not is_sentencepiece_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     ["Speech2TextTokenizer"]

try:
			if not is_speech_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     ["Speech2TextFeatureExtractor"]

try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     [
			    "TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "TFSpeech2TextForConditionalGeneration",
			    "TFSpeech2TextModel",
			    "TFSpeech2TextPreTrainedModel",
			]

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_A   =     [
			    "SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST",
			    "Speech2TextForConditionalGeneration",
			    "Speech2TextModel",
			    "Speech2TextPreTrainedModel",
			]


if TYPE_CHECKING:
			from .configuration_speech_to_text import SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextConfig
			from .processing_speech_to_text import SpeechaTextProcessor

			try:
						if not is_sentencepiece_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .tokenization_speech_to_text import SpeechaTextTokenizer

			try:
						if not is_speech_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .feature_extraction_speech_to_text import SpeechaTextFeatureExtractor

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_speech_to_text import (
						    TF_SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    TFSpeechaTextForConditionalGeneration,
						    TFSpeechaTextModel,
						    TFSpeechaTextPreTrainedModel,
						)

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_speech_to_text import (
						    SPEECH_TO_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    SpeechaTextForConditionalGeneration,
						    SpeechaTextModel,
						    SpeechaTextPreTrainedModel,
						)

else:
			import sys

			_A   =     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



