




from __future__ import annotations

import unittest

from transformers import FunnelConfig, is_tf_available
from transformers.testing_utils import require_tf

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
	import tensorflow as tf

	from transformers import (
	    TFFunnelBaseModel,
	    TFFunnelForMaskedLM,
	    TFFunnelForMultipleChoice,
	    TFFunnelForPreTraining,
	    TFFunnelForQuestionAnswering,
	    TFFunnelForSequenceClassification,
	    TFFunnelForTokenClassification,
	    TFFunnelModel,
	)
class        __snake_case  :



				def __init__(      self      :		str		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		Union[str, Any]=13		,	_UpperCAmelCase      :		Dict=7		,	_UpperCAmelCase      :		Optional[int]=True		,	_UpperCAmelCase      :		Optional[Any]=True		,	_UpperCAmelCase      :		Optional[int]=True		,	_UpperCAmelCase      :		Any=True		,	_UpperCAmelCase      :		int=99		,	_UpperCAmelCase      :		List[Any]=[1, 1, 2]		,	_UpperCAmelCase      :		Union[str, Any]=1		,	_UpperCAmelCase      :		int=32		,	_UpperCAmelCase      :		Optional[Any]=4		,	_UpperCAmelCase      :		List[str]=8		,	_UpperCAmelCase      :		List[str]=37		,	_UpperCAmelCase      :		Union[str, Any]="gelu_new"		,	_UpperCAmelCase      :		Optional[int]=0.1		,	_UpperCAmelCase      :		Union[str, Any]=0.1		,	_UpperCAmelCase      :		Tuple=0.0		,	_UpperCAmelCase      :		List[str]=512		,	_UpperCAmelCase      :		str=3		,	_UpperCAmelCase      :		Dict=0.02		,	_UpperCAmelCase      :		int=3		,	_UpperCAmelCase      :		Union[str, Any]=4		,	_UpperCAmelCase      :		Dict=None		,	_UpperCAmelCase      :		int=False		,	)  ->    str:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      parent
								_lowerCAmelCase    :    Any										=      batch_size
								_lowerCAmelCase    :    Dict										=      seq_length
								_lowerCAmelCase    :    Optional[Any]										=      is_training
								_lowerCAmelCase    :    int										=      use_input_mask
								_lowerCAmelCase    :    Optional[Any]										=      use_token_type_ids
								_lowerCAmelCase    :    Tuple										=      use_labels
								_lowerCAmelCase    :    Dict										=      vocab_size
								_lowerCAmelCase    :    str										=      block_sizes
								_lowerCAmelCase    :    List[str]										=      num_decoder_layers
								_lowerCAmelCase    :    str										=      d_model
								_lowerCAmelCase    :    Optional[int]										=      n_head
								_lowerCAmelCase    :    Tuple										=      d_head
								_lowerCAmelCase    :    Union[str, Any]										=      d_inner
								_lowerCAmelCase    :    Dict										=      hidden_act
								_lowerCAmelCase    :    int										=      hidden_dropout
								_lowerCAmelCase    :    str										=      attention_dropout
								_lowerCAmelCase    :    Union[str, Any]										=      activation_dropout
								_lowerCAmelCase    :    Tuple										=      max_position_embeddings
								_lowerCAmelCase    :    Union[str, Any]										=      type_vocab_size
								_lowerCAmelCase    :    Any										=      2
								_lowerCAmelCase    :    Dict										=      num_labels
								_lowerCAmelCase    :    Dict										=      num_choices
								_lowerCAmelCase    :    Union[str, Any]										=      scope
								_lowerCAmelCase    :    Optional[int]										=      initializer_std

								# Used in the tests to check the size of the first attention layer
								_lowerCAmelCase    :    List[str]										=      n_head
								# Used in the tests to check the size of the first hidden state
								_lowerCAmelCase    :    List[str]										=      self.d_model
								# Used in the tests to check the number of output hidden states/attentions
								_lowerCAmelCase    :    Dict										=      sum(self.block_sizes      ) + (0 if base else self.num_decoder_layers)
								# FunnelModel adds two hidden layers: input embeddings and the sum of the upsampled encoder hidden state with
								# the last hidden state of the first block (which is the first hidden state of the decoder).
								if not base:
												_lowerCAmelCase    :    List[Any]										=      self.num_hidden_layers + 2



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





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      ids_tensor([self.batch_size, self.seq_length]		,	self.vocab_size      )

								_lowerCAmelCase    :    List[str]										=      None
								if self.use_input_mask:
												_lowerCAmelCase    :    Tuple										=      random_attention_mask([self.batch_size, self.seq_length]      )

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

								_lowerCAmelCase    :    List[str]										=      None
								_lowerCAmelCase    :    str										=      None
								_lowerCAmelCase    :    Optional[Any]										=      None
								if self.use_labels:
												_lowerCAmelCase    :    Tuple										=      ids_tensor([self.batch_size]		,	self.type_sequence_label_size      )
												_lowerCAmelCase    :    int										=      ids_tensor([self.batch_size, self.seq_length]		,	self.num_labels      )
												_lowerCAmelCase    :    Any										=      ids_tensor([self.batch_size]		,	self.num_choices      )

								_lowerCAmelCase    :    Dict										=      FunnelConfig(
								    vocab_size=self.vocab_size		,	block_sizes=self.block_sizes		,	num_decoder_layers=self.num_decoder_layers		,	d_model=self.d_model		,	n_head=self.n_head		,	d_head=self.d_head		,	d_inner=self.d_inner		,	hidden_act=self.hidden_act		,	hidden_dropout=self.hidden_dropout		,	attention_dropout=self.attention_dropout		,	activation_dropout=self.activation_dropout		,	max_position_embeddings=self.max_position_embeddings		,	type_vocab_size=self.type_vocab_size		,	initializer_std=self.initializer_std		,	)

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



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





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      TFFunnelModel(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    Union[str, Any]										=      model(_UpperCAmelCase      )

								_lowerCAmelCase    :    Optional[Any]										=      [input_ids, input_mask]
								_lowerCAmelCase    :    int										=      model(_UpperCAmelCase      )

								_lowerCAmelCase    :    Any										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, self.seq_length, self.d_model)      )

								_lowerCAmelCase    :    Tuple										=      False
								_lowerCAmelCase    :    Optional[int]										=      TFFunnelModel(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, self.seq_length, self.d_model)      )

								_lowerCAmelCase    :    Optional[Any]										=      False
								_lowerCAmelCase    :    List[str]										=      TFFunnelModel(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    List[str]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, self.seq_length, self.d_model)      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      TFFunnelBaseModel(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    List[Any]										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    int										=      model(_UpperCAmelCase      )

								_lowerCAmelCase    :    int										=      [input_ids, input_mask]
								_lowerCAmelCase    :    Dict										=      model(_UpperCAmelCase      )

								_lowerCAmelCase    :    List[str]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, 2, self.d_model)      )

								_lowerCAmelCase    :    Dict										=      False
								_lowerCAmelCase    :    Tuple										=      TFFunnelBaseModel(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, 3, self.d_model)      )

								_lowerCAmelCase    :    Optional[int]										=      False
								_lowerCAmelCase    :    List[Any]										=      TFFunnelBaseModel(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    int										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.last_hidden_state.shape		,	(self.batch_size, 2, self.d_model)      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      TFFunnelForPreTraining(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Tuple										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    List[str]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.seq_length)      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      TFFunnelForMaskedLM(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Union[str, Any]										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    str										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.seq_length, self.vocab_size)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Tuple		,	_UpperCAmelCase      :		Tuple		,	_UpperCAmelCase      :		str		,	)  ->    int:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      self.num_labels
								_lowerCAmelCase    :    int										=      TFFunnelForSequenceClassification(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    Union[str, Any]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.num_labels)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]		,	_UpperCAmelCase      :		int		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		Optional[Any]		,	_UpperCAmelCase      :		Tuple		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		List[Any]		,	)  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      self.num_choices
								_lowerCAmelCase    :    Dict										=      TFFunnelForMultipleChoice(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    List[Any]										=      tf.tile(tf.expand_dims(_UpperCAmelCase		,	1      )		,	(1, self.num_choices, 1)      )
								_lowerCAmelCase    :    Optional[int]										=      tf.tile(tf.expand_dims(_UpperCAmelCase		,	1      )		,	(1, self.num_choices, 1)      )
								_lowerCAmelCase    :    Union[str, Any]										=      tf.tile(tf.expand_dims(_UpperCAmelCase		,	1      )		,	(1, self.num_choices, 1)      )
								_lowerCAmelCase    :    Optional[Any]										=      {
								    """input_ids""": multiple_choice_inputs_ids,
								    """attention_mask""": multiple_choice_input_mask,
								    """token_type_ids""": multiple_choice_token_type_ids,
								}
								_lowerCAmelCase    :    int										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.num_choices)      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      self.num_labels
								_lowerCAmelCase    :    Union[str, Any]										=      TFFunnelForTokenClassification(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    Union[str, Any]										=      model(_UpperCAmelCase      )
								self.parent.assertEqual(result.logits.shape		,	(self.batch_size, self.seq_length, self.num_labels)      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple		,	_UpperCAmelCase      :		Dict		,	_UpperCAmelCase      :		List[Any]		,	_UpperCAmelCase      :		Any		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		List[str]		,	_UpperCAmelCase      :		Union[str, Any]		,	_UpperCAmelCase      :		List[Any]		,	)  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      TFFunnelForQuestionAnswering(config=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[int]										=      {"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}
								_lowerCAmelCase    :    Union[str, Any]										=      model(_UpperCAmelCase      )
								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       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    Optional[Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      self.prepare_config_and_inputs()
								(
								    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    (
								    _lowerCAmelCase
								)					,    
								)    :    List[Any]										=      config_and_inputs
								_lowerCAmelCase    :    Union[str, Any]										=      {"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
								return config, inputs_dict






@require_tf
class        __snake_case  (_a						,	_a						,	unittest.TestCase		):
				lowerCAmelCase__				=     (
				    (
				        TFFunnelModel,
				        TFFunnelForMaskedLM,
				        TFFunnelForPreTraining,
				        TFFunnelForQuestionAnswering,
				        TFFunnelForTokenClassification,
				    )
				    if is_tf_available()
				    else ()
				)
				lowerCAmelCase__				=     (
				    {
				        "feature-extraction": (TFFunnelBaseModel, TFFunnelModel),
				        "fill-mask": TFFunnelForMaskedLM,
				        "question-answering": TFFunnelForQuestionAnswering,
				        "text-classification": TFFunnelForSequenceClassification,
				        "token-classification": TFFunnelForTokenClassification,
				        "zero-shot": TFFunnelForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)
				lowerCAmelCase__				=     False
				lowerCAmelCase__				=     False



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[int]      )  ->    Dict:





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      TFFunnelModelTester(self      )
								_lowerCAmelCase    :    List[str]										=      ConfigTester(self		,	config_class=_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Union[str, Any]      )  ->    List[Any]:





								'''simple docstring'''




								self.config_tester.run_common_tests()



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





								'''simple docstring'''




								_lowerCAmelCase    :    Tuple										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*_UpperCAmelCase      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_pretraining(*_UpperCAmelCase      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*_UpperCAmelCase      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*_UpperCAmelCase      )



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





								'''simple docstring'''




								_lowerCAmelCase    :    Optional[Any]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*_UpperCAmelCase      )






@require_tf
class        __snake_case  (_a						,	unittest.TestCase		):
				lowerCAmelCase__				=     (
				    (TFFunnelBaseModel, TFFunnelForMultipleChoice, TFFunnelForSequenceClassification) if is_tf_available() else ()
				)
				lowerCAmelCase__				=     False
				lowerCAmelCase__				=     False



				def       SCREAMING_SNAKE_CASE       (      self      :		List[Any]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      TFFunnelModelTester(self		,	base=_UpperCAmelCase      )
								_lowerCAmelCase    :    Optional[Any]										=      ConfigTester(self		,	config_class=_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]      )  ->    Optional[Any]:





								'''simple docstring'''




								self.config_tester.run_common_tests()



				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]      )  ->    List[str]:





								'''simple docstring'''




								_lowerCAmelCase    :    List[str]										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_base_model(*_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		str      )  ->    Any:





								'''simple docstring'''




								_lowerCAmelCase    :    Dict										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*_UpperCAmelCase      )



				def       SCREAMING_SNAKE_CASE       (      self      :		int      )  ->    Union[str, Any]:





								'''simple docstring'''




								_lowerCAmelCase    :    Any										=      self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*_UpperCAmelCase      )







