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"""LICENSE
2Copyright 2018 Hermann Krumrey <hermann@krumreyh.com>
4This file is part of bokkichat.
6bokkichat is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
11bokkichat is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
16You should have received a copy of the GNU General Public License
17along with bokkichat. If not, see <http://www.gnu.org/licenses/>.
18LICENSE"""
20from typing import List, Type
21from bokkichat.entities.Address import Address
22from bokkichat.entities.message.Message import Message
23from bokkichat.entities.message.TextMessage import TextMessage
24from bokkichat.connection.Connection import Connection
25from bokkichat.settings.impl.CliSettings import CliSettings
28class CliConnection(Connection):
29 """
30 Class that implements a CLI connection which can be used in testing
31 """
33 @classmethod
34 def name(cls) -> str:
35 """
36 The name of the connection class
37 :return: The connection class name
38 """
39 return "cli"
41 @property
42 def address(self) -> Address:
43 """
44 A CLI connection has no real entities,
45 so a dummy entities is generated.
46 :return: The entities of the connection
47 """
48 return Address("CLI")
50 @classmethod
51 def settings_cls(cls) -> Type[CliSettings]:
52 """
53 The settings class used by this connection
54 :return: The settings class
55 """
56 return CliSettings
58 # noinspection PyMethodMayBeStatic
59 def send(self, message: Message):
60 """
61 Prints a "sent" message
62 :param message: The message to "send"
63 :return: None
64 """
65 print(message)
67 def receive(self) -> List[Message]:
68 """
69 A CLI Connection receives messages by listening to the input
70 :return: A list of pending Message objects
71 """
72 return [TextMessage(self.address, self.address, input())]
74 def close(self):
75 """
76 Disconnects the Connection.
77 :return: None
78 """
79 pass