--- a/DebugClients/Python3/DebugClientBase.py Wed Sep 14 19:17:53 2016 +0200 +++ b/DebugClients/Python3/DebugClientBase.py Wed Sep 14 20:08:16 2016 +0200 @@ -26,6 +26,7 @@ from DebugConfig import ConfigVarTypeStrings from FlexCompleter import Completer from DebugUtilities import getargvalues, formatargvalues, prepareJsonCommand +import DebugVariables DebugClientInstance = None @@ -1430,251 +1431,26 @@ varlist = [] if scope != -1: - # search the correct dictionary - i = 0 - rvar = var[:] - dictkeys = None - obj = None - isDict = False - formatSequences = False - access = "" - oaccess = "" - odict = dict - - qtVariable = False - qvar = None - qvtype = "" - - while i < len(var): - if len(dict): - udict = dict - ndict = {} - # this has to be in line with VariablesViewer.indicators - if var[i][-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ - if i + 1 == len(var): - if var[i][:-2] == '...': - dictkeys = [var[i - 1]] - else: - dictkeys = [var[i][:-2]] - formatSequences = True - if not access and not oaccess: - if var[i][:-2] == '...': - access = '["{0!s}"]'.format(var[i - 1]) - dict = odict - else: - access = '["{0!s}"]'.format(var[i][:-2]) - else: - if var[i][:-2] == '...': - if oaccess: - access = oaccess - else: - access = '{0!s}[{1!s}]'.format( - access, var[i - 1]) - dict = odict - else: - if oaccess: - access = '{0!s}[{1!s}]'.format( - oaccess, var[i][:-2]) - oaccess = '' - else: - access = '{0!s}[{1!s}]'.format( - access, var[i][:-2]) - if var[i][-2:] == "{}": # __IGNORE_WARNING__ - isDict = True - break - else: - if not access: - if var[i][:-2] == '...': - access = '["{0!s}"]'.format(var[i - 1]) - dict = odict - else: - access = '["{0!s}"]'.format(var[i][:-2]) - else: - if var[i][:-2] == '...': - access = '{0!s}[{1!s}]'.format( - access, var[i - 1]) - dict = odict - else: - if oaccess: - access = '{0!s}[{1!s}]'.format( - oaccess, var[i][:-2]) - oaccess = '' - else: - access = '{0!s}[{1!s}]'.format( - access, var[i][:-2]) + variable = dict + for attribute in var: + if attribute[-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ + attribute = attribute[:-2] + typeObject, typeName, typeStr, resolver = \ + DebugVariables.getType(variable) + if resolver: + variable = resolver.resolve(variable, attribute) else: - if access: - if oaccess: - access = '{0!s}[{1!s}]'.format(oaccess, var[i]) - else: - access = '{0!s}[{1!s}]'.format(access, var[i]) - if var[i - 1][:-2] == '...': - oaccess = access - else: - oaccess = '' - try: - loc = {"dict": dict} - exec('mdict = dict{0!s}.__dict__\nobj = dict{0!s}' - .format(access), globals(), loc) - mdict = loc["mdict"] - obj = loc["obj"] - if "PyQt4." in str(type(obj)) or \ - "PyQt5." in str(type(obj)): - qtVariable = True - qvar = obj - qvtype = str(type(qvar))[1:-1].split()[1][1:-1] - ndict.update(mdict) - except Exception: - pass - try: - loc = {"dict": dict} - exec('mcdict = dict{0!s}.__class__.__dict__' - .format(access), globals(), loc) - ndict.update(loc["mcdict"]) - if mdict and "sipThis" not in mdict.keys(): - del rvar[0:2] - access = "" - except Exception: - pass - try: - loc = {"cdict": {}, "dict": dict} - exec('slv = dict{0!s}.__slots__'.format(access), - globals(), loc) - for v in loc["slv"]: - try: - loc["v"] = v - exec('cdict[v] = dict{0!s}.{1!s}'.format( - access, v), globals, loc) - except Exception: - pass - ndict.update(loc["cdict"]) - exec('obj = dict{0!s}'.format(access), - globals(), loc) - obj = loc["obj"] - access = "" - if "PyQt4." in str(type(obj)) or \ - "PyQt5." in str(type(obj)): - qtVariable = True - qvar = obj - qvtype = str(type(qvar))[1:-1].split()[1][1:-1] - except Exception: - pass - else: - try: - ndict.update(dict[var[i]].__dict__) - ndict.update(dict[var[i]].__class__.__dict__) - del rvar[0] - obj = dict[var[i]] - if "PyQt4." in str(type(obj)) or \ - "PyQt5." in str(type(obj)): - qtVariable = True - qvar = obj - qvtype = str(type(qvar))[1:-1].split()[1][1:-1] - except Exception: - pass - try: - slv = dict[var[i]].__slots__ - loc = {"cdict": {}, "dict": dict, - "var": var, "i": i} - for v in slv: - try: - loc["v"] = v - exec('cdict[v] = dict[var[i]].{0!s}' - .format(v), - globals(), loc) - except Exception: - pass - ndict.update(loc["cdict"]) - obj = dict[var[i]] - if "PyQt4." in str(type(obj)) or \ - "PyQt5." in str(type(obj)): - qtVariable = True - qvar = obj - qvtype = str(type(qvar))[1:-1].split()[1][1:-1] - except Exception: - pass - odict = dict - dict = ndict - i += 1 - - if qtVariable: - vlist = self.__formatQtVariable(qvar, qvtype) - elif ("sipThis" in dict.keys() and len(dict) == 1) or \ - (len(dict) == 0 and len(udict) > 0): - if access: - loc = {"udict": udict} - exec('qvar = udict{0!s}'.format(access), globals(), loc) - qvar = loc["qvar"] - # this has to be in line with VariablesViewer.indicators - elif rvar and rvar[0][-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ - loc = {"udict": udict} - exec('qvar = udict["{0!s}"][{1!s}]'.format(rvar[0][:-2], - rvar[1]), - globals(), loc) - qvar = loc["qvar"] - else: - qvar = udict[var[-1]] - qvtype = str(type(qvar))[1:-1].split()[1][1:-1] - if qvtype.startswith(("PyQt4", "PyQt5")): - vlist = self.__formatQtVariable(qvar, qvtype) - else: - vlist = [] - else: - qtVariable = False - if len(dict) == 0 and len(udict) > 0: - if access: - loc = {"udict": udict} - exec('qvar = udict{0!s}'.format(access), - globals(), loc) - qvar = loc["qvar"] - # this has to be in line with VariablesViewer.indicators - elif rvar and rvar[0][-2:] in ["[]", "()", "{}"]: # __IGNORE_WARNING__ - loc = {"udict": udict} - exec('qvar = udict["{0!s}"][{1!s}]'.format( - rvar[0][:-2], rvar[1]), globals(), loc) - qvar = loc["qvar"] - else: - qvar = udict[var[-1]] - qvtype = str(type(qvar))[1:-1].split()[1][1:-1] - if qvtype.startswith(("PyQt4", "PyQt5")): - qtVariable = True - - if qtVariable: - vlist = self.__formatQtVariable(qvar, qvtype) - else: - # format the dictionary found - if dictkeys is None: - dictkeys = dict.keys() - else: - # treatment for sequences and dictionaries - if access: - loc = {"dict": dict} - exec("dict = dict{0!s}".format(access), globals(), - loc) - dict = loc["dict"] - else: - dict = dict[dictkeys[0]] - if isDict: - dictkeys = dict.keys() - else: - dictkeys = range(len(dict)) - vlist = self.__formatVariablesList( - dictkeys, dict, scope, filter, formatSequences) - varlist.extend(vlist) - - if obj is not None and not formatSequences: - try: - if repr(obj).startswith('{'): - varlist.append( - ('...', 'dict', "{0:d}".format(len(obj.keys())))) - elif repr(obj).startswith('['): - varlist.append( - ('...', 'list', "{0:d}".format(len(obj)))) - elif repr(obj).startswith('('): - varlist.append( - ('...', 'tuple', "{0:d}".format(len(obj)))) - except Exception: - pass + break + typeObject, typeName, typeStr, resolver = \ + DebugVariables.getType(variable) + if typeStr.startswith(("PyQt5.", "PyQt4.")): + vlist = self.__formatQtVariable(variable, typeName) + varlist.extend(vlist) + elif resolver: + dict = resolver.getDictionary(variable) + vlist = self.__formatVariablesList( + list(dict.keys()), dict, scope, filter) + varlist.extend(vlist) self.sendJsonCommand("ResponseVariable", { "scope": scope, @@ -1682,17 +1458,16 @@ "variables": varlist, }) - def __formatQtVariable(self, value, vtype): + def __formatQtVariable(self, value, qttype): """ Private method to produce a formatted output of a simple Qt4/Qt5 type. @param value variable to be formatted - @param vtype type of the variable to be formatted (string) + @param qttype type of the Qt variable to be formatted (string) @return A tuple consisting of a list of formatted variables. Each variable entry is a tuple of three elements, the variable name, its type and value. """ - qttype = vtype.split('.')[-1] varlist = [] if qttype == 'QChar': varlist.append(("", "QChar", "{0}".format(chr(value.unicode())))) @@ -1882,7 +1657,7 @@ continue elif valtype == "sip.methoddescriptor": if ConfigVarTypeStrings.index( - 'instance method') in filter: + 'method') in filter: continue elif valtype == "sip.enumtype": if ConfigVarTypeStrings.index('class') in filter: @@ -1899,7 +1674,7 @@ continue elif valtype == "sip.methoddescriptor": if ConfigVarTypeStrings.index( - 'instance method') in filter: + 'method') in filter: continue elif valtype == "sip.enumtype": if ConfigVarTypeStrings.index('class') in filter: