29 class EricServer: |
29 class EricServer: |
30 """ |
30 """ |
31 Class implementing the eric remote server. |
31 Class implementing the eric remote server. |
32 """ |
32 """ |
33 |
33 |
34 def __init__(self, port=42024, useIPv6=False): |
34 def __init__(self, port=42024, useIPv6=False, clientId=""): |
35 """ |
35 """ |
36 Constructor |
36 Constructor |
37 |
37 |
38 @param port port to listen on (defaults to 42024) |
38 @param port port to listen on (defaults to 42024) |
39 @type int (optional) |
39 @type int (optional) |
40 @param useIPv6 flag indicating to use IPv6 protocol (defaults to False) |
40 @param useIPv6 flag indicating to use IPv6 protocol (defaults to False) |
41 @type bool (optional) |
41 @type bool (optional) |
42 """ |
42 @param clientId ID string used to check each received message for being |
|
43 sent by a valid eric IDE (defaults to "") |
|
44 @type str (optional) |
|
45 """ |
|
46 self.__clientId = clientId |
|
47 self.__address = ("", port) |
|
48 self.__useIPv6 = useIPv6 |
|
49 |
43 self.__requestCategoryHandlerRegistry = {} |
50 self.__requestCategoryHandlerRegistry = {} |
44 # Dictionary containing the defined and registered request category |
51 # Dictionary containing the defined and registered request category |
45 # handlers. The key is the request category and the value is the respective |
52 # handlers. The key is the request category and the value is the respective |
46 # handler method. This method must have the signature: |
53 # handler method. This method must have the signature: |
47 # handler(request:str, params:dict, reqestUuid:str) -> None |
54 # handler(request:str, params:dict, reqestUuid:str) -> None |
76 self.__editorConfigRequestHandler = EricServerEditorConfigRequestHandler(self) |
83 self.__editorConfigRequestHandler = EricServerEditorConfigRequestHandler(self) |
77 self.registerRequestHandler( |
84 self.registerRequestHandler( |
78 EricRequestCategory.EditorConfig, |
85 EricRequestCategory.EditorConfig, |
79 self.__editorConfigRequestHandler.handleRequest, |
86 self.__editorConfigRequestHandler.handleRequest, |
80 ) |
87 ) |
81 |
|
82 self.__address = ("", port) |
|
83 self.__useIPv6 = useIPv6 |
|
84 |
88 |
85 def getSelector(self): |
89 def getSelector(self): |
86 """ |
90 """ |
87 Public method to get a reference to the selector object. |
91 Public method to get a reference to the selector object. |
88 |
92 |
182 an issue while receiving data |
186 an issue while receiving data |
183 @rtype dict |
187 @rtype dict |
184 """ |
188 """ |
185 if self.isSocketClosed(sock): |
189 if self.isSocketClosed(sock): |
186 return None |
190 return None |
|
191 |
|
192 if self.__clientId and sock == self.__connection: |
|
193 msgClientIdBytes = self.__receiveBytes(len(self.__clientId), sock) |
|
194 try: |
|
195 msgClientId = str(msgClientIdBytes, encoding="utf-8") |
|
196 except UnicodeDecodeError: |
|
197 msgClientId = str(bytes(msgClientIdBytes)) |
|
198 if msgClientId != self.__clientId: |
|
199 print(f"Received illegal client ID '{msgClientId}'.") # noqa: M801 |
|
200 return {} |
187 |
201 |
188 header = self.__receiveBytes(struct.calcsize(b"!II"), sock) |
202 header = self.__receiveBytes(struct.calcsize(b"!II"), sock) |
189 if not header: |
203 if not header: |
190 return {} |
204 return {} |
191 |
205 |
324 Private method to accept the connection on the listening IDE server socket. |
338 Private method to accept the connection on the listening IDE server socket. |
325 |
339 |
326 @param sock reference to the listening socket |
340 @param sock reference to the listening socket |
327 @type socket.socket |
341 @type socket.socket |
328 """ |
342 """ |
329 connection, address = sock.accept() # Should be ready to read |
343 connection, address = sock.accept() # Should be ready to read. |
330 if self.__connection is None: |
344 if self.__connection is None: |
331 print(f"'eric-ide' connection from {address[0]}, port {address[1]}") |
345 print(f"'eric-ide' connection from {address[0]}, port {address[1]}") |
332 # noqa: M801 |
346 # noqa: M801 |
333 self.__connection = connection |
347 self.__connection = connection |
334 self.__connection.settimeout(10) |
348 self.__connection.settimeout(10) |