src/eric7/RemoteServer/EricServerBaseRequestHandler.py

branch
server
changeset 10767
b3672d3e7644
child 11090
f5f5f5803935
equal deleted inserted replaced
10766:d35d6f96c24b 10767:b3672d3e7644
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2024 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the request handler base class of the eric-ide server.
8 """
9
10 from .EricRequestCategory import EricRequestCategory
11
12
13 class EricServerBaseRequestHandler:
14 """
15 Class implementing the request handler base class of the eric-ide server.
16 """
17
18 def __init__(self, server):
19 """
20 Constructor
21
22 @param server reference to the eric-ide server object
23 @type EricServer
24 """
25 self._server = server
26
27 self._category = EricRequestCategory.Generic
28 # must be changed by derived classes
29
30 self._requestMethodMapping = {}
31 # must be filled by derived classes
32
33 def handleRequest(self, request, params, reqestUuid):
34 """
35 Public method handling the received file system requests.
36
37 @param request request name
38 @type str
39 @param params dictionary containing the request parameters
40 @type dict
41 @param reqestUuid UUID of the associated request as sent by the eric IDE
42 @type str
43 """
44 try:
45 result = self._requestMethodMapping[request](params)
46 if result is not None:
47 self._server.sendJson(
48 category=self._category,
49 reply=request,
50 params=result,
51 reqestUuid=reqestUuid,
52 )
53
54 except KeyError:
55 self.sendError(request=request, reqestUuid=reqestUuid)
56
57 def sendError(self, request, reqestUuid=""):
58 """
59 Public method to send an error report to the IDE.
60
61 @param request request name
62 @type str
63 @param reqestUuid UUID of the associated request as sent by the eric IDE
64 (defaults to "", i.e. no UUID received)
65 @type str
66 """
67 self._server.sendJson(
68 category=self._category,
69 reply=request,
70 params={"Error": f"Request type '{request}' is not supported."},
71 reqestUuid=reqestUuid,
72 )

eric ide

mercurial