mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 09:03:31 +07:00
fixed sorting of children in variable view (PY-2471)
This commit is contained in:
@@ -77,6 +77,7 @@ import pydevd_tracing
|
||||
import pydevd_vm_type
|
||||
import pydevd_file_utils
|
||||
import traceback
|
||||
from pydevd_utils import *
|
||||
|
||||
from pydevd_tracing import GetExceptionTracebackStr
|
||||
|
||||
@@ -615,9 +616,13 @@ class InternalGetVariable(InternalThreadCommand):
|
||||
valDict = pydevd_vars.resolveCompoundVariable(self.thread_id, self.frame_id, self.scope, self.attributes)
|
||||
keys = valDict.keys()
|
||||
if hasattr(keys, 'sort'):
|
||||
keys.sort() #Python 3.0 does not have it
|
||||
keys.sort(compare_object_attrs) #Python 3.0 does not have it
|
||||
else:
|
||||
keys = sorted(keys, key=str) #Jython 2.1 does not have it (and all must be compared as strings).
|
||||
if (IS_PY3K):
|
||||
keys = sorted(keys, key=cmp_to_key(compare_object_attrs)) #Jython 2.1 does not have it (and all must be compared as strings).
|
||||
else:
|
||||
keys = sorted(keys, cmp=compare_object_attrs) #Jython 2.1 does not have it (and all must be compared as strings).
|
||||
|
||||
for k in keys:
|
||||
xml += pydevd_vars.varToXML(valDict[k], str(k))
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
from numbers import *
|
||||
|
||||
def to_number(x):
|
||||
if isinstance(x, Number):
|
||||
return x
|
||||
if (isinstance(x, basestring)):
|
||||
try:
|
||||
n = float(x)
|
||||
return n
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
l = x.find('(')
|
||||
if (l != -1):
|
||||
y = x[0:l-1]
|
||||
#print y
|
||||
try:
|
||||
n = float(y)
|
||||
return n
|
||||
except ValueError:
|
||||
pass
|
||||
return None
|
||||
|
||||
def compare_object_attrs(x, y):
|
||||
try:
|
||||
x_num = to_number(x)
|
||||
y_num = to_number(y)
|
||||
if (x_num is not None and y_num is not None):
|
||||
return int(x_num - y_num)
|
||||
if ('__len__' == x):
|
||||
return -1
|
||||
if ('__len__' == y):
|
||||
return 1
|
||||
|
||||
return x.__cmp__(y)
|
||||
except:
|
||||
return cmp(str(x), str(y))
|
||||
|
||||
|
||||
def cmp_to_key(mycmp):
|
||||
'Convert a cmp= function into a key= function'
|
||||
class K(object):
|
||||
def __init__(self, obj, *args):
|
||||
self.obj = obj
|
||||
def __lt__(self, other):
|
||||
return mycmp(self.obj, other.obj) < 0
|
||||
def __gt__(self, other):
|
||||
return mycmp(self.obj, other.obj) > 0
|
||||
def __eq__(self, other):
|
||||
return mycmp(self.obj, other.obj) == 0
|
||||
def __le__(self, other):
|
||||
return mycmp(self.obj, other.obj) <= 0
|
||||
def __ge__(self, other):
|
||||
return mycmp(self.obj, other.obj) >= 0
|
||||
def __ne__(self, other):
|
||||
return mycmp(self.obj, other.obj) != 0
|
||||
return K
|
||||
|
||||
Reference in New Issue
Block a user