'''simple docstring'''





import json
import os
import unittest

from transformers import CLIPTokenizer, CLIPTokenizerFast
from transformers.models.clip.tokenization_clip import VOCAB_FILES_NAMES
from transformers.testing_utils import require_ftfy, require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin






@require_tokenizers
class 				UpperCAmelCase (       _SCREAMING_SNAKE_CASE   ,    unittest.TestCase ):




    '''simple docstring'''







    snake_case__							:   int							=						CLIPTokenizer
    snake_case__							:   Union[str, Any]							=						CLIPTokenizerFast
    snake_case__							:   str							=						True
    snake_case__							:   Optional[int]							=						{}
    snake_case__							:   int							=						False






    def       _UpperCamelCase    (       self )							-> Tuple:
         super().setUp()

         # fmt: off
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       ['l', 'o', 'w', 'e', 'r', 's', 't', 'i', 'd', 'n', 'lo', 'l</w>', 'w</w>', 'r</w>', 't</w>', 'low</w>', 'er</w>', 'lowest</w>', 'newer</w>', 'wider', '<unk>', '<|startoftext|>', '<|endoftext|>']
         # fmt: on
         SCREAMING_SNAKE_CASE					:			int    	=       dict(zip(lowercase__    ,							range(len(lowercase__ ) ) ) )
         SCREAMING_SNAKE_CASE					:			Dict    	=       ['#version: 0.2', 'l o', 'lo w</w>', 'e r</w>']
         SCREAMING_SNAKE_CASE					:			List[str]    	=       {'unk_token': '<unk>'}

         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       os.path.join(self.tmpdirname    ,							VOCAB_FILES_NAMES['vocab_file'] )
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       os.path.join(self.tmpdirname    ,							VOCAB_FILES_NAMES['merges_file'] )
         with open(self.vocab_file    ,							'w'    ,							encoding='utf-8' ) as fp:
              fp.write(json.dumps(lowercase__ ) + '\n' )
         with open(self.merges_file    ,							'w'    ,							encoding='utf-8' ) as fp:
              fp.write('\n'.join(lowercase__ ) )






    def       _UpperCamelCase    (       self    ,							**lowercase__ )							-> Dict:
         kwargs.update(self.special_tokens_map )
         return CLIPTokenizer.from_pretrained(self.tmpdirname    ,							**lowercase__ )






    def       _UpperCamelCase    (       self    ,							**lowercase__ )							-> Union[str, Any]:
         kwargs.update(self.special_tokens_map )
         return CLIPTokenizerFast.from_pretrained(self.tmpdirname    ,							**lowercase__ )






    def       _UpperCamelCase    (       self    ,							lowercase__ )							-> List[Any]:
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       'lower newer'
         SCREAMING_SNAKE_CASE					:			Dict    	=       'lower newer'
         return input_text, output_text






    def       _UpperCamelCase    (       self )							-> List[Any]:
         SCREAMING_SNAKE_CASE					:			str    	=       CLIPTokenizer(self.vocab_file    ,							self.merges_file    ,							**self.special_tokens_map )
         SCREAMING_SNAKE_CASE					:			Optional[int]    	=       'lower newer'
         SCREAMING_SNAKE_CASE					:			List[Any]    	=       ['lo', 'w', 'er</w>', 'n', 'e', 'w', 'er</w>']
         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       tokenizer.tokenize(lowercase__ )
         self.assertListEqual(lowercase__    ,							lowercase__ )

         SCREAMING_SNAKE_CASE					:			Any    	=       tokens + [tokenizer.unk_token]
         SCREAMING_SNAKE_CASE					:			int    	=       [10, 2, 16, 9, 3, 2, 16, 20]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(lowercase__ )    ,							lowercase__ )






    @require_ftfy
    def       _UpperCamelCase    (       self )							-> List[str]:
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})""" ):
                   SCREAMING_SNAKE_CASE					:			Dict    	=       self.tokenizer_class.from_pretrained(lowercase__    ,							**lowercase__ )
                   SCREAMING_SNAKE_CASE					:			List[Any]    	=       self.rust_tokenizer_class.from_pretrained(lowercase__    ,							**lowercase__ )

                   SCREAMING_SNAKE_CASE					:			Tuple    	=       'A\n\'ll 11p223RF☆ho!!to?\'d\'d\'\'d of a cat to-$\'\'d.'
                   SCREAMING_SNAKE_CASE					:			List[str]    	=       tokenizer_s.tokenize(lowercase__ )
                   SCREAMING_SNAKE_CASE					:			List[str]    	=       tokenizer_r.tokenize(lowercase__ )

                   self.assertListEqual(lowercase__    ,							lowercase__ )

                   # Test that the tokenization is identical on an example containing a character (Latin Small Letter A
                   # with Tilde) encoded in 2 different ways
                   SCREAMING_SNAKE_CASE					:			Tuple    	=       'xa\u0303y' + ' ' + 'x\xe3y'
                   SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       tokenizer_s.tokenize(lowercase__ )
                   SCREAMING_SNAKE_CASE					:			Dict    	=       tokenizer_r.tokenize(lowercase__ )

                   self.assertListEqual(lowercase__    ,							lowercase__ )

                   # Test that the tokenization is identical on unicode of space type
                   SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       [
                       '\u0009',  # (horizontal tab, '\t')
                       '\u000B',  # (vertical tab)
                       '\u000C',  # (form feed)
                       '\u0020',  # (space, ' ')
                       '\u200E',  # (left-to-right mark):w
                       '\u200F',  # (right-to-left mark)
                   ]
                   for unicode_seq in spaces_unicodes:
                        SCREAMING_SNAKE_CASE					:			Tuple    	=       tokenizer_s.tokenize(lowercase__ )
                        SCREAMING_SNAKE_CASE					:			Optional[int]    	=       tokenizer_r.tokenize(lowercase__ )

                        self.assertListEqual(lowercase__    ,							lowercase__ )

                   # Test that the tokenization is identical on unicode of line break type
                   SCREAMING_SNAKE_CASE					:			int    	=       [
                       '\u000A',  # (line feed, '\n')
                       '\r\n',  # (carriage return and line feed, '\r\n')
                       '\u000D',  # (carriage return, '\r')
                       '\r',  # (carriage return, '\r')
                       '\u000D',  # (carriage return, '\r')
                       '\u2028',  # (line separator)
                       '\u2029',  # (paragraph separator)
                       # "\u0085", # (next line)
                   ]

                   # The tokenization is not identical for the character "\u0085" (next line). The slow version using ftfy transforms
                   # it into the Horizontal Ellipsis character "…" ("\u2026") while the fast version transforms it into a
                   # space (and thus into an empty list).

                   for unicode_seq in line_break_unicodes:
                        SCREAMING_SNAKE_CASE					:			List[Any]    	=       tokenizer_s.tokenize(lowercase__ )
                        SCREAMING_SNAKE_CASE					:			int    	=       tokenizer_r.tokenize(lowercase__ )

                        self.assertListEqual(lowercase__    ,							lowercase__ )






    def       _UpperCamelCase    (       self )							-> int:
         # Test which aims to verify that the offsets are well adapted to the argument `add_prefix_space`
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})""" ):
                   SCREAMING_SNAKE_CASE					:			str    	=       'hello'  # `hello` is a token in the vocabulary of `pretrained_name`
                   SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       F"""{text_of_1_token} {text_of_1_token}"""

                   SCREAMING_SNAKE_CASE					:			List[str]    	=       self.rust_tokenizer_class.from_pretrained(
                       lowercase__    ,							use_fast=lowercase__    ,							)
                   SCREAMING_SNAKE_CASE					:			Tuple    	=       tokenizer_r(lowercase__    ,							return_offsets_mapping=lowercase__    ,							add_special_tokens=lowercase__ )
                   self.assertEqual(encoding.offset_mapping[0]    ,							(0, len(lowercase__ )) )
                   self.assertEqual(
                       encoding.offset_mapping[1]    ,							(len(lowercase__ ) + 1, len(lowercase__ ) + 1 + len(lowercase__ ))    ,							)

                   SCREAMING_SNAKE_CASE					:			Optional[int]    	=       F""" {text}"""

                   SCREAMING_SNAKE_CASE					:			Any    	=       self.rust_tokenizer_class.from_pretrained(
                       lowercase__    ,							use_fast=lowercase__    ,							)
                   SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       tokenizer_r(lowercase__    ,							return_offsets_mapping=lowercase__    ,							add_special_tokens=lowercase__ )
                   self.assertEqual(encoding.offset_mapping[0]    ,							(1, 1 + len(lowercase__ )) )
                   self.assertEqual(
                       encoding.offset_mapping[1]    ,							(1 + len(lowercase__ ) + 1, 1 + len(lowercase__ ) + 1 + len(lowercase__ ))    ,							)






    def       _UpperCamelCase    (       self )							-> int:
         # Test related to the breaking change introduced in transformers v4.17.0
         # We need to check that an error in raised when the user try to load a previous version of the tokenizer.
         with self.assertRaises(lowercase__ ) as context:
              self.rust_tokenizer_class.from_pretrained('robot-test/old-clip-tokenizer' )

         self.assertTrue(
             context.exception.args[0].startswith(
                 'The `backend_tokenizer` provided does not match the expected format.' ) )






    @require_ftfy
    def       _UpperCamelCase    (       self )							-> Union[str, Any]:
         super().test_tokenization_python_rust_equals()






    def       _UpperCamelCase    (       self )							-> int:
         # CLIP always lower cases letters
         pass




