





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


_snake_case           =			logging.getLogger()





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







  def   UpperCAmelCase					(      self  :Optional[Any]   ,							_lowercase  :Path   ,							_lowercase  :Union[str, None] = None   ,							_lowercase  :Union[List[str], None] = None   ,							_lowercase  :Union[str, List[str], None] = None   ,							_lowercase  :bool = True   ,							):






     '''simple docstring'''





     lowercase__			       =  [file for file in os.listdir(__snake_case ) if os.path.isfile(os.path.join(__snake_case   ,							__snake_case ) )]

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

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

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

     for file in files:
        # Open all files
        print("Testing"   ,							__snake_case )

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







  def   UpperCAmelCase					(      self  :str ):






     '''simple docstring'''





     lowercase__			       =  Path("src/transformers" )
     lowercase__			       =  'modeling'
     lowercase__			       =  [
         'modeling_ctrl.py',
         'modeling_tf_ctrl.py',
     ]
     self.analyze_directory(__snake_case   ,							identifier=__snake_case   ,							ignore_files=__snake_case )







  def   UpperCAmelCase					(      self  :List[Any] ):






     '''simple docstring'''





     lowercase__			       =  Path("src/transformers" )
     lowercase__			       =  'tokenization'
     self.analyze_directory(__snake_case   ,							identifier=__snake_case )







  def   UpperCAmelCase					(      self  :str ):






     '''simple docstring'''





     lowercase__			       =  Path("src/transformers" )
     lowercase__			       =  'configuration'
     self.analyze_directory(__snake_case   ,							identifier=__snake_case )







  def   UpperCAmelCase					(      self  :Any ):






     '''simple docstring'''





     lowercase__			       =  Path("src/transformers" )
     lowercase__			       =  ['configuration', 'modeling', 'tokenization']
     self.analyze_directory(__snake_case   ,							n_identifier=__snake_case )







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






     '''simple docstring'''





     lowercase__			       =  Path("docs/source" )
     lowercase__			       =  ['favicon.ico']
     self.analyze_directory(__snake_case   ,							ignore_files=__snake_case   ,							only_modules=__snake_case )













def _A       (   __magic_name__	):
   lowercase__			       =  ""
   for ch in key:
      if ch == " " or ch not in key_no_dups and ch.isalpha():
         key_no_dups += ch
   return key_no_dups


def _A       (   __magic_name__	):
   lowercase__			       =  [chr(i + 65	) for i in range(26	)]
   # Remove duplicate characters from key
   lowercase__			       =  remove_duplicates(key.upper()	)
   lowercase__			       =  len(__magic_name__	)
   # First fill cipher with key characters
   lowercase__			       =  {alphabet[i]: char for i, char in enumerate(__magic_name__	)}
   # Then map remaining characters in alphabet to
   # the alphabet from the beginning
   for i in range(len(__magic_name__	)  , 26	):
      lowercase__			       =  alphabet[i - offset]
      # Ensure we are not mapping letters to letters previously mapped
      while char in key:
         offset -= 1
         lowercase__			       =  alphabet[i - offset]
      lowercase__			       =  char
   return cipher_alphabet


def _A       (   __magic_name__  , __magic_name__	):
   return "".join(cipher_map.get(__magic_name__  , __magic_name__	) for ch in message.upper()	)


def _A       (   __magic_name__  , __magic_name__	):
   lowercase__			       =  {v: k for k, v in cipher_map.items()}
   return "".join(rev_cipher_map.get(__magic_name__  , __magic_name__	) for ch in message.upper()	)


def _A       (   ):
   lowercase__			       =  input("Enter message to encode or decode: "	).strip()
   lowercase__			       =  input("Enter keyword: "	).strip()
   lowercase__			       =  input("Encipher or decipher? E/D:"	).strip()[0].lower()
   try:
      lowercase__			       =  {"e": encipher, "d": decipher}[option]
   except KeyError:
      raise KeyError("invalid input option"	)
   lowercase__			       =  create_cipher_map(__magic_name__	)
   print(func(__magic_name__  , __magic_name__	)	)


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  main()