from __future__ import annotations
class        __snake_case  :



				def __init__(      self      :		Union[str, Any]		,	_UpperCAmelCase      :		int = 0      )  ->    Optional[int]:





								'''simple docstring'''




								_lowerCAmelCase    :    int										=      key



				def       SCREAMING_SNAKE_CASE       (      self      :		Dict		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		int      )  ->    list[str]:





								'''simple docstring'''




								assert isinstance(_UpperCAmelCase		,	_UpperCAmelCase      ) and isinstance(_UpperCAmelCase		,	_UpperCAmelCase      )

								_lowerCAmelCase    :    Optional[Any]										=      key or self.__key or 1

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

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



				def       SCREAMING_SNAKE_CASE       (      self      :		List[str]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		int      )  ->    list[str]:





								'''simple docstring'''




								assert isinstance(_UpperCAmelCase		,	_UpperCAmelCase      ) and isinstance(_UpperCAmelCase		,	_UpperCAmelCase      )

								_lowerCAmelCase    :    List[Any]										=      key or self.__key or 1

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

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



				def       SCREAMING_SNAKE_CASE       (      self      :		Optional[Any]		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		int = 0      )  ->    str:





								'''simple docstring'''




								assert isinstance(_UpperCAmelCase		,	_UpperCAmelCase      ) and isinstance(_UpperCAmelCase		,	_UpperCAmelCase      )

								_lowerCAmelCase    :    Union[str, Any]										=      key or self.__key or 1

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

								# This will be returned
								_lowerCAmelCase    :    List[str]										=      """"""

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

								return ans



				def       SCREAMING_SNAKE_CASE       (      self      :		Tuple		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		int = 0      )  ->    str:





								'''simple docstring'''




								assert isinstance(_UpperCAmelCase		,	_UpperCAmelCase      ) and isinstance(_UpperCAmelCase		,	_UpperCAmelCase      )

								_lowerCAmelCase    :    Any										=      key or self.__key or 1

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

								# This will be returned
								_lowerCAmelCase    :    List[Any]										=      """"""

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

								return ans



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





								'''simple docstring'''




								assert isinstance(_UpperCAmelCase		,	_UpperCAmelCase      ) and isinstance(_UpperCAmelCase		,	_UpperCAmelCase      )

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

								except OSError:
												return False

								return True



				def       SCREAMING_SNAKE_CASE       (      self      :		Any		,	_UpperCAmelCase      :		str		,	_UpperCAmelCase      :		int      )  ->    bool:





								'''simple docstring'''




								assert isinstance(_UpperCAmelCase		,	_UpperCAmelCase      ) and isinstance(_UpperCAmelCase		,	_UpperCAmelCase      )

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

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

