RefactoringRope/JsonClient.py

branch
server_client_variant
changeset 166
6fc202183b3b
parent 164
121d426d4ed7
child 168
53d76b4fc1ac
equal deleted inserted replaced
165:ea41742015af 166:6fc202183b3b
16 16
17 import sys 17 import sys
18 import socket 18 import socket
19 import select 19 import select
20 import traceback 20 import traceback
21 import time
22 import json 21 import json
23 22
24 23
25 class JsonClient(object): 24 class JsonClient(object):
26 """ 25 """
33 @param host ip address the background service is listening 32 @param host ip address the background service is listening
34 @type str 33 @type str
35 @param port port of the background service 34 @param port port of the background service
36 @type int 35 @type int
37 """ 36 """
37 self.__exitClient = False
38 self.__connection = socket.create_connection((host, port)) 38 self.__connection = socket.create_connection((host, port))
39 39
40 def sendJson(self, command, params): 40 def sendJson(self, command, params):
41 """ 41 """
42 Public method to send a single refactoring command to the server. 42 Public method to send a single refactoring command to the server.
79 }) 79 })
80 return 80 return
81 81
82 method = commandDict["method"] 82 method = commandDict["method"]
83 params = commandDict["params"] 83 params = commandDict["params"]
84 self.handleCall(method, params) 84
85 if method == "Exit":
86 self.__exitClient = True
87 else:
88 self.handleCall(method, params)
85 89
86 def handleCall(self, method, params): 90 def handleCall(self, method, params):
87 """ 91 """
88 Public method to handle a method call from the server. 92 Public method to handle a method call from the server.
89 93
110 # just carry on 114 # just carry on
111 continue 115 continue
112 116
113 if self.__connection in rrdy: 117 if self.__connection in rrdy:
114 self.__receiveJson() 118 self.__receiveJson()
119
120 if self.__exitClient:
121 break
115 122
116 except Exception: 123 except Exception:
117 exctype, excval, exctb = sys.exc_info() 124 exctype, excval, exctb = sys.exc_info()
118 tbinfofile = io.StringIO() 125 tbinfofile = io.StringIO()
119 traceback.print_tb(exctb, None, tbinfofile) 126 traceback.print_tb(exctb, None, tbinfofile)
125 "ExceptionValue": str(excval), 132 "ExceptionValue": str(excval),
126 "Traceback": tbinfo, 133 "Traceback": tbinfo,
127 }) 134 })
128 135
129 # Give time to process latest response on server side 136 # Give time to process latest response on server side
130 time.sleep(0.5)
131 self.__connection.shutdown(socket.SHUT_RDWR) 137 self.__connection.shutdown(socket.SHUT_RDWR)
132 self.__connection.close() 138 self.__connection.close()
133 139
134 def poll(self): 140 def poll(self):
135 """ 141 """

eric ide

mercurial