


"""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__					="\\n    Text data.\n    Second line of data."

UpperCAmelCase__					="file"


@pytest.fixture(scope="""session"""			)
def lowerCAmelCase_   (					UpperCamelCase__						:			Any			):






 """simple docstring"""







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


@pytest.fixture
def lowerCAmelCase_   (					UpperCamelCase__						:			Optional[int]			):






 """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__						:			Optional[int]					, UpperCamelCase__						:			Tuple					, UpperCamelCase__						:			int					, UpperCamelCase__						:			int					, UpperCamelCase__						:			Dict					, UpperCamelCase__						:			Optional[int]			):






 """simple docstring"""







 __lowercase						=						{"""gzip""": gz_file, """xz""": xz_file, """zstd""": zstd_path}
 __lowercase						=						input_paths[compression_format]
 __lowercase						=						tmp_path / """cache"""
 __lowercase						=						DownloadConfig(cache_dir=UpperCamelCase__					, extract_compressed_file=UpperCamelCase__			)
 __lowercase						=						cached_path(UpperCamelCase__					, download_config=UpperCamelCase__			)
 with open(UpperCamelCase__			) as f:
  __lowercase						=						f.read()
 with open(UpperCamelCase__			) as f:
  __lowercase						=						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__						:			Tuple					, UpperCamelCase__						:			int					, UpperCamelCase__						:			List[Any]					, UpperCamelCase__						:			Dict					, UpperCamelCase__						:			Any			):






 """simple docstring"""







 __lowercase						=						"""custom_cache"""
 __lowercase						=						"""custom_extracted_dir"""
 __lowercase						=						tmp_path / """custom_extracted_path"""
 if default_extracted:
  __lowercase						=						("""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__			)			)
  __lowercase						=						custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

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


def lowerCAmelCase_   (					UpperCamelCase__						:			str			):






 """simple docstring"""







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


def lowerCAmelCase_   (					UpperCamelCase__						:			Dict			):






 """simple docstring"""







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


def lowerCAmelCase_   (					UpperCamelCase__						:			str			):






 """simple docstring"""







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


@patch("""datasets.config.HF_DATASETS_OFFLINE"""					, UpperCamelCase__			)
def lowerCAmelCase_   (					):






 """simple docstring"""







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


@patch("""datasets.config.HF_DATASETS_OFFLINE"""					, UpperCamelCase__			)
def lowerCAmelCase_   (					UpperCamelCase__						:			Any			):






 """simple docstring"""







 __lowercase						=						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]			):






 """simple docstring"""







 __lowercase						=						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__						:			Union[str, Any]			):






 """simple docstring"""







 __lowercase						=						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"""

def lowerCAmelCase_   (					UpperCamelCase__						:			Union[str, Any]					, UpperCamelCase__						:			Union[str, Any]					, UpperCamelCase__						:			int			):






 """simple docstring"""







 if n == 0:
  return 1

 elif n % 2 == 1:
  return (binary_exponentiation(UpperCamelCase__					, n - 1					, UpperCamelCase__			) * a) % mod

 else:
  __lowercase						=						binary_exponentiation(UpperCamelCase__					, n / 2					, UpperCamelCase__			)
  return (b * b) % mod


# a prime number
UpperCAmelCase__					=701

UpperCAmelCase__					=10_0000_0000
UpperCAmelCase__					=10

# using binary exponentiation function, O(log(p)):
print((a / b) % p == (a * binary_exponentiation(b, p - 2, p)) % p)

print((a / b) % p == (a * b ** (p - 2)) % p)
