
"""simple docstring"""






import unittest

from transformers import MobileBertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    MODEL_FOR_PRETRAINING_MAPPING,
					    MobileBertForMaskedLM,
					    MobileBertForMultipleChoice,
					    MobileBertForNextSentencePrediction,
					    MobileBertForPreTraining,
					    MobileBertForQuestionAnswering,
					    MobileBertForSequenceClassification,
					    MobileBertForTokenClassification,
					    MobileBertModel,
					)



class 			lowercase					:






			def __init__(self  :	Any      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=13      ,SCREAMING_SNAKE_CASE_  :	str=7      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=True      ,SCREAMING_SNAKE_CASE_  :	Any=True      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=True      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=True      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=99      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=64      ,SCREAMING_SNAKE_CASE_  :	Tuple=32      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=5      ,SCREAMING_SNAKE_CASE_  :	Tuple=4      ,SCREAMING_SNAKE_CASE_  :	Any=37      ,SCREAMING_SNAKE_CASE_  :	List[Any]="gelu"      ,SCREAMING_SNAKE_CASE_  :	Any=0.1      ,SCREAMING_SNAKE_CASE_  :	str=0.1      ,SCREAMING_SNAKE_CASE_  :	List[str]=512      ,SCREAMING_SNAKE_CASE_  :	str=16      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=2      ,SCREAMING_SNAKE_CASE_  :	Optional[int]=0.02      ,SCREAMING_SNAKE_CASE_  :	Any=3      ,SCREAMING_SNAKE_CASE_  :	str=4      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=None      ,)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  parent
				lowerCAmelCase												=  batch_size
				lowerCAmelCase												=  seq_length
				lowerCAmelCase												=  is_training
				lowerCAmelCase												=  use_input_mask
				lowerCAmelCase												=  use_token_type_ids
				lowerCAmelCase												=  use_labels
				lowerCAmelCase												=  vocab_size
				lowerCAmelCase												=  hidden_size
				lowerCAmelCase												=  embedding_size
				lowerCAmelCase												=  num_hidden_layers
				lowerCAmelCase												=  num_attention_heads
				lowerCAmelCase												=  intermediate_size
				lowerCAmelCase												=  hidden_act
				lowerCAmelCase												=  hidden_dropout_prob
				lowerCAmelCase												=  attention_probs_dropout_prob
				lowerCAmelCase												=  max_position_embeddings
				lowerCAmelCase												=  type_vocab_size
				lowerCAmelCase												=  type_sequence_label_size
				lowerCAmelCase												=  initializer_range
				lowerCAmelCase												=  num_labels
				lowerCAmelCase												=  num_choices
				lowerCAmelCase												=  scope






			def 					UpperCAmelCase							(self  :	Dict			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]      ,self.vocab_size			)

				lowerCAmelCase												=  None
				if self.use_input_mask:
					lowerCAmelCase												=  random_attention_mask([self.batch_size, self.seq_length]			)

				lowerCAmelCase												=  None
				if self.use_token_type_ids:
					lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]      ,self.type_vocab_size			)

				lowerCAmelCase												=  None
				lowerCAmelCase												=  None
				lowerCAmelCase												=  None
				if self.use_labels:
					lowerCAmelCase												=  ids_tensor([self.batch_size]      ,self.type_sequence_label_size			)
					lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]      ,self.num_labels			)
					lowerCAmelCase												=  ids_tensor([self.batch_size]      ,self.num_choices			)

				lowerCAmelCase												=  self.get_config()

				return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels






			def 					UpperCAmelCase							(self  :	int			)       ->	Any:





				"""simple docstring"""


				return MobileBertConfig(
				    vocab_size=self.vocab_size      ,hidden_size=self.hidden_size      ,num_hidden_layers=self.num_hidden_layers      ,num_attention_heads=self.num_attention_heads      ,intermediate_size=self.intermediate_size      ,embedding_size=self.embedding_size      ,hidden_act=self.hidden_act      ,hidden_dropout_prob=self.hidden_dropout_prob      ,attention_probs_dropout_prob=self.attention_probs_dropout_prob      ,max_position_embeddings=self.max_position_embeddings      ,type_vocab_size=self.type_vocab_size      ,is_decoder=SCREAMING_SNAKE_CASE_      ,initializer_range=self.initializer_range      ,)






			def 					UpperCAmelCase							(self  :	str      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertModel(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_			)

				self.parent.assertEqual(result.last_hidden_state.shape      ,(self.batch_size, self.seq_length, self.hidden_size)			)
				self.parent.assertEqual(result.pooler_output.shape      ,(self.batch_size, self.hidden_size)			)






			def 					UpperCAmelCase							(self  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Dict      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertForMaskedLM(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_			)
				self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length, self.vocab_size)			)






			def 					UpperCAmelCase							(self  :	int      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	Dict      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	Tuple			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertForNextSentencePrediction(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(
				    SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_      ,)
				self.parent.assertEqual(result.logits.shape      ,(self.batch_size, 2)			)






			def 					UpperCAmelCase							(self  :	int      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Dict      ,SCREAMING_SNAKE_CASE_  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertForPreTraining(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(
				    SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_      ,next_sentence_label=SCREAMING_SNAKE_CASE_      ,)
				self.parent.assertEqual(result.prediction_logits.shape      ,(self.batch_size, self.seq_length, self.vocab_size)			)
				self.parent.assertEqual(result.seq_relationship_logits.shape      ,(self.batch_size, 2)			)






			def 					UpperCAmelCase							(self  :	Dict      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertForQuestionAnswering(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(
				    SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,start_positions=SCREAMING_SNAKE_CASE_      ,end_positions=SCREAMING_SNAKE_CASE_      ,)
				self.parent.assertEqual(result.start_logits.shape      ,(self.batch_size, self.seq_length)			)
				self.parent.assertEqual(result.end_logits.shape      ,(self.batch_size, self.seq_length)			)






			def 					UpperCAmelCase							(self  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	Dict      ,SCREAMING_SNAKE_CASE_  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	List[str]			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  self.num_labels
				lowerCAmelCase												=  MobileBertForSequenceClassification(SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_			)
				self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_labels)			)






			def 					UpperCAmelCase							(self  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  self.num_labels
				lowerCAmelCase												=  MobileBertForTokenClassification(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_			)
				self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.seq_length, self.num_labels)			)






			def 					UpperCAmelCase							(self  :	Dict      ,SCREAMING_SNAKE_CASE_  :	Dict      ,SCREAMING_SNAKE_CASE_  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  self.num_choices
				lowerCAmelCase												=  MobileBertForMultipleChoice(config=SCREAMING_SNAKE_CASE_			)
				model.to(SCREAMING_SNAKE_CASE_			)
				model.eval()
				lowerCAmelCase												=  input_ids.unsqueeze(1			).expand(-1      ,self.num_choices      ,-1			).contiguous()
				lowerCAmelCase												=  token_type_ids.unsqueeze(1			).expand(-1      ,self.num_choices      ,-1			).contiguous()
				lowerCAmelCase												=  input_mask.unsqueeze(1			).expand(-1      ,self.num_choices      ,-1			).contiguous()
				lowerCAmelCase												=  model(
				    SCREAMING_SNAKE_CASE_      ,attention_mask=SCREAMING_SNAKE_CASE_      ,token_type_ids=SCREAMING_SNAKE_CASE_      ,labels=SCREAMING_SNAKE_CASE_      ,)
				self.parent.assertEqual(result.logits.shape      ,(self.batch_size, self.num_choices)			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  self.prepare_config_and_inputs()
				(
				    (
				    lowerCAmelCase
				)							,       (
				    lowerCAmelCase
				)							,       (
				    lowerCAmelCase
				)							,       (
				    lowerCAmelCase
				)							,       (
				    lowerCAmelCase
				)							,       (
				    lowerCAmelCase
				)							,       (
				    lowerCAmelCase
				)							,       
				)												=  config_and_inputs
				lowerCAmelCase												=  {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
				return config, inputs_dict





@require_torch
class 			lowercase					( lowercase__   ,lowercase__   ,unittest.TestCase		):
			lowercase        =     (
			    (
			        MobileBertModel,
			        MobileBertForMaskedLM,
			        MobileBertForMultipleChoice,
			        MobileBertForNextSentencePrediction,
			        MobileBertForPreTraining,
			        MobileBertForQuestionAnswering,
			        MobileBertForSequenceClassification,
			        MobileBertForTokenClassification,
			    )
			    if is_torch_available()
			    else ()
			)
			lowercase        =     (
			    {
			        '''feature-extraction''': MobileBertModel,
			        '''fill-mask''': MobileBertForMaskedLM,
			        '''question-answering''': MobileBertForQuestionAnswering,
			        '''text-classification''': MobileBertForSequenceClassification,
			        '''token-classification''': MobileBertForTokenClassification,
			        '''zero-shot''': MobileBertForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			lowercase        =     True






			def 					UpperCAmelCase							(self  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	int      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]=False			)       ->	Any:





				"""simple docstring"""


				lowerCAmelCase												=  super()._prepare_for_class(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,return_labels=SCREAMING_SNAKE_CASE_			)

				if return_labels:
					if model_class in get_values(SCREAMING_SNAKE_CASE_			):
						lowerCAmelCase												=  torch.zeros(
						    (self.model_tester.batch_size, self.model_tester.seq_length)      ,dtype=torch.long      ,device=SCREAMING_SNAKE_CASE_			)
						lowerCAmelCase												=  torch.zeros(
						    self.model_tester.batch_size      ,dtype=torch.long      ,device=SCREAMING_SNAKE_CASE_			)
				return inputs_dict






			def 					UpperCAmelCase							(self  :	int			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertModelTester(self			)
				lowerCAmelCase												=  ConfigTester(self      ,config_class=SCREAMING_SNAKE_CASE_      ,hidden_size=37			)






			def 					UpperCAmelCase							(self  :	int			)       ->	Dict:





				"""simple docstring"""


				self.config_tester.run_common_tests()






			def 					UpperCAmelCase							(self  :	List[Any]			)       ->	Any:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_model(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_masked_lm(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_multiple_choice(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[Any]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_next_sequence_prediction(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Dict			)       ->	Optional[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_pretraining(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_question_answering(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_sequence_classification(*SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_mobilebert_for_token_classification(*SCREAMING_SNAKE_CASE_			)





def __magic_name__	(				_lowerCamelCase:		Optional[int]			)					->						Optional[int]:

	'''simple docstring'''




	return torch.tensor(
	    _lowerCamelCase,					dtype=torch.long,					device=_lowerCamelCase,					)


UpperCAmelCase        =				1e-3



@require_torch
@require_sentencepiece
@require_tokenizers
class 			lowercase					( unittest.TestCase		):






			@slow
			def 					UpperCAmelCase							(self  :	Any			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  MobileBertModel.from_pretrained('''google/mobilebert-uncased'''			).to(SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  _long_tensor([[101, 7_110, 1_005, 1_056, 2_023, 11_333, 17_413, 1_029, 102]]			)
				with torch.no_grad():
					lowerCAmelCase												=  model(SCREAMING_SNAKE_CASE_			)[0]
				lowerCAmelCase												=  torch.Size((1, 9, 512)			)
				self.assertEqual(output.shape      ,SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  torch.tensor(
				    [
				        [
				            [-2.4_736_526e07, 8.2_691_656e04, 1.6_521_838e05],
				            [-5.7_541_704e-01, 3.9_056_022e00, 4.4_011_507e00],
				            [2.6_047_359e00, 1.5_677_652e00, -1.7_324_188e-01],
				        ]
				    ]      ,device=SCREAMING_SNAKE_CASE_      ,)

				# MobileBERT results range from 10e0 to 10e8. Even a 0.0000001% difference with a value of 10e8 results in a
				# ~1 difference, it's therefore not a good idea to measure using addition.
				# Here, we instead divide the expected result with the result in order to obtain ~1. We then check that the
				# result is held between bounds: 1 - TOLERANCE < expected_result / result < 1 + TOLERANCE
				lowerCAmelCase												=  torch.all((expected_slice / output[..., :3, :3]) >= 1 - TOLERANCE			)
				lowerCAmelCase												=  torch.all((expected_slice / output[..., :3, :3]) <= 1 + TOLERANCE			)

				self.assertTrue(lower_bound and upper_bound			)




"""simple docstring"""






from __future__ import annotations



class 			lowercase					:






			def __init__(self  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	int = 0			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  key






			def 					UpperCAmelCase							(self  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	int			)       ->	list[str]:





				"""simple docstring"""


				assert isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			) and isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  key or self.__key or 1

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

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






			def 					UpperCAmelCase							(self  :	int      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	int			)       ->	list[str]:





				"""simple docstring"""


				assert isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			) and isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  key or self.__key or 1

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

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






			def 					UpperCAmelCase							(self  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	int = 0			)       ->	str:





				"""simple docstring"""


				assert isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			) and isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				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(SCREAMING_SNAKE_CASE_			) ^ key			)

				return ans






			def 					UpperCAmelCase							(self  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	int = 0			)       ->	str:





				"""simple docstring"""


				assert isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			) and isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

				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(SCREAMING_SNAKE_CASE_			) ^ key			)

				return ans






			def 					UpperCAmelCase							(self  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	int = 0			)       ->	bool:





				"""simple docstring"""


				assert isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			) and isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

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

				except OSError:
					return False

				return True






			def 					UpperCAmelCase							(self  :	List[Any]      ,SCREAMING_SNAKE_CASE_  :	str      ,SCREAMING_SNAKE_CASE_  :	int			)       ->	bool:





				"""simple docstring"""


				assert isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			) and isinstance(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)

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

				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")


