



"""simple docstring"""





from __future__ import annotations

from collections import deque
class  lowercase__  :







       '''simple docstring'''


       def __init__(				self     :    Optional[int]						,							_UpperCAmelCase     :    list[str]       )					->		Any:


             '''simple docstring'''




             UpperCAmelCase_     					=				[]
             self.adlist.append(
                 {"value": "", "next_states": [], "fail_state": 0, "output": []}       )

             for keyword in keywords:
                   self.add_keyword(_UpperCAmelCase       )
             self.set_fail_transitions()



       def 	lowercase__							(				self     :    Any						,							_UpperCAmelCase     :    int						,							_UpperCAmelCase     :    str       )					->		int | None:


             '''simple docstring'''




             for state in self.adlist[current_state]["next_states"]:
                   if char == self.adlist[state]["value"]:
                         return state
             return None



       def 	lowercase__							(				self     :    Union[str, Any]						,							_UpperCAmelCase     :    str       )					->		None:


             '''simple docstring'''




             UpperCAmelCase_     					=				0
             for character in keyword:
                   UpperCAmelCase_     					=				self.find_next_state(_UpperCAmelCase						,							_UpperCAmelCase       )
                   if next_state is None:
                         self.adlist.append(
                             {
                                 "value": character,
                                 "next_states": [],
                                 "fail_state": 0,
                                 "output": [],
                             }       )
                         self.adlist[current_state]["next_states"].append(len(self.adlist       ) - 1       )
                         UpperCAmelCase_     					=				len(self.adlist       ) - 1
                   else:
                         UpperCAmelCase_     					=				next_state
             self.adlist[current_state]["output"].append(_UpperCAmelCase       )



       def 	lowercase__							(				self     :    str       )					->		None:


             '''simple docstring'''




             UpperCAmelCase_     					=				deque()
             for node in self.adlist[0]["next_states"]:
                   q.append(_UpperCAmelCase       )
                   UpperCAmelCase_     					=				0
             while q:
                   UpperCAmelCase_     					=				q.popleft()
                   for child in self.adlist[r]["next_states"]:
                         q.append(_UpperCAmelCase       )
                         UpperCAmelCase_     					=				self.adlist[r]["fail_state"]
                         while (
                             self.find_next_state(_UpperCAmelCase						,							self.adlist[child]["value"]       ) is None
                             and state != 0
                         ):
                               UpperCAmelCase_     					=				self.adlist[state]["fail_state"]
                         UpperCAmelCase_     					=				self.find_next_state(
                             _UpperCAmelCase						,							self.adlist[child]["value"]       )
                         if self.adlist[child]["fail_state"] is None:
                               UpperCAmelCase_     					=				0
                         UpperCAmelCase_     					=				(
                             self.adlist[child]["output"]
                             + self.adlist[self.adlist[child]["fail_state"]]["output"]
                         )







       def 	lowercase__							(				self     :    Optional[Any]						,							_UpperCAmelCase     :    str       )					->		dict[str, list[int]]:


             '''simple docstring'''




             UpperCAmelCase_     					=				{}  # returns a dict with keywords and list of its occurrences
             UpperCAmelCase_     					=				0
             for i in range(len(_UpperCAmelCase       )       ):
                   while (
                       self.find_next_state(_UpperCAmelCase						,							string[i]       ) is None
                       and current_state != 0
                   ):
                         UpperCAmelCase_     					=				self.adlist[current_state]["fail_state"]
                   UpperCAmelCase_     					=				self.find_next_state(_UpperCAmelCase						,							string[i]       )
                   if next_state is None:
                         UpperCAmelCase_     					=				0
                   else:
                         UpperCAmelCase_     					=				next_state
                         for key in self.adlist[current_state]["output"]:
                               if key not in result:
                                     UpperCAmelCase_     					=				[]
                               result[key].append(i - len(_UpperCAmelCase       ) + 1       )
             return result


if __name__ == "__main__":
  import doctest

  doctest.testmod()








from unittest.mock import Mock, patch

from file_transfer.send_file import send_file
@patch("socket.socket"	)
@patch("builtins.open"	)
def 							UpperCamelCase_(					_A :Tuple					,  _A :str	)->		int:
			# ===== initialization =====
			UpperCamelCase__       =							Mock()
			UpperCamelCase__       =							conn, Mock()
			UpperCamelCase__       =							iter([1, None]	)
			UpperCamelCase__       =							lambda _A	: next(_A	)

			# ===== invoke =====
			send_file(filename="mytext.txt"					,  testing=_A	)

			# ===== ensurance =====
			sock.assert_called_once()
			sock.return_value.bind.assert_called_once()
			sock.return_value.listen.assert_called_once()
			sock.return_value.accept.assert_called_once()
			conn.recv.assert_called_once()

			file.return_value.__enter__.assert_called_once()
			file.return_value.__enter__.return_value.read.assert_called()

			conn.send.assert_called_once()
			conn.close.assert_called_once()
			sock.return_value.shutdown.assert_called_once()
			sock.return_value.close.assert_called_once()


