



"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A_						:    Any				=      {
    'configuration_electra': ['ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ElectraConfig', 'ElectraOnnxConfig'],
    'tokenization_electra': ['ElectraTokenizer'],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A_						:    Dict				=      ['ElectraTokenizerFast']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A_						:    Optional[Any]				=      [
							    'ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'ElectraForCausalLM',
							    'ElectraForMaskedLM',
							    'ElectraForMultipleChoice',
							    'ElectraForPreTraining',
							    'ElectraForQuestionAnswering',
							    'ElectraForSequenceClassification',
							    'ElectraForTokenClassification',
							    'ElectraModel',
							    'ElectraPreTrainedModel',
							    'load_tf_weights_in_electra',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A_						:    Optional[Any]				=      [
							    'TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFElectraForMaskedLM',
							    'TFElectraForMultipleChoice',
							    'TFElectraForPreTraining',
							    'TFElectraForQuestionAnswering',
							    'TFElectraForSequenceClassification',
							    'TFElectraForTokenClassification',
							    'TFElectraModel',
							    'TFElectraPreTrainedModel',
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							A_						:    Union[str, Any]				=      [
							    'FlaxElectraForCausalLM',
							    'FlaxElectraForMaskedLM',
							    'FlaxElectraForMultipleChoice',
							    'FlaxElectraForPreTraining',
							    'FlaxElectraForQuestionAnswering',
							    'FlaxElectraForSequenceClassification',
							    'FlaxElectraForTokenClassification',
							    'FlaxElectraModel',
							    'FlaxElectraPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_electra import ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP, ElectraConfig, ElectraOnnxConfig
							from .tokenization_electra import ElectraTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_electra_fast import ElectraTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_electra import (
														    ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    ElectraForCausalLM,
														    ElectraForMaskedLM,
														    ElectraForMultipleChoice,
														    ElectraForPreTraining,
														    ElectraForQuestionAnswering,
														    ElectraForSequenceClassification,
														    ElectraForTokenClassification,
														    ElectraModel,
														    ElectraPreTrainedModel,
														    load_tf_weights_in_electra,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_electra import (
														    TF_ELECTRA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFElectraForMaskedLM,
														    TFElectraForMultipleChoice,
														    TFElectraForPreTraining,
														    TFElectraForQuestionAnswering,
														    TFElectraForSequenceClassification,
														    TFElectraForTokenClassification,
														    TFElectraModel,
														    TFElectraPreTrainedModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_electra import (
														    FlaxElectraForCausalLM,
														    FlaxElectraForMaskedLM,
														    FlaxElectraForMultipleChoice,
														    FlaxElectraForPreTraining,
														    FlaxElectraForQuestionAnswering,
														    FlaxElectraForSequenceClassification,
														    FlaxElectraForTokenClassification,
														    FlaxElectraModel,
														    FlaxElectraPreTrainedModel,
														)

else:
							import sys

							A_						:    Dict				=      _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)










"""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  __snake_case							(	__A      :						str     )     ->       Dict:






				'''simple docstring'''
				assert "mock" in _fsspec_registry
				assert "bz2" in _fsspec_registry
def  __snake_case							(	)     ->       Union[str, Any]:






				'''simple docstring'''
				assert "mock" not in _fsspec_registry
				assert "bz2" in _fsspec_registry
def  __snake_case							(	)     ->       Tuple:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							Tuple							=     'mock-s3-bucket'
				SCREAMING_SNAKE_CASE						:							Tuple							=     F"""s3://{mock_bucket}"""
				SCREAMING_SNAKE_CASE						:							str							=     extract_path_from_uri(__A     )
				assert dataset_path.startswith('s3://'     ) is False

				SCREAMING_SNAKE_CASE						:							Optional[int]							=     './local/path'
				SCREAMING_SNAKE_CASE						:							str							=     extract_path_from_uri(__A     )
				assert dataset_path == new_dataset_path
def  __snake_case							(	__A      :						Tuple     )     ->       Optional[int]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							Tuple							=     is_remote_filesystem(__A     )
				assert is_remote is True

				SCREAMING_SNAKE_CASE						:							Dict							=     fsspec.filesystem('file'     )

				SCREAMING_SNAKE_CASE						:							Dict							=     is_remote_filesystem(__A     )
				assert is_remote is False
@pytest.mark.parametrize('compression_fs_class'							,		__A     )
def  __snake_case							(	__A      :						Any							,		__A      :						Optional[int]							,		__A      :						List[Any]							,		__A      :						Optional[Any]							,		__A      :						str							,		__A      :						Tuple							,		__A      :						Dict     )     ->       Tuple:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     {'gzip': gz_file, 'xz': xz_file, 'zstd': zstd_file, 'bz2': bza_file, 'lz4': lza_file}
				SCREAMING_SNAKE_CASE						:							List[Any]							=     input_paths[compression_fs_class.protocol]
				if input_path is None:
								SCREAMING_SNAKE_CASE						:							str							=     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(__A     )
				SCREAMING_SNAKE_CASE						:							Any							=     fsspec.filesystem(compression_fs_class.protocol							,		fo=__A     )
				assert isinstance(__A							,		__A     )
				SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     os.path.basename(__A     )
				SCREAMING_SNAKE_CASE						:							Dict							=     expected_filename[: expected_filename.rindex('.'     )]
				assert fs.glob('*'     ) == [expected_filename]
				with fs.open(__A							,		'r'							,		encoding='utf-8'     ) as f, open(__A							,		encoding='utf-8'     ) as expected_file:
								assert f.read() == expected_file.read()
@pytest.mark.parametrize('protocol'							,		['zip', 'gzip']     )
def  __snake_case							(	__A      :						Any							,		__A      :						int							,		__A      :						Union[str, Any]     )     ->       Union[str, Any]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							List[Any]							=     {'zip': zip_jsonl_path, 'gzip': jsonl_gz_path}
				SCREAMING_SNAKE_CASE						:							Optional[int]							=     compressed_file_paths[protocol]
				SCREAMING_SNAKE_CASE						:							str							=     'dataset.jsonl'
				SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     F"""{protocol}://{member_file_path}::{compressed_file_path}"""
				SCREAMING_SNAKE_CASE				,						*SCREAMING_SNAKE_CASE						:							Any							=     fsspec.get_fs_token_paths(__A     )
				assert fs.isfile(__A     )
				assert not fs.isfile('non_existing_' + member_file_path     )
@pytest.mark.integration
def  __snake_case							(	__A      :						List[str]							,		__A      :						int							,		__A      :						int							,		__A      :						Optional[int]     )     ->       Union[str, Any]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							List[str]							=     hf_api.dataset_info(__A							,		token=__A     )
				SCREAMING_SNAKE_CASE						:							str							=     HfFileSystem(repo_info=__A							,		token=__A     )
				assert sorted(hffs.glob('*'     )     ) == [".gitattributes", "data"]
				assert hffs.isdir('data'     )
				assert hffs.isfile('.gitattributes'     ) and hffs.isfile('data/text_data.txt'     )
				with open(__A     ) as f:
								assert hffs.open('data/text_data.txt'							,		'r'     ).read() == f.read()







def  __snake_case							(	)     ->       Union[str, Any]:






				'''simple docstring'''
				SCREAMING_SNAKE_CASE						:							Optional[int]							=     'bz2'

				# Import module
				import datasets.filesystems

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

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





