# Coverage for server/parts/hooks.py : 91%

## 20 statements 19 run 1 missing 4 excluded 1 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1# -*- coding: utf-8 -*-

2 from __future__ import annotations

3

4# -- stdlib --

5 from typing import Any, List, TYPE_CHECKING

6 import logging

7

8# -- third party --

9# -- own --

10 from game.base import EventHandler

11 from server.base import Game

12

13

14# -- typing --

15 if TYPE_CHECKING:

16 from server.core import Core # noqa: F401

17

18# -- code --

19 log = logging.getLogger('server.parts.hooks')

20

21

22 class ServerEventHooks(EventHandler):

23 def __init__(self) -> None:

24 self.hooks: List[EventHandler] = [

25 ]

26

27 def handle(self, evt_type: str, arg: Any) -> Any:

28 for h in self.hooks: 28 ↛ 29 line 28 didn't jump to line 29, because the loop on line 28 never started

29 arg = h.handle(evt_type, arg)

30

31 return arg

32

33

34 class Hooks(object):

35 def __init__(self, core: Core):

36 self.core = core

37 core.events.game_started += self.handle_game_started

38

39 def __repr__(self) -> str:

40 return self.__class__.__name__

41

42 def handle_game_started(self, g: Game) -> Game:

43 g.event_observer = ServerEventHooks()

44 return g