def exec_table_command(init_command, command_type, f_globals, f_locals): # noinspection PyUnresolvedReferences res = "" if command_type == TableCommandType.DF_INFO: if 'pd' not in sys.modules: exec('import pandas as pd', f_globals, f_locals) tmp_var = pydevd_vars.eval_in_context(init_command, f_globals, f_locals) is_exception_on_eval = is_error_on_eval(tmp_var) if is_exception_on_eval: return False, tmp_var.result res += str(type(tmp_var)) res += NEXT_VALUE_SEPARATOR res += str(tmp_var.shape[0]) res += NEXT_VALUE_SEPARATOR res += repr(tmp_var.head().to_html(notebook=True, max_cols=MAX_COLS)) elif command_type == TableCommandType.SLICE: import pandas as pd _jb_max_cols = pd.get_option('display.max_columns') _jb_max_colwidth = pd.get_option('display.max_colwidth') pd.set_option('display.max_colwidth', MAX_COLWIDTH) tmp_var = pydevd_vars.eval_in_context(init_command, f_globals, f_locals) is_exception_on_eval = is_error_on_eval(tmp_var) if is_exception_on_eval: return False, tmp_var.result res += repr(tmp_var.to_html(notebook=True, max_cols=MAX_COLS)) pd.set_option('display.max_colwidth', _jb_max_colwidth) return True, res
def loadFullValue(self, seq, scope_attrs): """ Evaluate full value for async Console variables in a separate thread and send results to IDE side :param seq: id of command :param scope_attrs: a sequence of variables with their attributes separated by NEXT_VALUE_SEPARATOR (i.e.: obj\tattr1\tattr2NEXT_VALUE_SEPARATORobj2\attr1\tattr2) :return: """ frame_variables = self.get_namespace() var_objects = [] vars = scope_attrs.split(NEXT_VALUE_SEPARATOR) for var_attrs in vars: if '\t' in var_attrs: name, attrs = var_attrs.split('\t', 1) else: name = var_attrs attrs = None if name in frame_variables: var_object = pydevd_vars.resolve_var_object(frame_variables[name], attrs) var_objects.append((var_object, name)) else: var_object = pydevd_vars.eval_in_context(name, frame_variables, frame_variables) var_objects.append((var_object, name)) from _pydevd_bundle.pydevd_comm import GetValueAsyncThreadConsole t = GetValueAsyncThreadConsole(self.get_server(), seq, var_objects) t.start()
def evaluate(self, expression): xml = StringIO.StringIO() xml.write("<xml>") result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) xml.write(pydevd_vars.var_to_xml(result, expression)) xml.write("</xml>") return xml.getvalue()
def loadFullValue(self, seq, scope_attrs): """ Evaluate full value for async Console variables in a separate thread and send results to IDE side :param seq: id of command :param scope_attrs: a sequence of variables with their attributes separated by NEXT_VALUE_SEPARATOR (i.e.: obj\tattr1\tattr2NEXT_VALUE_SEPARATORobj2\attr1\tattr2) :return: """ try: frame_variables = self.get_namespace() var_objects = [] # vars = scope_attrs.split(NEXT_VALUE_SEPARATOR) vars = scope_attrs for var_attrs in vars: if '\t' in var_attrs: name, attrs = var_attrs.split('\t', 1) else: name = var_attrs attrs = None if name in frame_variables.keys(): var_object = pydevd_vars.resolve_var_object(frame_variables[name], attrs) var_objects.append((var_object, name)) else: var_object = pydevd_vars.eval_in_context(name, frame_variables, frame_variables) var_objects.append((var_object, name)) from _pydev_bundle.pydev_console_commands import ThriftGetValueAsyncThreadConsole t = ThriftGetValueAsyncThreadConsole(self.get_server(), seq, var_objects) t.start() except: traceback.print_exc() raise PythonUnhandledException(traceback.format_exc())
def loadFullValue(self, seq, scope_attrs): """ Evaluate full value for async Console variables in a separate thread and send results to IDE side :param seq: id of command :param scope_attrs: a sequence of variables with their attributes separated by NEXT_VALUE_SEPARATOR (i.e.: obj\tattr1\tattr2NEXT_VALUE_SEPARATORobj2\attr1\tattr2) :return: """ frame_variables = self.get_namespace() var_objects = [] vars = scope_attrs.split(NEXT_VALUE_SEPARATOR) for var_attrs in vars: if '\t' in var_attrs: name, attrs = var_attrs.split('\t', 1) else: name = var_attrs attrs = None if name in frame_variables: var_object = pydevd_vars.resolve_var_object( frame_variables[name], attrs) var_objects.append((var_object, name)) else: var_object = pydevd_vars.eval_in_context( name, frame_variables, frame_variables) var_objects.append((var_object, name)) from _pydevd_bundle.pydevd_comm import GetValueAsyncThreadConsole t = GetValueAsyncThreadConsole(self.get_server(), seq, var_objects) t.start()
def getArray(self, attr, roffset, coffset, rows, cols, format): name = attr.split("\t")[-1] array = pydevd_vars.eval_in_context(name, self.get_namespace(), self.get_namespace()) return pydevd_vars.table_like_struct_to_xml(array, name, roffset, coffset, rows, cols, format)
def __resolve_reference__(self, text): """ :type text: str """ obj = None if '.' not in text: try: obj = self.get_namespace()[text] except KeyError: pass if obj is None: try: obj = self.get_namespace()['__builtins__'][text] except: pass if obj is None: try: obj = getattr(self.get_namespace()['__builtins__'], text, None) except: pass else: try: last_dot = text.rindex('.') parent_context = text[0:last_dot] res = pydevd_vars.eval_in_context(parent_context, self.get_namespace(), self.get_namespace()) obj = getattr(res, text[last_dot + 1:]) except: pass return obj
def execDataViewerAction(self, varName, action, args): try: tmp_var = pydevd_vars.eval_in_context(varName, self.get_namespace(), self.get_namespace()) return InternalDataViewerAction.act(tmp_var, action, args.split("\t")) except Exception as e: raise PythonUnhandledException(type(e).__name__ + "\n" + traceback.format_exc())
def evaluate(self, expression, do_trunc): # returns `DebugValue` of evaluated expression try: result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) return [pydevd_thrift.var_to_struct(result, expression, do_trim=do_trunc)] except: traceback.print_exc() raise PythonUnhandledException(traceback.format_exc())
def getArray(self, attr, roffset, coffset, rows, cols, format): try: name = attr.split("\t")[-1] array = pydevd_vars.eval_in_context(name, self.get_namespace(), self.get_namespace()) return pydevd_thrift.table_like_struct_to_thrift_struct(array, name, roffset, coffset, rows, cols, format) except: traceback.print_exc() raise PythonUnhandledException(traceback.format_exc())
def loadFullValue(self, expressions): xml = StringIO.StringIO() xml.write("<xml>") for expression in expressions: result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) xml.write(pydevd_vars.var_to_xml(result, expression, evaluate_full_value=True)) xml.write("</xml>") return xml.getvalue()
def evaluate_var_string_repr(self, var_obj): if self.is_default_value: return None context = {"self": var_obj} eval_result = pydevd_vars.eval_in_context(self.expression, context, context) return _obj_to_string(eval_result)
def evaluate(expression): ipython_shell = get_ipython() namespace = ipython_shell.user_ns result = eval_in_context(expression, namespace, namespace) xml = "<xml>" xml += var_to_xml(result, expression) xml += "</xml>" print(xml)
def evaluate(self, expression, do_trunc): # returns `DebugValue` of evaluated expression result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) return [ pydevd_thrift.var_to_struct(result, expression, do_trim=do_trunc) ]
def evaluate(self, expression): xml = "<xml>" result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) xml += pydevd_vars.var_to_xml(result, expression) xml += "</xml>" return xml
def get_array(text): ipython_shell = get_ipython() namespace = ipython_shell.user_ns roffset, coffset, rows, cols, format, attrs = text.split('\t', 5) name = attrs.split("\t")[-1] var = eval_in_context(name, namespace, namespace) xml = table_like_struct_to_xml(var, name, int(roffset), int(coffset), int(rows), int(cols), format) print(xml)
def do_it(self, dbg): try: frame = dbg.find_frame(self.thread_id, self.frame_id) var = pydevd_vars.eval_in_context(self.name, frame.f_globals, frame.f_locals) xml = pydevd_vars.table_like_struct_to_xml(var, self.name, self.roffset, self.coffset, self.rows, self.cols, self.format) cmd = dbg.cmd_factory.make_get_array_message(self.sequence, xml) dbg.writer.add_command(cmd) except: cmd = dbg.cmd_factory.make_error_message(self.sequence, "Error resolving array: " + get_exception_traceback_str()) dbg.writer.add_command(cmd)
def getArray(self, attr, roffset, coffset, rows, cols, format): xml = "<xml>" name = attr.split("\t")[-1] array = pydevd_vars.eval_in_context(name, self.get_namespace(), self.get_namespace()) array, metaxml, r, c, f = pydevd_vars.array_to_meta_xml(array, name, format) xml += metaxml format = '%' + f if rows == -1 and cols == -1: rows = r cols = c xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format) xml += "</xml>" return xml
def load_full_value(scope_attrs): ipython_shell = get_ipython() namespace = ipython_shell.user_ns vars = scope_attrs.split(NEXT_VALUE_SEPARATOR) xml_list = ["<xml>"] for var_attrs in vars: var_attrs = var_attrs.strip() if len(var_attrs) == 0: continue if '\t' in var_attrs: name, attrs = var_attrs.split('\t', 1) else: name = var_attrs attrs = None if name in namespace.keys(): var_object = resolve_var_object(namespace[name], attrs) xml_list.append( var_to_xml(var_object, name, evaluate_full_value=True)) else: var_object = eval_in_context(name, namespace, namespace) xml_list.append( var_to_xml(var_object, name, evaluate_full_value=True)) xml_list.append("</xml>") print(''.join(xml_list))
def evaluate(self, expression): # returns `DebugValue` of evaluated expression result = pydevd_vars.eval_in_context(expression, self.get_namespace(), self.get_namespace()) return [pydevd_thrift.var_to_struct(result, expression)]