





'''simple docstring'''






from __future__ import annotations
def    UpperCamelCase__      (		lowerCAmelCase							,	lowerCAmelCase  ):





      """simple docstring"""


      _lowerCAmelCase							     =							get_failure_array(__lowerCamelCase  )

      # 2) Step through text searching for pattern
      _lowerCAmelCase     ,							_lowerCAmelCase							     =							0, 0  # index into text, pattern
      while i < len(__lowerCamelCase  ):
            if pattern[j] == text[i]:
                  if j == (len(__lowerCamelCase  ) - 1):
                        return True
                  j += 1

            # if this is a prefix in our pattern
            # just go back far enough to continue
            elif j > 0:
                  _lowerCAmelCase							     =							failure[j - 1]
                  continue
            i += 1
      return False
def    UpperCamelCase__      (		lowerCAmelCase  ):





      """simple docstring"""


      _lowerCAmelCase							     =							[0]
      _lowerCAmelCase							     =							0
      _lowerCAmelCase							     =							1
      while j < len(__lowerCamelCase  ):
            if pattern[i] == pattern[j]:
                  i += 1
            elif i > 0:
                  _lowerCAmelCase							     =							failure[i - 1]
                  continue
            j += 1
            failure.append(__lowerCamelCase  )
      return failure


if __name__ == "__main__":
      # Test 1)
      A__				:   Optional[Any]      ='''abc1abc12'''
      A__				:   str      ='''alskfjaldsabc1abc1abc12k23adsfabcabc'''
      A__				:   List[str]      ='''alskfjaldsk23adsfabcabc'''
      assert kmp(pattern, texta) and not kmp(pattern, texta)

      # Test 2)
      A__				:   str      ='''ABABX'''
      A__				:   int      ='''ABABZABABYABABX'''
      assert kmp(pattern, text)

      # Test 3)
      A__				:   Any      ='''AAAB'''
      A__				:   int      ='''ABAAAAAB'''
      assert kmp(pattern, text)

      # Test 4)
      A__				:   Optional[Any]      ='''abcdabcy'''
      A__				:   Tuple      ='''abcxabcdabxabcdabcdabcy'''
      assert kmp(pattern, text)

      # Test 5)
      A__				:   Optional[int]      ='''aabaabaaa'''
      assert get_failure_array(pattern) == [0, 1, 0, 1, 2, 3, 4, 5, 2]













'''simple docstring'''

from typing import List

from .keymap import KEYMAP, get_character





def lowerCamelCase						(     __lowerCamelCase :    str    )						->Optional[int]:

    def decorator(__lowerCamelCase :    int    ):
        _SCREAMING_SNAKE_CASE									=			getattr(__lowerCamelCase					,       """handle_key"""					,       []    )
        handle += [key]
        setattr(__lowerCamelCase					,       """handle_key"""					,       __lowerCamelCase    )
        return func

    return decorator





def lowerCamelCase						(     *__lowerCamelCase :    List[str]    )						->Dict:

    def decorator(__lowerCamelCase :    int    ):
        _SCREAMING_SNAKE_CASE									=			getattr(__lowerCamelCase					,       """handle_key"""					,       []    )
        handle += keys
        setattr(__lowerCamelCase					,       """handle_key"""					,       __lowerCamelCase    )
        return func

    return decorator


class 					a_     (				snake_case_       ):

    '''simple docstring'''


    def __new__(		cls ,		A ,		A ,		A       )		->   int:
        _SCREAMING_SNAKE_CASE									=			super().__new__(cls ,		A ,		A ,		A       )
        if not hasattr(A ,		"""key_handler"""       ):
            setattr(A ,		"""key_handler""" ,		{}       )
        setattr(A ,		"""handle_input""" ,		KeyHandler.handle_input       )

        for value in attrs.values():
            _SCREAMING_SNAKE_CASE									=			getattr(A ,		"""handle_key""" ,		[]       )
            for key in handled_keys:
                _SCREAMING_SNAKE_CASE									=			value
        return new_cls





    @staticmethod
    def 			snake_case_(		cls       )		->   str:
        _SCREAMING_SNAKE_CASE									=			get_character()
        if char != KEYMAP["undefined"]:
            _SCREAMING_SNAKE_CASE									=			ord(A       )
        _SCREAMING_SNAKE_CASE									=			cls.key_handler.get(A       )
        if handler:
            _SCREAMING_SNAKE_CASE									=			char
            return handler(cls       )
        else:
            return None





def lowerCamelCase						(     cls :    Any    )						->Dict:
    return KeyHandler(cls.__name__					,       cls.__bases__					,       cls.__dict__.copy()    )



