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


Python dis.findlinestarts方法代码示例

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


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

示例1: __init__

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def __init__(self, co_origin):
    if not isinstance(co_origin, types.CodeType):
      raise Exception('The creation of the `CodeObject` should get the original code_object')

    self.co_origin = co_origin
    self.fields = dict(zip(CO_FIELDS, [getattr(self.co_origin, f) for f in CO_FIELDS]))
    self.code = array('B')
    self.linestarts = dict(findlinestarts(co_origin))

    self.lnotab = array('B')
    self.append_code = self.code.append
    self.insert_code = self.code.insert
    self.prev_lineno = -1

    # Used for conversion from a LOAD_NAME in the probe code to a LOAD_FAST
    # in the final bytecode if the names are variable names (in co_varnames)
    self.name_to_fast = set()

    # Used for conversion from a LOAD_NAME in the probe code to a LOAD_GLOBAL
    # when the name is from an injected import
    self.name_to_global = set() 
开发者ID:neuroo,项目名称:equip,代码行数:23,代码来源:merger.py

示例2: collect_return_info

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def collect_return_info(co, use_func_first_line=False):
    if not hasattr(co, 'co_lnotab'):
        return []

    if use_func_first_line:
        firstlineno = co.co_firstlineno
    else:
        firstlineno = 0

    lst = []
    op_offset_to_line = dict(dis.findlinestarts(co))
    for instruction in _iter_instructions(co):
        curr_op_name = instruction.opname
        if curr_op_name == 'RETURN_VALUE':
            lst.append(ReturnInfo(_get_line(op_offset_to_line, instruction.offset, firstlineno, search=True)))

    return lst 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:19,代码来源:pydevd_collect_bytecode_info.py

示例3: __init__

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def __init__(self, co, firstlineno, level=0):
        self.co = co
        self.firstlineno = firstlineno
        self.level = level
        self.instructions = list(_iter_instructions(co))
        op_offset_to_line = self.op_offset_to_line = dict(dis.findlinestarts(co))

        # Update offsets so that all offsets have the line index (and update it based on
        # the passed firstlineno).
        line_index = co.co_firstlineno - firstlineno
        for instruction in self.instructions:
            new_line_index = op_offset_to_line.get(instruction.offset)
            if new_line_index is not None:
                line_index = new_line_index - firstlineno
                op_offset_to_line[instruction.offset] = line_index
            else:
                op_offset_to_line[instruction.offset] = line_index 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:19,代码来源:pydevd_collect_bytecode_info.py

示例4: build_line_to_contents

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def build_line_to_contents(self):
        co = self.co

        op_offset_to_line = dict(dis.findlinestarts(co))
        curr_line_index = 0

        instructions = self.instructions
        while instructions:
            instruction = instructions[0]
            new_line_index = op_offset_to_line.get(instruction.offset)
            if new_line_index is not None:
                if new_line_index is not None:
                    curr_line_index = new_line_index

            self._process_next(curr_line_index)
        return self.writer.line_to_contents 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:18,代码来源:pydevd_code_to_source.py

示例5: _get_instructions

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def _get_instructions(co):
        code = co.co_code
        linestarts = dict(findlinestarts(co))
        n = len(code)
        i = 0
        extended_arg = 0
        while i < n:
            offset = i
            c = code[i]
            op = ord(c)
            lineno = linestarts.get(i)
            argval = None
            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 * 65536

                if op in hasconst:
                    argval = co.co_consts[oparg]
            yield Instruction(offset, argval, opname[op], lineno) 
开发者ID:alexmojaki,项目名称:executing,代码行数:25,代码来源:executing.py

示例6: _findlinestarts

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def _findlinestarts(code):
        """Find the offsets in a byte code which are start of lines in the source.

        Generate pairs (offset, lineno) as described in Python/compile.c.

        """
        byte_increments = [ord(c) for c in code.co_lnotab[0::2]]
        line_increments = [ord(c) for c in code.co_lnotab[1::2]]

        lastlineno = None
        lineno = code.co_firstlineno
        addr = 0
        for byte_incr, line_incr in zip(byte_increments, line_increments):
            if byte_incr:
                if lineno != lastlineno:
                    yield (addr, lineno)
                    lastlineno = lineno
                addr += byte_incr
            lineno += line_incr
        if lineno != lastlineno:
            yield (addr, lineno) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:23,代码来源:unittest.py

示例7: _get_breakpoints_in_code

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def _get_breakpoints_in_code(self, f_code):

        bps_in_file = self._get_breakpoints_in_file(f_code.co_filename)

        code_id = id(f_code)
        result = self._code_breakpoints_cache.get(code_id, None)

        if result is None:
            if not bps_in_file:
                result = set()
            else:
                co_linenos = self._code_linenos_cache.get(code_id, None)
                if co_linenos is None:
                    co_linenos = {pair[1] for pair in dis.findlinestarts(f_code)}
                    self._code_linenos_cache[code_id] = co_linenos

                result = bps_in_file.intersection(co_linenos)

            self._code_breakpoints_cache[code_id] = result

        return result 
