summaryrefslogtreecommitdiff
path: root/python/helpers/pydev/pydevd_resolver.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/helpers/pydev/pydevd_resolver.py')
-rw-r--r--python/helpers/pydev/pydevd_resolver.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/python/helpers/pydev/pydevd_resolver.py b/python/helpers/pydev/pydevd_resolver.py
index 614549f74f37..3fe895c504a7 100644
--- a/python/helpers/pydev/pydevd_resolver.py
+++ b/python/helpers/pydev/pydevd_resolver.py
@@ -13,6 +13,7 @@ except:
setattr(__builtin__, 'False', 0)
import pydevd_constants
+from pydevd_constants import DictIterItems, xrange, izip
MAX_ITEMS_TO_HANDLE = 500
@@ -58,7 +59,7 @@ except:
class AbstractResolver:
'''
This class exists only for documentation purposes to explain how to create a resolver.
-
+
Some examples on how to resolve things:
- list: getDictionary could return a dict with index->item and use the index to resolve it later
- set: getDictionary could return a dict with id(object)->object and reiterate in that array to resolve it later
@@ -69,7 +70,7 @@ class AbstractResolver:
'''
In this method, we'll resolve some child item given the string representation of the item in the key
representing the previously asked dictionary.
-
+
@param var: this is the actual variable to be resolved.
@param attribute: this is the string representation of a key previously returned in getDictionary.
'''
@@ -78,7 +79,7 @@ class AbstractResolver:
def getDictionary(self, var):
'''
@param var: this is the variable that should have its children gotten.
-
+
@return: a dictionary where each pair key, value should be shown to the user as children items
in the variables view for the given var.
'''
@@ -128,12 +129,12 @@ class DefaultResolver:
declaredMethods = obj.getDeclaredMethods()
declaredFields = obj.getDeclaredFields()
- for i in range(len(declaredMethods)):
+ for i in xrange(len(declaredMethods)):
name = declaredMethods[i].getName()
ret[name] = declaredMethods[i].toString()
found.put(name, 1)
- for i in range(len(declaredFields)):
+ for i in xrange(len(declaredFields)):
name = declaredFields[i].getName()
found.put(name, 1)
#if declaredFields[i].isAccessible():
@@ -145,7 +146,7 @@ class DefaultResolver:
ret[name] = declaredFields[i].toString()
#this simple dir does not always get all the info, that's why we have the part before
- #(e.g.: if we do a dir on String, some methods that are from other interfaces such as
+ #(e.g.: if we do a dir on String, some methods that are from other interfaces such as
#charAt don't appear)
try:
d = dir(original)
@@ -169,8 +170,8 @@ class DefaultResolver:
names = var.__members__
d = {}
- #Be aware that the order in which the filters are applied attempts to
- #optimize the operation by removing as many items as possible in the
+ #Be aware that the order in which the filters are applied attempts to
+ #optimize the operation by removing as many items as possible in the
#first filters, leaving fewer items for later filters
if filterBuiltIn or filterFunction:
@@ -212,18 +213,18 @@ class DefaultResolver:
class DictResolver:
def resolve(self, dict, key):
- if key == '__len__':
+ if key in ('__len__', TOO_LARGE_ATTR):
return None
if '(' not in key:
#we have to treat that because the dict resolver is also used to directly resolve the global and local
- #scopes (which already have the items directly)
+ #scopes (which already have the items directly)
return dict[key]
#ok, we have to iterate over the items to find the one that matches the id, because that's the only way
#to actually find the reference from the string we have before.
expected_id = int(key.split('(')[-1][:-1])
- for key, val in dict.items():
+ for key, val in DictIterItems(dict):
if id(key) == expected_id:
return val
@@ -241,10 +242,15 @@ class DictResolver:
def getDictionary(self, dict):
ret = {}
- for key, val in dict.items():
+ i = 0
+ for key, val in DictIterItems(dict):
+ i += 1
#we need to add the id because otherwise we cannot find the real object to get its contents later on.
key = '%s (%s)' % (self.keyStr(key), id(key))
ret[key] = val
+ if i > MAX_ITEMS_TO_HANDLE:
+ ret[TOO_LARGE_ATTR] = TOO_LARGE_MSG
+ break
ret['__len__'] = len(dict)
return ret
@@ -261,7 +267,7 @@ class TupleResolver: #to enumerate tuples and lists
@param var: that's the original attribute
@param attribute: that's the key passed in the dict (as a string)
'''
- if attribute == '__len__' or attribute == TOO_LARGE_ATTR:
+ if attribute in ('__len__', TOO_LARGE_ATTR):
return None
return var[int(attribute)]
@@ -270,12 +276,12 @@ class TupleResolver: #to enumerate tuples and lists
# modified 'cause jython does not have enumerate support
l = len(var)
d = {}
-
+
if l < MAX_ITEMS_TO_HANDLE:
format = '%0' + str(int(len(str(l)))) + 'd'
-
-
- for i, item in zip(range(l), var):
+
+
+ for i, item in izip(xrange(l), var):
d[ format % i ] = item
else:
d[TOO_LARGE_ATTR] = TOO_LARGE_MSG
@@ -293,7 +299,7 @@ class SetResolver:
'''
def resolve(self, var, attribute):
- if attribute == '__len__':
+ if attribute in ('__len__', TOO_LARGE_ATTR):
return None
attribute = int(attribute)
@@ -305,8 +311,16 @@ class SetResolver:
def getDictionary(self, var):
d = {}
+ i = 0
for item in var:
- d[ id(item) ] = item
+ i+= 1
+ d[id(item)] = item
+
+ if i > MAX_ITEMS_TO_HANDLE:
+ d[TOO_LARGE_ATTR] = TOO_LARGE_MSG
+ break
+
+
d['__len__'] = len(var)
return d
@@ -325,7 +339,7 @@ class InstanceResolver:
ret = {}
declaredFields = obj.__class__.getDeclaredFields()
- for i in range(len(declaredFields)):
+ for i in xrange(len(declaredFields)):
name = declaredFields[i].getName()
try:
declaredFields[i].setAccessible(True)
@@ -352,7 +366,7 @@ class JyArrayResolver:
def getDictionary(self, obj):
ret = {}
- for i in range(len(obj)):
+ for i in xrange(len(obj)):
ret[ i ] = obj[i]
ret['__len__'] = len(obj)