当前位置: 首页>>代码示例>>Python>>正文


Python new.code方法代码示例

本文整理汇总了Python中new.code方法的典型用法代码示例。如果您正苦于以下问题:Python new.code方法的具体用法?Python new.code怎么用?Python new.code使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在new的用法示例。


在下文中一共展示了new.code方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: python

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def python(self, argv):
        import code
        ns = self._get_ns()
        console = code.InteractiveConsole(ns)
        console.raw_input = self._ui.user_input
        try:
            saveps1, saveps2 = sys.ps1, sys.ps2
        except AttributeError:
            saveps1, saveps2 = ">>> ", "... "
        sys.ps1, sys.ps2 = "%%GPython%%N:%s> " % (self._obj.__class__.__name__,), "more> "
        if readline:
            oc = readline.get_completer()
            readline.set_completer(Completer(ns).complete)
        console.interact("You are now in Python. ^D exits.")
        if readline:
            readline.set_completer(oc)
        sys.ps1, sys.ps2 = saveps1, saveps2
        self._reset_scopes()


# This is needed to reset PagedIO so background events don't cause the pager to activate. 
开发者ID:kdart,项目名称:pycopia,代码行数:23,代码来源:CLI.py

示例2: python

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def python(self, argv):
        import code
        ns = self._get_ns()
        console = code.InteractiveConsole(ns)
        console.raw_input = self._ui.user_input
        try:
            saveps1, saveps2 = sys.ps1, sys.ps2
        except AttributeError:
            saveps1, saveps2 = ">>> ", "... "
        sys.ps1, sys.ps2 = "%%GPython%%N:%s> " % (self._obj.__class__.__name__,), "more> "
        if readline:
            oc = readline.get_completer()
            readline.set_completer(Completer(ns).complete)
        console.interact("You are now in Python. ^D exits.")
        if readline:
            readline.set_completer(oc)
        sys.ps1, sys.ps2 = saveps1, saveps2
        self._reset_scopes() 
开发者ID:kdart,项目名称:pycopia,代码行数:20,代码来源:CLI.py

示例3: calc_lnotab

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def calc_lnotab(self):
        '''
        Creates a new co_lineno after modifying bytecode
        '''
        rvalue = ""

        prev_lineno = self.code.co_firstlineno
        prev_offset = self.head.addr

        for current in self.nodes():
            if current.co_lnotab == prev_lineno:
                continue

            new_offset = current.co_lnotab - prev_lineno
            new_offset = 0xff if new_offset > 0xff else new_offset

            rvalue += struct.pack("BB", current.addr - prev_offset,
                                  (current.co_lnotab - prev_lineno) & 0xff)

            prev_lineno = current.co_lnotab
            prev_offset = current.addr
        return rvalue 
开发者ID:fireeye,项目名称:flare-bytecode_graph,代码行数:24,代码来源:bytecode_graph.py

示例4: nextBlock

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def nextBlock(self, block=None):
        # XXX think we need to specify when there is implicit transfer
        # from one block to the next.  might be better to represent this
        # with explicit JUMP_ABSOLUTE instructions that are optimized
        # out when they are unnecessary.
        #
        # I think this strategy works: each block has a child
        # designated as "next" which is returned as the last of the
        # children.  because the nodes in a graph are emitted in
        # reverse post order, the "next" block will always be emitted
        # immediately after its parent.
        # Worry: maintaining this invariant could be tricky
        if block is None:
            block = self.newBlock()

        # Note: If the current block ends with an unconditional
        # control transfer, then it is incorrect to add an implicit
        # transfer to the block graph.  The current code requires
        # these edges to get the blocks emitted in the right order,
        # however. :-(  If a client needs to remove these edges, call
        # pruneEdges().

        self.current.addNext(block)
        self.startBlock(block) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:26,代码来源:pyassem.py

示例5: pruneNext

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def pruneNext(self):
        """Remove bogus edge for unconditional transfers

        Each block has a next edge that accounts for implicit control
        transfers, e.g. from a JUMP_IF_FALSE to the block that will be
        executed if the test is true.

        These edges must remain for the current assembler code to
        work. If they are removed, the dfs_postorder gets things in
        weird orders.  However, they shouldn't be there for other
        purposes, e.g. conversion to SSA form.  This method will
        remove the next edge when it follows an unconditional control
        transfer.
        """
        try:
            op, arg = self.insts[-1]
        except (IndexError, ValueError):
            return
        if op in self._uncond_transfer:
            self.next = [] 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:pyassem.py

示例6: extract_code_globals

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def extract_code_globals(co):
        """
        Find all globals names read or written to by codeblock co
        """
        code = co.co_code
        names = co.co_names
        out_names = set()

        n = len(code)
        i = 0
        extended_arg = 0
        while i < n:
            op = code[i]

            i = i+1
            if op >= HAVE_ARGUMENT:
                oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
                extended_arg = 0
                i = i+2
                if op == EXTENDED_ARG:
                    extended_arg = oparg*65536L
                if op in GLOBAL_OPS:
                    out_names.add(names[oparg])
        #print 'extracted', out_names, ' from ', names
        return out_names 
开发者ID:adobe-research,项目名称:spark-cluster-deployment,代码行数:27,代码来源:cloudpickle.py

示例7: _make_skel_func

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def _make_skel_func(code, num_closures, base_globals = None):
    """ Creates a skeleton function object that contains just the provided
        code and the correct number of cells in func_closure.  All other
        func attributes (e.g. func_globals) are empty.
    """
    #build closure (cells):
    if not ctypes:
        raise Exception('ctypes failed to import; cannot build function')

    cellnew = ctypes.pythonapi.PyCell_New
    cellnew.restype = ctypes.py_object
    cellnew.argtypes = (ctypes.py_object,)
    dummy_closure = tuple(map(lambda i: cellnew(None), range(num_closures)))

    if base_globals is None:
        base_globals = {}
    base_globals['__builtins__'] = __builtins__

    return types.FunctionType(code, base_globals,
                              None, None, dummy_closure)

# this piece of opaque code is needed below to modify 'cell' contents 
开发者ID:adobe-research,项目名称:spark-cluster-deployment,代码行数:24,代码来源:cloudpickle.py

示例8: debug

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def debug(self, argv):
        """debug ["on"|"off"]
    Enables debugging for CLI code. 
    Enters the debugger if an exception occurs."""
        global _DEBUG
        if len(argv) > 1:
            cmd = argv[1]
            if cmd == "on":
                _DEBUG = True
            else:
                _DEBUG = False
        else:
            self._ui.printf(
                 "Debugging is currently %%I%s%%N." % (IF(_DEBUG, "on", "off"),)) 
开发者ID:kdart,项目名称:pycopia,代码行数:16,代码来源:CLI.py

示例9: alias

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def alias(self, argv):
        """alias [newalias]
    With no argument prints the current set of aliases. With an argument of the
    form alias ..., sets a new alias.  """
        if len(argv) == 1:
            for name, val in self._aliases.items():
                self._print("alias %s='%s'" % (name, " ".join(val)))
            return 0
        elif len(argv) == 2 and '=' not in argv[1]:
            name = argv[1]
            try:
                self._print("%s=%s" % (name, " ".join(self._aliases[name])))
            except KeyError:
                self._print("undefined alias.")
            return 0
        # else
        try: # this icky code to handle different permutations of where the '=' is.
            argv.pop(0) # discard 'alias'
            name = argv.pop(0)
            if "=" in name:
                name, rh = name.split("=", 1)
                argv.insert(0,rh)
            elif argv[0].startswith("="):
                if len(argv[0]) > 1: # if argv[1] is '=something'
                    argv[0] = argv[0][1:]
                else:
                    del argv[0] # remove the '='
            self._aliases[name] = argv
        except:
            ex, val = sys.exc_info()[:2]
            self._print("alias: Could not set alias. Usage: alias name=value")
            self._print("%s (%s)" % (ex, val))
            return 1 
开发者ID:kdart,项目名称:pycopia,代码行数:35,代码来源:CLI.py

示例10: pyeval

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def pyeval(self, argv):
        snippet = " ".join(argv[1:]).strip()+"\n"
        ns = self._get_ns()
        try:
            code = compile(snippet, '<CLI>', 'eval')
            rv = eval(code, globals(), ns)
        except:
            t, v, tb = sys.exc_info()
            self._print('*** %s (%s)' % (t, v))
        else:
            self._print(rv)
            return rv 
开发者ID:kdart,项目名称:pycopia,代码行数:14,代码来源:CLI.py

示例11: pyexec

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def pyexec(self, argv):
        snippet = " ".join(argv[1:]).strip()+"\n"
        ns = self._get_ns()
        try:
            code = compile(snippet, '<CLI>', 'exec')
            exec code in globals(), ns
        except:
            t, v, tb = sys.exc_info()
            self._print('*** %s (%s)' % (t, v)) 
开发者ID:kdart,项目名称:pycopia,代码行数:11,代码来源:CLI.py

示例12: debug

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def debug(self, argv):
        """debug ["on"|"off"]
    Enables debugging for CLI code.
    Enters the debugger if an exception occurs."""
        global _DEBUG
        if len(argv) > 1:
            cmd = argv[1]
            if cmd == "on":
                _DEBUG = True
            else:
                _DEBUG = False
        else:
            self._ui.printf(
                 "Debugging is currently %%I%s%%N." % ("on" if _DEBUG else "off",)) 
开发者ID:kdart,项目名称:pycopia,代码行数:16,代码来源:CLI.py

示例13: pyexec

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def pyexec(self, argv):
        snippet = " ".join(argv[1:]).strip()+"\n"
        ns = self._get_ns()
        try:
            code = compile(snippet, '<CLI>', 'exec')
            exec(code, globals(), ns)
        except:
            t, v, tb = sys.exc_info()
            self._print('*** %s (%s)' % (t, v)) 
开发者ID:kdart,项目名称:pycopia,代码行数:11,代码来源:CLI.py

示例14: read

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def read(self, f):
        if isinstance(f, basestring):
            f = open(f, "rb")
        self.magic = f.read(4)
        self.modtime = f.read(4)
        self.code = marshal.load(f) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:8,代码来源:hack_pyc.py

示例15: write

# 需要导入模块: import new [as 别名]
# 或者: from new import code [as 别名]
def write(self, f):
        if isinstance(f, basestring):
            f = open(f, "wb")
        f.write(self.magic)
        f.write(self.modtime)
        marshal.dump(self.code, f) 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:8,代码来源:hack_pyc.py


注:本文中的new.code方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。