



'''simple docstring'''





import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


lowercase_									=    threading.Lock()
lowercase_									=    None

lowercase_									=    {
    "debug": logging.DEBUG,
    "info": logging.INFO,
    "warning": logging.WARNING,
    "error": logging.ERROR,
    "critical": logging.CRITICAL,
}

lowercase_									=    logging.WARNING

lowercase_									=    True




def lowerCAmelCase    ():



     """simple docstring"""



     _a           =    os.getenv('''TRANSFORMERS_VERBOSITY'''    ,      __A)
     if env_level_str:
          if env_level_str in log_levels:
               return log_levels[env_level_str]
          else:
               logging.getLogger().warning(
                   F'''Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '''
                   F'''has to be one of: { ', '.join(log_levels.keys()) }''')
     return _default_log_level




def lowerCAmelCase    ():



     """simple docstring"""



     return __name__.split('''.''')[0]




def lowerCAmelCase    ():



     """simple docstring"""



     return logging.getLogger(_get_library_name())




def lowerCAmelCase    ():



     """simple docstring"""



     global _default_handler

     with _lock:
          if _default_handler:
               # This library has already configured the library root logger.
               return
          _a           =    logging.StreamHandler()  # Set sys.stderr as stream.
          _a           =    sys.stderr.flush

          # Apply our default configuration to the library root logger.
          _a           =    _get_library_root_logger()
          library_root_logger.addHandler(_default_handler)
          library_root_logger.setLevel(_get_default_logging_level())
          _a           =    False




def lowerCAmelCase    ():



     """simple docstring"""



     global _default_handler

     with _lock:
          if not _default_handler:
               return

          _a           =    _get_library_root_logger()
          library_root_logger.removeHandler(_default_handler)
          library_root_logger.setLevel(logging.NOTSET)
          _a           =    None




def lowerCAmelCase    ():



     """simple docstring"""



     return log_levels




