353 self.sendSyntaxError(message, filename, lineno, charno) |
352 self.sendSyntaxError(message, filename, lineno, charno) |
354 return None |
353 return None |
355 |
354 |
356 return code |
355 return code |
357 |
356 |
358 def handleLine(self, line): |
|
359 """ |
|
360 Public method to handle the receipt of a complete line. |
|
361 |
|
362 It first looks for a valid protocol token at the start of the line. |
|
363 Thereafter it trys to execute the lines accumulated so far. |
|
364 |
|
365 @param line the received line |
|
366 """ |
|
367 # Remove any newline. |
|
368 if line[-1] == '\n': |
|
369 line = line[:-1] |
|
370 |
|
371 ## printerr(line) ##debug |
|
372 |
|
373 self.handleJsonCommand(line) |
|
374 |
|
375 def handleJsonCommand(self, jsonStr): |
357 def handleJsonCommand(self, jsonStr): |
376 """ |
358 """ |
377 Public method to handle a command serialized as a JSON string. |
359 Public method to handle a command serialized as a JSON string. |
378 |
360 |
379 @param jsonStr string containing the command received from the IDE |
361 @param jsonStr string containing the command received from the IDE |
380 @type str |
362 @type str |
381 """ |
363 """ |
|
364 ## printerr(jsonStr) ##debug |
|
365 |
382 try: |
366 try: |
383 commandDict = json.loads(jsonStr.strip()) |
367 commandDict = json.loads(jsonStr.strip()) |
384 except (TypeError, ValueError) as err: |
368 except (TypeError, ValueError) as err: |
|
369 printerr("Error handling command: " + jsonStr) |
385 printerr(str(err)) |
370 printerr(str(err)) |
386 return |
371 return |
387 |
372 |
388 method = commandDict["method"] |
373 method = commandDict["method"] |
389 params = commandDict["params"] |
374 params = commandDict["params"] |
391 params["filename"] = params["filename"].encode( |
376 params["filename"] = params["filename"].encode( |
392 sys.getfilesystemencoding()) |
377 sys.getfilesystemencoding()) |
393 |
378 |
394 if method == "RequestVariables": |
379 if method == "RequestVariables": |
395 self.__dumpVariables( |
380 self.__dumpVariables( |
396 params["frameNumber"], params["scope"], params["filters"]) |
381 params["frameNumber"], params["scope"], params["filters"], |
|
382 params["maxSize"]) |
397 |
383 |
398 elif method == "RequestVariable": |
384 elif method == "RequestVariable": |
399 self.__dumpVariable( |
385 self.__dumpVariable( |
400 params["variable"], params["frameNumber"], |
386 params["variable"], params["frameNumber"], |
401 params["scope"], params["filters"]) |
387 params["scope"], params["filters"], |
|
388 params["maxSize"]) |
402 |
389 |
403 elif method == "RequestThreadList": |
390 elif method == "RequestThreadList": |
404 self.dumpThreadList() |
391 self.dumpThreadList() |
405 |
392 |
406 elif method == "RequestThreadSet": |
393 elif method == "RequestThreadSet": |
1027 Public method called when there is data ready to be read. |
1014 Public method called when there is data ready to be read. |
1028 |
1015 |
1029 @param stream file like object that has data to be written |
1016 @param stream file like object that has data to be written |
1030 """ |
1017 """ |
1031 try: |
1018 try: |
1032 got = stream.readline_p() |
1019 self.lockClient() |
|
1020 command = stream.readCommand() |
|
1021 self.unlockClient() |
1033 except Exception: |
1022 except Exception: |
1034 return |
1023 return |
1035 |
1024 |
1036 if len(got) == 0: |
1025 if len(command) == 0: |
1037 self.sessionClose() |
1026 self.sessionClose() |
1038 return |
1027 return |
1039 |
1028 |
1040 self.__receiveBuffer = self.__receiveBuffer + got |
1029 self.handleJsonCommand(command) |
1041 |
|
1042 # Call handleLine for the line if it is complete. |
|
1043 eol = self.__receiveBuffer.find('\n') |
|
1044 while eol >= 0: |
|
1045 line = self.__receiveBuffer[:eol + 1] |
|
1046 self.__receiveBuffer = self.__receiveBuffer[eol + 1:] |
|
1047 self.handleLine(line) |
|
1048 eol = self.__receiveBuffer.find('\n') |
|
1049 |
1030 |
1050 def writeReady(self, stream): |
1031 def writeReady(self, stream): |
1051 """ |
1032 """ |
1052 Public method called when we are ready to write data. |
1033 Public method called when we are ready to write data. |
1053 |
1034 |
1319 }) |
1300 }) |
1320 |
1301 |
1321 # reset coding |
1302 # reset coding |
1322 self.__coding = self.defaultCoding |
1303 self.__coding = self.defaultCoding |
1323 |
1304 |
1324 def __dumpVariables(self, frmnr, scope, filterList): |
1305 def __dumpVariables(self, frmnr, scope, filterList, maxSize): |
1325 """ |
1306 """ |
1326 Private method to return the variables of a frame to the debug server. |
1307 Private method to return the variables of a frame to the debug server. |
1327 |
1308 |
1328 @param frmnr distance of frame reported on. 0 is the current frame |
1309 @param frmnr distance of frame reported on. 0 is the current frame |
1329 (int) |
1310 @type int |
1330 @param scope 1 to report global variables, 0 for local variables (int) |
1311 @param scope 1 to report global variables, 0 for local variables |
|
1312 @type int |
1331 @param filterList the indices of variable types to be filtered |
1313 @param filterList the indices of variable types to be filtered |
1332 (list of int) |
1314 @type list of int |
|
1315 @param maxSize maximum size the formatted value of a variable will |
|
1316 be shown. If it is bigger than that, a 'too big' indication will |
|
1317 be given. |
|
1318 @type int |
1333 """ |
1319 """ |
1334 if self.currentThread is None: |
1320 if self.currentThread is None: |
1335 return |
1321 return |
1336 |
1322 |
1337 frmnr += self.currentThread.skipFrames |
1323 frmnr += self.currentThread.skipFrames |
1360 |
1346 |
1361 if scope != -1: |
1347 if scope != -1: |
1362 keylist = varDict.keys() |
1348 keylist = varDict.keys() |
1363 |
1349 |
1364 vlist = self.__formatVariablesList( |
1350 vlist = self.__formatVariablesList( |
1365 keylist, varDict, scope, filterList) |
1351 keylist, varDict, scope, filterList, maxSize=maxSize) |
1366 varlist.extend(vlist) |
1352 varlist.extend(vlist) |
1367 |
1353 |
1368 self.sendJsonCommand("ResponseVariables", { |
1354 self.sendJsonCommand("ResponseVariables", { |
1369 "scope": scope, |
1355 "scope": scope, |
1370 "variables": varlist, |
1356 "variables": varlist, |
1371 }) |
1357 }) |
1372 |
1358 |
1373 def __dumpVariable(self, var, frmnr, scope, filterList): |
1359 def __dumpVariable(self, var, frmnr, scope, filterList, maxSize): |
1374 """ |
1360 """ |
1375 Private method to return the variables of a frame to the debug server. |
1361 Private method to return the variables of a frame to the debug server. |
1376 |
1362 |
1377 @param var list encoded name of the requested variable |
1363 @param var list encoded name of the requested variable |
1378 (list of strings) |
1364 @type list of strings |
1379 @param frmnr distance of frame reported on. 0 is the current frame |
1365 @param frmnr distance of frame reported on. 0 is the current frame |
1380 (int) |
1366 @type int |
1381 @param scope 1 to report global variables, 0 for local variables (int) |
1367 @param scope 1 to report global variables, 0 for local variables (int) |
1382 @param filterList the indices of variable types to be filtered |
1368 @param filterList the indices of variable types to be filtered |
1383 (list of int) |
1369 @type list of int |
|
1370 @param maxSize maximum size the formatted value of a variable will |
|
1371 be shown. If it is bigger than that, a 'too big' indication will |
|
1372 be given. |
|
1373 @type int |
1384 """ |
1374 """ |
1385 if self.currentThread is None: |
1375 if self.currentThread is None: |
1386 return |
1376 return |
1387 |
1377 |
1388 frmnr += self.currentThread.skipFrames |
1378 frmnr += self.currentThread.skipFrames |
1427 vlist = self.__formatQtVariable(variable, typeName) |
1417 vlist = self.__formatQtVariable(variable, typeName) |
1428 varlist.extend(vlist) |
1418 varlist.extend(vlist) |
1429 elif resolver: |
1419 elif resolver: |
1430 varDict = resolver.getDictionary(variable) |
1420 varDict = resolver.getDictionary(variable) |
1431 vlist = self.__formatVariablesList( |
1421 vlist = self.__formatVariablesList( |
1432 list(varDict.keys()), varDict, scope, filterList) |
1422 list(varDict.keys()), varDict, scope, filterList, |
|
1423 maxSize=maxSize) |
1433 varlist.extend(vlist) |
1424 varlist.extend(vlist) |
1434 |
1425 |
1435 self.sendJsonCommand("ResponseVariable", { |
1426 self.sendJsonCommand("ResponseVariable", { |
1436 "scope": scope, |
1427 "scope": scope, |
1437 "variable": var, |
1428 "variable": var, |
1598 ("address", "QHostAddress", "{0}".format(value.toString()))) |
1589 ("address", "QHostAddress", "{0}".format(value.toString()))) |
1599 |
1590 |
1600 return varlist |
1591 return varlist |
1601 |
1592 |
1602 def __formatVariablesList(self, keylist, dict_, scope, filterList=None, |
1593 def __formatVariablesList(self, keylist, dict_, scope, filterList=None, |
1603 formatSequences=False): |
1594 formatSequences=False, maxSize=0): |
1604 """ |
1595 """ |
1605 Private method to produce a formated variables list. |
1596 Private method to produce a formated variables list. |
1606 |
1597 |
1607 The dictionary passed in to it is scanned. Variables are |
1598 The dictionary passed in to it is scanned. Variables are |
1608 only added to the list, if their type is not contained |
1599 only added to the list, if their type is not contained |
1609 in the filter list and their name doesn't match any of the filter |
1600 in the filter list and their name doesn't match any of the filter |
1610 expressions. The formated variables list (a list of tuples of 3 |
1601 expressions. The formated variables list (a list of tuples of 3 |
1611 values) is returned. |
1602 values) is returned. |
1612 |
1603 |
1613 @param keylist keys of the dictionary |
1604 @param keylist keys of the dictionary to be formatted |
|
1605 @type list of str |
1614 @param dict_ the dictionary to be scanned |
1606 @param dict_ the dictionary to be scanned |
|
1607 @type dict |
1615 @param scope 1 to filter using the globals filter, 0 using the locals |
1608 @param scope 1 to filter using the globals filter, 0 using the locals |
1616 filter (int). |
1609 filter. |
1617 Variables are only added to the list, if their name do not match |
1610 Variables are only added to the list, if their name do not match |
1618 any of the filter expressions. |
1611 any of the filter expressions. |
|
1612 @type int |
1619 @param filterList the indices of variable types to be filtered. |
1613 @param filterList the indices of variable types to be filtered. |
1620 Variables are only added to the list, if their type is not |
1614 Variables are only added to the list, if their type is not |
1621 contained in the filter list. |
1615 contained in the filter list. |
|
1616 @type list of int |
1622 @param formatSequences flag indicating, that sequence or dictionary |
1617 @param formatSequences flag indicating, that sequence or dictionary |
1623 variables should be formatted. If it is 0 (or false), just the |
1618 variables should be formatted. If it is 0 (or false), just the |
1624 number of items contained in these variables is returned. (boolean) |
1619 number of items contained in these variables is returned. |
|
1620 @type bool |
|
1621 @param maxSize maximum size the formatted value of a variable will |
|
1622 be shown. If it is bigger than that, a 'too big' indication will |
|
1623 be placed in the value field. |
|
1624 @type int |
1625 @return A tuple consisting of a list of formatted variables. Each |
1625 @return A tuple consisting of a list of formatted variables. Each |
1626 variable entry is a tuple of three elements, the variable name, |
1626 variable entry is a tuple of three elements, the variable name, |
1627 its type and value. |
1627 its type and value. |
|
1628 @rtype list of tuple of (str, str, str) |
1628 """ |
1629 """ |
1629 filterList = [] if filterList is None else filterList[:] |
1630 filterList = [] if filterList is None else filterList[:] |
1630 |
1631 |
1631 varlist = [] |
1632 varlist = [] |
1632 if scope: |
1633 if scope: |