


'''simple docstring'''

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,
)


a_  :				str						= """\
    Text data.
    Second line of data."""

a_  :				str						= """file"""





@pytest.fixture(scope="session"		)
def __snake_case					(      UpperCAmelCase_						:						str		):
 lowerCamelCase_      =  tmp_path_factory.mktemp("data"		) / (FILE_PATH + ".zstd")
 lowerCamelCase_      =  bytes(UpperCAmelCase_					,				"utf-8"		)
 with zstd.open(UpperCAmelCase_					,				"wb"		) as f:
  f.write(UpperCAmelCase_		)
 return path





@pytest.fixture
def __snake_case					(      UpperCAmelCase_						:						Union[str, Any]		):
 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 __snake_case					(      UpperCAmelCase_						:						List[str]					,				UpperCAmelCase_						:						Dict					,				UpperCAmelCase_						:						Optional[int]					,				UpperCAmelCase_						:						str					,				UpperCAmelCase_						:						List[str]					,				UpperCAmelCase_						:						Optional[int]		):
 lowerCamelCase_      =  {"gzip": gz_file, "xz": xz_file, "zstd": zstd_path}
 lowerCamelCase_      =  input_paths[compression_format]
 lowerCamelCase_      =  tmp_path / "cache"
 lowerCamelCase_      =  DownloadConfig(cache_dir=UpperCAmelCase_					,				extract_compressed_file=UpperCAmelCase_		)
 lowerCamelCase_      =  cached_path(UpperCAmelCase_					,				download_config=UpperCAmelCase_		)
 with open(UpperCAmelCase_		) as f:
  lowerCamelCase_      =  f.read()
 with open(UpperCAmelCase_		) as f:
  lowerCamelCase_      =  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 __snake_case					(      UpperCAmelCase_						:						Any					,				UpperCAmelCase_						:						Optional[Any]					,				UpperCAmelCase_						:						int					,				UpperCAmelCase_						:						Tuple					,				UpperCAmelCase_						:						List[str]		):
 lowerCamelCase_      =  "custom_cache"
 lowerCamelCase_      =  "custom_extracted_dir"
 lowerCamelCase_      =  tmp_path / "custom_extracted_path"
 if default_extracted:
  lowerCamelCase_      =  ("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_		)		)
  lowerCamelCase_      =  custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

 lowerCamelCase_      =  xz_file
 lowerCamelCase_      =  (
     DownloadConfig(extract_compressed_file=UpperCAmelCase_		)
     if default_cache_dir
     else DownloadConfig(cache_dir=tmp_path / custom_cache_dir					,				extract_compressed_file=UpperCAmelCase_		)
 )
 lowerCamelCase_      =  cached_path(UpperCAmelCase_					,				download_config=UpperCAmelCase_		)
 assert Path(UpperCAmelCase_		).parent.parts[-2:] == expected





def __snake_case					(      UpperCAmelCase_						:						List[str]		):
 # absolute path
 lowerCamelCase_      =  str(Path(UpperCAmelCase_		).resolve()		)
 assert cached_path(UpperCAmelCase_		) == text_file
 # relative path
 lowerCamelCase_      =  str(Path(UpperCAmelCase_		).resolve().relative_to(Path(os.getcwd()		)		)		)
 assert cached_path(UpperCAmelCase_		) == text_file





def __snake_case					(      UpperCAmelCase_						:						Union[str, Any]		):
 # absolute path
 lowerCamelCase_      =  str(tmp_path.resolve() / "__missing_file__.txt"		)
 with pytest.raises(UpperCAmelCase_		):
  cached_path(UpperCAmelCase_		)
 # relative path
 lowerCamelCase_      =  "./__missing_file__.txt"
 with pytest.raises(UpperCAmelCase_		):
  cached_path(UpperCAmelCase_		)





def __snake_case					(      UpperCAmelCase_						:						str		):
 lowerCamelCase_      =  get_from_cache(F'''tmp://{tmpfs_file}'''		)
 with open(UpperCAmelCase_		) as f:
  lowerCamelCase_      =  f.read()
 assert output_file_content == FILE_CONTENT





@patch("datasets.config.HF_DATASETS_OFFLINE"					,				UpperCAmelCase_		)
def __snake_case					(      ):
 with pytest.raises(UpperCAmelCase_		):
  cached_path("https://huggingface.co"		)





@patch("datasets.config.HF_DATASETS_OFFLINE"					,				UpperCAmelCase_		)
def __snake_case					(      UpperCAmelCase_						:						int		):
 lowerCamelCase_      =  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 __snake_case					(      UpperCAmelCase_						:						Optional[int]		):
 lowerCamelCase_      =  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 __snake_case					(      UpperCAmelCase_						:						Dict		):
 lowerCamelCase_      =  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"		)







'''simple docstring'''

from __future__ import annotations





def __snake_case					(      UpperCAmelCase_						:						int		):
 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()



