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


Python dis.dis方法代码示例

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


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

示例1: easy_debug

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def easy_debug(code: str, should_exec=False, ctx=None):
    res = to_tagged_ast(parse(code).result)
    c = py_compile(res)
    print("-----------code")
    print(code)
    print("-----------Python")
    print(dis.dis(code))
    print("-----------YaPyPy")
    print(dis.dis(c))
    print("-----------astpretty")
    astpretty.pprint(ast.parse(code))
    print("----------- Python exec result")
    exec(code, ctx or {})
    print("-----------YaPyPy exec result")
    if should_exec:
        exec(c, ctx or {})
    else:
        print("\t(skip)") 
开发者ID:Xython,项目名称:YAPyPy,代码行数:20,代码来源:easy_debug.py

示例2: __init__

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def __init__(self, module, block, module_name, extra):
        self.module = module
        self.block = block
        self.module_name = module_name
        self._extra = extra

        method_block_index = self.get_code_block_index(self.block)
        if method_block_index is None:
            raise Exception('Block of code of a method from %s module was not found', self.module_name)

        self.name = self.block[method_block_index + 1].arg
        self._id = uuid3(UUID('{baa187e0-2c51-4ef6-aa42-b3421c22d5e1}'), self.full_name)
        self.start_line_no = self.block[method_block_index].lineno
        self.code_object = self.block[method_block_index].arg

#        dis.dis(code_object)
        self.code, self.dictionary_defs = preprocess_method_body(self.code_object)

        self.bytecode = Bytecode.from_code(self.code)

        self.evaluate_annotations(method_block_index)
        self.setup() 
开发者ID:CityOfZion,项目名称:neo-boa,代码行数:24,代码来源:method.py

示例3: do_disassembly_test

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def do_disassembly_test(self, func, expected):
        s = StringIO.StringIO()
        save_stdout = sys.stdout
        sys.stdout = s
        dis.dis(func)
        sys.stdout = save_stdout
        got = s.getvalue()
        # Trim trailing blanks (if any).
        lines = got.split('\n')
        lines = [line.rstrip() for line in lines]
        expected = expected.split("\n")
        import difflib
        if expected != lines:
            self.fail(
                "events did not match expectation:\n" +
                "\n".join(difflib.ndiff(expected,
                                        lines))) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_dis.py

示例4: _unpack_opargs

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def _unpack_opargs(code, inserted_code_list, current_index):
    """
    Modified version of `_unpack_opargs` function from module `dis`.
    We have to use it, because sometimes code can be in an inconsistent state: if EXTENDED_ARG
    operator was introduced into the code, but it hasn't been inserted into `code_list` yet.
    In this case we can't use standard `_unpack_opargs` and we should check whether there are
    some new operators in `inserted_code_list`.
    """
    extended_arg = 0
    for i in range(0, len(code), 2):
        op = code[i]
        if op >= HAVE_ARGUMENT:
            if not extended_arg:
                # in case if we added EXTENDED_ARG, but haven't inserted it to the source code yet.
                for code_index in range(current_index, len(inserted_code_list)):
                    inserted_offset, inserted_code = inserted_code_list[code_index]
                    if inserted_offset == i and inserted_code[0] == EXTENDED_ARG:
                        extended_arg = inserted_code[1] << 8
            arg = code[i + 1] | extended_arg
            extended_arg = (arg << 8) if op == EXTENDED_ARG else 0
        else:
            arg = None
        yield (i, op, arg) 
开发者ID:fabioz,项目名称:PyDev.Debugger,代码行数:25,代码来源:pydevd_modify_bytecode.py

示例5: func_bytes

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def func_bytes(fl):
	import console, dis
	"""
	This function reads a script and
	prints it's memory address.
	"""
	f = open(fl).readlines()
	for line in f:
		try:
			co = compile(line,"<none>","exec")
			t = str(str(co).split("at ")[1]).split(",")[0]
			print t, co.consts
		except:
			pass
	console.set_font("Menlo",10)
	f = open(fl).readlines()
	for line in f:
		try:
			dis.dis(line)
		except:
			pass
	console.set_font() 
