





import os

import pytest
import yaml

from datasets.features.features import Features, Value
from datasets.info import DatasetInfo, DatasetInfosDict

@pytest.mark.parametrize(
    "files"					,					[
        ["full:README.md", "dataset_infos.json"],
        ["empty:README.md", "dataset_infos.json"],
        ["dataset_infos.json"],
        ["full:README.md"],
    ]					,					)
def   __snake_case    (       _lowerCAmelCase			:			Optional[Any]					,					_lowerCAmelCase			:			Optional[int]						)			->    Dict:
   A_       :					List[Any]        =      tmp_path_factory.mktemp("dset_infos_dir"						)
   if "full:README.md" in files:
      with open(dataset_infos_dir / "README.md"					,					"w"						) as f:
         f.write("---\ndataset_info:\n  dataset_size: 42\n---"						)
   if "empty:README.md" in files:
      with open(dataset_infos_dir / "README.md"					,					"w"						) as f:
         f.write(""						)
    # we want to support dataset_infos.json for backward compatibility
   if "dataset_infos.json" in files:
      with open(dataset_infos_dir / "dataset_infos.json"					,					"w"						) as f:
         f.write("{\"default\": {\"dataset_size\": 42}}"						)
   A_       :					int        =      DatasetInfosDict.from_directory(_lowerCAmelCase						)
   assert dataset_infos
   assert dataset_infos["default"].dataset_size == 42

@pytest.mark.parametrize(
    "dataset_info"					,					[
        DatasetInfo(),
        DatasetInfo(
            description="foo"					,					features=Features({"a": Value("int32"						)}						)					,					builder_name="builder"					,					config_name="config"					,					version="1.0.0"					,					splits=[{"name": "train"}]					,					download_size=42					,					),
    ]					,					)
def   __snake_case    (       _lowerCAmelCase			:			Any					,					_lowerCAmelCase			:			DatasetInfo						)			->    List[str]:
   A_       :					Union[str, Any]        =      str(_lowerCAmelCase						)
   dataset_info.write_to_directory(_lowerCAmelCase						)
   A_       :					int        =      DatasetInfo.from_directory(_lowerCAmelCase						)
   assert dataset_info == reloaded
   assert os.path.exists(os.path.join(_lowerCAmelCase					,					"dataset_info.json"						)						)

def   __snake_case    (       )			->    int:
   A_       :					List[Any]        =      DatasetInfo(
       description="foo"					,					citation="bar"					,					homepage="https://foo.bar"					,					license="CC0"					,					features=Features({"a": Value("int32"						)}						)					,					post_processed={}					,					supervised_keys=()					,					task_templates=[]					,					builder_name="builder"					,					config_name="config"					,					version="1.0.0"					,					splits=[{"name": "train", "num_examples": 42}]					,					download_checksums={}					,					download_size=1337					,					post_processing_size=442					,					dataset_size=1234					,					size_in_bytes=1337 + 442 + 1234					,					)
   A_       :					List[str]        =      dataset_info._to_yaml_dict()
   assert sorted(_lowerCAmelCase						) == sorted(DatasetInfo._INCLUDED_INFO_IN_YAML						)
   for key in DatasetInfo._INCLUDED_INFO_IN_YAML:
      assert key in dataset_info_yaml_dict
      assert isinstance(dataset_info_yaml_dict[key]					,					(list, dict, int, str)						)
   A_       :					Dict        =      yaml.safe_dump(_lowerCAmelCase						)
   A_       :					Tuple        =      yaml.safe_load(_lowerCAmelCase						)
   assert dataset_info_yaml_dict == reloaded

def   __snake_case    (       )			->    Optional[Any]:
   A_       :					List[Any]        =      DatasetInfo()
   A_       :					Optional[Any]        =      dataset_info._to_yaml_dict()
   assert dataset_info_yaml_dict == {}





@pytest.mark.parametrize(
    "dataset_infos_dict"					,					[
        DatasetInfosDict(),
        DatasetInfosDict({"default": DatasetInfo()}						),
        DatasetInfosDict({"my_config_name": DatasetInfo()}						),
        DatasetInfosDict(
            {
                "default": DatasetInfo(
                    description="foo"					,					features=Features({"a": Value("int32"						)}						)					,					builder_name="builder"					,					config_name="config"					,					version="1.0.0"					,					splits=[{"name": "train"}]					,					download_size=42					,					)
            }						),
        DatasetInfosDict(
            {
                "v1": DatasetInfo(dataset_size=42						),
                "v2": DatasetInfo(dataset_size=1337						),
            }						),
    ]					,					)