开发者ID:thonny,项目名称:thonny,代码行数:23,代码来源:backend.py

示例8: find_source_lines

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def find_source_lines(self):
        """Mark all executable source lines in fn as executed 0 times."""
        if self.filename is None:
            return
        strs = self._find_docstrings(self.filename)
        lines = {ln for off, ln in dis.findlinestarts(self.fn.__code__)
                 if ln not in strs}
        for lineno in lines:
            self.sourcelines.setdefault(lineno, 0)
        if lines:
            self.firstcodelineno = min(lines)
        else:  # pragma: nocover
            # This branch cannot be reached, I'm just being paranoid.
            self.firstcodelineno = self.firstlineno 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:16,代码来源:profilehooks.py

示例9: lasti2lineno

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def lasti2lineno(code, lasti):
    import dis
    linestarts = list(dis.findlinestarts(code))
    linestarts.reverse()
    for i, lineno in linestarts:
        if lasti >= i:
            return lineno
    return 0 
开发者ID:pdbpp,项目名称:pdbpp,代码行数:10,代码来源:pdbpp.py

示例10: find_lines_from_code

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def find_lines_from_code(code, strs):
    """Return dict where keys are lines in the line number table."""
    linenos = {}

    for _, lineno in dis.findlinestarts(code):
        if lineno not in strs:
            linenos[lineno] = 1

    return linenos 
开发者ID:glmcdona,项目名称:meddle,代码行数:11,代码来源:trace.py

示例11: _get_func_lines

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def _get_func_lines(f_code):
    try:
        return set(lineno for (_, lineno) in dis.findlinestarts(f_code))
    except:
        return None 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:7,代码来源:pydevd_frame.py

示例12: warnAboutFunction

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def warnAboutFunction(offender, warningString):
    """
    Issue a warning string, identifying C{offender} as the responsible code.

    This function is used to deprecate some behavior of a function.  It differs
    from L{warnings.warn} in that it is not limited to deprecating the behavior
    of a function currently on the call stack.

    @param function: The function that is being deprecated.

    @param warningString: The string that should be emitted by this warning.
    @type warningString: C{str}

    @since: 11.0
    """
    # inspect.getmodule() is attractive, but somewhat
    # broken in Python < 2.6.  See Python bug 4845.
    offenderModule = sys.modules[offender.__module__]
    filename = inspect.getabsfile(offenderModule)
    lineStarts = list(findlinestarts(offender.__code__))
    lastLineNo = lineStarts[-1][1]
    globals = offender.__globals__

    kwargs = dict(
        category=DeprecationWarning,
        filename=filename,
        lineno=lastLineNo,
        module=offenderModule.__name__,
        registry=globals.setdefault("__warningregistry__", {}),
        module_globals=None)

    warn_explicit(warningString, **kwargs) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:34,代码来源:deprecate.py

示例13: _find_lines_from_code

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def _find_lines_from_code(code, strs):
    """Return dict where keys are lines in the line number table."""
    linenos = {}

    for _, lineno in dis.findlinestarts(code):
        if lineno not in strs:
            linenos[lineno] = 1

    return linenos 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:trace.py

示例14: lasti2lineno

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def lasti2lineno(code, lasti):
    linestarts = list(dis.findlinestarts(code))
    linestarts.reverse()
    for i, lineno in linestarts:
        if lasti >= i:
            return lineno
    return 0 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:9,代码来源:pdb.py

示例15: disassemble

# 需要导入模块: import dis [as 别名]
# 或者: from dis import findlinestarts [as 别名]
def disassemble(co):
    code = co.co_code
    labels = dis.findlabels(code)
    linestarts = dict(dis.findlinestarts(co))
    n = len(code)
    i = 0
    extended_arg = 0
    free = None
    lineno = None
    while i < n:
        c = code[i]
        op = ord(c)
        lineno = linestarts.get(i, lineno)
        is_label = i in labels
        ist = i
        i += 1
        if op >= opcode.HAVE_ARGUMENT:
            oparg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg
            extended_arg = 0
            i += 2
            if op == opcode.EXTENDED_ARG:
                extended_arg = oparg * 65536L
            if op in opcode.hasconst:
                arg = co.co_consts[oparg]
            elif op in opcode.hasname:
                arg = co.co_names[oparg]
            elif op in opcode.hasjrel:
                arg = i + oparg
            elif op in opcode.haslocal:
                arg = co.co_varnames[oparg]
            elif op in opcode.hascompare:
                arg = opcode.cmp_op[oparg]
            elif op in opcode.hasfree:
                if free is None:
                    free = co.co_cellvars + co.co_freevars
                arg = free[oparg]
            else:
                arg = NOVAL
        else:
            arg = NOVAL
        yield ist, lineno, is_label, opcode.opname[op], arg 
开发者ID:ebranca,项目名称:owasp-pysec,代码行数:43,代码来源:tb.py


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