





from collections.abc import Generator
from math import sin






def 		lowerCAmelCase  (	UpperCamelCase__   :   bytes					)      ->    bytes:

						"""simple docstring"""





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

						__SCREAMING_SNAKE_CASE:				List[Any]           =   b''''''
						for i in [3, 2, 1, 0]:
												little_endian += string_aa[8 * i : 8 * i + 8]
						return little_endian






def 		lowerCAmelCase  (	UpperCamelCase__   :   int					)      ->    bytes:

						"""simple docstring"""





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

						__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   format(UpperCamelCase__       ,			'''08x'''					)[-8:]
						__SCREAMING_SNAKE_CASE:				List[str]           =   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 		lowerCAmelCase  (	UpperCamelCase__   :   bytes					)      ->    bytes:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Optional[Any]           =   b''''''
						for char in message:
												bit_string += format(UpperCamelCase__       ,			'''08b'''					).encode('''utf-8'''					)
						__SCREAMING_SNAKE_CASE:				List[Any]           =   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 		lowerCAmelCase  (	UpperCamelCase__   :   bytes					)      ->    Generator[list[int], None, None]:

						"""simple docstring"""





						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					):
												__SCREAMING_SNAKE_CASE:				int           =   bit_string[pos : pos + 512]
												__SCREAMING_SNAKE_CASE:				Optional[Any]           =   []
												for i in range(0       ,			512       ,			32					):
																		block_words.append(int(to_little_endian(block[i : i + 32]					)       ,			2					)					)
												yield block_words






def 		lowerCAmelCase  (	UpperCamelCase__   :   int					)      ->    int:

						"""simple docstring"""





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

						__SCREAMING_SNAKE_CASE:				Tuple           =   format(UpperCamelCase__       ,			'''032b'''					)
						__SCREAMING_SNAKE_CASE:				List[str]           =   ''''''
						for c in i_str:
												new_str += "1" if c == "0" else "0"
						return int(UpperCamelCase__       ,			2					)






def 		lowerCAmelCase  (	UpperCamelCase__   :   int       ,			UpperCamelCase__   :   int					)      ->    int:

						"""simple docstring"""





						return (a + b) % 2**32






def 		lowerCAmelCase  (	UpperCamelCase__   :   int       ,			UpperCamelCase__   :   int					)      ->    int:

						"""simple docstring"""





						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 		lowerCAmelCase  (	UpperCamelCase__   :   bytes					)      ->    bytes:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				List[Any]           =   preprocess(UpperCamelCase__					)

						__SCREAMING_SNAKE_CASE:				Optional[Any]           =   [int(2**32 * abs(sin(i + 1					)					)					) for i in range(64					)]

						# Starting states
						__SCREAMING_SNAKE_CASE:				Tuple           =   0x6745_2301
						__SCREAMING_SNAKE_CASE:				int           =   0xefcd_ab89
						__SCREAMING_SNAKE_CASE:				int           =   0x98ba_dcfe
						__SCREAMING_SNAKE_CASE:				List[Any]           =   0x1032_5476

						__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   [
						    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__					):
												__SCREAMING_SNAKE_CASE:				int           =   aa
												__SCREAMING_SNAKE_CASE:				Tuple           =   ba
												__SCREAMING_SNAKE_CASE:				str           =   ca
												__SCREAMING_SNAKE_CASE:				List[Any]           =   da

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

												# Add hashed chunk to running total
												__SCREAMING_SNAKE_CASE:				Optional[Any]           =   sum_aa(UpperCamelCase__       ,			UpperCamelCase__					)
												__SCREAMING_SNAKE_CASE:				List[Any]           =   sum_aa(UpperCamelCase__       ,			UpperCamelCase__					)
												__SCREAMING_SNAKE_CASE:				Dict           =   sum_aa(UpperCamelCase__       ,			UpperCamelCase__					)
												__SCREAMING_SNAKE_CASE:				Optional[int]           =   sum_aa(UpperCamelCase__       ,			UpperCamelCase__					)

						__SCREAMING_SNAKE_CASE:				Any           =   reformat_hex(UpperCamelCase__					) + reformat_hex(UpperCamelCase__					) + reformat_hex(UpperCamelCase__					) + reformat_hex(UpperCamelCase__					)
						return digest


if __name__ == "__main__":
							import doctest

							doctest.testmod()










import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    IMAGE_PROCESSOR_MAPPING,
    AutoConfig,
    AutoImageProcessor,
    CLIPConfig,
    CLIPImageProcessor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER


sys.path.append(str(Path(__file__).parent.parent.parent.parent / """utils"""))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_image_processing import CustomImageProcessor  # noqa E402





