


'''simple docstring'''






import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


__UpperCAmelCase					       =							logging.getLogger()




@unittest.skip("Temporarily disable the doc tests."						)
@require_torch
@require_tf
@slow
class 	a__       (							unittest.TestCase						):





							'''simple docstring'''






							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_ = None      ,					lowerCamelCase_ = None      ,					lowerCamelCase_ = None      ,					lowerCamelCase_ = True      ,					) ->							int:
														lowerCAmelCase__      =			[file for file in os.listdir(lowerCamelCase_     ) if os.path.isfile(os.path.join(lowerCamelCase_      ,					lowerCamelCase_     )     )]

														if identifier is not None:
																					lowerCAmelCase__      =			[file for file in files if identifier in file]

														if n_identifier is not None:
																					if isinstance(lowerCamelCase_      ,					lowerCamelCase_     ):
																												for n_ in n_identifier:
																																			lowerCAmelCase__      =			[file for file in files if n_ not in file]
																					else:
																												lowerCAmelCase__      =			[file for file in files if n_identifier not in file]

														lowerCAmelCase__      =			ignore_files or []
														ignore_files.append('''__init__.py'''     )
														lowerCAmelCase__      =			[file for file in files if file not in ignore_files]

														for file in files:
																					# Open all files
																					print('''Testing'''      ,					lowerCamelCase_     )

																					if only_modules:
																												lowerCAmelCase__      =			file.split('''.'''     )[0]
																												try:
																																			lowerCAmelCase__      =			getattr(lowerCamelCase_      ,					lowerCamelCase_     )
																																			lowerCAmelCase__      =			doctest.DocTestSuite(lowerCamelCase_     )
																																			lowerCAmelCase__      =			unittest.TextTestRunner().run(lowerCamelCase_     )
																																			self.assertIs(len(result.failures     )      ,					0     )
																												except AttributeError:
																																			logger.info(F"""{module_identifier} is not a module."""     )
																					else:
																												lowerCAmelCase__      =			doctest.testfile(str('''..''' / directory / file     )      ,					optionflags=doctest.ELLIPSIS     )
																												self.assertIs(result.failed      ,					0     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Optional[Any]:
														lowerCAmelCase__      =			Path('''src/transformers'''     )
														lowerCAmelCase__      =			'''modeling'''
														lowerCAmelCase__      =			[
														    '''modeling_ctrl.py''',
														    '''modeling_tf_ctrl.py''',
														]
														self.analyze_directory(lowerCamelCase_      ,					identifier=lowerCamelCase_      ,					ignore_files=lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Tuple:
														lowerCAmelCase__      =			Path('''src/transformers'''     )
														lowerCAmelCase__      =			'''tokenization'''
														self.analyze_directory(lowerCamelCase_      ,					identifier=lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Dict:
														lowerCAmelCase__      =			Path('''src/transformers'''     )
														lowerCAmelCase__      =			'''configuration'''
														self.analyze_directory(lowerCamelCase_      ,					identifier=lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														lowerCAmelCase__      =			Path('''src/transformers'''     )
														lowerCAmelCase__      =			['''configuration''', '''modeling''', '''tokenization''']
														self.analyze_directory(lowerCamelCase_      ,					n_identifier=lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Union[str, Any]:
														lowerCAmelCase__      =			Path('''docs/source'''     )
														lowerCAmelCase__      =			['''favicon.ico''']
														self.analyze_directory(lowerCamelCase_      ,					ignore_files=lowerCamelCase_      ,					only_modules=lowerCamelCase_     )



'''simple docstring'''






from __future__ import annotations




class 	a__       :





							'''simple docstring'''






							def __init__(	self      ,					lowerCamelCase_ = 0     ) ->							List[Any]:
														lowerCAmelCase__      =			key







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							list[str]:
														assert isinstance(lowerCamelCase_      ,					lowerCamelCase_     ) and isinstance(lowerCamelCase_      ,					lowerCamelCase_     )

														lowerCAmelCase__      =			key or self.__key or 1

														# make sure key is an appropriate size
														key %= 2_55

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







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							list[str]:
														assert isinstance(lowerCamelCase_      ,					lowerCamelCase_     ) and isinstance(lowerCamelCase_      ,					lowerCamelCase_     )

														lowerCAmelCase__      =			key or self.__key or 1

														# make sure key is an appropriate size
														key %= 2_55

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







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_ = 0     ) ->							str:
														assert isinstance(lowerCamelCase_      ,					lowerCamelCase_     ) and isinstance(lowerCamelCase_      ,					lowerCamelCase_     )

														lowerCAmelCase__      =			key or self.__key or 1

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

														# This will be returned
														lowerCAmelCase__      =			''''''

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

														return ans







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_ = 0     ) ->							str:
														assert isinstance(lowerCamelCase_      ,					lowerCamelCase_     ) and isinstance(lowerCamelCase_      ,					lowerCamelCase_     )

														lowerCAmelCase__      =			key or self.__key or 1

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

														# This will be returned
														lowerCAmelCase__      =			''''''

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

														return ans







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_ = 0     ) ->							bool:
														assert isinstance(lowerCamelCase_      ,					lowerCamelCase_     ) and isinstance(lowerCamelCase_      ,					lowerCamelCase_     )

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

														except OSError:
																					return False

														return True







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							bool:
														assert isinstance(lowerCamelCase_      ,					lowerCamelCase_     ) and isinstance(lowerCamelCase_      ,					lowerCamelCase_     )

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

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