






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


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

_UpperCamelCase						:						str  =					'file'
@pytest.fixture(scope='''session'''		)
def __UpperCAmelCase   (					A					:			Dict		)    ->   str:
			UpperCAmelCase_      :       Any          =       tmp_path_factory.mktemp('''data'''		) / (FILE_PATH + '''.zstd''')
			UpperCAmelCase_      :       Optional[int]          =       bytes(A			,       '''utf-8'''		)
			with zstd.open(A			,       '''wb'''		) as f:
						f.write(A		)
			return path
@pytest.fixture
def __UpperCAmelCase   (					A					:			Union[str, Any]		)    ->   Tuple:
			with open(os.path.join(tmpfs.local_root_dir			,       A		)			,       '''w'''		) as f:
						f.write(A		)
			return FILE_PATH
@pytest.mark.parametrize('''compression_format'''			,       ['''gzip''', '''xz''', '''zstd''']		)
def __UpperCAmelCase   (					A					:			List[str]			,       A					:			List[str]			,       A					:			Tuple			,       A					:			Optional[Any]			,       A					:			Any			,       A					:			Optional[Any]		)    ->   str:
			UpperCAmelCase_      :       Optional[int]          =       {'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
			UpperCAmelCase_      :       List[str]          =       input_paths[compression_format]
			UpperCAmelCase_      :       Optional[int]          =       tmp_path / '''cache'''
			UpperCAmelCase_      :       Any          =       DownloadConfig(cache_dir=A			,       extract_compressed_file=A		)
			UpperCAmelCase_      :       List[Any]          =       cached_path(A			,       download_config=A		)
			with open(A		) as f:
						UpperCAmelCase_      :       Any          =       f.read()
			with open(A		) as f:
						UpperCAmelCase_      :       List[Any]          =       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 __UpperCAmelCase   (					A					:			Tuple			,       A					:			str			,       A					:			Optional[int]			,       A					:			Tuple			,       A					:			Dict		)    ->   Dict:
			UpperCAmelCase_      :       Dict          =       '''custom_cache'''
			UpperCAmelCase_      :       Optional[int]          =       '''custom_extracted_dir'''
			UpperCAmelCase_      :       Optional[int]          =       tmp_path / '''custom_extracted_path'''
			if default_extracted:
						UpperCAmelCase_      :       Optional[int]          =       ('''downloads''' if default_cache_dir else custom_cache_dir, '''extracted''')
			else:
						monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_DIR'''			,       A		)
						monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH'''			,       str(A		)		)
						UpperCAmelCase_      :       Tuple          =       custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

			UpperCAmelCase_      :       Any          =       xz_file
			UpperCAmelCase_      :       Union[str, Any]          =       (
			    DownloadConfig(extract_compressed_file=A		)
			    if default_cache_dir
			    else DownloadConfig(cache_dir=tmp_path / custom_cache_dir			,       extract_compressed_file=A		)
			)
			UpperCAmelCase_      :       Optional[Any]          =       cached_path(A			,       download_config=A		)
			assert Path(A		).parent.parts[-2:] == expected
def __UpperCAmelCase   (					A					:			Optional[Any]		)    ->   Union[str, Any]:
			# absolute path
			UpperCAmelCase_      :       Dict          =       str(Path(A		).resolve()		)
			assert cached_path(A		) == text_file
			# relative path
			UpperCAmelCase_      :       List[Any]          =       str(Path(A		).resolve().relative_to(Path(os.getcwd()		)		)		)
			assert cached_path(A		) == text_file
def __UpperCAmelCase   (					A					:			Optional[int]		)    ->   Optional[Any]:
			# absolute path
			UpperCAmelCase_      :       str          =       str(tmp_path.resolve() / '''__missing_file__.txt'''		)
			with pytest.raises(A		):
						cached_path(A		)
			# relative path
			UpperCAmelCase_      :       int          =       '''./__missing_file__.txt'''
			with pytest.raises(A		):
						cached_path(A		)
def __UpperCAmelCase   (					A					:			Any		)    ->   Union[str, Any]:
			UpperCAmelCase_      :       str          =       get_from_cache(F"tmp://{tmpfs_file}"		)
			with open(A		) as f:
						UpperCAmelCase_      :       Any          =       f.read()
			assert output_file_content == FILE_CONTENT
@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,       A		)
def __UpperCAmelCase   (					)    ->   Optional[int]:
			with pytest.raises(A		):
						cached_path('''https://huggingface.co'''		)
@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,       A		)
def __UpperCAmelCase   (					A					:			Optional[int]		)    ->   Optional[Any]:
			UpperCAmelCase_      :       str          =       tmp_path_factory.mktemp('''data'''		) / '''file.html'''
			with pytest.raises(A		):
						http_get('''https://huggingface.co'''			,       temp_file=A		)
			with pytest.raises(A		):
						http_head('''https://huggingface.co'''		)
@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,       A		)
def __UpperCAmelCase   (					A					:			Optional[int]		)    ->   Dict:
			UpperCAmelCase_      :       Union[str, Any]          =       tmp_path_factory.mktemp('''data'''		) / '''file.html'''
			with pytest.raises(A		):
						ftp_get('''ftp://huggingface.co'''			,       temp_file=A		)
			with pytest.raises(A		):
						ftp_head('''ftp://huggingface.co'''		)







@patch('''datasets.config.HF_DATASETS_OFFLINE'''			,       A		)
def __UpperCAmelCase   (					A					:			List[str]		)    ->   Tuple:
			UpperCAmelCase_      :       Any          =       tmp_path_factory.mktemp('''data'''		) / '''file.html'''
			with pytest.raises(A		):
						fsspec_get('''s3://huggingface.co'''			,       temp_file=A		)
			with pytest.raises(A		):
						fsspec_head('''s3://huggingface.co'''		)










'''simple docstring'''





_UpperCamelCase						:						List[str]  =					[sum(int(c, 10) ** 2 for c in i.__str__()) for i in range(100_000)]
def __UpperCAmelCase   (					A					:			int		)    ->   int:
			UpperCAmelCase_      :       str          =       0
			while number:
						# Increased Speed Slightly by checking every 5 digits together.
						sum_of_digits_squared += DIGITS_SQUARED[number % 1_0_0_0_0_0]
						number //= 1_0_0_0_0_0

			return sum_of_digits_squared


# There are 2 Chains made,
# One ends with 89 with the chain member 58 being the one which when declared first,
# there will be the least number of iterations for all the members to be checked.

# The other one ends with 1 and has only one element 1.

# So 58 and 1 are chosen to be declared at the starting.

# Changed dictionary to an array to quicken the solution
_UpperCamelCase						:						list[bool | None]  =					[None] * 10_000_000
_UpperCamelCase						:						List[str]  =					True
_UpperCamelCase						:						Tuple  =					False
def __UpperCAmelCase   (					A					:			int		)    ->   bool:

			if CHAINS[number - 1] is not None:
						return CHAINS[number - 1]  # type: ignore

			UpperCAmelCase_      :       Dict          =       chain(next_number(A		)		)
			UpperCAmelCase_      :       int          =       number_chain

			while number < 1_0_0_0_0_0_0_0:
						UpperCAmelCase_      :       Optional[Any]          =       number_chain
						number *= 1_0

			return number_chain
def __UpperCAmelCase   (					A					:			int = 1_0_0_0_0_0_0_0		)    ->   int:
			for i in range(1			,       A		):
						if CHAINS[i] is None:
									chain(i + 1		)

			return CHAINS[:number].count(A		)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						print(f'''{solution() = }''')


