我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用pydoc.cram()。
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
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
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
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
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