290 @param prompt the prompt to be shown (string) |
290 @param prompt the prompt to be shown (string) |
291 @return the entered string evaluated as a Python expresion |
291 @return the entered string evaluated as a Python expresion |
292 """ |
292 """ |
293 return eval(self.raw_input(prompt, True)) |
293 return eval(self.raw_input(prompt, True)) |
294 |
294 |
295 def sessionClose(self, exit=True): |
295 def sessionClose(self, terminate=True): |
296 """ |
296 """ |
297 Public method to close the session with the debugger and optionally |
297 Public method to close the session with the debugger and optionally |
298 terminate. |
298 terminate. |
299 |
299 |
300 @param exit flag indicating to terminate (boolean) |
300 @param terminate flag indicating to terminate (boolean) |
301 """ |
301 """ |
302 try: |
302 try: |
303 self.set_quit() |
303 self.set_quit() |
304 except Exception: |
304 except Exception: |
305 pass |
305 pass |
311 # SHOULD be closed on exit, but it does not hurt to do it here |
311 # SHOULD be closed on exit, but it does not hurt to do it here |
312 self.readstream.close(True) |
312 self.readstream.close(True) |
313 self.writestream.close(True) |
313 self.writestream.close(True) |
314 self.errorstream.close(True) |
314 self.errorstream.close(True) |
315 |
315 |
316 if exit: |
316 if terminate: |
317 # Ok, go away. |
317 # Ok, go away. |
318 sys.exit() |
318 sys.exit() |
319 |
319 |
320 def __compileFileSource(self, filename, mode='exec'): |
320 def __compileFileSource(self, filename, mode='exec'): |
321 """ |
321 """ |
1318 }) |
1318 }) |
1319 |
1319 |
1320 # reset coding |
1320 # reset coding |
1321 self.__coding = self.defaultCoding |
1321 self.__coding = self.defaultCoding |
1322 |
1322 |
1323 def __dumpVariables(self, frmnr, scope, filter): |
1323 def __dumpVariables(self, frmnr, scope, filterList): |
1324 """ |
1324 """ |
1325 Private method to return the variables of a frame to the debug server. |
1325 Private method to return the variables of a frame to the debug server. |
1326 |
1326 |
1327 @param frmnr distance of frame reported on. 0 is the current frame |
1327 @param frmnr distance of frame reported on. 0 is the current frame |
1328 (int) |
1328 (int) |
1329 @param scope 1 to report global variables, 0 for local variables (int) |
1329 @param scope 1 to report global variables, 0 for local variables (int) |
1330 @param filter the indices of variable types to be filtered |
1330 @param filterList the indices of variable types to be filtered |
1331 (list of int) |
1331 (list of int) |
1332 """ |
1332 """ |
1333 if self.currentThread is None: |
1333 if self.currentThread is None: |
1334 return |
1334 return |
1335 |
1335 |
1343 f = f.f_back |
1343 f = f.f_back |
1344 frmnr -= 1 |
1344 frmnr -= 1 |
1345 |
1345 |
1346 if f is None: |
1346 if f is None: |
1347 if scope: |
1347 if scope: |
1348 dict = self.debugMod.__dict__ |
1348 varDict = self.debugMod.__dict__ |
1349 else: |
1349 else: |
1350 scope = -1 |
1350 scope = -1 |
1351 elif scope: |
1351 elif scope: |
1352 dict = f.f_globals |
1352 varDict = f.f_globals |
1353 elif f.f_globals is f.f_locals: |
1353 elif f.f_globals is f.f_locals: |
1354 scope = -1 |
1354 scope = -1 |
1355 else: |
1355 else: |
1356 dict = f.f_locals |
1356 varDict = f.f_locals |
1357 |
1357 |
1358 varlist = [] |
1358 varlist = [] |
1359 |
1359 |
1360 if scope != -1: |
1360 if scope != -1: |
1361 keylist = dict.keys() |
1361 keylist = varDict.keys() |
1362 |
1362 |
1363 vlist = self.__formatVariablesList(keylist, dict, scope, filter) |
1363 vlist = self.__formatVariablesList( |
|
1364 keylist, varDict, scope, filterList) |
1364 varlist.extend(vlist) |
1365 varlist.extend(vlist) |
1365 |
1366 |
1366 self.sendJsonCommand("ResponseVariables", { |
1367 self.sendJsonCommand("ResponseVariables", { |
1367 "scope": scope, |
1368 "scope": scope, |
1368 "variables": varlist, |
1369 "variables": varlist, |
1369 }) |
1370 }) |
1370 |
1371 |
1371 def __dumpVariable(self, var, frmnr, scope, filter): |
1372 def __dumpVariable(self, var, frmnr, scope, filterList): |
1372 """ |
1373 """ |
1373 Private method to return the variables of a frame to the debug server. |
1374 Private method to return the variables of a frame to the debug server. |
1374 |
1375 |
1375 @param var list encoded name of the requested variable |
1376 @param var list encoded name of the requested variable |
1376 (list of strings) |
1377 (list of strings) |
1377 @param frmnr distance of frame reported on. 0 is the current frame |
1378 @param frmnr distance of frame reported on. 0 is the current frame |
1378 (int) |
1379 (int) |
1379 @param scope 1 to report global variables, 0 for local variables (int) |
1380 @param scope 1 to report global variables, 0 for local variables (int) |
1380 @param filter the indices of variable types to be filtered |
1381 @param filterList the indices of variable types to be filtered |
1381 (list of int) |
1382 (list of int) |
1382 """ |
1383 """ |
1383 if self.currentThread is None: |
1384 if self.currentThread is None: |
1384 return |
1385 return |
1385 |
1386 |
1390 f = f.f_back |
1391 f = f.f_back |
1391 frmnr -= 1 |
1392 frmnr -= 1 |
1392 |
1393 |
1393 if f is None: |
1394 if f is None: |
1394 if scope: |
1395 if scope: |
1395 dict = self.debugMod.__dict__ |
1396 varDict = self.debugMod.__dict__ |
1396 else: |
1397 else: |
1397 scope = -1 |
1398 scope = -1 |
1398 elif scope: |
1399 elif scope: |
1399 dict = f.f_globals |
1400 varDict = f.f_globals |
1400 elif f.f_globals is f.f_locals: |
1401 elif f.f_globals is f.f_locals: |
1401 scope = -1 |
1402 scope = -1 |
1402 else: |
1403 else: |
1403 dict = f.f_locals |
1404 varDict = f.f_locals |
1404 |
1405 |
1405 varlist = [] |
1406 varlist = [] |
1406 |
1407 |
1407 if scope != -1: |
1408 if scope != -1: |
1408 variable = dict |
1409 variable = varDict |
1409 for attribute in var: |
1410 for attribute in var: |
1410 attribute = self.__extractIndicators(attribute)[0] |
1411 attribute = self.__extractIndicators(attribute)[0] |
1411 typeObject, typeName, typeStr, resolver = \ |
1412 typeObject, typeName, typeStr, resolver = \ |
1412 DebugVariables.getType(variable) |
1413 DebugVariables.getType(variable) |
1413 if resolver: |
1414 if resolver: |
1423 DebugVariables.getType(variable) |
1424 DebugVariables.getType(variable) |
1424 if typeStr.startswith(("PyQt5.", "PyQt4.")): |
1425 if typeStr.startswith(("PyQt5.", "PyQt4.")): |
1425 vlist = self.__formatQtVariable(variable, typeName) |
1426 vlist = self.__formatQtVariable(variable, typeName) |
1426 varlist.extend(vlist) |
1427 varlist.extend(vlist) |
1427 elif resolver: |
1428 elif resolver: |
1428 dict = resolver.getDictionary(variable) |
1429 varDict = resolver.getDictionary(variable) |
1429 vlist = self.__formatVariablesList( |
1430 vlist = self.__formatVariablesList( |
1430 list(dict.keys()), dict, scope, filter) |
1431 list(dict.keys()), varDict, scope, filterList) |
1431 varlist.extend(vlist) |
1432 varlist.extend(vlist) |
1432 |
1433 |
1433 self.sendJsonCommand("ResponseVariable", { |
1434 self.sendJsonCommand("ResponseVariable", { |
1434 "scope": scope, |
1435 "scope": scope, |
1435 "variable": var, |
1436 "variable": var, |
1595 varlist.append( |
1596 varlist.append( |
1596 ("address", "QHostAddress", "{0}".format(value.toString()))) |
1597 ("address", "QHostAddress", "{0}".format(value.toString()))) |
1597 |
1598 |
1598 return varlist |
1599 return varlist |
1599 |
1600 |
1600 def __formatVariablesList(self, keylist, dict_, scope, filter=[], |
1601 def __formatVariablesList(self, keylist, dict_, scope, filterList=[], |
1601 formatSequences=False): |
1602 formatSequences=False): |
1602 """ |
1603 """ |
1603 Private method to produce a formated variables list. |
1604 Private method to produce a formated variables list. |
1604 |
1605 |
1605 The dictionary passed in to it is scanned. Variables are |
1606 The dictionary passed in to it is scanned. Variables are |
1612 @param dict_ the dictionary to be scanned |
1613 @param dict_ the dictionary to be scanned |
1613 @param scope 1 to filter using the globals filter, 0 using the locals |
1614 @param scope 1 to filter using the globals filter, 0 using the locals |
1614 filter (int). |
1615 filter (int). |
1615 Variables are only added to the list, if their name do not match |
1616 Variables are only added to the list, if their name do not match |
1616 any of the filter expressions. |
1617 any of the filter expressions. |
1617 @param filter the indices of variable types to be filtered. Variables |
1618 @param filterList the indices of variable types to be filtered. |
1618 are only added to the list, if their type is not contained in the |
1619 Variables are only added to the list, if their type is not |
1619 filter list. |
1620 contained in the filter list. |
1620 @param formatSequences flag indicating, that sequence or dictionary |
1621 @param formatSequences flag indicating, that sequence or dictionary |
1621 variables should be formatted. If it is 0 (or false), just the |
1622 variables should be formatted. If it is 0 (or false), just the |
1622 number of items contained in these variables is returned. (boolean) |
1623 number of items contained in these variables is returned. (boolean) |
1623 @return A tuple consisting of a list of formatted variables. Each |
1624 @return A tuple consisting of a list of formatted variables. Each |
1624 variable entry is a tuple of three elements, the variable name, |
1625 variable entry is a tuple of three elements, the variable name, |
1639 break |
1640 break |
1640 if matched: |
1641 if matched: |
1641 continue |
1642 continue |
1642 |
1643 |
1643 # filter hidden attributes (filter #0) |
1644 # filter hidden attributes (filter #0) |
1644 if 0 in filter and str(key)[:2] == '__' and not ( |
1645 if 0 in filterList and str(key)[:2] == '__' and not ( |
1645 key == "___len___" and |
1646 key == "___len___" and |
1646 DebugVariables.TooLargeAttribute in keylist): |
1647 DebugVariables.TooLargeAttribute in keylist): |
1647 continue |
1648 continue |
1648 |
1649 |
1649 # special handling for '__builtins__' (it's way too big) |
1650 # special handling for '__builtins__' (it's way too big) |
1656 _, valtype = valtypestr.split(' ', 1) |
1657 _, valtype = valtypestr.split(' ', 1) |
1657 valtype = valtype[1:-1] |
1658 valtype = valtype[1:-1] |
1658 valtypename = type(value).__name__ |
1659 valtypename = type(value).__name__ |
1659 if valtype not in ConfigVarTypeStrings: |
1660 if valtype not in ConfigVarTypeStrings: |
1660 if valtype in ["numpy.ndarray", "array.array"]: |
1661 if valtype in ["numpy.ndarray", "array.array"]: |
1661 if ConfigVarTypeStrings.index('list') in filter: |
1662 if ConfigVarTypeStrings.index('list') in filterList: |
1662 continue |
1663 continue |
1663 elif valtypename == "MultiValueDict": |
1664 elif valtypename == "MultiValueDict": |
1664 if ConfigVarTypeStrings.index('dict') in filter: |
1665 if ConfigVarTypeStrings.index('dict') in filterList: |
1665 continue |
1666 continue |
1666 elif valtype == "sip.methoddescriptor": |
1667 elif valtype == "sip.methoddescriptor": |
1667 if ConfigVarTypeStrings.index( |
1668 if ConfigVarTypeStrings.index( |
1668 'method') in filter: |
1669 'method') in filterList: |
1669 continue |
1670 continue |
1670 elif valtype == "sip.enumtype": |
1671 elif valtype == "sip.enumtype": |
1671 if ConfigVarTypeStrings.index('class') in filter: |
1672 if ConfigVarTypeStrings.index('class') in filterList: |
1672 continue |
1673 continue |
1673 elif ConfigVarTypeStrings.index('instance') in filter: |
1674 elif ConfigVarTypeStrings.index('instance') in filterList: |
1674 continue |
1675 continue |
1675 |
1676 |
1676 if (not valtypestr.startswith('type ') and |
1677 if (not valtypestr.startswith('type ') and |
1677 valtypename not in |
1678 valtypename not in |
1678 ["ndarray", "MultiValueDict", "array"]): |
1679 ["ndarray", "MultiValueDict", "array"]): |
1681 try: |
1682 try: |
1682 # Strip 'instance' to be equal with Python 3 |
1683 # Strip 'instance' to be equal with Python 3 |
1683 if valtype == "instancemethod": |
1684 if valtype == "instancemethod": |
1684 valtype = "method" |
1685 valtype = "method" |
1685 |
1686 |
1686 if ConfigVarTypeStrings.index(valtype) in filter: |
1687 if ConfigVarTypeStrings.index(valtype) in filterList: |
1687 continue |
1688 continue |
1688 except ValueError: |
1689 except ValueError: |
1689 if valtype == "classobj": |
1690 if valtype == "classobj": |
1690 if ConfigVarTypeStrings.index( |
1691 if ConfigVarTypeStrings.index( |
1691 'instance') in filter: |
1692 'instance') in filterList: |
1692 continue |
1693 continue |
1693 elif valtype == "sip.methoddescriptor": |
1694 elif valtype == "sip.methoddescriptor": |
1694 if ConfigVarTypeStrings.index( |
1695 if ConfigVarTypeStrings.index( |
1695 'method') in filter: |
1696 'method') in filterList: |
1696 continue |
1697 continue |
1697 elif valtype == "sip.enumtype": |
1698 elif valtype == "sip.enumtype": |
1698 if ConfigVarTypeStrings.index('class') in filter: |
1699 if ConfigVarTypeStrings.index('class') in \ |
|
1700 filterList: |
1699 continue |
1701 continue |
1700 elif not valtype.startswith("PySide") and \ |
1702 elif not valtype.startswith("PySide") and \ |
1701 ConfigVarTypeStrings.index('other') in filter: |
1703 (ConfigVarTypeStrings.index('other') in |
|
1704 filterList): |
1702 continue |
1705 continue |
1703 |
1706 |
1704 try: |
1707 try: |
1705 if valtype in ['list', 'tuple', 'dict', 'set', |
1708 if valtype in ['list', 'tuple', 'dict', 'set', |
1706 'frozenset', 'array.array']: |
1709 'frozenset', 'array.array']: |