'''simple docstring'''





import argparse
import struct
import unittest






class 				UpperCAmelCase :




    '''simple docstring'''







    def __init__(       self    ,							lowercase__ )							-> None:
         SCREAMING_SNAKE_CASE					:			List[str]    	=       data

         # Initialize hash values
         SCREAMING_SNAKE_CASE					:			str    	=       [
             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
         SCREAMING_SNAKE_CASE					:			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,
         ]

         SCREAMING_SNAKE_CASE					:			List[Any]    	=       self.preprocessing(self.data )
         self.final_hash()






    @staticmethod
    def       _UpperCamelCase    (       lowercase__ )							-> bytes:
         SCREAMING_SNAKE_CASE					:			str    	=       B'\x80' + (B'\x00' * (63 - (len(lowercase__ ) + 8) % 64))
         SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       struct.pack('>Q'    ,							(len(lowercase__ ) * 8) )
         return data + padding + big_endian_integer






    def       _UpperCamelCase    (       self )							-> None:
         # Convert into blocks of 64 bytes
         SCREAMING_SNAKE_CASE					:			Dict    	=       [
             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
              SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       list(struct.unpack('>16L'    ,							lowercase__ ) )
              # add 48 0-ed integers
              words += [0] * 48

              SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE					:			Dict    	=       self.hashes

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

                        SCREAMING_SNAKE_CASE					:			Tuple    	=       (
                            words[index - 16] + sa + words[index - 7] + sa
                        ) % 0X1_00_00_00_00

                   # Compression
                   SCREAMING_SNAKE_CASE					:			Any    	=       self.ror(lowercase__    ,							6 ) ^ self.ror(lowercase__    ,							11 ) ^ self.ror(lowercase__    ,							25 )
                   SCREAMING_SNAKE_CASE					:			Any    	=       (e & f) ^ ((~e & 0XFF_FF_FF_FF) & g)
                   SCREAMING_SNAKE_CASE					:			str    	=       (
                       h + sa + ch + self.round_constants[index] + words[index]
                   ) % 0X1_00_00_00_00
                   SCREAMING_SNAKE_CASE					:			Any    	=       self.ror(lowercase__    ,							2 ) ^ self.ror(lowercase__    ,							13 ) ^ self.ror(lowercase__    ,							22 )
                   SCREAMING_SNAKE_CASE					:			str    	=       (a & b) ^ (a & c) ^ (b & c)
                   SCREAMING_SNAKE_CASE					:			Tuple    	=       (sa + maj) % 0X1_00_00_00_00

                   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE	,   SCREAMING_SNAKE_CASE					:			List[Any]    	=       (
                       g,
                       f,
                       e,
                       ((d + tempa) % 0X1_00_00_00_00),
                       c,
                       b,
                       a,
                       ((tempa + tempa) % 0X1_00_00_00_00),
                   )

              SCREAMING_SNAKE_CASE					:			Union[str, Any]    	=       [a, b, c, d, e, f, g, h]

              # Modify final values
              SCREAMING_SNAKE_CASE					:			Tuple    	=       [
                  ((element + mutated_hash_values[index]) % 0X1_00_00_00_00)
                  for index, element in enumerate(self.hashes )
              ]

         SCREAMING_SNAKE_CASE					:			Tuple    	=       ''.join([hex(lowercase__ )[2:].zfill(8 ) for value in self.hashes] )






    def       _UpperCamelCase    (       self    ,							lowercase__    ,							lowercase__ )							-> int:
         return 0XFF_FF_FF_FF & (value << (32 - rotations)) | (value >> rotations)






class 				UpperCAmelCase (       unittest.TestCase ):




    '''simple docstring'''







    def       _UpperCamelCase    (       self )							-> None:
         import hashlib

         SCREAMING_SNAKE_CASE					:			Optional[Any]    	=       bytes('Test String'    ,							'utf-8' )
         self.assertEqual(SHAaaa(lowercase__ ).hash    ,							hashlib.shaaaa(lowercase__ ).hexdigest() )






def     __lowerCAmelCase						(       )      ->	None:





     '''simple docstring'''





     import doctest

     doctest.testmod()

     SCREAMING_SNAKE_CASE					:			List[str]    	=       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'		)

     SCREAMING_SNAKE_CASE					:			Tuple    	=       parser.parse_args()

     SCREAMING_SNAKE_CASE					:			List[Any]    	=       args.input_string

     # hash input should be a bytestring
     if args.input_file:
          with open(args.input_file       ,      'rb'		) as f:
               SCREAMING_SNAKE_CASE					:			List[Any]    	=       f.read()
     else:
          SCREAMING_SNAKE_CASE					:			Any    	=       bytes(a_       ,      'utf-8'		)

     print(SHAaaa(a_		).hash		)


if __name__ == "__main__":
 main()