class 				a			(      unittest.TestCase			):






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				Optional[int]           =   0






				def 			snake_case_    (  self					):

										"""simple docstring"""




										__SCREAMING_SNAKE_CASE:				List[str]           =   AutoImageProcessor.from_pretrained('''openai/clip-vit-base-patch32'''					)
										self.assertIsInstance(_lowerCAmelCase			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with tempfile.TemporaryDirectory() as tmpdirname:
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   Path(_lowerCAmelCase					) / '''preprocessor_config.json'''
																__SCREAMING_SNAKE_CASE:				List[str]           =   Path(_lowerCAmelCase					) / '''config.json'''
																json.dump(
																    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}			, open(_lowerCAmelCase			, '''w'''					)			, )
																json.dump({'''model_type''': '''clip'''}			, open(_lowerCAmelCase			, '''w'''					)					)

																__SCREAMING_SNAKE_CASE:				Dict           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase					)
																self.assertIsInstance(_lowerCAmelCase			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with tempfile.TemporaryDirectory() as tmpdirname:
																__SCREAMING_SNAKE_CASE:				int           =   Path(_lowerCAmelCase					) / '''preprocessor_config.json'''
																__SCREAMING_SNAKE_CASE:				Tuple           =   Path(_lowerCAmelCase					) / '''config.json'''
																json.dump(
																    {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}			, open(_lowerCAmelCase			, '''w'''					)			, )
																json.dump({'''model_type''': '''clip'''}			, open(_lowerCAmelCase			, '''w'''					)					)

																__SCREAMING_SNAKE_CASE:				str           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase					)
																self.assertIsInstance(_lowerCAmelCase			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with tempfile.TemporaryDirectory() as tmpdirname:
																__SCREAMING_SNAKE_CASE:				int           =   CLIPConfig()

																# Create a dummy config file with image_proceesor_type
																__SCREAMING_SNAKE_CASE:				Any           =   Path(_lowerCAmelCase					) / '''preprocessor_config.json'''
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   Path(_lowerCAmelCase					) / '''config.json'''
																json.dump(
																    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}			, open(_lowerCAmelCase			, '''w'''					)			, )
																json.dump({'''model_type''': '''clip'''}			, open(_lowerCAmelCase			, '''w'''					)					)

																# remove image_processor_type to make sure config.json alone is enough to load image processor locally
																__SCREAMING_SNAKE_CASE:				Any           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase					).to_dict()

																config_dict.pop('''image_processor_type'''					)
																__SCREAMING_SNAKE_CASE:				List[str]           =   CLIPImageProcessor(**_lowerCAmelCase					)

																# save in new folder
																model_config.save_pretrained(_lowerCAmelCase					)
																config.save_pretrained(_lowerCAmelCase					)

																__SCREAMING_SNAKE_CASE:				Dict           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase					)

																# make sure private variable is not incorrectly saved
																__SCREAMING_SNAKE_CASE:				int           =   json.loads(config.to_json_string()					)
																self.assertTrue('''_processor_class''' not in dict_as_saved					)

										self.assertIsInstance(_lowerCAmelCase			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with tempfile.TemporaryDirectory() as tmpdirname:
																__SCREAMING_SNAKE_CASE:				Optional[int]           =   Path(_lowerCAmelCase					) / '''preprocessor_config.json'''
																json.dump(
																    {'''image_processor_type''': '''CLIPImageProcessor''', '''processor_class''': '''CLIPProcessor'''}			, open(_lowerCAmelCase			, '''w'''					)			, )

																__SCREAMING_SNAKE_CASE:				int           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase					)
																self.assertIsInstance(_lowerCAmelCase			, _lowerCAmelCase					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with self.assertRaisesRegex(
										    _lowerCAmelCase			, '''clip-base is not a local folder and is not a valid model identifier'''					):
																__SCREAMING_SNAKE_CASE:				Tuple           =   AutoImageProcessor.from_pretrained('''clip-base'''					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with self.assertRaisesRegex(
										    _lowerCAmelCase			, R'''aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)'''					):
																__SCREAMING_SNAKE_CASE:				Dict           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase			, revision='''aaaaaa'''					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with self.assertRaisesRegex(
										    _lowerCAmelCase			, '''hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json.'''			, ):
																__SCREAMING_SNAKE_CASE:				int           =   AutoImageProcessor.from_pretrained('''hf-internal-testing/config-no-model'''					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										with self.assertRaises(_lowerCAmelCase					):
																__SCREAMING_SNAKE_CASE:				Optional[Any]           =   AutoImageProcessor.from_pretrained('''hf-internal-testing/test_dynamic_image_processor'''					)
										# If remote code is disabled, we can't load this config.
										with self.assertRaises(_lowerCAmelCase					):
																__SCREAMING_SNAKE_CASE:				Any           =   AutoImageProcessor.from_pretrained(
																    '''hf-internal-testing/test_dynamic_image_processor'''			, trust_remote_code=_lowerCAmelCase					)

										__SCREAMING_SNAKE_CASE:				Optional[Any]           =   AutoImageProcessor.from_pretrained(
										    '''hf-internal-testing/test_dynamic_image_processor'''			, trust_remote_code=_lowerCAmelCase					)
										self.assertEqual(image_processor.__class__.__name__			, '''NewImageProcessor'''					)

										# Test image processor can be reloaded.
										with tempfile.TemporaryDirectory() as tmp_dir:
																image_processor.save_pretrained(_lowerCAmelCase					)
																__SCREAMING_SNAKE_CASE:				List[str]           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase			, trust_remote_code=_lowerCAmelCase					)
										self.assertEqual(reloaded_image_processor.__class__.__name__			, '''NewImageProcessor'''					)






				def 			snake_case_    (  self					):

										"""simple docstring"""




										try:
																AutoConfig.register('''custom'''			, _lowerCAmelCase					)
																AutoImageProcessor.register(_lowerCAmelCase			, _lowerCAmelCase					)
																# Trying to register something existing in the Transformers library will raise an error
																with self.assertRaises(_lowerCAmelCase					):
																						AutoImageProcessor.register(_lowerCAmelCase			, _lowerCAmelCase					)

																with tempfile.TemporaryDirectory() as tmpdirname:
																						__SCREAMING_SNAKE_CASE:				Optional[int]           =   Path(_lowerCAmelCase					) / '''preprocessor_config.json'''
																						__SCREAMING_SNAKE_CASE:				Union[str, Any]           =   Path(_lowerCAmelCase					) / '''config.json'''
																						json.dump(
																						    {'''feature_extractor_type''': '''CLIPFeatureExtractor''', '''processor_class''': '''CLIPProcessor'''}			, open(_lowerCAmelCase			, '''w'''					)			, )
																						json.dump({'''model_type''': '''clip'''}			, open(_lowerCAmelCase			, '''w'''					)					)

																						__SCREAMING_SNAKE_CASE:				List[str]           =   CustomImageProcessor.from_pretrained(_lowerCAmelCase					)

																# Now that the config is registered, it can be used as any other config with the auto-API
																with tempfile.TemporaryDirectory() as tmp_dir:
																						image_processor.save_pretrained(_lowerCAmelCase					)
																						__SCREAMING_SNAKE_CASE:				int           =   AutoImageProcessor.from_pretrained(_lowerCAmelCase					)
																						self.assertIsInstance(_lowerCAmelCase			, _lowerCAmelCase					)

										finally:
																if "custom" in CONFIG_MAPPING._extra_content:
																						del CONFIG_MAPPING._extra_content["custom"]
																if CustomConfig in IMAGE_PROCESSOR_MAPPING._extra_content:
																						del IMAGE_PROCESSOR_MAPPING._extra_content[CustomConfig]






				def 			snake_case_    (  self					):

										"""simple docstring"""




										class 				a			(      __lowercase			):
														SCREAMING_SNAKE_CASE__     :   Tuple		      =     True

										try:
																AutoConfig.register('''custom'''			, _lowerCAmelCase					)
																AutoImageProcessor.register(_lowerCAmelCase			, _lowerCAmelCase					)
																# If remote code is not set, the default is to use local
																__SCREAMING_SNAKE_CASE:				str           =   AutoImageProcessor.from_pretrained('''hf-internal-testing/test_dynamic_image_processor'''					)
																self.assertEqual(image_processor.__class__.__name__			, '''NewImageProcessor'''					)
																self.assertTrue(image_processor.is_local					)

																# If remote code is disabled, we load the local one.
																__SCREAMING_SNAKE_CASE:				Tuple           =   AutoImageProcessor.from_pretrained(
																    '''hf-internal-testing/test_dynamic_image_processor'''			, trust_remote_code=_lowerCAmelCase					)
																self.assertEqual(image_processor.__class__.__name__			, '''NewImageProcessor'''					)
																self.assertTrue(image_processor.is_local					)

																# If remote is enabled, we load from the Hub
																__SCREAMING_SNAKE_CASE:				Any           =   AutoImageProcessor.from_pretrained(
																    '''hf-internal-testing/test_dynamic_image_processor'''			, trust_remote_code=_lowerCAmelCase					)
																self.assertEqual(image_processor.__class__.__name__			, '''NewImageProcessor'''					)
																self.assertTrue(not hasattr(_lowerCAmelCase			, '''is_local'''					)					)

										finally:
																if "custom" in CONFIG_MAPPING._extra_content:
																						del CONFIG_MAPPING._extra_content["custom"]
																if CustomConfig in IMAGE_PROCESSOR_MAPPING._extra_content:
																						del IMAGE_PROCESSOR_MAPPING._extra_content[CustomConfig]



