示例#1
0
文件: qdb.py 项目: llazzaro/gqdb
 def do_environment(self):
     "return current frame local and global environment"
     env = {'locals': {}, 'globals': {}}
     # converts the frame global and locals to a short text representation:
     if self.frame:
         for name, value in self.frame_locals.items():
             env['locals'][name] = pydoc.cram(repr(value), 255), repr(type(value))
         for name, value in self.frame.f_globals.items():
             env['globals'][name] = pydoc.cram(repr(value), 20), repr(type(value))
     return env
示例#2
0
 def do_environment(self):
     "return current frame local and global environment"
     env = {'locals': {}, 'globals': {}}
     # converts the frame global and locals to a short text representation:
     if self.frame:
         for name, value in self.frame_locals.items():
             env['locals'][name] = pydoc.cram(repr(
                 value), 255), repr(type(value))
         for name, value in self.frame.f_globals.items():
             env['globals'][name] = pydoc.cram(repr(
                 value), 20), repr(type(value))
     return env
示例#3
0
 def do_eval(self, arg, safe=True):
     if self.frame:
         ret = eval(arg, self.frame.f_globals, self.frame_locals)
     else:
         ret = RPCError("No current frame available to eval")
     if safe:
         ret = pydoc.cram(repr(ret), 255)
     return ret
示例#4
0
文件: qdb.py 项目: llazzaro/gqdb
 def do_eval(self, arg, safe=True):
     if self.frame:
         ret = eval(arg, self.frame.f_globals,
                     self.frame_locals)
     else:
         ret = RPCError("No current frame available to eval")
     if safe:
         ret = pydoc.cram(repr(ret), 255)
     return ret
示例#5
0
def pformat(obj, max_len=MAX_LEN, quote=True):
    """Pretty prints an object."""
    if hasattr(obj, '__len__') and len(obj) == 1:
        obj = obj[0]
    if isinstance(obj, (int, float)):
        pstr = '{:.4n}'.format(obj)
    else:
        pstr = pprint.pformat(obj)
    pstr = re.sub(r'u(["\'])', r'\1', pstr)
    if not quote:
        pstr = pstr.strip("'").strip('"')
    pstr = pydoc.cram(pstr, max_len)
    return pstr
示例#6
0
文件: qdb.py 项目: Focus3D/rad2py
 def do_environment(self):
     "return current frame local and global environment"
     env = {'locals': {}, 'globals': {}}
     # converts the frame global and locals to a short text representation:
     if self.frame:
         for scope, max_length, vars in (
                 ("locals", 255, self.frame_locals.items()),
                 ("globals", 20, self.frame.f_globals.items()), ):
             for (name, value) in vars:
                 try:
                     short_repr = pydoc.cram(repr(value), max_length)                    
                 except Exception as e:
                     # some objects cannot be represented...
                     short_repr = "**exception** %s" % repr(e)
                 env[scope][name] = (short_repr, repr(type(value)))
     return env
示例#7
0
 def do_environment(self):
     "return current frame local and global environment"
     env = {'locals': {}, 'globals': {}}
     # converts the frame global and locals to a short text representation:
     if self.frame:
         for scope, max_length, vars in (
                 ("locals", 255, list(self.frame_locals.items())),
                 ("globals", 20, list(self.frame.f_globals.items())), ):
             for (name, value) in vars:
                 try:
                     short_repr = pydoc.cram(repr(value), max_length)                    
                 except Exception as e:
                     # some objects cannot be represented...
                     short_repr = "**exception** %s" % repr(e)
                 env[scope][name] = (short_repr, repr(type(value)))
     return env
示例#8
0
文件: qdb.py 项目: llazzaro/gqdb
 def do_exec(self, arg, safe=True):
     if not self.frame:
         ret = RPCError("No current frame available to exec")
     else:
         locals = self.frame_locals
         globals = self.frame.f_globals
         code = compile(arg + '\n', '<stdin>', 'single')
         save_displayhook = sys.displayhook
         self.displayhook_value = None
         try:
             sys.displayhook = self.displayhook
             exec(code, globals, locals)
             ret = self.displayhook_value
         finally:
             sys.displayhook = save_displayhook
     if safe:
         ret = pydoc.cram(repr(ret), 255)
     return ret
示例#9
0
 def do_exec(self, arg, safe=True):
     if not self.frame:
         ret = RPCError("No current frame available to exec")
     else:
         locals = self.frame_locals
         globals = self.frame.f_globals
         code = compile(arg + '\n', '<stdin>', 'single')
         save_displayhook = sys.displayhook
         self.displayhook_value = None
         try:
             sys.displayhook = self.displayhook
             exec code in globals, locals
             ret = self.displayhook_value
         finally:
             sys.displayhook = save_displayhook
     if safe:
         ret = pydoc.cram(repr(ret), 255)
     return ret
示例#10
0
 def do_eval(self, arg, safe=True):
     ret = eval(arg, self.frame.f_globals,
                self.frame_locals)
     if safe:
         ret = pydoc.cram(repr(ret), 255)
     return ret
示例#11
0
 def update_event(self, inp=-1):
     self.set_output_val(0, pydoc.cram(self.input(0), self.input(1)))
示例#12
0
def _format_warnings_dd(result, suppress=frozenset(), max_width=MAX_WIDTH):
    """String formatter for DuplicateExampleDetector LintResults."""
    egs = result.lint_samples[0].examples
    lines = [DD_PREAMBLE.format(result.warnings[0], len(egs))]
    cols = sorted(set(f for eg in egs
                      for f in eg.features.feature))[:DD_MAX_COLS]
    col_vals = {col: [] for col in cols}
    col_widths = {
        col: min(len(col), DD_MAX_VAL_LEN - BORDER_SZ)
        for col in cols
    }
    for eg in egs:
        for col in cols:
            feature = eg.features.feature.get(col)
            if not feature:
                col_vals[col].append('')
                continue
            kind = feature.WhichOneof('kind')
            if kind is None:
                col_vals[col].append('')
                continue
            vals = getattr(feature, kind).value
            if not vals:
                col_vals[col].append('')
                continue
            val_str = pformat(vals, max_len=DD_MAX_VAL_LEN)
            col_vals[col].append(val_str)
            col_widths[col] = max(col_widths[col],
                                  min(len(val_str), DD_MAX_VAL_LEN))

    col_groups = [[]]
    tot_width = 0
    for col in cols:
        colwidth = col_widths[col] + BORDER_SZ
        if tot_width + colwidth >= max_width:
            col_groups.append([col])
            tot_width = 0
        else:
            col_groups[-1].append(col)
            tot_width += colwidth

    col_group_strs = []
    for i, col_group in enumerate(col_groups, 1):
        if i == 1:
            borders = '| {} ' + ('|' if len(col_groups) == 1 else '')
        elif i < len(col_groups):
            borders = ' {} '
        else:
            borders = ' {} |'

        heading = borders.format(
            COLSEP.join(
                pydoc.cram(c, col_widths[c]).center(col_widths[c])
                for c in col_group))
        hrule = '-' * len(heading)
        cg_lines = [hrule, heading, hrule]
        for j in range(len(egs)):
            l = borders.format(
                COLSEP.join(col_vals[c][j].center(col_widths[c])
                            for c in col_group))
            cg_lines.append(l)
        cg_lines.append(hrule)
        col_group_strs.append('\n'.join(cg_lines))

    lines.append('\n\n'.join(col_group_strs))

    return lines