def   __snake_case    (       _lowerCAmelCase			:			Optional[Any]					,					_lowerCAmelCase			:			DatasetInfosDict						)			->    Dict:
   A_       :					Tuple        =      str(_lowerCAmelCase						)
   dataset_infos_dict.write_to_directory(_lowerCAmelCase						)
   A_       :					Optional[Any]        =      DatasetInfosDict.from_directory(_lowerCAmelCase						)

   # the config_name of the dataset_infos_dict take over the attribute
   for config_name, dataset_info in dataset_infos_dict.items():
      A_       :					str        =      config_name
      # the yaml representation doesn't include fields like description or citation
      # so we just test that we can recover what we can from the yaml
      A_       :					Dict        =      DatasetInfo._from_yaml_dict(dataset_info._to_yaml_dict()						)
   assert dataset_infos_dict == reloaded

   if dataset_infos_dict:
      assert os.path.exists(os.path.join(_lowerCAmelCase					,					"README.md"						)						)







import argparse
import struct
import unittest


class        __magic_name__	:





     """simple docstring"""



     def __init__(				self							:str      ,   snake_case							:bytes	):





        '''simple docstring'''




        A_       :					Dict        =      data

        # Initialize hash values
        A_       :					Union[str, Any]        =      [
            0x6a_09_e6_67,
            0xbb_67_ae_85,
            0x3c_6e_f3_72,
            0xa5_4f_f5_3a,
            0x51_0e_52_7f,
            0x9b_05_68_8c,
            0x1f_83_d9_ab,
            0x5b_e0_cd_19,
        ]

        # Initialize round constants
        A_       :					List[Any]        =      [
            0x42_8a_2f_98,
            0x71_37_44_91,
            0xb5_c0_fb_cf,
            0xe9_b5_db_a5,
            0x39_56_c2_5b,
            0x59_f1_11_f1,
            0x92_3f_82_a4,
            0xab_1c_5e_d5,
            0xd8_07_aa_98,
            0x12_83_5b_01,
            0x24_31_85_be,
            0x55_0c_7d_c3,
            0x72_be_5d_74,
            0x80_de_b1_fe,
            0x9b_dc_06_a7,
            0xc1_9b_f1_74,
            0xe4_9b_69_c1,
            0xef_be_47_86,
            0x0f_c1_9d_c6,
            0x24_0c_a1_cc,
            0x2d_e9_2c_6f,
            0x4a_74_84_aa,
            0x5c_b0_a9_dc,
            0x76_f9_88_da,
            0x98_3e_51_52,
            0xa8_31_c6_6d,
            0xb0_03_27_c8,
            0xbf_59_7f_c7,
            0xc6_e0_0b_f3,
            0xd5_a7_91_47,
            0x06_ca_63_51,
            0x14_29_29_67,
            0x27_b7_0a_85,
            0x2e_1b_21_38,
            0x4d_2c_6d_fc,
            0x53_38_0d_13,
            0x65_0a_73_54,
            0x76_6a_0a_bb,
            0x81_c2_c9_2e,
            0x92_72_2c_85,
            0xa2_bf_e8_a1,
            0xa8_1a_66_4b,
            0xc2_4b_8b_70,
            0xc7_6c_51_a3,
            0xd1_92_e8_19,
            0xd6_99_06_24,
            0xf4_0e_35_85,
            0x10_6a_a0_70,
            0x19_a4_c1_16,
            0x1e_37_6c_08,
            0x27_48_77_4c,
            0x34_b0_bc_b5,
            0x39_1c_0c_b3,
            0x4e_d8_aa_4a,
            0x5b_9c_ca_4f,
            0x68_2e_6f_f3,
            0x74_8f_82_ee,
            0x78_a5_63_6f,
            0x84_c8_78_14,
            0x8c_c7_02_08,
            0x90_be_ff_fa,
            0xa4_50_6c_eb,
            0xbe_f9_a3_f7,
            0xc6_71_78_f2,
        ]

        A_       :					Any        =      self.preprocessing(self.data	)
        self.final_hash()



     @staticmethod
     def     SCREAMING_SNAKE_CASE		(				snake_case							:bytes	):





        '''simple docstring'''




        A_       :					List[Any]        =      B"\x80" + (B"\x00" * (63 - (len(snake_case	) + 8) % 64))
        A_       :					str        =      struct.pack(">Q"      ,   (len(snake_case	) * 8)	)
        return data + padding + big_endian_integer



     def     SCREAMING_SNAKE_CASE		(				self							:Any	):





        '''simple docstring'''




        A_       :					Tuple        =      [
            self.preprocessed_data[x : x + 64]
            for x in range(0      ,   len(self.preprocessed_data	)      ,   64	)
        ]

        for block in self.blocks:
           # Convert the given block into a list of 4 byte integers
           A_       :					Dict        =      list(struct.unpack(">16L"      ,   snake_case	)	)
           # add 48 0-ed integers
           words += [0] * 48

           A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_       :					int        =      self.hashes

           for index in range(0      ,   64	):
              if index > 15:
                 # modify the zero-ed indexes at the end of the array
                 A_       :					int        =      (
                     self.ror(words[index - 15]      ,   7	)
                     ^ self.ror(words[index - 15]      ,   18	)
                     ^ (words[index - 15] >> 3)
                 )
                 A_       :					Any        =      (
                     self.ror(words[index - 2]      ,   17	)
                     ^ self.ror(words[index - 2]      ,   19	)
                     ^ (words[index - 2] >> 10)
                 )

                 A_       :					Optional[int]        =      (
                     words[index - 16] + sa + words[index - 7] + sa
                 ) % 0x1_00_00_00_00

              # Compression
              A_       :					Dict        =      self.ror(snake_case      ,   6	) ^ self.ror(snake_case      ,   11	) ^ self.ror(snake_case      ,   25	)
              A_       :					int        =      (e & f) ^ ((~e & 0xff_ff_ff_ff) & g)
              A_       :					Optional[Any]        =      (
                  h + sa + ch + self.round_constants[index] + words[index]
              ) % 0x1_00_00_00_00
              A_       :					List[str]        =      self.ror(snake_case      ,   2	) ^ self.ror(snake_case      ,   13	) ^ self.ror(snake_case      ,   22	)
              A_       :					List[Any]        =      (a & b) ^ (a & c) ^ (b & c)
              A_       :					Dict        =      (sa + maj) % 0x1_00_00_00_00

              A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_   ,    A_       :					Optional[int]        =      (
                  g,
                  f,
                  e,
                  ((d + tempa) % 0x1_00_00_00_00),
                  c,
                  b,
                  a,
                  ((tempa + tempa) % 0x1_00_00_00_00),
              )

           A_       :					List[str]        =      [a, b, c, d, e, f, g, h]

           # Modify final values
           A_       :					List[str]        =      [
               ((element + mutated_hash_values[index]) % 0x1_00_00_00_00)
               for index, element in enumerate(self.hashes	)
           ]

        A_       :					Optional[int]        =      "".join([hex(snake_case	)[2:].zfill(8	) for value in self.hashes]	)





     def     SCREAMING_SNAKE_CASE		(				self							:Optional[Any]      ,   snake_case							:int      ,   snake_case							:int	):





        '''simple docstring'''




        return 0xff_ff_ff_ff & (value << (32 - rotations)) | (value >> rotations)