def lowerCAmelCase    (__A = None):



     """simple docstring"""



     if name is None:
          _a           =    _get_library_name()

     _configure_library_root_logger()
     return logging.getLogger(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     _configure_library_root_logger()
     return _get_library_root_logger().getEffectiveLevel()




def lowerCAmelCase    (__A):



     """simple docstring"""



     _configure_library_root_logger()
     _get_library_root_logger().setLevel(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     return set_verbosity(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     return set_verbosity(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     return set_verbosity(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     return set_verbosity(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     _configure_library_root_logger()

     assert _default_handler is not None
     _get_library_root_logger().removeHandler(_default_handler)




def lowerCAmelCase    ():



     """simple docstring"""



     _configure_library_root_logger()

     assert _default_handler is not None
     _get_library_root_logger().addHandler(_default_handler)




def lowerCAmelCase    (__A):



     """simple docstring"""



     _configure_library_root_logger()

     assert handler is not None
     _get_library_root_logger().addHandler(__A)




def lowerCAmelCase    (__A):



     """simple docstring"""



     _configure_library_root_logger()

     assert handler is not None and handler not in _get_library_root_logger().handlers
     _get_library_root_logger().removeHandler(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     _configure_library_root_logger()
     _a           =    False




def lowerCAmelCase    ():



     """simple docstring"""



     _configure_library_root_logger()
     _a           =    True




def lowerCAmelCase    ():



     """simple docstring"""



     _a           =    _get_library_root_logger().handlers

     for handler in handlers:
          _a           =    logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s''')
          handler.setFormatter(__A)




def lowerCAmelCase    ():



     """simple docstring"""



     _a           =    _get_library_root_logger().handlers

     for handler in handlers:
          handler.setFormatter(__A)




def lowerCAmelCase    (self    ,      *__A    ,      **__A):



     """simple docstring"""



     _a           =    os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''    ,      __A)
     if no_advisory_warnings:
          return
     self.warning(*__A    ,      **__A)


lowercase_									=    warning_advice




@functools.lru_cache(__A)
def lowerCAmelCase    (self    ,      *__A    ,      **__A):



     """simple docstring"""



     self.warning(*__A    ,      **__A)


lowercase_									=    warning_once






class __A     :



 '''simple docstring'''







 def __init__(self					,  *A					,  **A			)       ->	str:  # pylint: disable=unused-argument


      """simple docstring"""



      _a           =    args[0] if args else None



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


      """simple docstring"""



      return iter(self._iterator			)



 def __getattr__(self					,  A			)       ->	Optional[int]:


      """simple docstring"""



      def empty_fn(*A					,  **A			):  # pylint: disable=unused-argument
           return

      return empty_fn



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


      """simple docstring"""



      return self



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


      """simple docstring"""



      return






class __A     :



 '''simple docstring'''







 def __call__(self					,  *A					,  **A			)       ->	Optional[Any]:


      """simple docstring"""



      if _tqdm_active:
           return tqdm_lib.tqdm(*A					,  **A			)
      else:
           return EmptyTqdm(*A					,  **A			)



 def    a__    (self					,  *A					,  **A			)       ->	Optional[int]:


      """simple docstring"""



      _a           =    None
      if _tqdm_active:
           return tqdm_lib.tqdm.set_lock(*A					,  **A			)



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


      """simple docstring"""



      if _tqdm_active:
           return tqdm_lib.tqdm.get_lock()





lowercase_									=    _tqdm_cls()




def lowerCAmelCase    ():



     """simple docstring"""



     global _tqdm_active
     return bool(_tqdm_active)




def lowerCAmelCase    ():



     """simple docstring"""



     global _tqdm_active
     _a           =    True
     hf_hub_utils.enable_progress_bars()




def lowerCAmelCase    ():



     """simple docstring"""



     global _tqdm_active
     _a           =    False
     hf_hub_utils.disable_progress_bars()







__UpperCamelCase     		=							2_5_6
# Modulus to hash a string
__UpperCamelCase     		=							1_0_0_0_0_0_3
def 							UpperCamelCase_(					_A :str					,  _A :str	)->		bool:
			UpperCamelCase__       =							len(_A	)
			UpperCamelCase__       =							len(_A	)
			if p_len > t_len:
						return False

			UpperCamelCase__       =							0
			UpperCamelCase__       =							0
			UpperCamelCase__       =							1

			# Calculating the hash of pattern and substring of text
			for i in range(_A	):
						UpperCamelCase__       =							(ord(pattern[i]	) + p_hash * alphabet_size) % modulus
						UpperCamelCase__       =							(ord(text[i]	) + text_hash * alphabet_size) % modulus
						if i == p_len - 1:
									continue
						UpperCamelCase__       =							(modulus_power * alphabet_size) % modulus

			for i in range(0					,  t_len - p_len + 1	):
						if text_hash == p_hash and text[i : i + p_len] == pattern:
									return True
						if i == t_len - p_len:
									continue
						# Calculate the https://en.wikipedia.org/wiki/Rolling_hash
						UpperCamelCase__       =							(
						    (text_hash - ord(text[i]	) * modulus_power) * alphabet_size
						    + ord(text[i + p_len]	)
						) % modulus
			return False
def 							UpperCamelCase_(					)->		None:
			UpperCamelCase__       =							"abc1abc12"
			UpperCamelCase__       =							"alskfjaldsabc1abc1abc12k23adsfabcabc"
			UpperCamelCase__       =							"alskfjaldsk23adsfabcabc"
			assert rabin_karp(_A					,  _A	) and not rabin_karp(_A					,  _A	)

			# Test 2)
			UpperCamelCase__       =							"ABABX"
			UpperCamelCase__       =							"ABABZABABYABABX"
			assert rabin_karp(_A					,  _A	)

			# Test 3)
			UpperCamelCase__       =							"AAAB"
			UpperCamelCase__       =							"ABAAAAAB"
			assert rabin_karp(_A					,  _A	)

			# Test 4)
			UpperCamelCase__       =							"abcdabcy"
			UpperCamelCase__       =							"abcxabcdabxabcdabcdabcy"
			assert rabin_karp(_A					,  _A	)

			# Test 5)
			UpperCamelCase__       =							"Lü"
			UpperCamelCase__       =							"Lüsai"
			assert rabin_karp(_A					,  _A	)
			UpperCamelCase__       =							"Lue"
			assert not rabin_karp(_A					,  _A	)
			print("Success."	)


if __name__ == "__main__":
						test_rabin_karp()


