RefactoringRope/JsonServer.py

branch
server_client_variant
changeset 168
53d76b4fc1ac
parent 166
6fc202183b3b
child 175
72a1d9030d67
equal deleted inserted replaced
167:3c8e875d0326 168:53d76b4fc1ac
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import json 12 import json
13 13
14 from PyQt5.QtCore import pyqtSlot, QProcess, QThread 14 from PyQt5.QtCore import pyqtSlot, QProcess
15 from PyQt5.QtNetwork import QTcpServer, QHostAddress 15 from PyQt5.QtNetwork import QTcpServer, QHostAddress
16 16
17 from E5Gui import E5MessageBox 17 from E5Gui import E5MessageBox
18 18
19 import Preferences 19 import Preferences
131 @param params dictionary with method specific parameters 131 @param params dictionary with method specific parameters
132 @type dict 132 @type dict
133 """ 133 """
134 pass 134 pass
135 135
136 def sendJson(self, command, params): 136 def sendJson(self, command, params, flush=False):
137 """ 137 """
138 Public method to send a single refactoring command to the client. 138 Public method to send a single refactoring command to the client.
139 139
140 @param command command name to be sent 140 @param command command name to be sent
141 @type str 141 @type str
142 @param params dictionary of named parameters for the command 142 @param params dictionary of named parameters for the command
143 @type dict 143 @type dict
144 @param flush flag indicating to flush the data to the socket
145 @type bool
144 """ 146 """
145 commandDict = { 147 commandDict = {
146 "jsonrpc": "2.0", 148 "jsonrpc": "2.0",
147 "method": command, 149 "method": command,
148 "params": params, 150 "params": params,
149 } 151 }
150 cmd = json.dumps(commandDict) + '\n' 152 cmd = json.dumps(commandDict) + '\n'
151 153
152 if self.__connection is not None: 154 if self.__connection is not None:
153 self.__connection.write(cmd.encode('utf8', 'backslashreplace')) 155 self.__connection.write(cmd.encode('utf8', 'backslashreplace'))
156 if flush:
157 self.__connection.flush()
154 158
155 def startClient(self, interpreter, clientScript, clientArgs): 159 def startClient(self, interpreter, clientScript, clientArgs):
156 """ 160 """
157 Public method to start the client process. 161 Public method to start the client process.
158 162
181 185
182 def stopClient(self): 186 def stopClient(self):
183 """ 187 """
184 Public method to stop the client process. 188 Public method to stop the client process.
185 """ 189 """
186 self.sendJson("Exit", {}) 190 self.sendJson("Exit", {}, flush=True)
187 191
188 QThread.msleep(200) 192 if self.__connection is not None:
193 self.__connection.waitForDisconnected()
189 194
190 self.__clientProcess.close() 195 self.__clientProcess.close()
191 self.__clientProcess = None 196 self.__clientProcess = None
192
193 #
194 # eflag: noqa = M801

eric ide

mercurial