


'''simple docstring'''







import importlib
import os

import fsspec
import pytest
from fsspec import register_implementation
from fsspec.registry import _registry as _fsspec_registry

from datasets.filesystems import COMPRESSION_FILESYSTEMS, HfFileSystem, extract_path_from_uri, is_remote_filesystem

from .utils import require_lza, require_zstandard






def 			lowercase				(_A					):







       """simple docstring"""







       assert "mock" in _fsspec_registry
       assert "bz2" in _fsspec_registry






def 			lowercase				():







       """simple docstring"""







       assert "mock" not in _fsspec_registry
       assert "bz2" in _fsspec_registry






def 			lowercase				():







       """simple docstring"""







       _lowerCAmelCase    :							int   			=       'mock-s3-bucket'
       _lowerCAmelCase    :							str   			=       f's3://{mock_bucket}'
       _lowerCAmelCase    :							Any   			=       extract_path_from_uri(lowerCAmelCase__					)
       assert dataset_path.startswith('s3://'					) is False

       _lowerCAmelCase    :							List[Any]   			=       './local/path'
       _lowerCAmelCase    :							str   			=       extract_path_from_uri(lowerCAmelCase__					)
       assert dataset_path == new_dataset_path






def 			lowercase				(_A					):







       """simple docstring"""







       _lowerCAmelCase    :							int   			=       is_remote_filesystem(lowerCAmelCase__					)
       assert is_remote is True

       _lowerCAmelCase    :							Union[str, Any]   			=       fsspec.filesystem('file'					)

       _lowerCAmelCase    :							List[str]   			=       is_remote_filesystem(lowerCAmelCase__					)
       assert is_remote is False






@pytest.mark.parametrize('compression_fs_class'   ,						lowerCAmelCase__					)
def 			lowercase				(_A   ,						_A   ,						_A   ,						_A   ,						_A   ,						_A   ,						_A					):







       """simple docstring"""







       _lowerCAmelCase    :							List[str]   			=       {'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_file, 'bz2': bza_file, 'lz4': lza_file}
       _lowerCAmelCase    :							int   			=       input_paths[compression_fs_class.protocol]
       if input_path is None:
              _lowerCAmelCase    :							int   			=       f'for \'{compression_fs_class.protocol}\' compression protocol, '
              if compression_fs_class.protocol == "lz4":
                     reason += require_lza.kwargs["reason"]
              elif compression_fs_class.protocol == "zstd":
                     reason += require_zstandard.kwargs["reason"]
              pytest.skip(lowerCAmelCase__					)
       _lowerCAmelCase    :							List[Any]   			=       fsspec.filesystem(compression_fs_class.protocol   ,						fo=lowerCAmelCase__					)
       assert isinstance(lowerCAmelCase__   ,						lowerCAmelCase__					)
       _lowerCAmelCase    :							Tuple   			=       os.path.basename(lowerCAmelCase__					)
       _lowerCAmelCase    :							Any   			=       expected_filename[: expected_filename.rindex('.'					)]
       assert fs.glob('*'					) == [expected_filename]
       with fs.open(lowerCAmelCase__   ,						'r'   ,						encoding='utf-8'					) as f, open(lowerCAmelCase__   ,						encoding='utf-8'					) as expected_file:
              assert f.read() == expected_file.read()






@pytest.mark.parametrize('protocol'   ,						['zip', 'gzip']					)
def 			lowercase				(_A   ,						_A   ,						_A					):







       """simple docstring"""







       _lowerCAmelCase    :							Dict   			=       {'zip': zip_jsonl_path, 'gzip': jsonl_gz_path}
       _lowerCAmelCase    :							int   			=       compressed_file_paths[protocol]
       _lowerCAmelCase    :							List[Any]   			=       'dataset.jsonl'
       _lowerCAmelCase    :							Any   			=       f'{protocol}://{member_file_path}::{compressed_file_path}'
       _lowerCAmelCase    :							List[str]   			=       fsspec.get_fs_token_paths(lowerCAmelCase__					)
       assert fs.isfile(lowerCAmelCase__					)
       assert not fs.isfile('non_existing_' + member_file_path					)






@pytest.mark.integration
def 			lowercase				(_A   ,						_A   ,						_A   ,						_A					):







       """simple docstring"""







       _lowerCAmelCase    :							Tuple   			=       hf_api.dataset_info(lowerCAmelCase__   ,						token=lowerCAmelCase__					)
       _lowerCAmelCase    :							Union[str, Any]   			=       HfFileSystem(repo_info=lowerCAmelCase__   ,						token=lowerCAmelCase__					)
       assert sorted(hffs.glob('*'					)					) == [".gitattributes", "data"]
       assert hffs.isdir('data'					)
       assert hffs.isfile('.gitattributes'					) and hffs.isfile('data/text_data.txt'					)
       with open(lowerCAmelCase__					) as f:
              assert hffs.open('data/text_data.txt'   ,						'r'					).read() == f.read()






def 			lowercase				():







       """simple docstring"""







       _lowerCAmelCase    :							int   			=       'bz2'

       # Import module
       import datasets.filesystems

       # Overwrite protocol and reload
       register_implementation(lowerCAmelCase__   ,						lowerCAmelCase__   ,						clobber=lowerCAmelCase__					)
       with pytest.warns(lowerCAmelCase__					) as warning_info:
              importlib.reload(datasets.filesystems					)

       assert len(lowerCAmelCase__					) == 1
       assert (
           str(warning_info[0].message					)
           == f'A filesystem protocol was already set for {protocol} and will be overwritten.'
       )





'''simple docstring'''







from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase    :     Optional[int]					=						{
    """configuration_mctct""": ["""MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """MCTCTConfig"""],
    """feature_extraction_mctct""": ["""MCTCTFeatureExtractor"""],
    """processing_mctct""": ["""MCTCTProcessor"""],
}


try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       lowerCAmelCase    :     List[str]					=						[
           """MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """MCTCTForCTC""",
           """MCTCTModel""",
           """MCTCTPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
       from .feature_extraction_mctct import MCTCTFeatureExtractor
       from .processing_mctct import MCTCTProcessor

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
       import sys

       lowerCAmelCase    :     Tuple					=						_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)