开发者ID:RussianOtter,项目名称:networking,代码行数:24,代码来源:stacks.py

示例6: yapypy_debug

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def yapypy_debug(code: str, should_exec=False, ctx=None):
    res = to_tagged_ast(parse(code).result)
    c = py_compile(res)
    print("-----------Code")
    print(code)
    print("-----------YaPyPy")
    print(dis.dis(c))
    print("-----------YaPyPy exec result")
    if should_exec:
        exec(c, ctx or {})
    else:
        print("\t(skip)") 
开发者ID:Xython,项目名称:YAPyPy,代码行数:14,代码来源:easy_debug.py

示例7: show_code

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def show_code(code: types.CodeType, f, contains=()):
    if code in contains:
        return

    f.write('\n\n\n')
    f.write(code.co_name)
    f.write(':\n\n')
    dis.show_code(code, file=f)
    for each in code.co_consts:
        if isinstance(each, types.CodeType):
            show_code(each, f, (*contains, code)) 
开发者ID:Xython,项目名称:YAPyPy,代码行数:13,代码来源:snippet.py

示例8: dis_code

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def dis_code(code: types.CodeType, f):
    f.write(code.co_name)
    f.write('\n')
    # def print(*args):
    #     for each in args:
    #         f.write(str(each))
    #         f.write(' ')
    #     f.write('\n')

    dis.dis(code, file=f)
    if sys.version_info < (3, 7):
        # dump_bytecode(Bytecode.from_code(code), print=print)
        for each in code.co_consts:
            if isinstance(each, types.CodeType):
                dis_code(each, f) 
开发者ID:Xython,项目名称:YAPyPy,代码行数:17,代码来源:snippet.py

示例9: getCodeDisassembly

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def getCodeDisassembly(code):
    """Provides disassembly of a code object"""
    fileLikeObject = StringIO()
    dis.dis(code, file=fileLikeObject)
    fileLikeObject.seek(0)
    return fileLikeObject.read() 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:8,代码来源:disasm.py

示例10: test_opmap

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def test_opmap(self):
        self.assertEqual(dis.opmap["STOP_CODE"], 0)
        self.assertIn(dis.opmap["LOAD_CONST"], dis.hasconst)
        self.assertIn(dis.opmap["STORE_NAME"], dis.hasname) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_dis.py

示例11: test_opname

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def test_opname(self):
        self.assertEqual(dis.opname[dis.opmap["LOAD_FAST"]], "LOAD_FAST") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_dis.py

示例12: test_boundaries

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def test_boundaries(self):
        self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG)
        self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_dis.py

示例13: disassemble

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def disassemble(func):
    f = StringIO()
    tmp = sys.stdout
    sys.stdout = f
    dis.dis(func)
    sys.stdout = tmp
    result = f.getvalue()
    f.close()
    return result 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_peepholer.py

示例14: flip_dict

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def flip_dict(the_dict):
    new_dict = dict()
    for k,v in the_dict.items():
        new_dict[v] = k
    return new_dict
    
# dis.dis() prints straight to stdout
# so we have to redirect stdout to capture the output 
开发者ID:tenable,项目名称:poc,代码行数:10,代码来源:convert_pyc_opcodes.py

示例15: capture_disassembly

# 需要导入模块: import dis [as 别名]
# 或者: from dis import dis [as 别名]
def capture_disassembly(code_obj):
    output = ''
    new_stdout = StringIO()
    orig_stdout = sys.stdout
    sys.stdout = new_stdout
    # disassemble
    dis.dis(code_obj)
    # restore stdout 
    sys.stdout = orig_stdout
    output = new_stdout.getvalue()
    new_stdout.close()
    return output 
开发者ID:tenable,项目名称:poc,代码行数:14,代码来源:convert_pyc_opcodes.py


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