當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。