Python pydoc 模块,cram() 实例源码

我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用pydoc.cram()

项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
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
项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
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
项目:rekall-agent-server    作者:rekall-innovations    | 项目源码 | 文件源码
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
项目:rekall-agent-server    作者:rekall-innovations    | 项目源码 | 文件源码
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
项目:touch-pay-client    作者:HackPucBemobi    | 项目源码 | 文件源码
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
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
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
项目:true_review_web2py    作者:lucadealfaro    | 项目源码 | 文件源码
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
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
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
项目:spc    作者:whbrewer    | 项目源码 | 文件源码
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
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
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
项目:Problematica-public    作者:TechMaz    | 项目源码 | 文件源码
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
项目:rekall-agent-server    作者:rekall-innovations    | 项目源码 | 文件源码
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
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
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
项目:slugiot-client    作者:slugiot    | 项目源码 | 文件源码
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
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
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
项目:StuffShare    作者:StuffShare    | 项目源码 | 文件源码
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