



'''simple docstring'''

import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_video_inputs


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import VivitImageProcessor

class __snake_case(				unittest.TestCase ):


						'''simple docstring'''



						def __init__( self     ,	A_     ,	A_=7     ,	A_=3     ,	A_=10     ,	A_=18     ,	A_=30     ,	A_=400     ,	A_=True     ,	A_=None     ,	A_=True     ,	A_=[0.5, 0.5, 0.5]     ,	A_=[0.5, 0.5, 0.5]     ,	A_=None     ,	)     ->     Dict:
							lowerCAmelCase   =     size if size is not None else {"""shortest_edge""": 18}
							lowerCAmelCase   =     crop_size if crop_size is not None else {"""height""": 18, """width""": 18}

							lowerCAmelCase   =     parent
							lowerCAmelCase   =     batch_size
							lowerCAmelCase   =     num_channels
							lowerCAmelCase   =     num_frames
							lowerCAmelCase   =     image_size
							lowerCAmelCase   =     min_resolution
							lowerCAmelCase   =     max_resolution
							lowerCAmelCase   =     do_resize
							lowerCAmelCase   =     size
							lowerCAmelCase   =     do_normalize
							lowerCAmelCase   =     image_mean
							lowerCAmelCase   =     image_std
							lowerCAmelCase   =     crop_size




						def     __snake_case   ( self				)     ->     Optional[int]:
							return {
							    "image_mean": self.image_mean,
							    "image_std": self.image_std,
							    "do_normalize": self.do_normalize,
							    "do_resize": self.do_resize,
							    "size": self.size,
							    "crop_size": self.crop_size,
							}







@require_torch
@require_vision
class __snake_case(				_UpperCamelCase		,							unittest.TestCase ):


						'''simple docstring'''



						UpperCAmelCase							:   Any									=		VivitImageProcessor if is_vision_available() else None


						def     __snake_case   ( self				)     ->     Union[str, Any]:
							lowerCAmelCase   =     VivitImageProcessingTester(self				)


						@property
						def     __snake_case   ( self				)     ->     Optional[int]:
							return self.image_processor_tester.prepare_image_processor_dict()


						def     __snake_case   ( self				)     ->     List[str]:
							lowerCAmelCase   =     self.image_processing_class(**self.image_processor_dict				)
							self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,	"""image_mean"""				)				)
							self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,	"""image_std"""				)				)
							self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,	"""do_normalize"""				)				)
							self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,	"""do_resize"""				)				)
							self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,	"""do_center_crop"""				)				)
							self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE     ,	"""size"""				)				)


						def     __snake_case   ( self				)     ->     Optional[Any]:
							lowerCAmelCase   =     self.image_processing_class.from_dict(self.image_processor_dict				)
							self.assertEqual(image_processor.size     ,	{"""shortest_edge""": 18}				)
							self.assertEqual(image_processor.crop_size     ,	{"""height""": 18, """width""": 18}				)

							lowerCAmelCase   =     self.image_processing_class.from_dict(self.image_processor_dict     ,	size=42     ,	crop_size=84				)
							self.assertEqual(image_processor.size     ,	{"""shortest_edge""": 42}				)
							self.assertEqual(image_processor.crop_size     ,	{"""height""": 84, """width""": 84}				)


						def     __snake_case   ( self				)     ->     Dict:
							# Initialize image_processing
							lowerCAmelCase   =     self.image_processing_class(**self.image_processor_dict				)
							# create random PIL videos
							lowerCAmelCase   =     prepare_video_inputs(self.image_processor_tester     ,	equal_resolution=_SCREAMING_SNAKE_CASE				)
							for video in video_inputs:
								self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,	_SCREAMING_SNAKE_CASE				)
								self.assertIsInstance(video[0]     ,	Image.Image				)

							# Test not batched input
							lowerCAmelCase   =     image_processing(video_inputs[0]     ,	return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_videos.shape     ,	(
							        1,
							        self.image_processor_tester.num_frames,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )     ,	)

							# Test batched
							lowerCAmelCase   =     image_processing(_SCREAMING_SNAKE_CASE     ,	return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_videos.shape     ,	(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_frames,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )     ,	)


						def     __snake_case   ( self				)     ->     Optional[Any]:
							# Initialize image_processing
							lowerCAmelCase   =     self.image_processing_class(**self.image_processor_dict				)
							# create random numpy tensors
							lowerCAmelCase   =     prepare_video_inputs(self.image_processor_tester     ,	equal_resolution=_SCREAMING_SNAKE_CASE     ,	numpify=_SCREAMING_SNAKE_CASE				)
							for video in video_inputs:
								self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,	_SCREAMING_SNAKE_CASE				)
								self.assertIsInstance(video[0]     ,	np.ndarray				)

							# Test not batched input
							lowerCAmelCase   =     image_processing(video_inputs[0]     ,	return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_videos.shape     ,	(
							        1,
							        self.image_processor_tester.num_frames,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )     ,	)

							# Test batched
							lowerCAmelCase   =     image_processing(_SCREAMING_SNAKE_CASE     ,	return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_videos.shape     ,	(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_frames,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )     ,	)




						def     __snake_case   ( self				)     ->     str:
							# Initialize image_processing
							lowerCAmelCase   =     self.image_processing_class(**self.image_processor_dict				)
							# create random PyTorch tensors
							lowerCAmelCase   =     prepare_video_inputs(self.image_processor_tester     ,	equal_resolution=_SCREAMING_SNAKE_CASE     ,	torchify=_SCREAMING_SNAKE_CASE				)
							for video in video_inputs:
								self.assertIsInstance(_SCREAMING_SNAKE_CASE     ,	_SCREAMING_SNAKE_CASE				)
								self.assertIsInstance(video[0]     ,	torch.Tensor				)

							# Test not batched input
							lowerCAmelCase   =     image_processing(video_inputs[0]     ,	return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_videos.shape     ,	(
							        1,
							        self.image_processor_tester.num_frames,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )     ,	)

							# Test batched
							lowerCAmelCase   =     image_processing(_SCREAMING_SNAKE_CASE     ,	return_tensors="""pt"""				).pixel_values
							self.assertEqual(
							    encoded_videos.shape     ,	(
							        self.image_processor_tester.batch_size,
							        self.image_processor_tester.num_frames,
							        self.image_processor_tester.num_channels,
							        self.image_processor_tester.crop_size["""height"""],
							        self.image_processor_tester.crop_size["""width"""],
							    )     ,	)




