



from collections.abc import Generator
from math import sin






def     __a					(		__UpperCAmelCase       ):
 if len(__UpperCAmelCase       ) != 32:
  raise ValueError('''Input must be of length 32'''       )

 a__												= B''''''
 for i in [3, 2, 1, 0]:
  little_endian += string_aa[8 * i : 8 * i + 8]
 return little_endian






def     __a					(		__UpperCAmelCase       ):
 if i < 0:
  raise ValueError('''Input must be non-negative'''       )

 a__												= format(__UpperCAmelCase							,  '''08x'''       )[-8:]
 a__												= B''''''
 for i in [3, 2, 1, 0]:
  little_endian_hex += hex_rep[2 * i : 2 * i + 2].encode('''utf-8'''       )
 return little_endian_hex






def     __a					(		__UpperCAmelCase       ):
 a__												= B''''''
 for char in message:
  bit_string += format(__UpperCAmelCase							,  '''08b'''       ).encode('''utf-8'''       )
 a__												= format(len(__UpperCAmelCase       )							,  '''064b'''       ).encode('''utf-8'''       )

 # Pad bit_string to a multiple of 512 chars
 bit_string += b"1"
 while len(__UpperCAmelCase       ) % 512 != 448:
  bit_string += b"0"
 bit_string += to_little_endian(start_len[32:]       ) + to_little_endian(start_len[:32]       )

 return bit_string






def     __a					(		__UpperCAmelCase       ):
 if len(__UpperCAmelCase       ) % 512 != 0:
  raise ValueError('''Input must have length that\'s a multiple of 512'''       )

 for pos in range(0							,  len(__UpperCAmelCase       )							,  512       ):
  a__												= bit_string[pos : pos + 512]
  a__												= []
  for i in range(0							,  512							,  32       ):
   block_words.append(int(to_little_endian(block[i : i + 32]       )							,  2       )       )
  yield block_words






def     __a					(		__UpperCAmelCase       ):
 if i < 0:
  raise ValueError('''Input must be non-negative'''       )

 a__												= format(__UpperCAmelCase							,  '''032b'''       )
 a__												= ''''''
 for c in i_str:
  new_str += "1" if c == "0" else "0"
 return int(__UpperCAmelCase							,  2       )






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase       ):
 return (a + b) % 2**32






def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase       ):
 if i < 0:
  raise ValueError('''Input must be non-negative'''       )
 if shift < 0:
  raise ValueError('''Shift must be non-negative'''       )
 return ((i << shift) ^ (i >> (32 - shift))) % 2**32






def     __a					(		__UpperCAmelCase       ):
 a__												= preprocess(__UpperCAmelCase       )

 a__												= [int(2**32 * abs(sin(i + 1       )       )       ) for i in range(64       )]

 # Starting states
 a__												= 0X67452301
 a__												= 0Xefcdab89
 a__												= 0X98badcfe
 a__												= 0X10325476

 a__												= [
     7,
     12,
     17,
     22,
     7,
     12,
     17,
     22,
     7,
     12,
     17,
     22,
     7,
     12,
     17,
     22,
     5,
     9,
     14,
     20,
     5,
     9,
     14,
     20,
     5,
     9,
     14,
     20,
     5,
     9,
     14,
     20,
     4,
     11,
     16,
     23,
     4,
     11,
     16,
     23,
     4,
     11,
     16,
     23,
     4,
     11,
     16,
     23,
     6,
     10,
     15,
     21,
     6,
     10,
     15,
     21,
     6,
     10,
     15,
     21,
     6,
     10,
     15,
     21,
 ]

 # Process bit string in chunks, each with 16 32-char words
 for block_words in get_block_words(__UpperCAmelCase       ):
  a__												= aa
  a__												= ba
  a__												= ca
  a__												= da

  # Hash current chunk
  for i in range(64       ):
   if i <= 15:
    # f = (b & c) | (not_32(b) & d)     # Alternate definition for f
    a__												= d ^ (b & (c ^ d))
    a__												= i
   elif i <= 31:
    # f = (d & b) | (not_32(d) & c)     # Alternate definition for f
    a__												= c ^ (d & (b ^ c))
    a__												= (5 * i + 1) % 16
   elif i <= 47:
    a__												= b ^ c ^ d
    a__												= (3 * i + 5) % 16
   else:
    a__												= c ^ (b | not_aa(__UpperCAmelCase       ))
    a__												= (7 * i) % 16
   a__												= (f + a + added_consts[i] + block_words[g]) % 2**32
   a__												= d
   a__												= c
   a__												= b
   a__												= sum_aa(__UpperCAmelCase							,  left_rotate_aa(__UpperCAmelCase							,  shift_amounts[i]       )       )

  # Add hashed chunk to running total
  a__												= sum_aa(__UpperCAmelCase							,  __UpperCAmelCase       )
  a__												= sum_aa(__UpperCAmelCase							,  __UpperCAmelCase       )
  a__												= sum_aa(__UpperCAmelCase							,  __UpperCAmelCase       )
  a__												= sum_aa(__UpperCAmelCase							,  __UpperCAmelCase       )

 a__												= reformat_hex(__UpperCAmelCase       ) + reformat_hex(__UpperCAmelCase       ) + reformat_hex(__UpperCAmelCase       ) + reformat_hex(__UpperCAmelCase       )
 return digest


