RefactoringRope/RefactoringClient.py

branch
server_client_variant
changeset 162
55eaaed9d590
parent 161
f5d6fb1a009b
child 163
6a9e7b37a18b
equal deleted inserted replaced
161:f5d6fb1a009b 162:55eaaed9d590
49 @param projectPath path to the project 49 @param projectPath path to the project
50 @type str 50 @type str
51 """ 51 """
52 self.__connection = socket.create_connection((host, port)) 52 self.__connection = socket.create_connection((host, port))
53 53
54 from FileSystemCommands import RefactoringClientFileSystemCommands
55 self.__fsCommands = RefactoringClientFileSystemCommands(self)
56
54 self.__projectpath = projectPath 57 self.__projectpath = projectPath
55 self.__project = rope.base.project.Project( 58 self.__project = rope.base.project.Project(
56 self.__projectpath)#, fscommands=self.__fsCommands) 59 self.__projectpath, fscommands=self.__fsCommands)
57 60
58 def __processJson(self, jsonStr): 61 def __processJson(self, jsonStr):
59 """ 62 """
60 Public method to handle a command serialized as a JSON string. 63 Public method to handle a command serialized as a JSON string.
61 64
63 @type str 66 @type str
64 """ 67 """
65 try: 68 try:
66 commandDict = json.loads(jsonStr.strip()) 69 commandDict = json.loads(jsonStr.strip())
67 except (TypeError, ValueError) as err: 70 except (TypeError, ValueError) as err:
68 self.__sendJson("ClientException", { 71 self.sendJson("ClientException", {
69 "ExceptionType": "ProtocolError", 72 "ExceptionType": "ProtocolError",
70 "ExceptionValue": str(err), 73 "ExceptionValue": str(err),
71 "ProtocolData": jsonStr.strip(), 74 "ProtocolData": jsonStr.strip(),
72 }) 75 })
73 return 76 return
77 if "filename" in params and sys.version_info[0] == 2: 80 if "filename" in params and sys.version_info[0] == 2:
78 params["filename"] = params["filename"].encode( 81 params["filename"] = params["filename"].encode(
79 sys.getfilesystemencoding()) 82 sys.getfilesystemencoding())
80 83
81 if method == "ping": 84 if method == "ping":
82 self.__sendJson("pong", {}) 85 self.sendJson("pong", {})
83 86
84 def __sendJson(self, command, params): 87 def sendJson(self, command, params):
85 """ 88 """
86 Private method to send a single refactoring command to the client. 89 Public method to send a single refactoring command to the client.
87 90
88 @param command command name to be sent 91 @param command command name to be sent
89 @type str 92 @type str
90 @param params dictionary of named parameters for the command 93 @param params dictionary of named parameters for the command
91 @type dict 94 @type dict
123 """ 126 """
124 try: 127 try:
125 while True: 128 while True:
126 try: 129 try:
127 rrdy, wrdy, xrdy = select.select( 130 rrdy, wrdy, xrdy = select.select(
128 [self.__connection], [self.__connection], []) 131 [self.__connection], [], [])
129 except (select.error, KeyboardInterrupt, socket.error): 132 except (select.error, KeyboardInterrupt, socket.error):
130 # just carry on 133 # just carry on
131 continue 134 continue
132 135
133 if self.__connection in rrdy: 136 if self.__connection in rrdy:
134 self.__receiveJson() 137 self.__receiveJson()
135 ## 138
136 ## if self.__connection in wrdy:
137 ## self.__connection.flush()
138
139 except Exception: 139 except Exception:
140 exctype, excval, exctb = sys.exc_info() 140 exctype, excval, exctb = sys.exc_info()
141 tbinfofile = io.StringIO() 141 tbinfofile = io.StringIO()
142 traceback.print_tb(exctb, None, tbinfofile) 142 traceback.print_tb(exctb, None, tbinfofile)
143 tbinfofile.seek(0) 143 tbinfofile.seek(0)
144 tbinfo = tbinfofile.read() 144 tbinfo = tbinfofile.read()
145 del exctb 145 del exctb
146 self.__sendJson("ClientException", { 146 self.sendJson("ClientException", {
147 "ExceptionType": str(exctype), 147 "ExceptionType": str(exctype),
148 "ExceptionValue": str(excval), 148 "ExceptionValue": str(excval),
149 "Traceback": tbinfo, 149 "Traceback": tbinfo,
150 }) 150 })
151 151

eric ide

mercurial