1428 dict = f.f_locals |
1429 dict = f.f_locals |
1429 |
1430 |
1430 varlist = [] |
1431 varlist = [] |
1431 |
1432 |
1432 if scope != -1: |
1433 if scope != -1: |
1433 # search the correct dictionary |
1434 variable = dict |
1434 i = 0 |
1435 for attribute in var: |
1435 rvar = var[:] |
1436 if attribute[-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ |
1436 dictkeys = None |
1437 attribute = attribute[:-2] |
1437 obj = None |
1438 typeObject, typeName, typeStr, resolver = \ |
1438 isDict = False |
1439 DebugVariables.getType(variable) |
1439 formatSequences = False |
1440 if resolver: |
1440 access = "" |
1441 variable = resolver.resolve(variable, attribute) |
1441 oaccess = "" |
|
1442 odict = dict |
|
1443 |
|
1444 qtVariable = False |
|
1445 qvar = None |
|
1446 qvtype = "" |
|
1447 |
|
1448 while i < len(var): |
|
1449 if len(dict): |
|
1450 udict = dict |
|
1451 ndict = {} |
|
1452 # this has to be in line with VariablesViewer.indicators |
|
1453 if var[i][-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ |
|
1454 if i + 1 == len(var): |
|
1455 if var[i][:-2] == '...': |
|
1456 dictkeys = [var[i - 1]] |
|
1457 else: |
|
1458 dictkeys = [var[i][:-2]] |
|
1459 formatSequences = True |
|
1460 if not access and not oaccess: |
|
1461 if var[i][:-2] == '...': |
|
1462 access = '["{0!s}"]'.format(var[i - 1]) |
|
1463 dict = odict |
|
1464 else: |
|
1465 access = '["{0!s}"]'.format(var[i][:-2]) |
|
1466 else: |
|
1467 if var[i][:-2] == '...': |
|
1468 if oaccess: |
|
1469 access = oaccess |
|
1470 else: |
|
1471 access = '{0!s}[{1!s}]'.format( |
|
1472 access, var[i - 1]) |
|
1473 dict = odict |
|
1474 else: |
|
1475 if oaccess: |
|
1476 access = '{0!s}[{1!s}]'.format( |
|
1477 oaccess, var[i][:-2]) |
|
1478 oaccess = '' |
|
1479 else: |
|
1480 access = '{0!s}[{1!s}]'.format( |
|
1481 access, var[i][:-2]) |
|
1482 if var[i][-2:] == "{}": # __IGNORE_WARNING__ |
|
1483 isDict = True |
|
1484 break |
|
1485 else: |
|
1486 if not access: |
|
1487 if var[i][:-2] == '...': |
|
1488 access = '["{0!s}"]'.format(var[i - 1]) |
|
1489 dict = odict |
|
1490 else: |
|
1491 access = '["{0!s}"]'.format(var[i][:-2]) |
|
1492 else: |
|
1493 if var[i][:-2] == '...': |
|
1494 access = '{0!s}[{1!s}]'.format( |
|
1495 access, var[i - 1]) |
|
1496 dict = odict |
|
1497 else: |
|
1498 if oaccess: |
|
1499 access = '{0!s}[{1!s}]'.format( |
|
1500 oaccess, var[i][:-2]) |
|
1501 oaccess = '' |
|
1502 else: |
|
1503 access = '{0!s}[{1!s}]'.format( |
|
1504 access, var[i][:-2]) |
|
1505 else: |
1442 else: |
1506 if access: |
1443 break |
1507 if oaccess: |
1444 typeObject, typeName, typeStr, resolver = \ |
1508 access = '{0!s}[{1!s}]'.format(oaccess, var[i]) |
1445 DebugVariables.getType(variable) |
1509 else: |
1446 if typeStr.startswith(("PyQt5.", "PyQt4.")): |
1510 access = '{0!s}[{1!s}]'.format(access, var[i]) |
1447 vlist = self.__formatQtVariable(variable, typeName) |
1511 if var[i - 1][:-2] == '...': |
1448 varlist.extend(vlist) |
1512 oaccess = access |
1449 elif resolver: |
1513 else: |
1450 dict = resolver.getDictionary(variable) |
1514 oaccess = '' |
1451 vlist = self.__formatVariablesList( |
1515 try: |
1452 list(dict.keys()), dict, scope, filter) |
1516 loc = {"dict": dict} |
1453 varlist.extend(vlist) |
1517 exec('mdict = dict{0!s}.__dict__\nobj = dict{0!s}' |
|
1518 .format(access), globals(), loc) |
|
1519 mdict = loc["mdict"] |
|
1520 obj = loc["obj"] |
|
1521 if "PyQt4." in str(type(obj)) or \ |
|
1522 "PyQt5." in str(type(obj)): |
|
1523 qtVariable = True |
|
1524 qvar = obj |
|
1525 qvtype = str(type(qvar))[1:-1].split()[1][1:-1] |
|
1526 ndict.update(mdict) |
|
1527 except Exception: |
|
1528 pass |
|
1529 try: |
|
1530 loc = {"dict": dict} |
|
1531 exec('mcdict = dict{0!s}.__class__.__dict__' |
|
1532 .format(access), globals(), loc) |
|
1533 ndict.update(loc["mcdict"]) |
|
1534 if mdict and "sipThis" not in mdict.keys(): |
|
1535 del rvar[0:2] |
|
1536 access = "" |
|
1537 except Exception: |
|
1538 pass |
|
1539 try: |
|
1540 loc = {"cdict": {}, "dict": dict} |
|
1541 exec('slv = dict{0!s}.__slots__'.format(access), |
|
1542 globals(), loc) |
|
1543 for v in loc["slv"]: |
|
1544 try: |
|
1545 loc["v"] = v |
|
1546 exec('cdict[v] = dict{0!s}.{1!s}'.format( |
|
1547 access, v), globals, loc) |
|
1548 except Exception: |
|
1549 pass |
|
1550 ndict.update(loc["cdict"]) |
|
1551 exec('obj = dict{0!s}'.format(access), |
|
1552 globals(), loc) |
|
1553 obj = loc["obj"] |
|
1554 access = "" |
|
1555 if "PyQt4." in str(type(obj)) or \ |
|
1556 "PyQt5." in str(type(obj)): |
|
1557 qtVariable = True |
|
1558 qvar = obj |
|
1559 qvtype = str(type(qvar))[1:-1].split()[1][1:-1] |
|
1560 except Exception: |
|
1561 pass |
|
1562 else: |
|
1563 try: |
|
1564 ndict.update(dict[var[i]].__dict__) |
|
1565 ndict.update(dict[var[i]].__class__.__dict__) |
|
1566 del rvar[0] |
|
1567 obj = dict[var[i]] |
|
1568 if "PyQt4." in str(type(obj)) or \ |
|
1569 "PyQt5." in str(type(obj)): |
|
1570 qtVariable = True |
|
1571 qvar = obj |
|
1572 qvtype = str(type(qvar))[1:-1].split()[1][1:-1] |
|
1573 except Exception: |
|
1574 pass |
|
1575 try: |
|
1576 slv = dict[var[i]].__slots__ |
|
1577 loc = {"cdict": {}, "dict": dict, |
|
1578 "var": var, "i": i} |
|
1579 for v in slv: |
|
1580 try: |
|
1581 loc["v"] = v |
|
1582 exec('cdict[v] = dict[var[i]].{0!s}' |
|
1583 .format(v), |
|
1584 globals(), loc) |
|
1585 except Exception: |
|
1586 pass |
|
1587 ndict.update(loc["cdict"]) |
|
1588 obj = dict[var[i]] |
|
1589 if "PyQt4." in str(type(obj)) or \ |
|
1590 "PyQt5." in str(type(obj)): |
|
1591 qtVariable = True |
|
1592 qvar = obj |
|
1593 qvtype = str(type(qvar))[1:-1].split()[1][1:-1] |
|
1594 except Exception: |
|
1595 pass |
|
1596 odict = dict |
|
1597 dict = ndict |
|
1598 i += 1 |
|
1599 |
|
1600 if qtVariable: |
|
1601 vlist = self.__formatQtVariable(qvar, qvtype) |
|
1602 elif ("sipThis" in dict.keys() and len(dict) == 1) or \ |
|
1603 (len(dict) == 0 and len(udict) > 0): |
|
1604 if access: |
|
1605 loc = {"udict": udict} |
|
1606 exec('qvar = udict{0!s}'.format(access), globals(), loc) |
|
1607 qvar = loc["qvar"] |
|
1608 # this has to be in line with VariablesViewer.indicators |
|
1609 elif rvar and rvar[0][-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ |
|
1610 loc = {"udict": udict} |
|
1611 exec('qvar = udict["{0!s}"][{1!s}]'.format(rvar[0][:-2], |
|
1612 rvar[1]), |
|
1613 globals(), loc) |
|
1614 qvar = loc["qvar"] |
|
1615 else: |
|
1616 qvar = udict[var[-1]] |
|
1617 qvtype = str(type(qvar))[1:-1].split()[1][1:-1] |
|
1618 if qvtype.startswith(("PyQt4", "PyQt5")): |
|
1619 vlist = self.__formatQtVariable(qvar, qvtype) |
|
1620 else: |
|
1621 vlist = [] |
|
1622 else: |
|
1623 qtVariable = False |
|
1624 if len(dict) == 0 and len(udict) > 0: |
|
1625 if access: |
|
1626 loc = {"udict": udict} |
|
1627 exec('qvar = udict{0!s}'.format(access), |
|
1628 globals(), loc) |
|
1629 qvar = loc["qvar"] |
|
1630 # this has to be in line with VariablesViewer.indicators |
|
1631 elif rvar and rvar[0][-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ |
|
1632 loc = {"udict": udict} |
|
1633 exec('qvar = udict["{0!s}"][{1!s}]'.format( |
|
1634 rvar[0][:-2], rvar[1]), globals(), loc) |
|
1635 qvar = loc["qvar"] |
|
1636 else: |
|
1637 qvar = udict[var[-1]] |
|
1638 qvtype = str(type(qvar))[1:-1].split()[1][1:-1] |
|
1639 if qvtype.startswith(("PyQt4", "PyQt5")): |
|
1640 qtVariable = True |
|
1641 |
|
1642 if qtVariable: |
|
1643 vlist = self.__formatQtVariable(qvar, qvtype) |
|
1644 else: |
|
1645 # format the dictionary found |
|
1646 if dictkeys is None: |
|
1647 dictkeys = dict.keys() |
|
1648 else: |
|
1649 # treatment for sequences and dictionaries |
|
1650 if access: |
|
1651 loc = {"dict": dict} |
|
1652 exec("dict = dict{0!s}".format(access), globals(), |
|
1653 loc) |
|
1654 dict = loc["dict"] |
|
1655 else: |
|
1656 dict = dict[dictkeys[0]] |
|
1657 if isDict: |
|
1658 dictkeys = dict.keys() |
|
1659 else: |
|
1660 dictkeys = range(len(dict)) |
|
1661 vlist = self.__formatVariablesList( |
|
1662 dictkeys, dict, scope, filter, formatSequences) |
|
1663 varlist.extend(vlist) |
|
1664 |
|
1665 if obj is not None and not formatSequences: |
|
1666 try: |
|
1667 if repr(obj).startswith('{'): |
|
1668 varlist.append( |
|
1669 ('...', 'dict', "{0:d}".format(len(obj.keys())))) |
|
1670 elif repr(obj).startswith('['): |
|
1671 varlist.append( |
|
1672 ('...', 'list', "{0:d}".format(len(obj)))) |
|
1673 elif repr(obj).startswith('('): |
|
1674 varlist.append( |
|
1675 ('...', 'tuple', "{0:d}".format(len(obj)))) |
|
1676 except Exception: |
|
1677 pass |
|
1678 |
1454 |
1679 self.sendJsonCommand("ResponseVariable", { |
1455 self.sendJsonCommand("ResponseVariable", { |
1680 "scope": scope, |
1456 "scope": scope, |
1681 "variable": var, |
1457 "variable": var, |
1682 "variables": varlist, |
1458 "variables": varlist, |
1683 }) |
1459 }) |
1684 |
1460 |
1685 def __formatQtVariable(self, value, vtype): |
1461 def __formatQtVariable(self, value, qttype): |
1686 """ |
1462 """ |
1687 Private method to produce a formatted output of a simple Qt4/Qt5 type. |
1463 Private method to produce a formatted output of a simple Qt4/Qt5 type. |
1688 |
1464 |
1689 @param value variable to be formatted |
1465 @param value variable to be formatted |
1690 @param vtype type of the variable to be formatted (string) |
1466 @param qttype type of the Qt variable to be formatted (string) |
1691 @return A tuple consisting of a list of formatted variables. Each |
1467 @return A tuple consisting of a list of formatted variables. Each |
1692 variable entry is a tuple of three elements, the variable name, |
1468 variable entry is a tuple of three elements, the variable name, |
1693 its type and value. |
1469 its type and value. |
1694 """ |
1470 """ |
1695 qttype = vtype.split('.')[-1] |
|
1696 varlist = [] |
1471 varlist = [] |
1697 if qttype == 'QChar': |
1472 if qttype == 'QChar': |
1698 varlist.append(("", "QChar", "{0}".format(chr(value.unicode())))) |
1473 varlist.append(("", "QChar", "{0}".format(chr(value.unicode())))) |
1699 varlist.append(("", "int", "{0:d}".format(value.unicode()))) |
1474 varlist.append(("", "int", "{0:d}".format(value.unicode()))) |
1700 elif qttype == 'QByteArray': |
1475 elif qttype == 'QByteArray': |