if __name__ == "__main__":
     import doctest

     doctest.testmod()










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_      :      int    =     '\\n    Text data.\n    Second line of data.'

a_      :      Optional[Any]    =     'file'






@pytest.fixture(scope='''session'''       )
def     __a					(		__UpperCAmelCase       ):
 a__												= tmp_path_factory.mktemp('''data'''       ) / (FILE_PATH + '''.zstd''')
 a__												= bytes(__UpperCAmelCase							,  '''utf-8'''       )
 with zstd.open(__UpperCAmelCase							,  '''wb'''       ) as f:
  f.write(__UpperCAmelCase       )
 return path






@pytest.fixture
def     __a					(		__UpperCAmelCase       ):
 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     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= {'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_path}
 a__												= input_paths[compression_format]
 a__												= tmp_path / '''cache'''
 a__												= DownloadConfig(cache_dir=__UpperCAmelCase							,  extract_compressed_file=__UpperCAmelCase       )
 a__												= cached_path(__UpperCAmelCase							,  download_config=__UpperCAmelCase       )
 with open(__UpperCAmelCase       ) as f:
  a__												= f.read()
 with open(__UpperCAmelCase       ) as f:
  a__												= 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					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase       ):
 a__												= '''custom_cache'''
 a__												= '''custom_extracted_dir'''
 a__												= tmp_path / '''custom_extracted_path'''
 if default_extracted:
  a__												= ('''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       )       )
  a__												= custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

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






def     __a					(		__UpperCAmelCase       ):
 # absolute path
 a__												= str(Path(__UpperCAmelCase       ).resolve()       )
 assert cached_path(__UpperCAmelCase       ) == text_file
 # relative path
 a__												= str(Path(__UpperCAmelCase       ).resolve().relative_to(Path(os.getcwd()       )       )       )
 assert cached_path(__UpperCAmelCase       ) == text_file






def     __a					(		__UpperCAmelCase       ):
 # absolute path
 a__												= str(tmp_path.resolve() / '''__missing_file__.txt'''       )
 with pytest.raises(__UpperCAmelCase       ):
  cached_path(__UpperCAmelCase       )
 # relative path
 a__												= '''./__missing_file__.txt'''
 with pytest.raises(__UpperCAmelCase       ):
  cached_path(__UpperCAmelCase       )






def     __a					(		__UpperCAmelCase       ):
 a__												= get_from_cache(f"tmp://{tmpfs_file}"       )
 with open(__UpperCAmelCase       ) as f:
  a__												= f.read()
 assert output_file_content == FILE_CONTENT






@patch('''datasets.config.HF_DATASETS_OFFLINE'''							,  __UpperCAmelCase       )
def     __a					(		):
 with pytest.raises(__UpperCAmelCase       ):
  cached_path('''https://huggingface.co'''       )






@patch('''datasets.config.HF_DATASETS_OFFLINE'''							,  __UpperCAmelCase       )
def     __a					(		__UpperCAmelCase       ):
 a__												= 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     __a					(		__UpperCAmelCase       ):
 a__												= 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     __a					(		__UpperCAmelCase       ):
 a__												= 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'''       )





