





import os
from pathlib import Path
from unittest.mock import patch

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


lowerCAmelCase							:       Optional[Any]					 =	'\\n    Text data.\n    Second line of data.'

lowerCAmelCase							:       Optional[Any]					 =	'file'






@pytest.fixture(scope='''session'''					)
def 		lowerCAmelCase  (	UpperCamelCase__   :   List[Any]					)      ->    List[Any]:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Any           =   tmp_path_factory.mktemp('''data'''					) / (FILE_PATH + '''.zstd''')
						__SCREAMING_SNAKE_CASE:				Tuple           =   bytes(UpperCAmelCase__       ,			'''utf-8'''					)
						with zstd.open(UpperCAmelCase__       ,			'''wb'''					) as f:
												f.write(UpperCAmelCase__					)
						return path






@pytest.fixture
def 		lowerCAmelCase  (	UpperCamelCase__   :   List[Any]					)      ->    Union[str, Any]:

						"""simple docstring"""





						with open(os.path.join(tmpfs.local_root_dir       ,			UpperCAmelCase__					)       ,			'''w'''					) as f:
												f.write(UpperCAmelCase__					)
						return FILE_PATH






@pytest.mark.parametrize('''compression_format'''       ,			['''gzip''', '''xz''', '''zstd''']					)
def 		lowerCAmelCase  (	UpperCamelCase__   :   Tuple       ,			UpperCamelCase__   :   Optional[Any]       ,			UpperCamelCase__   :   Optional[Any]       ,			UpperCamelCase__   :   str       ,			UpperCamelCase__   :   Dict       ,			UpperCamelCase__   :   int					)      ->    int:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Optional[Any]           =   {'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
						__SCREAMING_SNAKE_CASE:				Optional[int]           =   input_paths[compression_format]
						__SCREAMING_SNAKE_CASE:				Optional[int]           =   tmp_path / '''cache'''
						__SCREAMING_SNAKE_CASE:				Dict           =   DownloadConfig(cache_dir=UpperCAmelCase__       ,			extract_compressed_file=UpperCAmelCase__					)
						__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   cached_path(UpperCAmelCase__       ,			download_config=UpperCAmelCase__					)
						with open(UpperCAmelCase__					) as f:
												__SCREAMING_SNAKE_CASE:				Tuple           =   f.read()
						with open(UpperCAmelCase__					) as f:
												__SCREAMING_SNAKE_CASE:				List[str]           =   f.read()
						assert extracted_file_content == expected_file_content






@pytest.mark.parametrize('''default_extracted'''       ,			[True, False]					)
@pytest.mark.parametrize('''default_cache_dir'''       ,			[True, False]					)
def 		lowerCAmelCase  (	UpperCamelCase__   :   int       ,			UpperCamelCase__   :   List[str]       ,			UpperCamelCase__   :   int       ,			UpperCamelCase__   :   List[Any]       ,			UpperCamelCase__   :   Union[str, Any]					)      ->    int:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				List[Any]           =   '''custom_cache'''
						__SCREAMING_SNAKE_CASE:				Optional[int]           =   '''custom_extracted_dir'''
						__SCREAMING_SNAKE_CASE:				List[Any]           =   tmp_path / '''custom_extracted_path'''
						if default_extracted:
												__SCREAMING_SNAKE_CASE:				Tuple           =   ('''downloads''' if default_cache_dir else custom_cache_dir, '''extracted''')
						else:
												monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_DIR'''       ,			UpperCAmelCase__					)
												monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''       ,			str(UpperCAmelCase__					)					)
												__SCREAMING_SNAKE_CASE:				Optional[Any]           =   custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

						__SCREAMING_SNAKE_CASE:				Optional[int]           =   xz_file
						__SCREAMING_SNAKE_CASE:				str           =   (
						    DownloadConfig(extract_compressed_file=UpperCAmelCase__					)
						    if default_cache_dir
						    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir       ,			extract_compressed_file=UpperCAmelCase__					)
						)
						__SCREAMING_SNAKE_CASE:				List[str]           =   cached_path(UpperCAmelCase__       ,			download_config=UpperCAmelCase__					)
						assert Path(UpperCAmelCase__					).parent.parts[-2:] == expected






def 		lowerCAmelCase  (	UpperCamelCase__   :   Union[str, Any]					)      ->    Optional[Any]:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   str(Path(UpperCAmelCase__					).resolve()					)
						assert cached_path(UpperCAmelCase__					) == text_file
						# relative path
						__SCREAMING_SNAKE_CASE:				int           =   str(Path(UpperCAmelCase__					).resolve().relative_to(Path(os.getcwd()					)					)					)
						assert cached_path(UpperCAmelCase__					) == text_file






def 		lowerCAmelCase  (	UpperCamelCase__   :   Any					)      ->    str:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				List[Any]           =   str(tmp_path.resolve() / '''__missing_file__.txt'''					)
						with pytest.raises(UpperCAmelCase__					):
												cached_path(UpperCAmelCase__					)
						# relative path
						__SCREAMING_SNAKE_CASE:				Any           =   '''./__missing_file__.txt'''
						with pytest.raises(UpperCAmelCase__					):
												cached_path(UpperCAmelCase__					)






def 		lowerCAmelCase  (	UpperCamelCase__   :   List[str]					)      ->    Optional[int]:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Optional[int]           =   get_from_cache(F"""tmp://{tmpfs_file}"""					)
						with open(UpperCAmelCase__					) as f:
												__SCREAMING_SNAKE_CASE:				Any           =   f.read()
						assert output_file_content == FILE_CONTENT






@patch('''datasets.config.HF_DATASETS_OFFLINE'''       ,			UpperCAmelCase__					)
def 		lowerCAmelCase  (	)      ->    List[str]:

						"""simple docstring"""





						with pytest.raises(UpperCAmelCase__					):
												cached_path('''https://huggingface.co'''					)






@patch('''datasets.config.HF_DATASETS_OFFLINE'''       ,			UpperCAmelCase__					)
def 		lowerCAmelCase  (	UpperCamelCase__   :   List[Any]					)      ->    Any:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Optional[int]           =   tmp_path_factory.mktemp('''data'''					) / '''file.html'''
						with pytest.raises(UpperCAmelCase__					):
												http_get('''https://huggingface.co'''       ,			temp_file=UpperCAmelCase__					)
						with pytest.raises(UpperCAmelCase__					):
												http_head('''https://huggingface.co'''					)






@patch('''datasets.config.HF_DATASETS_OFFLINE'''       ,			UpperCAmelCase__					)
def 		lowerCAmelCase  (	UpperCamelCase__   :   Optional[Any]					)      ->    Union[str, Any]:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				List[str]           =   tmp_path_factory.mktemp('''data'''					) / '''file.html'''
						with pytest.raises(UpperCAmelCase__					):
												ftp_get('''ftp://huggingface.co'''       ,			temp_file=UpperCAmelCase__					)
						with pytest.raises(UpperCAmelCase__					):
												ftp_head('''ftp://huggingface.co'''					)






@patch('''datasets.config.HF_DATASETS_OFFLINE'''       ,			UpperCAmelCase__					)
def 		lowerCAmelCase  (	UpperCamelCase__   :   List[Any]					)      ->    str:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Tuple           =   tmp_path_factory.mktemp('''data'''					) / '''file.html'''
						with pytest.raises(UpperCAmelCase__					):
												fsspec_get('''s3://huggingface.co'''       ,			temp_file=UpperCAmelCase__					)
						with pytest.raises(UpperCAmelCase__					):
												fsspec_head('''s3://huggingface.co'''					)








from __future__ import annotations

def      __lowercase(						UpperCAmelCase__			):


      """simple docstring"""



      lowerCamelCase             =		2
      lowerCamelCase             =		[]
      while i * i <= n:
            if n % i:
                  i += 1
            else:
                  n //= i
                  factors.append(UpperCAmelCase__			)
      if n > 1:
            factors.append(UpperCAmelCase__			)
      return factors


if __name__ == "__main__":
     import doctest

     doctest.testmod()