





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


__lowercase	: Union[str, Any]       ="""\
    Text data.
    Second line of data."""

__lowercase	: Dict       ="""file"""




@pytest.fixture(scope="session"	)
def      a__			(       lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           =tmp_path_factory.mktemp("data"	) / (FILE_PATH + ".zstd")
   UpperCAmelCase_           =bytes(lowercase__	,     "utf-8"	)
   with zstd.open(lowercase__	,     "wb"	) as f:
      f.write(lowercase__	)
   return path




@pytest.fixture
def      a__			(       lowercase__	):






   '''simple docstring'''






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




@pytest.mark.parametrize("compression_format"	,     ["gzip", "xz", "zstd"]	)
def      a__			(       lowercase__	,     lowercase__	,     lowercase__	,     lowercase__	,     lowercase__	,     lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           ={"gzip": gz_file, "xz": xz_file, "zstd": zstd_path}
   UpperCAmelCase_           =input_paths[compression_format]
   UpperCAmelCase_           =tmp_path / "cache"
   UpperCAmelCase_           =DownloadConfig(cache_dir=lowercase__	,     extract_compressed_file=lowercase__	)
   UpperCAmelCase_           =cached_path(lowercase__	,     download_config=lowercase__	)
   with open(lowercase__	) as f:
      UpperCAmelCase_           =f.read()
   with open(lowercase__	) as f:
      UpperCAmelCase_           =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      a__			(       lowercase__	,     lowercase__	,     lowercase__	,     lowercase__	,     lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           ="custom_cache"
   UpperCAmelCase_           ="custom_extracted_dir"
   UpperCAmelCase_           =tmp_path / "custom_extracted_path"
   if default_extracted:
      UpperCAmelCase_           =("downloads" if default_cache_dir else custom_cache_dir, "extracted")
   else:
      monkeypatch.setattr("datasets.config.EXTRACTED_DATASETS_DIR"	,     lowercase__	)
      monkeypatch.setattr("datasets.config.EXTRACTED_DATASETS_PATH"	,     str(lowercase__	)	)
      UpperCAmelCase_           =custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

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




def      a__			(       lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           =str(Path(lowercase__	).resolve()	)
   assert cached_path(lowercase__	) == text_file
   # relative path
   UpperCAmelCase_           =str(Path(lowercase__	).resolve().relative_to(Path(os.getcwd()	)	)	)
   assert cached_path(lowercase__	) == text_file




def      a__			(       lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           =str(tmp_path.resolve() / "__missing_file__.txt"	)
   with pytest.raises(lowercase__	):
      cached_path(lowercase__	)
   # relative path
   UpperCAmelCase_           ="./__missing_file__.txt"
   with pytest.raises(lowercase__	):
      cached_path(lowercase__	)




def      a__			(       lowercase__	):






   '''simple docstring'''






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




@patch("datasets.config.HF_DATASETS_OFFLINE"	,     lowercase__	)
def      a__			(       ):






   '''simple docstring'''






   with pytest.raises(lowercase__	):
      cached_path("https://huggingface.co"	)




@patch("datasets.config.HF_DATASETS_OFFLINE"	,     lowercase__	)
def      a__			(       lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           =tmp_path_factory.mktemp("data"	) / "file.html"
   with pytest.raises(lowercase__	):
      http_get("https://huggingface.co"	,     temp_file=lowercase__	)
   with pytest.raises(lowercase__	):
      http_head("https://huggingface.co"	)




@patch("datasets.config.HF_DATASETS_OFFLINE"	,     lowercase__	)
def      a__			(       lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           =tmp_path_factory.mktemp("data"	) / "file.html"
   with pytest.raises(lowercase__	):
      ftp_get("ftp://huggingface.co"	,     temp_file=lowercase__	)
   with pytest.raises(lowercase__	):
      ftp_head("ftp://huggingface.co"	)





@patch("datasets.config.HF_DATASETS_OFFLINE"	,     lowercase__	)
def      a__			(       lowercase__	):






   '''simple docstring'''






   UpperCAmelCase_           =tmp_path_factory.mktemp("data"	) / "file.html"
   with pytest.raises(lowercase__	):
      fsspec_get("s3://huggingface.co"	,     temp_file=lowercase__	)
   with pytest.raises(lowercase__	):
      fsspec_head("s3://huggingface.co"	)









'''simple docstring'''
def A__       (	UpperCAmelCase_    ,    UpperCAmelCase_				):
						return base * power(UpperCAmelCase_    ,    (exponent - 1)				) if exponent else 1


if __name__ == "__main__":
					print('Raise base to the power of exponent using recursion...')
					snake_case_					:      int    			=    int(input('Enter the base: ').strip())
					snake_case_					:      Optional[int]    			=    int(input('Enter the exponent: ').strip())
					snake_case_					:      Optional[int]    			=    power(base, abs(exponent))
					if exponent < 0:  # power() does not properly deal w/ negative exponents
										snake_case_					:      List[Any]    			=    1 / result
					print(F"""{base} to the power of {exponent} is {result}""")


