src/eric7/Cooperation/CooperationClient.py

Sat, 23 Dec 2023 15:48:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 15:48:12 +0100
branch
eric7
changeset 10439
21c28b0f9e41
parent 10423
299802979277
child 10853
1f651b204780
permissions
-rw-r--r--

Updated copyright for 2024.

149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10423
diff changeset
3 # Copyright (c) 2010 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the client of the cooperation package.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import collections
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
12 from PyQt6.QtCore import QObject, QProcess, pyqtSignal
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
13 from PyQt6.QtNetwork import QAbstractSocket, QHostAddress, QHostInfo, QNetworkInterface
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
15 from eric7 import Preferences
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
16
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
17 from .Connection import Connection
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
18 from .CooperationServer import CooperationServer
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
19
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
20
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class CooperationClient(QObject):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing the client of the cooperation package.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
24
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
25 @signal newMessage(user, message) emitted after a new message has
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
26 arrived (string, string)
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
27 @signal newParticipant(nickname) emitted after a new participant joined
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
28 (string)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @signal participantLeft(nickname) emitted after a participant left (string)
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
30 @signal connectionError(message) emitted when a connection error occurs
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
31 (string)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 @signal cannotConnect() emitted, if the initial connection fails
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
33 @signal editorCommand(hash, filename, message) emitted when an editor
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
34 command has been received (string, string, string)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
37 newMessage = pyqtSignal(str, str)
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
38 newParticipant = pyqtSignal(str)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 participantLeft = pyqtSignal(str)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 connectionError = pyqtSignal(str)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
41 cannotConnect = pyqtSignal()
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
42 editorCommand = pyqtSignal(str, str, str)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
44 def __init__(self, parent=None):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
48 @param parent reference to the parent object
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
49 @type QObject
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
51 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
53 self.__chatWidget = parent
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
55 self.__servers = []
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
56 for networkInterface in QNetworkInterface.allInterfaces():
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
57 for addressEntry in networkInterface.addressEntries():
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
58 address = addressEntry.ip()
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
59 # fix scope of link local addresses
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
60 if address.toString().lower().startswith("fe80"):
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
61 address.setScopeId(networkInterface.humanReadableName())
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
62 server = CooperationServer(address, self)
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
63 server.newConnection.connect(self.__newConnection)
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
64 self.__servers.append(server)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
65
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 self.__peers = collections.defaultdict(list)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
67
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.__initialConnection = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
70 envVariables = ["USERNAME", "USERDOMAIN", "USER", "HOSTNAME", "DOMAINNAME"]
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 environment = QProcess.systemEnvironment()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 found = False
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 for envVariable in envVariables:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 for env in environment:
7775
4a1db75550bd Changed code to not use deprecated 'QRegExp' anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
75 if env.startswith(envVariable):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 envList = env.split("=")
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 if len(envList) == 2:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 self.__username = envList[1].strip()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 found = True
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 break
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if found:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 break
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
84
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if self.__username == "":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
86 self.__username = self.tr("unknown")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
88 self.__listening = False
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
89 self.__serversErrorString = ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
90
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
91 def chatWidget(self):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
93 Public method to get a reference to the chat widget.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
95 @return reference to the chat widget
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
96 @rtype ChatWidget
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
98 return self.__chatWidget
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
99
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def sendMessage(self, message):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Public method to send a message.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
104 @param message message to be sent
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
105 @type str
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 if message == "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
109
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 for connectionList in self.__peers.values():
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 for connection in connectionList:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 connection.sendMessage(message)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def nickName(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Public method to get the nick name.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
118 @return nick name
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
119 @rtype str
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
121 return "{0}@{1}@{2}".format(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
122 self.__username, QHostInfo.localHostName(), self.__servers[0].serverPort()
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
124
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
125 def hasConnection(self, senderIp, senderPort=-1):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 Public method to check for an existing connection.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
128
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
129 @param senderIp address of the sender
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
130 @type QHostAddress
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
131 @param senderPort port of the sender
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
132 @type int
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
133 @return flag indicating an existing connection
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
134 @rtype bool
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 if senderPort == -1:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 return senderIp in self.__peers
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
138
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 if senderIp not in self.__peers:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 return False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
142 return any(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
143 connection.peerPort() == senderPort for connection in self.__peers[senderIp]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
145
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 def hasConnections(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 Public method to check, if there are any connections established.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
149
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
150 @return flag indicating the presence of connections
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
151 @rtype bool
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
153 return any(bool(connectionList) for connectionList in self.__peers.values())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
154
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
155 def removeConnection(self, connection):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 """
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
157 Public method to remove a connection.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
158
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
159 @param connection reference to the connection to be removed
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
160 @type Connection
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
162 if (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
163 connection.peerAddress() in self.__peers
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164 and connection in self.__peers[connection.peerAddress()]
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
165 ):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 self.__peers[connection.peerAddress()].remove(connection)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 nick = connection.name()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 if nick != "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 self.participantLeft.emit(nick)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
170
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
171 if connection.isValid():
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
172 connection.abort()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
173
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 def disconnectConnections(self):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 Public slot to disconnect from the chat network.
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 for connectionList in self.__peers.values():
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 while connectionList:
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
180 self.removeConnection(connectionList[0])
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 def __newConnection(self, connection):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 Private slot to handle a new connection.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
185
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
186 @param connection reference to the new connection
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
187 @type Connection
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 """
162
28f235c426c4 Added functionality to cut/copy/... the chat and to interactively accept/reject connections.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 155
diff changeset
189 connection.setParent(self)
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
190 connection.setClient(self)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191 connection.setGreetingMessage(self.__username, self.__servers[0].serverPort())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
192
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
193 connection.error.connect(lambda err: self.__connectionError(err, connection))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
194 connection.disconnected.connect(lambda: self.__disconnected(connection))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
195 connection.readyForUse.connect(lambda: self.__readyForUse(connection))
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
196 connection.rejected.connect(self.__connectionRejected)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
197
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
198 def __connectionRejected(self, msg):
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
199 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
200 Private slot to handle the rejection of a connection.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
201
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
202 @param msg error message
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
203 @type str
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
204 """
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
205 self.connectionError.emit(msg)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
207 def __connectionError(self, socketError, connection):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 Private slot to handle a connection error.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
210
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
211 @param socketError reference to the error object
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
212 @type QAbstractSocket.SocketError
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
213 @param connection connection that caused the error
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
214 @type Connection
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 """
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
216 if socketError != QAbstractSocket.SocketError.RemoteHostClosedError:
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 if connection.peerPort() != 0:
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
218 msg = "* {0}:{1}\n{2}\n".format(
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
219 connection.peerAddress().toString(),
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
220 connection.peerPort(),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
221 connection.errorString(),
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 )
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 else:
164
b395b006d2a8 Fixed a few issues with the new cooperation stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 162
diff changeset
224 msg = "* {0}\n".format(connection.errorString())
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 self.connectionError.emit(msg)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 if connection == self.__initialConnection:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 self.cannotConnect.emit()
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
228 self.removeConnection(connection)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
229
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
230 def __disconnected(self, connection):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 Private slot to handle the disconnection of a chat client.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
233
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
234 @param connection connection that was disconnected
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
235 @type Connection
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
237 self.removeConnection(connection)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
239 def __readyForUse(self, connection):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 Private slot to handle a connection getting ready for use.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
242
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
243 @param connection connection that got ready for use
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
244 @type Connection
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 if self.hasConnection(connection.peerAddress(), connection.peerPort()):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
248
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 connection.newMessage.connect(self.newMessage)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
250 connection.getParticipants.connect(lambda: self.__getParticipants(connection))
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
251 connection.editorCommand.connect(self.editorCommand)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 self.__peers[connection.peerAddress()].append(connection)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 nick = connection.name()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 if nick != "":
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 self.newParticipant.emit(nick)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
257
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 if connection == self.__initialConnection:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 connection.sendGetParticipants()
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 self.__initialConnection = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
261
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 def connectToHost(self, host, port):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 Public method to connect to a host.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
265
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
266 @param host host to connect to
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
267 @type str
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
268 @param port port to connect to
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
269 @type int
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 self.__initialConnection = Connection(self)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 self.__newConnection(self.__initialConnection)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 self.__initialConnection.participants.connect(self.__processParticipants)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 self.__initialConnection.connectToHost(host, port)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
276 def __getParticipants(self, reqConnection):
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 Private slot to handle the request for a list of participants.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279
6115
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
280 @param reqConnection reference to the connection to get
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
281 participants for
ac3a98f3ebc2 Started removing the use of QObject.sender() because it causes trouble sometimes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
282 @type Connection
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 participants = []
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285 for connectionList in self.__peers.values():
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 for connection in connectionList:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 if connection != reqConnection:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
288 participants.append(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
289 "{0}@{1}".format(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
290 connection.peerAddress().toString(), connection.serverPort()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
291 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
292 )
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 reqConnection.sendParticipants(participants)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
294
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 def __processParticipants(self, participants):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297 Private slot to handle the receipt of a list of participants.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
298
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
299 @param participants list of participants (list of "host:port" strings)
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
300 @type list of str
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301 """
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 for participant in participants:
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
303 host, port = participant.split("@")
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 port = int(port)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
305
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 if port == 0:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307 msg = self.tr("Illegal address: {0}@{1}\n").format(host, port)
149
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 self.connectionError.emit(msg)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 else:
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 if not self.hasConnection(QHostAddress(host), port):
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311 connection = Connection(self)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 self.__newConnection(connection)
a134031209be Added stage 1 of the cooperation functions (chat system).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 connection.connectToHost(host, port)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
314
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
315 def sendEditorCommand(self, projectHash, filename, message):
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
316 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
317 Public method to send an editor command.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
319 @param projectHash hash of the project
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
320 @type str
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
321 @param filename project relative universal file name of
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
322 the sending editor
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
323 @type str
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
324 @param message editor command to be sent
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
325 @type str
155
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
326 """
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
327 for connectionList in self.__peers.values():
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
328 for connection in connectionList:
375e3c884874 Added code to transmit selections to remote editors.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 149
diff changeset
329 connection.sendEditorCommand(projectHash, filename, message)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
330
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
331 def __findConnections(self, nick):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
332 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
333 Private method to get a list of connection given a nick name.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
334
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
335 @param nick nick name in the format of self.nickName()
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
336 @type str
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
337 @return list of references to the connection objects
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
338 @rtype list of Connection
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
339 """
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
340 if "@" not in nick:
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
341 # nick given in wrong format
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
342 return []
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
343
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
344 user, host, port = nick.split("@")
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
345 senderIp = QHostAddress(host)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
346
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
347 if senderIp not in self.__peers:
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
348 return []
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
349
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
350 return self.__peers[senderIp][:]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
351
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
352 def kickUser(self, nick):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
353 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
354 Public method to kick a user by its nick name.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
355
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
356 @param nick nick name in the format of self.nickName()
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
357 @type str
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
358 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
359 for connection in self.__findConnections(nick):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
360 connection.abort()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
361
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
362 def banUser(self, nick):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
363 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
364 Public method to ban a user by its nick name.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
365
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
366 @param nick nick name in the format of self.nickName()
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
367 @type str
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
368 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
369 Preferences.syncPreferences()
2285
a6fc5bda1de9 Corrected a few issues in the Cooperation function introduced during the IPv6 extension.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
370 user = nick.rsplit("@")[0]
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
371 bannedUsers = Preferences.getCooperation("BannedUsers")[:]
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
372 if user not in bannedUsers:
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
373 bannedUsers.append(user)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
374 Preferences.setCooperation("BannedUsers", bannedUsers)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
375
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
376 def banKickUser(self, nick):
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
377 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
378 Public method to ban and kick a user by its nick name.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
379
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
380 @param nick nick name in the format of self.nickName()
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
381 @type str
165
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
382 """
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
383 self.banUser(nick)
3302a726fd1e Added functionality to kick and ban users and to manage banned users.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 164
diff changeset
384 self.kickUser(nick)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
385
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
386 def startListening(self, port=-1):
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
387 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
388 Public method to start listening for new connections.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
389
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
390 @param port port to listen on
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
391 @type int
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
392 @return tuple giving a flag indicating success and the port the
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
393 server listens on
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
394 @rtype tuple of (bool, int)
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
395 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
396 if self.__servers:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
397 # do first server and determine free port
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
398 res, port = self.__servers[0].startListening(port, True)
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
399 if res and len(self.__servers) > 1:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
400 for server in self.__servers[1:]:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
401 res, port = server.startListening(port, False)
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
402 if not res:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
403 self.__serversErrorString = server.errorString()
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
404 else:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
405 self.__serversErrorString = self.__servers[0].errorString()
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
406 else:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
407 res = False
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
408 self.__serversErrorString = self.tr("No servers present.")
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
409
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
410 if res:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
411 self.__serversErrorString = ""
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
412 self.__listening = res
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
413 return res, port
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
414
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
415 def isListening(self):
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
416 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
417 Public method to check, if the client is listening for connections.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
418
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
419 @return flag indicating the listening state
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
420 @rtype bool
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
421 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
422 return self.__listening
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
423
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
424 def close(self):
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
425 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
426 Public method to close all connections and stop listening.
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
427 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
428 for server in self.__servers:
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
429 server.close()
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
430 self.__listening = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
431
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
432 def errorString(self):
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
433 """
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
434 Public method to get a human readable error message about the last
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
435 server error.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
436
2986
cd4e2cab7eb2 Started to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
437 @return human readable error message about the last server error
10423
299802979277 Converted some source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
438 @rtype str
1221
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
439 """
291dc0a51947 Added code to the cooperation functions to support IPv6.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1131
diff changeset
440 return self.__serversErrorString

eric ide

mercurial