




import json
import sys
import tempfile
import unittest
from pathlib import Path

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
)
from transformers.testing_utils import DUMMY_UNKNOWN_IDENTIFIER, get_tests_dir


sys.path.append(str(Path(__file__).parent.parent.parent.parent / 'utils'))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402


UpperCamelCase								=					get_tests_dir('fixtures')
UpperCamelCase								=					get_tests_dir('fixtures/dummy_feature_extractor_config.json')
UpperCamelCase								=					get_tests_dir('fixtures/dummy-config.json')





class 			__lowerCamelCase	(   unittest.TestCase   ):




    """simple docstring"""

    def        a				(	self					:					Union[str, Any]       )				->	str:
         lowerCAmelCase__          =			0


    def        a				(	self					:					Optional[int]       )				->	Optional[Any]:
         lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h"       )
         self.assertIsInstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Tuple       )				->	Dict:
         lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       )
         self.assertIsInstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Optional[int]       )				->	Tuple:
         with tempfile.TemporaryDirectory() as tmpdirname:
              lowerCAmelCase__          =			WavaVecaConfig()

              # remove feature_extractor_type to make sure config.json alone is enough to load feature processor locally
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       ).to_dict()

              config_dict.pop("feature_extractor_type"       )
              lowerCAmelCase__          =			WavaVecaFeatureExtractor(**SCREAMING_SNAKE_CASE__       )

              # save in new folder
              model_config.save_pretrained(SCREAMING_SNAKE_CASE__       )
              config.save_pretrained(SCREAMING_SNAKE_CASE__       )

              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       )

              # make sure private variable is not incorrectly saved
              lowerCAmelCase__          =			json.loads(config.to_json_string()       )
              self.assertTrue("_processor_class" not in dict_as_saved       )

         self.assertIsInstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					List[str]       )				->	Dict:
         lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       )
         self.assertIsInstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )


    def        a				(	self					:					Optional[int]       )				->	Dict:
         with self.assertRaisesRegex(
             SCREAMING_SNAKE_CASE__       ,     "bert-base is not a local folder and is not a valid model identifier"       ):
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained("bert-base"       )


    def        a				(	self					:					Tuple       )				->	str:
         with self.assertRaisesRegex(
             SCREAMING_SNAKE_CASE__       ,     r"aaaaaa is not a valid git identifier \(branch name, tag name or commit id\)"       ):
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       ,     revision="aaaaaa"       )


    def        a				(	self					:					int       )				->	Dict:
         with self.assertRaisesRegex(
             SCREAMING_SNAKE_CASE__       ,     "hf-internal-testing/config-no-model does not appear to have a file named preprocessor_config.json."       ,     ):
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained("hf-internal-testing/config-no-model"       )


    def        a				(	self					:					List[Any]       )				->	List[Any]:
         # If remote code is not set, we will time out when asking whether to load the model.
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(
                  "hf-internal-testing/test_dynamic_feature_extractor"       )
         # If remote code is disabled, we can't load this config.
         with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(
                  "hf-internal-testing/test_dynamic_feature_extractor"       ,     trust_remote_code=SCREAMING_SNAKE_CASE__       )

         lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(
             "hf-internal-testing/test_dynamic_feature_extractor"       ,     trust_remote_code=SCREAMING_SNAKE_CASE__       )
         self.assertEqual(feature_extractor.__class__.__name__       ,     "NewFeatureExtractor"       )

         # Test feature extractor can be reloaded.
         with tempfile.TemporaryDirectory() as tmp_dir:
              feature_extractor.save_pretrained(SCREAMING_SNAKE_CASE__       )
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       ,     trust_remote_code=SCREAMING_SNAKE_CASE__       )
         self.assertEqual(reloaded_feature_extractor.__class__.__name__       ,     "NewFeatureExtractor"       )


    def        a				(	self					:					int       )				->	Tuple:
         try:
              AutoConfig.register("custom"       ,     SCREAMING_SNAKE_CASE__       )
              AutoFeatureExtractor.register(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )
              # Trying to register something existing in the Transformers library will raise an error
              with self.assertRaises(SCREAMING_SNAKE_CASE__       ):
                   AutoFeatureExtractor.register(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )

              # Now that the config is registered, it can be used as any other config with the auto-API
              lowerCAmelCase__          =			CustomFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       )
              with tempfile.TemporaryDirectory() as tmp_dir:
                   feature_extractor.save_pretrained(SCREAMING_SNAKE_CASE__       )
                   lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(SCREAMING_SNAKE_CASE__       )
                   self.assertIsInstance(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )

         finally:
              if "custom" in CONFIG_MAPPING._extra_content:
                   del CONFIG_MAPPING._extra_content["custom"]
              if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                   del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]


    def        a				(	self					:					Tuple       )				->	Dict:





         class 			__lowerCamelCase	(   UpperCamelCase__   ):




             """simple docstring"""

             snake_case__ =				True

         try:
              AutoConfig.register("custom"       ,     SCREAMING_SNAKE_CASE__       )
              AutoFeatureExtractor.register(SCREAMING_SNAKE_CASE__       ,     SCREAMING_SNAKE_CASE__       )
              # If remote code is not set, the default is to use local
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(
                  "hf-internal-testing/test_dynamic_feature_extractor"       )
              self.assertEqual(feature_extractor.__class__.__name__       ,     "NewFeatureExtractor"       )
              self.assertTrue(feature_extractor.is_local       )

              # If remote code is disabled, we load the local one.
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(
                  "hf-internal-testing/test_dynamic_feature_extractor"       ,     trust_remote_code=SCREAMING_SNAKE_CASE__       )
              self.assertEqual(feature_extractor.__class__.__name__       ,     "NewFeatureExtractor"       )
              self.assertTrue(feature_extractor.is_local       )

              # If remote is enabled, we load from the Hub
              lowerCAmelCase__          =			AutoFeatureExtractor.from_pretrained(
                  "hf-internal-testing/test_dynamic_feature_extractor"       ,     trust_remote_code=SCREAMING_SNAKE_CASE__       )
              self.assertEqual(feature_extractor.__class__.__name__       ,     "NewFeatureExtractor"       )
              self.assertTrue(not hasattr(SCREAMING_SNAKE_CASE__       ,     "is_local"       )       )

         finally:
              if "custom" in CONFIG_MAPPING._extra_content:
                   del CONFIG_MAPPING._extra_content["custom"]
              if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
                   del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]






import string



def 							_A       (						lowerCAmelCase_					: str      ):
     """simple docstring"""

     for key in range(len(string.ascii_uppercase      )      ):
          lowerCAmelCase__          =			""
          for symbol in message:
               if symbol in string.ascii_uppercase:
                    lowerCAmelCase__          =			string.ascii_uppercase.find(lowerCAmelCase_      )
                    lowerCAmelCase__          =			num - key
                    if num < 0:
                         lowerCAmelCase__          =			num + len(string.ascii_uppercase      )
                    lowerCAmelCase__          =			translated + string.ascii_uppercase[num]
               else:
                    lowerCAmelCase__          =			translated + symbol
          print(F'Decryption using Key #{key}: {translated}'      )



def 							_A       (						):
     """simple docstring"""

     lowerCAmelCase__          =			input("Encrypted message: "      )
     lowerCAmelCase__          =			message.upper()
     decrypt(lowerCAmelCase_      )


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     main()
