|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.RemoteServer.EricServer</title> |
|
4 <meta charset="UTF-8"> |
|
5 <link rel="stylesheet" href="styles.css"> |
|
6 </head> |
|
7 <body> |
|
8 <a NAME="top" ID="top"></a> |
|
9 <h1>eric7.RemoteServer.EricServer</h1> |
|
10 <p> |
|
11 Module implementing the eric remote server. |
|
12 </p> |
|
13 |
|
14 <h3>Global Attributes</h3> |
|
15 <table> |
|
16 <tr><td>None</td></tr> |
|
17 </table> |
|
18 |
|
19 <h3>Classes</h3> |
|
20 <table> |
|
21 <tr> |
|
22 <td><a href="#EricServer">EricServer</a></td> |
|
23 <td>Class implementing the eric remote server.</td> |
|
24 </tr> |
|
25 </table> |
|
26 |
|
27 <h3>Functions</h3> |
|
28 <table> |
|
29 <tr><td>None</td></tr> |
|
30 </table> |
|
31 |
|
32 <hr /> |
|
33 <hr /> |
|
34 <a NAME="EricServer" ID="EricServer"></a> |
|
35 <h2>EricServer</h2> |
|
36 <p> |
|
37 Class implementing the eric remote server. |
|
38 </p> |
|
39 |
|
40 <h3>Derived from</h3> |
|
41 None |
|
42 <h3>Class Attributes</h3> |
|
43 <table> |
|
44 <tr><td>None</td></tr> |
|
45 </table> |
|
46 |
|
47 <h3>Class Methods</h3> |
|
48 <table> |
|
49 <tr><td>None</td></tr> |
|
50 </table> |
|
51 |
|
52 <h3>Methods</h3> |
|
53 <table> |
|
54 <tr> |
|
55 <td><a href="#EricServer.__init__">EricServer</a></td> |
|
56 <td>Constructor</td> |
|
57 </tr> |
|
58 <tr> |
|
59 <td><a href="#EricServer.__acceptIdeConnection">__acceptIdeConnection</a></td> |
|
60 <td>Private method to accept the connection on the listening IDE server socket.</td> |
|
61 </tr> |
|
62 <tr> |
|
63 <td><a href="#EricServer.__closeIdeConnection">__closeIdeConnection</a></td> |
|
64 <td>Private method to close the connection to an eric-ide.</td> |
|
65 </tr> |
|
66 <tr> |
|
67 <td><a href="#EricServer.__handleEchoRequest">__handleEchoRequest</a></td> |
|
68 <td>Private method to handle an 'Echo' request.</td> |
|
69 </tr> |
|
70 <tr> |
|
71 <td><a href="#EricServer.__handleRequest">__handleRequest</a></td> |
|
72 <td>Private method handling or dispatching the received requests.</td> |
|
73 </tr> |
|
74 <tr> |
|
75 <td><a href="#EricServer.__handleServerRequest">__handleServerRequest</a></td> |
|
76 <td>Private method to handle a 'Server' request.</td> |
|
77 </tr> |
|
78 <tr> |
|
79 <td><a href="#EricServer.__initializeIdeSocket">__initializeIdeSocket</a></td> |
|
80 <td>Private method to initialize and register the eric-ide server socket.</td> |
|
81 </tr> |
|
82 <tr> |
|
83 <td><a href="#EricServer.__receiveBytes">__receiveBytes</a></td> |
|
84 <td>Private method to receive the given length of bytes.</td> |
|
85 </tr> |
|
86 <tr> |
|
87 <td><a href="#EricServer.__receiveJson">__receiveJson</a></td> |
|
88 <td>Private method to receive a JSON encoded command and data from the server.</td> |
|
89 </tr> |
|
90 <tr> |
|
91 <td><a href="#EricServer.__registerInternalHandlers">__registerInternalHandlers</a></td> |
|
92 <td>Private method to register request handler categories of this class.</td> |
|
93 </tr> |
|
94 <tr> |
|
95 <td><a href="#EricServer.__serviceIdeConnection">__serviceIdeConnection</a></td> |
|
96 <td>Private method to service the eric-ide connection.</td> |
|
97 </tr> |
|
98 <tr> |
|
99 <td><a href="#EricServer.__shutdown">__shutdown</a></td> |
|
100 <td>Private method to shut down the server.</td> |
|
101 </tr> |
|
102 <tr> |
|
103 <td><a href="#EricServer.__unregisterIdeSocket">__unregisterIdeSocket</a></td> |
|
104 <td>Private method to unregister the eric-ide server socket because only one connection is allowed.</td> |
|
105 </tr> |
|
106 <tr> |
|
107 <td><a href="#EricServer.getSelector">getSelector</a></td> |
|
108 <td>Public method to get a reference to the selector object.</td> |
|
109 </tr> |
|
110 <tr> |
|
111 <td><a href="#EricServer.isSocketClosed">isSocketClosed</a></td> |
|
112 <td>Public method to check, if a given socket is closed.</td> |
|
113 </tr> |
|
114 <tr> |
|
115 <td><a href="#EricServer.receiveJsonCommand">receiveJsonCommand</a></td> |
|
116 <td>Public method to receive a JSON encoded command and data.</td> |
|
117 </tr> |
|
118 <tr> |
|
119 <td><a href="#EricServer.registerRequestHandler">registerRequestHandler</a></td> |
|
120 <td>Public method to register a request handler method for the given request category.</td> |
|
121 </tr> |
|
122 <tr> |
|
123 <td><a href="#EricServer.run">run</a></td> |
|
124 <td>Public method implementing the remote server main loop.</td> |
|
125 </tr> |
|
126 <tr> |
|
127 <td><a href="#EricServer.sendJson">sendJson</a></td> |
|
128 <td>Public method to send a single refactoring command to the server.</td> |
|
129 </tr> |
|
130 <tr> |
|
131 <td><a href="#EricServer.sendJsonCommand">sendJsonCommand</a></td> |
|
132 <td>Public method to send a JSON encoded command/response via a given socket.</td> |
|
133 </tr> |
|
134 <tr> |
|
135 <td><a href="#EricServer.unregisterRequestHandler">unregisterRequestHandler</a></td> |
|
136 <td>Public method to unregister a handler for the given request category.</td> |
|
137 </tr> |
|
138 </table> |
|
139 |
|
140 <h3>Static Methods</h3> |
|
141 <table> |
|
142 <tr><td>None</td></tr> |
|
143 </table> |
|
144 |
|
145 |
|
146 <a NAME="EricServer.__init__" ID="EricServer.__init__"></a> |
|
147 <h4>EricServer (Constructor)</h4> |
|
148 <b>EricServer</b>(<i>port=42024, useIPv6=False</i>) |
|
149 <p> |
|
150 Constructor |
|
151 </p> |
|
152 |
|
153 <dl> |
|
154 |
|
155 <dt><i>port</i> (int (optional))</dt> |
|
156 <dd> |
|
157 port to listen on (defaults to 42024) |
|
158 </dd> |
|
159 <dt><i>useIPv6</i> (bool (optional))</dt> |
|
160 <dd> |
|
161 flag indicating to use IPv6 protocol (defaults to False) |
|
162 </dd> |
|
163 </dl> |
|
164 <a NAME="EricServer.__acceptIdeConnection" ID="EricServer.__acceptIdeConnection"></a> |
|
165 <h4>EricServer.__acceptIdeConnection</h4> |
|
166 <b>__acceptIdeConnection</b>(<i>sock</i>) |
|
167 <p> |
|
168 Private method to accept the connection on the listening IDE server socket. |
|
169 </p> |
|
170 |
|
171 <dl> |
|
172 |
|
173 <dt><i>sock</i> (socket.socket)</dt> |
|
174 <dd> |
|
175 reference to the listening socket |
|
176 </dd> |
|
177 </dl> |
|
178 <a NAME="EricServer.__closeIdeConnection" ID="EricServer.__closeIdeConnection"></a> |
|
179 <h4>EricServer.__closeIdeConnection</h4> |
|
180 <b>__closeIdeConnection</b>(<i>shutdown=False</i>) |
|
181 <p> |
|
182 Private method to close the connection to an eric-ide. |
|
183 </p> |
|
184 |
|
185 <dl> |
|
186 |
|
187 <dt><i>shutdown</i> (bool)</dt> |
|
188 <dd> |
|
189 flag indicating a shutdown process |
|
190 </dd> |
|
191 </dl> |
|
192 <a NAME="EricServer.__handleEchoRequest" ID="EricServer.__handleEchoRequest"></a> |
|
193 <h4>EricServer.__handleEchoRequest</h4> |
|
194 <b>__handleEchoRequest</b>(<i>request, params, reqestUuid</i>) |
|
195 <p> |
|
196 Private method to handle an 'Echo' request. |
|
197 </p> |
|
198 |
|
199 <dl> |
|
200 |
|
201 <dt><i>request</i> (str)</dt> |
|
202 <dd> |
|
203 request name |
|
204 </dd> |
|
205 <dt><i>params</i> (dict)</dt> |
|
206 <dd> |
|
207 request parameters |
|
208 </dd> |
|
209 <dt><i>reqestUuid</i> (str)</dt> |
|
210 <dd> |
|
211 UUID of the associated request as sent by the eric IDE |
|
212 (defaults to "", i.e. no UUID received) |
|
213 </dd> |
|
214 </dl> |
|
215 <a NAME="EricServer.__handleRequest" ID="EricServer.__handleRequest"></a> |
|
216 <h4>EricServer.__handleRequest</h4> |
|
217 <b>__handleRequest</b>(<i>category, request, params, reqestUuid</i>) |
|
218 <p> |
|
219 Private method handling or dispatching the received requests. |
|
220 </p> |
|
221 |
|
222 <dl> |
|
223 |
|
224 <dt><i>category</i> (EricRequestCategory)</dt> |
|
225 <dd> |
|
226 category of the request |
|
227 </dd> |
|
228 <dt><i>request</i> (str)</dt> |
|
229 <dd> |
|
230 request name |
|
231 </dd> |
|
232 <dt><i>params</i> (dict)</dt> |
|
233 <dd> |
|
234 request parameters |
|
235 </dd> |
|
236 <dt><i>reqestUuid</i> (str)</dt> |
|
237 <dd> |
|
238 UUID of the associated request as sent by the eric IDE |
|
239 </dd> |
|
240 </dl> |
|
241 <a NAME="EricServer.__handleServerRequest" ID="EricServer.__handleServerRequest"></a> |
|
242 <h4>EricServer.__handleServerRequest</h4> |
|
243 <b>__handleServerRequest</b>(<i>request, params, reqestUuid</i>) |
|
244 <p> |
|
245 Private method to handle a 'Server' request. |
|
246 </p> |
|
247 |
|
248 <dl> |
|
249 |
|
250 <dt><i>request</i> (str)</dt> |
|
251 <dd> |
|
252 request name |
|
253 </dd> |
|
254 <dt><i>params</i> (dict)</dt> |
|
255 <dd> |
|
256 request parameters |
|
257 </dd> |
|
258 <dt><i>reqestUuid</i> (str)</dt> |
|
259 <dd> |
|
260 UUID of the associated request as sent by the eric IDE |
|
261 (defaults to "", i.e. no UUID received) |
|
262 </dd> |
|
263 </dl> |
|
264 <a NAME="EricServer.__initializeIdeSocket" ID="EricServer.__initializeIdeSocket"></a> |
|
265 <h4>EricServer.__initializeIdeSocket</h4> |
|
266 <b>__initializeIdeSocket</b>(<i></i>) |
|
267 <p> |
|
268 Private method to initialize and register the eric-ide server socket. |
|
269 </p> |
|
270 |
|
271 <a NAME="EricServer.__receiveBytes" ID="EricServer.__receiveBytes"></a> |
|
272 <h4>EricServer.__receiveBytes</h4> |
|
273 <b>__receiveBytes</b>(<i>length, sock</i>) |
|
274 <p> |
|
275 Private method to receive the given length of bytes. |
|
276 </p> |
|
277 |
|
278 <dl> |
|
279 |
|
280 <dt><i>length</i> (int)</dt> |
|
281 <dd> |
|
282 bytes to receive |
|
283 </dd> |
|
284 <dt><i>sock</i> (socket.socket)</dt> |
|
285 <dd> |
|
286 reference to the socket to receive the data from |
|
287 </dd> |
|
288 </dl> |
|
289 <dl> |
|
290 <dt>Return:</dt> |
|
291 <dd> |
|
292 received bytes or None if connection closed |
|
293 </dd> |
|
294 </dl> |
|
295 <dl> |
|
296 <dt>Return Type:</dt> |
|
297 <dd> |
|
298 bytes |
|
299 </dd> |
|
300 </dl> |
|
301 <a NAME="EricServer.__receiveJson" ID="EricServer.__receiveJson"></a> |
|
302 <h4>EricServer.__receiveJson</h4> |
|
303 <b>__receiveJson</b>(<i></i>) |
|
304 <p> |
|
305 Private method to receive a JSON encoded command and data from the |
|
306 server. |
|
307 </p> |
|
308 |
|
309 <dl> |
|
310 <dt>Return:</dt> |
|
311 <dd> |
|
312 tuple containing the received service category, the command, |
|
313 a dictionary containing the associated data and the UUID of the |
|
314 request |
|
315 </dd> |
|
316 </dl> |
|
317 <dl> |
|
318 <dt>Return Type:</dt> |
|
319 <dd> |
|
320 tuple of (int, str, dict, str) |
|
321 </dd> |
|
322 </dl> |
|
323 <a NAME="EricServer.__registerInternalHandlers" ID="EricServer.__registerInternalHandlers"></a> |
|
324 <h4>EricServer.__registerInternalHandlers</h4> |
|
325 <b>__registerInternalHandlers</b>(<i></i>) |
|
326 <p> |
|
327 Private method to register request handler categories of this class. |
|
328 </p> |
|
329 |
|
330 <a NAME="EricServer.__serviceIdeConnection" ID="EricServer.__serviceIdeConnection"></a> |
|
331 <h4>EricServer.__serviceIdeConnection</h4> |
|
332 <b>__serviceIdeConnection</b>(<i>key</i>) |
|
333 <p> |
|
334 Private method to service the eric-ide connection. |
|
335 </p> |
|
336 |
|
337 <dl> |
|
338 |
|
339 <dt><i>key</i> (selectors.SelectorKey)</dt> |
|
340 <dd> |
|
341 reference to the SelectorKey object associated with the connection |
|
342 to be serviced |
|
343 </dd> |
|
344 </dl> |
|
345 <a NAME="EricServer.__shutdown" ID="EricServer.__shutdown"></a> |
|
346 <h4>EricServer.__shutdown</h4> |
|
347 <b>__shutdown</b>(<i></i>) |
|
348 <p> |
|
349 Private method to shut down the server. |
|
350 </p> |
|
351 |
|
352 <a NAME="EricServer.__unregisterIdeSocket" ID="EricServer.__unregisterIdeSocket"></a> |
|
353 <h4>EricServer.__unregisterIdeSocket</h4> |
|
354 <b>__unregisterIdeSocket</b>(<i></i>) |
|
355 <p> |
|
356 Private method to unregister the eric-ide server socket because only one |
|
357 connection is allowed. |
|
358 </p> |
|
359 |
|
360 <a NAME="EricServer.getSelector" ID="EricServer.getSelector"></a> |
|
361 <h4>EricServer.getSelector</h4> |
|
362 <b>getSelector</b>(<i></i>) |
|
363 <p> |
|
364 Public method to get a reference to the selector object. |
|
365 </p> |
|
366 |
|
367 <dl> |
|
368 <dt>Return:</dt> |
|
369 <dd> |
|
370 reference to the selector object |
|
371 </dd> |
|
372 </dl> |
|
373 <dl> |
|
374 <dt>Return Type:</dt> |
|
375 <dd> |
|
376 selectors.BaseSelector |
|
377 </dd> |
|
378 </dl> |
|
379 <a NAME="EricServer.isSocketClosed" ID="EricServer.isSocketClosed"></a> |
|
380 <h4>EricServer.isSocketClosed</h4> |
|
381 <b>isSocketClosed</b>(<i>sock</i>) |
|
382 <p> |
|
383 Public method to check, if a given socket is closed. |
|
384 </p> |
|
385 |
|
386 <dl> |
|
387 |
|
388 <dt><i>sock</i> (socket.socket)</dt> |
|
389 <dd> |
|
390 reference to the socket to be checked |
|
391 </dd> |
|
392 </dl> |
|
393 <dl> |
|
394 <dt>Return:</dt> |
|
395 <dd> |
|
396 flag indicating a closed state |
|
397 </dd> |
|
398 </dl> |
|
399 <dl> |
|
400 <dt>Return Type:</dt> |
|
401 <dd> |
|
402 bool |
|
403 </dd> |
|
404 </dl> |
|
405 <a NAME="EricServer.receiveJsonCommand" ID="EricServer.receiveJsonCommand"></a> |
|
406 <h4>EricServer.receiveJsonCommand</h4> |
|
407 <b>receiveJsonCommand</b>(<i>sock</i>) |
|
408 <p> |
|
409 Public method to receive a JSON encoded command and data. |
|
410 </p> |
|
411 |
|
412 <dl> |
|
413 |
|
414 <dt><i>sock</i> (socket.socket)</dt> |
|
415 <dd> |
|
416 reference to the socket to receive the data from |
|
417 </dd> |
|
418 </dl> |
|
419 <dl> |
|
420 <dt>Return:</dt> |
|
421 <dd> |
|
422 dictionary containing the JSON command data or None to signal |
|
423 an issue while receiving data |
|
424 </dd> |
|
425 </dl> |
|
426 <dl> |
|
427 <dt>Return Type:</dt> |
|
428 <dd> |
|
429 dict |
|
430 </dd> |
|
431 </dl> |
|
432 <a NAME="EricServer.registerRequestHandler" ID="EricServer.registerRequestHandler"></a> |
|
433 <h4>EricServer.registerRequestHandler</h4> |
|
434 <b>registerRequestHandler</b>(<i>requestCategory, handler</i>) |
|
435 <p> |
|
436 Public method to register a request handler method for the given request |
|
437 category. |
|
438 </p> |
|
439 |
|
440 <dl> |
|
441 |
|
442 <dt><i>requestCategory</i> (EricRequestCategory or int (>= EricRequestCategory.UserCategory))</dt> |
|
443 <dd> |
|
444 request category to be registered |
|
445 </dd> |
|
446 <dt><i>handler</i> (function(request:str, params:dict, requestUuid:str))</dt> |
|
447 <dd> |
|
448 reference to the handler method. This handler must accept |
|
449 the parameters 'request', 'params', and 'requestUuid' |
|
450 </dd> |
|
451 </dl> |
|
452 <dl> |
|
453 |
|
454 <dt>Raises <b>ValueError</b>:</dt> |
|
455 <dd> |
|
456 raised to signal a request category collision |
|
457 </dd> |
|
458 </dl> |
|
459 <a NAME="EricServer.run" ID="EricServer.run"></a> |
|
460 <h4>EricServer.run</h4> |
|
461 <b>run</b>(<i></i>) |
|
462 <p> |
|
463 Public method implementing the remote server main loop. |
|
464 </p> |
|
465 <p> |
|
466 Exiting the inner loop, that receives and dispatches the requests, will |
|
467 cause the server to stop and exit. The main loop handles these requests. |
|
468 <ul> |
|
469 <li>exit - exit the handler loop and wait for the next connection</li> |
|
470 <li>shutdown - exit the handler loop and perform a clean shutdown</li> |
|
471 </ul> |
|
472 </p> |
|
473 |
|
474 <dl> |
|
475 <dt>Return:</dt> |
|
476 <dd> |
|
477 flag indicating a clean shutdown |
|
478 </dd> |
|
479 </dl> |
|
480 <dl> |
|
481 <dt>Return Type:</dt> |
|
482 <dd> |
|
483 bool |
|
484 </dd> |
|
485 </dl> |
|
486 <a NAME="EricServer.sendJson" ID="EricServer.sendJson"></a> |
|
487 <h4>EricServer.sendJson</h4> |
|
488 <b>sendJson</b>(<i>category, reply, params, reqestUuid=""</i>) |
|
489 <p> |
|
490 Public method to send a single refactoring command to the server. |
|
491 </p> |
|
492 |
|
493 <dl> |
|
494 |
|
495 <dt><i>category</i> (EricRequestCategory)</dt> |
|
496 <dd> |
|
497 service category |
|
498 </dd> |
|
499 <dt><i>reply</i> (str)</dt> |
|
500 <dd> |
|
501 reply name to be sent |
|
502 </dd> |
|
503 <dt><i>params</i> (dict)</dt> |
|
504 <dd> |
|
505 dictionary of named parameters for the request |
|
506 </dd> |
|
507 <dt><i>reqestUuid</i> (str)</dt> |
|
508 <dd> |
|
509 UUID of the associated request as sent by the eric IDE |
|
510 (defaults to "", i.e. no UUID received) |
|
511 </dd> |
|
512 </dl> |
|
513 <a NAME="EricServer.sendJsonCommand" ID="EricServer.sendJsonCommand"></a> |
|
514 <h4>EricServer.sendJsonCommand</h4> |
|
515 <b>sendJsonCommand</b>(<i>jsonCommand, sock</i>) |
|
516 <p> |
|
517 Public method to send a JSON encoded command/response via a given socket. |
|
518 </p> |
|
519 |
|
520 <dl> |
|
521 |
|
522 <dt><i>jsonCommand</i> (dict or str)</dt> |
|
523 <dd> |
|
524 dictionary containing the command data or a JSON encoded |
|
525 command string |
|
526 </dd> |
|
527 <dt><i>sock</i> (socket.socket)</dt> |
|
528 <dd> |
|
529 reference to the socket to send the data to |
|
530 </dd> |
|
531 </dl> |
|
532 <dl> |
|
533 <dt>Return:</dt> |
|
534 <dd> |
|
535 flag indicating a successful transmission |
|
536 </dd> |
|
537 </dl> |
|
538 <dl> |
|
539 <dt>Return Type:</dt> |
|
540 <dd> |
|
541 bool |
|
542 </dd> |
|
543 </dl> |
|
544 <a NAME="EricServer.unregisterRequestHandler" ID="EricServer.unregisterRequestHandler"></a> |
|
545 <h4>EricServer.unregisterRequestHandler</h4> |
|
546 <b>unregisterRequestHandler</b>(<i>requestCategory, ignoreError=False</i>) |
|
547 <p> |
|
548 Public method to unregister a handler for the given request category. |
|
549 </p> |
|
550 <p> |
|
551 Note: This method will raise a KeyError exception in case the request |
|
552 category has not been registered and ignoreError is False (the default). |
|
553 </p> |
|
554 |
|
555 <dl> |
|
556 |
|
557 <dt><i>requestCategory</i> (EricRequestCategory or int (>= EricRequestCategory.UserCategory))</dt> |
|
558 <dd> |
|
559 request category to be unregistered |
|
560 </dd> |
|
561 <dt><i>ignoreError</i> (bool (optional))</dt> |
|
562 <dd> |
|
563 flag indicating to ignore errors (defaults to False) |
|
564 </dd> |
|
565 </dl> |
|
566 <div align="right"><a href="#top">Up</a></div> |
|
567 <hr /> |
|
568 </body></html> |