'''simple docstring'''

from __future__ import annotations

class __snake_case:


						'''simple docstring'''



						def __init__( self     ,	A_ = 0				)     ->     Dict:
							lowerCAmelCase   =     key


						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     list[str]:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key is an appropriate size
							key %= 255

							return [chr(ord(A_				) ^ key				) for ch in content]


						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     list[str]:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key is an appropriate size
							key %= 255

							return [chr(ord(A_				) ^ key				) for ch in content]


						def     __snake_case   ( self     ,	A_     ,	A_ = 0				)     ->     str:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key can be any size
							while key > 255:
								key -= 255

							# This will be returned
							lowerCAmelCase   =     """"""

							for ch in content:
								ans += chr(ord(A_				) ^ key				)

							return ans


						def     __snake_case   ( self     ,	A_     ,	A_ = 0				)     ->     str:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							lowerCAmelCase   =     key or self.__key or 1

							# make sure key can be any size
							while key > 255:
								key -= 255

							# This will be returned
							lowerCAmelCase   =     """"""

							for ch in content:
								ans += chr(ord(A_				) ^ key				)

							return ans


						def     __snake_case   ( self     ,	A_     ,	A_ = 0				)     ->     bool:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							try:
								with open(A_				) as fin, open("""encrypt.out"""     ,	"""w+"""				) as fout:
									# actual encrypt-process
									for line in fin:
										fout.write(self.encrypt_string(A_     ,	A_				)				)

							except OSError:
								return False

							return True




						def     __snake_case   ( self     ,	A_     ,	A_				)     ->     bool:
							assert isinstance(A_     ,	A_				) and isinstance(A_     ,	A_				)

							try:
								with open(A_				) as fin, open("""decrypt.out"""     ,	"""w+"""				) as fout:
									# actual encrypt-process
									for line in fin:
										fout.write(self.decrypt_string(A_     ,	A_				)				)

							except OSError:
								return False

							return True


# Tests
# crypt = XORCipher()
# key = 67

# # test encrypt
# print(crypt.encrypt("hallo welt",key))
# # test decrypt
# print(crypt.decrypt(crypt.encrypt("hallo welt",key), key))

# # test encrypt_string
# print(crypt.encrypt_string("hallo welt",key))

# # test decrypt_string
# print(crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key))

# if (crypt.encrypt_file("test.txt",key)):
#       print("encrypt successful")
# else:
#       print("encrypt unsuccessful")

# if (crypt.decrypt_file("encrypt.out",key)):
#       print("decrypt successful")
# else:
#       print("decrypt unsuccessful")