src/eric7/RemoteServer/EricServer.py

Tue, 11 Jun 2024 16:42:56 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 11 Jun 2024 16:42:56 +0200
branch
server
changeset 10774
7f7ff7456904
parent 10719
34901362f648
child 10946
5ca9e14751ba
permissions
-rw-r--r--

Created a handler and interface for remote handling 'editor config' files.

10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the eric remote server.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import io
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import json
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
12 import selectors
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import socket
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import struct
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 import sys
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 import traceback
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
17 import types
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 import zlib
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
10719
34901362f648 Removed the dependency on 'eric7.UI.Info.Version' in favor of the new 'eric7.__version__.Version'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10633
diff changeset
20 from eric7.__version__ import Version
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 from .EricRequestCategory import EricRequestCategory
10574
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
23 from .EricServerCoverageRequestHandler import EricServerCoverageRequestHandler
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
24 from .EricServerDebuggerRequestHandler import EricServerDebuggerRequestHandler
10774
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
25 from .EricServerEditorConfigRequestHandler import EricServerEditorConfigRequestHandler
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
26 from .EricServerFileSystemRequestHandler import EricServerFileSystemRequestHandler
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 class EricServer:
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Class implementing the eric remote server.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 def __init__(self, port=42024, useIPv6=False):
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Constructor
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param port port to listen on (defaults to 42024)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @type int (optional)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 @param useIPv6 flag indicating to use IPv6 protocol (defaults to False)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 @type bool (optional)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 """
10539
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
43 self.__requestCategoryHandlerRegistry = {}
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
44 # Dictionary containing the defined and registered request category
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
45 # handlers. The key is the request category and the value is the respective
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
46 # handler method. This method must have the signature:
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
47 # handler(request:str, params:dict, reqestUuid:str) -> None
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
48 self.__registerInternalHandlers()
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.__connection = None
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
52 self.__selector = selectors.DefaultSelector()
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
53
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
54 # create and register the 'Debugger' request handler
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
55 self.__debuggerRequestHandler = EricServerDebuggerRequestHandler(self)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
56 self.registerRequestHandler(
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
57 EricRequestCategory.Debugger,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
58 self.__debuggerRequestHandler.handleRequest,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
59 )
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
60
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
61 # create and register the 'File System' request handler
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
62 self.__fileSystemRequestHandler = EricServerFileSystemRequestHandler(self)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
63 self.registerRequestHandler(
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
64 EricRequestCategory.FileSystem,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
65 self.__fileSystemRequestHandler.handleRequest,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
66 )
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
67
10574
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
68 # create and register the 'Coverage' request handler
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
69 self.__coverageRequestHandler = EricServerCoverageRequestHandler(self)
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
70 self.registerRequestHandler(
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
71 EricRequestCategory.Coverage,
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
72 self.__coverageRequestHandler.handleRequest,
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
73 )
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
74
10774
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
75 # create and register the 'Editor Config' request handler
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
76 self.__editorConfigRequestHandler = EricServerEditorConfigRequestHandler(self)
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
77 self.registerRequestHandler(
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
78 EricRequestCategory.EditorConfig,
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
79 self.__editorConfigRequestHandler.handleRequest,
7f7ff7456904 Created a handler and interface for remote handling 'editor config' files.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10719
diff changeset
80 )
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
81
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
82 self.__address = ("", port)
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
83 self.__useIPv6 = useIPv6
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
84
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
85 def getSelector(self):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
86 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
87 Public method to get a reference to the selector object.
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
88
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
89 @return reference to the selector object
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
90 @rtype selectors.BaseSelector
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
91 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
92 return self.__selector
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 #######################################################################
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 ## Methods for receiving requests and sending the results.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 #######################################################################
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 def sendJson(self, category, reply, params, reqestUuid=""):
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 Public method to send a single refactoring command to the server.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 @param category service category
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @type EricRequestCategory
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @param reply reply name to be sent
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @param params dictionary of named parameters for the request
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @type dict
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 @param reqestUuid UUID of the associated request as sent by the eric IDE
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 (defaults to "", i.e. no UUID received)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 """
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
112 if self.__connection is not None:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
113 commandDict = {
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
114 "jsonrpc": "2.0",
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
115 "category": category,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
116 "reply": reply,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
117 "params": params,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
118 "uuid": reqestUuid,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
119 }
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
120 self.sendJsonCommand(commandDict, self.__connection)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
121
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
122 def sendJsonCommand(self, jsonCommand, sock):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
123 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
124 Public method to send a JSON encoded command/response via a given socket.
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
125
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
126 @param jsonCommand dictionary containing the command data or a JSON encoded
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
127 command string
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
128 @type dict or str
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
129 @param sock reference to the socket to send the data to
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
130 @type socket.socket
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
131 @return flag indicating a successful transmission
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
132 @rtype bool
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
133 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
134 if isinstance(jsonCommand, dict):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
135 jsonCommand = json.dumps(jsonCommand)
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
136 # - print("Eric Server Send:", jsonCommand) # for debugging
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
137
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
138 data = jsonCommand.encode("utf8", "backslashreplace")
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 header = struct.pack(b"!II", len(data), zlib.adler32(data) & 0xFFFFFFFF)
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
140 try:
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
141 sock.sendall(header)
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
142 sock.sendall(data)
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
143 return True
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
144 except BrokenPipeError:
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
145 return False
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
147 def __receiveBytes(self, length, sock):
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 Private method to receive the given length of bytes.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @param length bytes to receive
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 @type int
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
153 @param sock reference to the socket to receive the data from
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
154 @type socket.socket
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 @return received bytes or None if connection closed
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 @rtype bytes
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 data = bytearray()
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
159 while sock is not None and len(data) < length:
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
160 try:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
161 newData = sock.recv(length - len(data))
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
162 if not newData:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
163 return None
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
164
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
165 data += newData
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
166 except OSError as err:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
167 if err.errno != 11:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
168 data = None # in case some data was received already
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
169 break
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
170 return data
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
171
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
172 def receiveJsonCommand(self, sock):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
173 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
174 Public method to receive a JSON encoded command and data.
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
175
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
176 @param sock reference to the socket to receive the data from
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
177 @type socket.socket
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
178 @return dictionary containing the JSON command data or None to signal
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
179 an issue while receiving data
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
180 @rtype dict
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
181 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
182 if self.isSocketClosed(sock):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
183 return None
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
184
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
185 header = self.__receiveBytes(struct.calcsize(b"!II"), sock)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
186 if not header:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
187 return {}
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
188
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
189 length, datahash = struct.unpack(b"!II", header)
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
191 length = int(length)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
192 data = self.__receiveBytes(length, sock)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
193 if data is None:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
194 return None
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
195
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
196 if not data or zlib.adler32(data) & 0xFFFFFFFF != datahash:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
197 self.sendJson(
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
198 category=EricRequestCategory.Error,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
199 reply="EricServerChecksumException",
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
200 params={
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
201 "ExceptionType": "ProtocolChecksumError",
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
202 "ExceptionValue": "The checksum of the data does not match.",
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
203 "ProtocolData": data.decode("utf8", "backslashreplace"),
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
204 },
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
205 )
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
206 return {}
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
207
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
208 jsonStr = data.decode("utf8", "backslashreplace")
10633
dda7e43934dc Corrected some code formatting and coding style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10630
diff changeset
209 print("Eric Server Receive:", jsonStr) # for debugging # noqa: M801
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
210 try:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
211 return json.loads(jsonStr.strip())
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
212 except (TypeError, ValueError) as err:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
213 self.sendJson(
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
214 category=EricRequestCategory.Error,
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
215 reply="EricServerException",
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
216 params={
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
217 "ExceptionType": "ProtocolError",
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
218 "ExceptionValue": str(err),
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
219 "ProtocolData": jsonStr.strip(),
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
220 },
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
221 )
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
222 return {}
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 def __receiveJson(self):
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 Private method to receive a JSON encoded command and data from the
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 server.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 @return tuple containing the received service category, the command,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 a dictionary containing the associated data and the UUID of the
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 request
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 @rtype tuple of (int, str, dict, str)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 """
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
234 requestDict = self.receiveJsonCommand(self.__connection)
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
236 if not requestDict:
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 return EricRequestCategory.Error, None, None, None
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 category = requestDict["category"]
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 request = requestDict["request"]
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 params = requestDict["params"]
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 reqestUuid = requestDict["uuid"]
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 return category, request, params, reqestUuid
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
246 def isSocketClosed(self, sock):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
247 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
248 Public method to check, if a given socket is closed.
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
249
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
250 @param sock reference to the socket to be checked
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
251 @type socket.socket
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
252 @return flag indicating a closed state
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
253 @rtype bool
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
254 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
255 try:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
256 # this will try to read bytes without removing them from buffer (peek only)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
257 data = sock.recv(16, socket.MSG_PEEK)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
258 if len(data) == 0:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
259 return True
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
260 except BlockingIOError:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
261 return False # socket is open and reading from it would block
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
262 except ConnectionError:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
263 return True # socket was closed for some other reason
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
264 except Exception:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
265 return False
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
266 return False
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
267
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 #######################################################################
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 ## Methods for the server main loop.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 #######################################################################
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
272 def __initializeIdeSocket(self):
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
273 """
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
274 Private method to initialize and register the eric-ide server socket.
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
275 """
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
276 if socket.has_dualstack_ipv6() and self.__useIPv6:
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
277 self.__socket = socket.create_server(
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
278 self.__address, family=socket.AF_INET6, backlog=0, dualstack_ipv6=True
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
279 )
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
280 else:
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
281 self.__socket = socket.create_server(
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
282 self.__address, family=socket.AF_INET, backlog=0
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
283 )
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
284
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
285 self.__socket.listen(0)
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
286 self.__socket.setblocking(False)
10630
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
287 address = self.__socket.getsockname()
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
288 print( # noqa: M801
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
289 f"Listening for 'eric-ide' connections on {address[0]}, port {address[1]}"
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
290 )
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
291 data = types.SimpleNamespace(
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
292 name="server", acceptHandler=self.__acceptIdeConnection
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
293 )
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
294 self.__selector.register(self.__socket, selectors.EVENT_READ, data=data)
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
295
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
296 def __unregisterIdeSocket(self):
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
297 """
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
298 Private method to unregister the eric-ide server socket because only one
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
299 connection is allowed.
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
300 """
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
301 self.__selector.unregister(self.__socket)
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
302 self.__socket.shutdown(socket.SHUT_RDWR)
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
303 self.__socket.close()
10567
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
304 self.__socket = None
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
305
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 def __shutdown(self):
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 Private method to shut down the server.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 """
10567
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
310 self.__closeIdeConnection(shutdown=True)
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
311
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
312 print("Stop listening for 'eric-ide' connections.") # noqa: M801
10567
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
313 if self.__socket is not None:
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
314 self.__socket.shutdown(socket.SHUT_RDWR)
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
315 self.__socket.close()
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
317 self.__selector.close()
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
318
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
319 def __acceptIdeConnection(self, sock):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
320 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
321 Private method to accept the connection on the listening IDE server socket.
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
322
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
323 @param sock reference to the listening socket
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
324 @type socket.socket
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
325 """
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
326 connection, address = sock.accept() # Should be ready to read
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
327 if self.__connection is None:
10630
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
328 print(f"'eric-ide' connection from {address[0]}, port {address[1]}")
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
329 # noqa: M801
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
330 self.__connection = connection
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
331 data = types.SimpleNamespace(
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
332 name="eric-ide", address=address, handler=self.__serviceIdeConnection
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
333 )
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
334 events = selectors.EVENT_READ
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
335 self.__selector.register(self.__connection, events, data=data)
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
336
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
337 self.__unregisterIdeSocket()
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
338 else:
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
339 print( # noqa: M801
10630
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
340 f"'eric-ide' connection from {address[0]}, port {address[1]} rejected"
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
341 )
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
342 connection.close()
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
343
10567
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
344 def __closeIdeConnection(self, shutdown=False):
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
345 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
346 Private method to close the connection to an eric-ide.
10597
fbe93720ee9f Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10574
diff changeset
347
10574
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
348 @param shutdown flag indicating a shutdown process
622e59b51640 Implemented the profiling and code coverage interface of the dialogs to the eric-ide server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10567
diff changeset
349 @type bool
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
350 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
351 if self.__connection is not None:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
352 self.__selector.unregister(self.__connection)
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
353 try:
10630
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
354 address = self.__connection.getpeername()
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
355 print( # noqa: M801
10630
552a790fd9bc Corrected some issues and improved some existing code with respect to eric-ide server use.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10610
diff changeset
356 f"Closing 'eric-ide' connection to {address[0]}, port {address[1]}."
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
357 )
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
358 self.__connection.shutdown(socket.SHUT_RDWR)
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
359 self.__connection.close()
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
360 except OSError:
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
361 print("'eric-ide' connection gone.") # noqa: M801
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
362 self.__connection = None
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
363
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
364 self.__debuggerRequestHandler.shutdownClients()
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
365
10567
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
366 if not shutdown:
b098e0d028cc Added some code to handle error conditions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10565
diff changeset
367 self.__initializeIdeSocket()
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
368
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
369 def __serviceIdeConnection(self, key):
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
370 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
371 Private method to service the eric-ide connection.
10597
fbe93720ee9f Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10574
diff changeset
372
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
373 @param key reference to the SelectorKey object associated with the connection
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
374 to be serviced
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
375 @type selectors.SelectorKey
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
376 """
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
377 if key.data.name == "eric-ide":
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
378 category, request, params, reqestUuid = self.__receiveJson()
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
379 if category == EricRequestCategory.Error or request is None:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
380 self.__closeIdeConnection()
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
381 return
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
382
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
383 if category == EricRequestCategory.Server and request.lower() == "shutdown":
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
384 self.__shouldStop = True
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
385 return
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
386
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
387 self.__handleRequest(category, request, params, reqestUuid)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
388
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
389 def run(self):
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
390 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
391 Public method implementing the remote server main loop.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
392
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
393 Exiting the inner loop, that receives and dispatches the requests, will
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
394 cause the server to stop and exit. The main loop handles these requests.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
395 <ul>
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
396 <li>exit - exit the handler loop and wait for the next connection</li>
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
397 <li>shutdown - exit the handler loop and perform a clean shutdown</li>
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
398 </ul>
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
399
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
400 @return flag indicating a clean shutdown
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
401 @rtype bool
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
402 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
403 cleanExit = True
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
404 self.__shouldStop = False
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
405
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
406 # initialize the eric-ide server socket and listen for new connections
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
407 self.__initializeIdeSocket()
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
408
10563
b4b47c1a02ba Made the eric-ide server a single connection server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10561
diff changeset
409 # initialize the debug client server socket
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
410 self.__debuggerRequestHandler.initServerSocket()
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
411
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
412 while True:
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
413 try:
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
414 events = self.__selector.select(timeout=None)
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
415 for key, _mask in events:
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
416 if key.data.name == "server":
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
417 # it is an event for a server socket
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
418 key.data.acceptHandler(key.fileobj)
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
419 else:
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
420 key.data.handler(key)
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
421
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
422 except KeyboardInterrupt:
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
423 # intercept user pressing Ctrl+C
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
424 self.__shouldStop = True
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
425
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
426 except Exception:
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
427 exctype, excval, exctb = sys.exc_info()
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
428 tbinfofile = io.StringIO()
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
429 traceback.print_tb(exctb, None, tbinfofile)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
430 tbinfofile.seek(0)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
431 tbinfo = tbinfofile.read()
10597
fbe93720ee9f Corrected a few formatting and style issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10574
diff changeset
432
10610
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
433 print("Stopping due to an exception.\nDetails:") # noqa: M801
bb0149571d94 Finished adapting the project functions to support an 'eric-ide' server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10597
diff changeset
434 print(f"{str(exctype)} / {str(excval)} / {tbinfo}") # noqa: M801
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
435
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
436 self.__shouldStop = True
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
437 cleanExit = False
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
438
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
439 if self.__shouldStop:
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
440 # exit the outer loop and shut down the server
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
441 self.__shutdown()
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
442 break
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
443
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
444 return cleanExit
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
445
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
446 #######################################################################
10539
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
447 ## Methods for registering and unregistering handlers.
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
448 #######################################################################
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
449
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
450 def registerRequestHandler(self, requestCategory, handler):
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
451 """
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
452 Public method to register a request handler method for the given request
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
453 category.
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
454
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
455 @param requestCategory request category to be registered
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
456 @type EricRequestCategory or int (>= EricRequestCategory.UserCategory)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
457 @param handler reference to the handler method. This handler must accept
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
458 the parameters 'request', 'params', and 'requestUuid'
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
459 @type function(request:str, params:dict, requestUuid:str)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
460 @exception ValueError raised to signal a request category collision
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
461 """
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
462 if requestCategory in self.__requestCategoryHandlerRegistry:
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
463 raise ValueError(f"Request category '{requestCategory} already registered.")
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
464
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
465 self.__requestCategoryHandlerRegistry[requestCategory] = handler
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
466
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
467 def unregisterRequestHandler(self, requestCategory, ignoreError=False):
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
468 """
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
469 Public method to unregister a handler for the given request category.
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
470
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
471 Note: This method will raise a KeyError exception in case the request
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
472 category has not been registered and ignoreError is False (the default).
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
473
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
474 @param requestCategory request category to be unregistered
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
475 @type EricRequestCategory or int (>= EricRequestCategory.UserCategory)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
476 @param ignoreError flag indicating to ignore errors (defaults to False)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
477 @type bool (optional)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
478 """
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
479 try:
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
480 del self.__requestCategoryHandlerRegistry[requestCategory]
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
481 except KeyError:
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
482 if not ignoreError:
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
483 raise
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
484
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
485 def __registerInternalHandlers(self):
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
486 """
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
487 Private method to register request handler categories of this class.
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
488 """
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
489 self.registerRequestHandler(EricRequestCategory.Echo, self.__handleEchoRequest)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
490 self.registerRequestHandler(
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
491 EricRequestCategory.Server, self.__handleServerRequest
10539
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
492 )
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
493 self.registerRequestHandler(EricRequestCategory.Error, None)
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
494 # Register a None handler to indicate we are not expecting a request of the
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
495 # 'Error' category.
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
496
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
497 #######################################################################
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
498 ## Request handler methods.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
499 #######################################################################
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
500
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
501 def __handleRequest(self, category, request, params, reqestUuid):
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
502 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
503 Private method handling or dispatching the received requests.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
504
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
505 @param category category of the request
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
506 @type EricRequestCategory
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
507 @param request request name
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
508 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
509 @param params request parameters
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
510 @type dict
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
511 @param reqestUuid UUID of the associated request as sent by the eric IDE
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
512 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
513 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
514 try:
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
515 handler = self.__requestCategoryHandlerRegistry[category]
10555
08e853c0c77b Implemented an eric-ide Server Shell.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10547
diff changeset
516 handler(request=request, params=params, reqestUuid=reqestUuid)
10539
4274f189ff78 eric-ide Server
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10531
diff changeset
517 except KeyError:
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
518 self.sendJson(
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
519 category=EricRequestCategory.Error,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
520 reply="UnsupportedServiceCategory",
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
521 params={"Category": category},
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
522 )
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
523
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
524 def __handleEchoRequest(self, request, params, reqestUuid): # noqa: U100
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
525 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
526 Private method to handle an 'Echo' request.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
527
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
528 @param request request name
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
529 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
530 @param params request parameters
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
531 @type dict
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
532 @param reqestUuid UUID of the associated request as sent by the eric IDE
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
533 (defaults to "", i.e. no UUID received)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
534 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
535 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
536 self.sendJson(
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
537 category=EricRequestCategory.Echo,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
538 reply="Echo",
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
539 params=params,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
540 reqestUuid=reqestUuid,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
541 )
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
542
10561
be23a662d709 Implemented (most) of the eric-ide server debugging functionality.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10555
diff changeset
543 def __handleServerRequest(self, request, params, reqestUuid): # noqa: U100
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
544 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
545 Private method to handle a 'Server' request.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
546
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
547 @param request request name
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
548 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
549 @param params request parameters
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
550 @type dict
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
551 @param reqestUuid UUID of the associated request as sent by the eric IDE
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
552 (defaults to "", i.e. no UUID received)
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
553 @type str
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
554 """
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
555 # 'Exit' and 'Shutdown' are handled in the 'run()' method.
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
556
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
557 if request.lower() == "versions":
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
558 self.sendJson(
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
559 category=EricRequestCategory.Server,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
560 reply="Versions",
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
561 params={
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
562 "python": sys.version.split()[0],
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
563 "py_bitsize": "64-Bit" if sys.maxsize > 2**32 else "32-Bit",
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
564 "version": Version,
10565
3583a10ce4d4 Changed the eric-ide server versions display to show the server host name as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10563
diff changeset
565 "hostname": socket.gethostname(),
10531
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
566 },
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
567 reqestUuid=reqestUuid,
3308e8349e4c Started implementing an eric-ide server for remote development (e.g. on a different host or in a Docker container).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
568 )

eric ide

mercurial