def makeGetVariableMessage(self, seq, payload): try: return NetCommand(CMD_GET_VARIABLE, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeThreadKilledMessage(self, id): try: return NetCommand(CMD_THREAD_KILL, 0, str(id)) except: return self.makeErrorMessage(0, GetExceptionTracebackStr())
def makeThreadRunMessage(self, id, reason): try: return NetCommand(CMD_THREAD_RUN, 0, str(id) + "\t" + str(reason)) except: return self.makeErrorMessage(0, GetExceptionTracebackStr())
def makeGetCompletionsMessage(self, seq, payload): try: return NetCommand(CMD_GET_COMPLETIONS, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeVersionMessage(self, seq): try: return NetCommand(CMD_VERSION, seq, VERSION_STRING) except: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeThreadSuspendMessage(self, thread_id, frame, stop_reason): try: return NetCommand(CMD_THREAD_SUSPEND, 0, self.makeThreadSuspendStr(thread_id, frame, stop_reason)) except: return self.makeErrorMessage(0, GetExceptionTracebackStr())
def makeCustomOperationMessage(self, seq, payload): try: return NetCommand(CMD_RUN_CUSTOM_OPERATION, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeSendBreakpointExceptionMessage(self, seq, payload): try: return NetCommand(CMD_GET_BREAKPOINT_EXCEPTION, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeSendCurrExceptionTraceProceededMessage(self, seq, thread_id): try: return NetCommand(CMD_SEND_CURR_EXCEPTION_TRACE_PROCEEDED, 0, str(thread_id)) except: return self.makeErrorMessage(0, GetExceptionTracebackStr())
def doIt(self, dbg): """ Converts request into python variable """ try: result = pydevd_vars.changeAttrExpression(self.thread_id, self.frame_id, self.attr, self.expression) xml = "<xml>" xml += pydevd_vars.varToXML(result, "") xml += "</xml>" cmd = dbg.cmdFactory.makeVariableChangedMessage(self.sequence, xml) dbg.writer.addCommand(cmd) except Exception: cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error changing variable attr:%s expression:%s traceback:%s" % (self.attr, self.expression, GetExceptionTracebackStr())) dbg.writer.addCommand(cmd)
def makeGetFileContents(self, seq, payload): try: return NetCommand(CMD_GET_FILE_CONTENTS, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def doIt(self, dbg): """ Converts request into python variable """ try: xml = "<xml>" valDict = pydevd_vars.resolveCompoundVariable(self.thread_id, self.frame_id, self.scope, self.attributes) if valDict is None: valDict = {} keys = valDict.keys() if hasattr(keys, 'sort'): keys.sort(compare_object_attrs) #Python 3.0 does not have it else: 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], to_string(k)) xml += "</xml>" cmd = dbg.cmdFactory.makeGetVariableMessage(self.sequence, xml) dbg.writer.addCommand(cmd) except Exception: cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error resolving variables " + GetExceptionTracebackStr()) dbg.writer.addCommand(cmd)
def makeThreadSuspendMessage(self, thread_id, frame, stop_reason, message): """ <xml> <thread id="id" stop_reason="reason"> <frame id="id" name="functionName " file="file" line="line"> <var variable stuffff.... </frame> </thread> """ try: cmdTextList = ["<xml>"] if message: message = pydevd_vars.makeValidXmlValue(str(message)) cmdTextList.append('<thread id="%s" stop_reason="%s" message="%s">' % (thread_id, stop_reason, message)) curFrame = frame try: while curFrame: #print cmdText myId = str(id(curFrame)) #print "id is ", myId if curFrame.f_code is None: break #Iron Python sometimes does not have it! myName = curFrame.f_code.co_name #method name (if in method) or ? if global if myName is None: break #Iron Python sometimes does not have it! #print "name is ", myName filename, base = pydevd_file_utils.GetFilenameAndBase(curFrame) myFile = pydevd_file_utils.NormFileToClient(filename) if file_system_encoding.lower() != "utf-8" and hasattr(myFile, "decode"): # myFile is a byte string encoded using the file system encoding # convert it to utf8 myFile = myFile.decode(file_system_encoding).encode("utf-8") #print "file is ", myFile #myFile = inspect.getsourcefile(curFrame) or inspect.getfile(frame) myLine = str(curFrame.f_lineno) #print "line is ", myLine #the variables are all gotten 'on-demand' #variables = pydevd_vars.frameVarsToXML(curFrame.f_locals) variables = '' cmdTextList.append('<frame id="%s" name="%s" ' % (myId , pydevd_vars.makeValidXmlValue(myName))) cmdTextList.append('file="%s" line="%s">"' % (quote(myFile, '/>_= \t'), myLine)) cmdTextList.append(variables) cmdTextList.append("</frame>") curFrame = curFrame.f_back except : traceback.print_exc() cmdTextList.append("</thread></xml>") cmdText = ''.join(cmdTextList) return NetCommand(CMD_THREAD_SUSPEND, 0, cmdText) except: return self.makeErrorMessage(0, GetExceptionTracebackStr())
def doIt(self, dbg): """ Converts request into python variable """ try: pydevd_vars.changeAttrExpression(self.thread_id, self.frame_id, self.attr, self.expression) except Exception: cmd = dbg.cmdFactory.makeErrorMessage(self.sequence, "Error changing variable attr:%s expression:%s traceback:%s" % (self.attr, self.expression, GetExceptionTracebackStr())) dbg.writer.addCommand(cmd)
def makeGetFrameMessage(self, seq, payload): try: return NetCommand(CMD_GET_FRAME, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeSendConsoleMessage(self, seq, payload): try: return NetCommand(CMD_EVALUATE_CONSOLE_EXPRESSION, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def makeEvaluateExpressionMessage(self, seq, payload): try: return NetCommand(CMD_EVALUATE_EXPRESSION, seq, payload) except Exception: return self.makeErrorMessage(seq, GetExceptionTracebackStr())
def doIt(self, dbg): """ Converts request into completions """ try: remove_path = None try: import _completer except: try: path = os.environ['PYDEV_COMPLETER_PYTHONPATH'] except: path = os.path.dirname(__file__) sys.path.append(path) remove_path = path try: import _completer except: pass try: frame = pydevd_vars.findFrame(self.thread_id, self.frame_id) if frame is not None: #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 updated_globals = {} updated_globals.update(frame.f_globals) updated_globals.update( frame.f_locals ) #locals later because it has precedence over the actual globals locals = frame.f_locals else: updated_globals = {} locals = {} if pydevconsole.IPYTHON: completions = pydevconsole.get_completions( self.act_tok, self.act_tok, updated_globals, locals) else: try: completer = _completer.Completer(updated_globals, None) #list(tuple(name, descr, parameters, type)) completions = completer.complete(self.act_tok) except: completions = [] def makeValid(s): return pydevd_vars.makeValidXmlValue( pydevd_vars.quote(s, '/>_= \t')) msg = "<xml>" for comp in completions: msg += '<comp p0="%s" p1="%s" p2="%s" p3="%s"/>' % ( makeValid(comp[0]), makeValid(comp[1]), makeValid(comp[2]), makeValid(comp[3]), ) msg += "</xml>" cmd = dbg.cmdFactory.makeGetCompletionsMessage( self.sequence, msg) dbg.writer.addCommand(cmd) finally: if remove_path is not None: sys.path.remove(remove_path) except: exc = GetExceptionTracebackStr() sys.stderr.write('%s\n' % (exc, )) cmd = dbg.cmdFactory.makeErrorMessage( self.sequence, "Error getting completion " + exc) dbg.writer.addCommand(cmd)