class        __magic_name__	(				unittest.TestCase				):





     """simple docstring"""



     def     SCREAMING_SNAKE_CASE		(				self							:List[Any]	):





        '''simple docstring'''




        import hashlib

        A_       :					int        =      bytes("Test String"      ,   "utf-8"	)
        self.assertEqual(SHAaaa(snake_case	).hash      ,   hashlib.shaaaa(snake_case	).hexdigest()	)




def   __snake_case    (       )			->    None:
   import doctest

   doctest.testmod()

   A_       :					Optional[Any]        =      argparse.ArgumentParser()
   parser.add_argument(
       "-s"					,					"--string"					,					dest="input_string"					,					default="Hello World!! Welcome to Cryptography"					,					help="Hash the string"					,					)
   parser.add_argument(
       "-f"					,					"--file"					,					dest="input_file"					,					help="Hash contents of a file"						)

   A_       :					List[Any]        =      parser.parse_args()

   A_       :					List[Any]        =      args.input_string

   # hash input should be a bytestring
   if args.input_file:
      with open(args.input_file					,					"rb"						) as f:
         A_       :					Optional[Any]        =      f.read()
   else:
      A_       :					Any        =      bytes(_lowerCAmelCase					,					"utf-8"						)

   print(SHAaaa(_lowerCAmelCase						).hash						)


if __name__ == "__main__":
 main()
