mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Array viewer for console variables (PY-14182).
This commit is contained in:
@@ -385,16 +385,21 @@ class BaseInterpreterInterface:
|
||||
|
||||
return xml
|
||||
|
||||
def getArray(self, attr):
|
||||
def getArray(self, attr, roffset, coffset, rows, cols, format):
|
||||
xml = "<xml>"
|
||||
valDict = pydevd_vars.resolveVar(self.getNamespace(), attributes)
|
||||
if valDict is None:
|
||||
valDict = {}
|
||||
array = pydevd_vars.evalInContext(attr, self.getNamespace(), self.getNamespace())
|
||||
|
||||
keys = valDict.keys()
|
||||
xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format)
|
||||
|
||||
for k in keys:
|
||||
xml += pydevd_vars.varToXML(valDict[k], to_string(k))
|
||||
xml += "</xml>"
|
||||
|
||||
return xml
|
||||
|
||||
def evaluate(self, expression):
|
||||
xml = "<xml>"
|
||||
result = pydevd_vars.evalInContext(expression, self.getNamespace(), self.getNamespace())
|
||||
|
||||
xml += pydevd_vars.varToXML(result, expression)
|
||||
|
||||
xml += "</xml>"
|
||||
|
||||
|
||||
@@ -293,6 +293,8 @@ def start_server(host, port, interpreter):
|
||||
server.register_function(handshake)
|
||||
server.register_function(interpreter.connectToDebugger)
|
||||
server.register_function(interpreter.hello)
|
||||
server.register_function(interpreter.getArray)
|
||||
server.register_function(interpreter.evaluate)
|
||||
|
||||
# Functions for GUI main loop integration
|
||||
server.register_function(interpreter.enableGui)
|
||||
|
||||
@@ -277,6 +277,43 @@ def customOperation(thread_id, frame_id, scope, attrs, style, code_or_file, oper
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
def evalInContext(expression, globals, locals):
|
||||
result = None
|
||||
try:
|
||||
result = eval(expression, globals, locals)
|
||||
except Exception:
|
||||
s = StringIO()
|
||||
traceback.print_exc(file=s)
|
||||
result = s.getvalue()
|
||||
|
||||
try:
|
||||
try:
|
||||
etype, value, tb = sys.exc_info()
|
||||
result = value
|
||||
finally:
|
||||
etype = value = tb = None
|
||||
except:
|
||||
pass
|
||||
|
||||
result = ExceptionOnEvaluate(result)
|
||||
|
||||
# Ok, we have the initial error message, but let's see if we're dealing with a name mangling error...
|
||||
try:
|
||||
if '__' in expression:
|
||||
# Try to handle '__' name mangling...
|
||||
split = expression.split('.')
|
||||
curr = locals.get(split[0])
|
||||
for entry in split[1:]:
|
||||
if entry.startswith('__') and not hasattr(curr, entry):
|
||||
entry = '_%s%s' % (curr.__class__.__name__, entry)
|
||||
curr = getattr(curr, entry)
|
||||
|
||||
result = curr
|
||||
except:
|
||||
pass
|
||||
return result
|
||||
|
||||
|
||||
def evaluateExpression(thread_id, frame_id, expression, doExec):
|
||||
'''returns the result of the evaluated expression
|
||||
@param doExec: determines if we should do an exec or an eval
|
||||
@@ -285,9 +322,6 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
|
||||
if frame is None:
|
||||
return
|
||||
|
||||
expression = str(expression.replace('@LINE@', '\n'))
|
||||
|
||||
|
||||
#Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329
|
||||
#(Names not resolved in generator expression in method)
|
||||
#See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html
|
||||
@@ -296,6 +330,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
|
||||
updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals
|
||||
|
||||
try:
|
||||
expression = str(expression.replace('@LINE@', '\n'))
|
||||
|
||||
if doExec:
|
||||
try:
|
||||
@@ -312,42 +347,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
|
||||
return
|
||||
|
||||
else:
|
||||
result = None
|
||||
try:
|
||||
result = eval(expression, updated_globals, frame.f_locals)
|
||||
except Exception:
|
||||
s = StringIO()
|
||||
traceback.print_exc(file=s)
|
||||
result = s.getvalue()
|
||||
|
||||
try:
|
||||
try:
|
||||
etype, value, tb = sys.exc_info()
|
||||
result = value
|
||||
finally:
|
||||
etype = value = tb = None
|
||||
except:
|
||||
pass
|
||||
|
||||
result = ExceptionOnEvaluate(result)
|
||||
|
||||
# Ok, we have the initial error message, but let's see if we're dealing with a name mangling error...
|
||||
try:
|
||||
if '__' in expression:
|
||||
# Try to handle '__' name mangling...
|
||||
split = expression.split('.')
|
||||
curr = frame.f_locals.get(split[0])
|
||||
for entry in split[1:]:
|
||||
if entry.startswith('__') and not hasattr(curr, entry):
|
||||
entry = '_%s%s' % (curr.__class__.__name__, entry)
|
||||
curr = getattr(curr, entry)
|
||||
|
||||
result = curr
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
return result
|
||||
return evalInContext(expression, updated_globals, frame.f_locals)
|
||||
finally:
|
||||
#Should not be kept alive if an exception happens and this frame is kept in the stack.
|
||||
del updated_globals
|
||||
|
||||
Reference in New Issue
Block a user