本文整理汇总了Python中types.FunctionType.optimizable方法的典型用法代码示例。如果您正苦于以下问题:Python FunctionType.optimizable方法的具体用法?Python FunctionType.optimizable怎么用?Python FunctionType.optimizable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.FunctionType
的用法示例。
在下文中一共展示了FunctionType.optimizable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_get_single_ctrl
# 需要导入模块: from types import FunctionType [as 别名]
# 或者: from types.FunctionType import optimizable [as 别名]
def build_get_single_ctrl(query, args_names, field_names):
"""
Create optimized controller.
"""
codes = [
opcode.opmap['LOAD_GLOBAL'], 0, 0,
opcode.opmap['LOAD_CONST'], 1, 0
]
for i in range(len(args_names)):
codes.extend((opcode.opmap['LOAD_FAST'], i, 0))
codes.extend((
opcode.opmap['BUILD_TUPLE'], len(args_names), 0,
opcode.opmap['CALL_FUNCTION'], 2, 0,
opcode.opmap['LOAD_ATTR'], 1, 0,
opcode.opmap['CALL_FUNCTION'], 0, 0,
opcode.opmap['STORE_FAST'], len(args_names), 0, # store to 'values'
opcode.opmap['LOAD_FAST'], len(args_names), 0, # load from 'values'
opcode.opmap['LOAD_CONST'], 0, 0,
opcode.opmap['COMPARE_OP'], 8, 0,
opcode.opmap['POP_JUMP_IF_FALSE'], len(args_names) * 3 + 37, 0,
opcode.opmap['LOAD_FAST'], len(args_names), 0,
opcode.opmap['RETURN_VALUE'],
opcode.opmap['LOAD_GLOBAL'], 2, 0, # (dict)
opcode.opmap['LOAD_GLOBAL'], 3, 0, # (zip)
opcode.opmap['LOAD_CONST'], 2, 0,
opcode.opmap['LOAD_FAST'], len(args_names), 0, # load from 'values'
opcode.opmap['CALL_FUNCTION'], 2, 0,
opcode.opmap['CALL_FUNCTION'], 1, 0,
opcode.opmap['RETURN_VALUE'],
))
ctrl = FunctionType(
CodeType(
len(args_names), # argcount
0, # kwonlyargcount
len(args_names) + 1, # + nb var used
7, # stacksize
67, # flags
bytes(codes), # codestring
(None, query, field_names), # constants
('sql_execute', 'fetchone', 'dict', 'zip'), # names
tuple(args_names) + ('values',), # varnames + var used
__file__, # filename
'ctrl', # name
0, # firstlineno
b'\x00\x01\x1b\x01\x0c\x01\x04\x01' # lnotab
), {'dict': dict, 'zip': zip, 'sql_execute': MetaResource.db.execute}
)
ctrl.single = True
ctrl.optimizable = True
return ctrl