本文整理汇总了Python中dis.hasconst方法的典型用法代码示例。如果您正苦于以下问题:Python dis.hasconst方法的具体用法?Python dis.hasconst怎么用?Python dis.hasconst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dis
的用法示例。
在下文中一共展示了dis.hasconst方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_instructions
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [as 别名]
def get_instructions(co):
code = co.co_code
n = len(code)
i = 0
extended_arg = 0
while i < n:
offset = i
c = code[i]
op = ord(c)
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])
示例2: _get_instructions
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [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)
示例3: test_opmap
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [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)
示例4: test_opmap
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [as 别名]
def test_opmap(self):
self.assertEqual(dis.opmap["NOP"], 9)
self.assertIn(dis.opmap["LOAD_CONST"], dis.hasconst)
self.assertIn(dis.opmap["STORE_NAME"], dis.hasname)
示例5: _get_base_class_names
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [as 别名]
def _get_base_class_names(frame):
"""Get baseclass names from the code object"""
co, lasti = frame.f_code, frame.f_lasti
code = co.co_code
i = 0
extended_arg = 0
extends = []
while i <= lasti:
c = code[i]
op = ord(c)
i += 1
if op >= dis.HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i + 1]) * 256 + extended_arg
extended_arg = 0
i += 2
if op == dis.EXTENDED_ARG:
extended_arg = oparg * int(65536)
if op in dis.hasconst:
if type(co.co_consts[oparg]) == str:
extends = []
elif op in dis.hasname:
if dis.opname[op] == 'LOAD_NAME':
extends.append(('name', co.co_names[oparg]))
if dis.opname[op] == 'LOAD_ATTR':
extends.append(('attr', co.co_names[oparg]))
items = []
previous_item = []
for t, s in extends:
if t == 'name':
if previous_item:
items.append(previous_item)
previous_item = [s]
else:
previous_item += [s]
if previous_item:
items.append(previous_item)
return items
示例6: test_opmap
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [as 别名]
def test_opmap(self):
self.assertEqual(dis.opmap["STOP_CODE"], 0)
self.assertEqual(dis.opmap["LOAD_CONST"] in dis.hasconst, True)
self.assertEqual(dis.opmap["STORE_NAME"] in dis.hasname, True)
示例7: _get_base_class_names
# 需要导入模块: import dis [as 别名]
# 或者: from dis import hasconst [as 别名]
def _get_base_class_names(frame):
"""Get baseclass names from the code object"""
co, lasti = frame.f_code, frame.f_lasti
code = co.co_code
i = 0
extended_arg = 0
extends = []
while i <= lasti:
c = code[i]
op = ord(c)
i += 1
if op >= dis.HAVE_ARGUMENT:
oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
extended_arg = 0
i += 2
if op == dis.EXTENDED_ARG:
extended_arg = oparg*int(65536)
if op in dis.hasconst:
if type(co.co_consts[oparg]) == str:
extends = []
elif op in dis.hasname:
if dis.opname[op] == 'LOAD_NAME':
extends.append(('name', co.co_names[oparg]))
if dis.opname[op] == 'LOAD_ATTR':
extends.append(('attr', co.co_names[oparg]))
items = []
previous_item = []
for t, s in extends:
if t == 'name':
if previous_item:
items.append(previous_item)
previous_item = [s]
else:
previous_item += [s]
if previous_item:
items.append(previous_item)
return items