@classmethod<EOL><INDENT>def from_code(cls, co):<DEDENT>
co_code = co.co_code<EOL>labels = dict((addr, Label()) for addr in findlabels(co_code))<EOL>linestarts = dict(cls._findlinestarts(co))<EOL>cellfree = co.co_cellvars + co.co_freevars<EOL>code = CodeList()<EOL>n = len(co_code)<EOL>i = <NUM_LIT:0><EOL>extended_arg = <NUM_LIT:0><EOL>while i < n:<EOL><INDENT>op = Opcode(ord(co_code[i]))<EOL>if i in labels:<EOL><INDENT>code.append((labels[i], None))<EOL><DEDENT>if i in linestarts:<EOL><INDENT>code.append((SetLineno, linestarts[i]))<EOL><DEDENT>i += <NUM_LIT:1><EOL>if op in hascode:<EOL><INDENT>lastop, lastarg = code[-<NUM_LIT:1>]<EOL>if lastop != LOAD_CONST:<EOL><INDENT>raise ValueError("<STR_LIT>" % op)<EOL><DEDENT>code[-<NUM_LIT:1>] = (LOAD_CONST, Code.from_code(lastarg))<EOL><DEDENT>if op not in hasarg:<EOL><INDENT>code.append((op, None))<EOL><DEDENT>else:<EOL><INDENT>arg = ord(co_code[i]) + ord(co_code[i+<NUM_LIT:1>])*<NUM_LIT> + extended_arg<EOL>extended_arg = <NUM_LIT:0><EOL>i += <NUM_LIT:2><EOL>if op == opcode.EXTENDED_ARG:<EOL><INDENT>extended_arg = arg << <NUM_LIT:16><EOL><DEDENT>elif op in hasconst:<EOL><INDENT>code.append((op, co.co_consts[arg]))<EOL><DEDENT>elif op in hasname:<EOL><INDENT>code.append((op, co.co_names[arg]))<EOL><DEDENT>elif op in hasjabs:<EOL><INDENT>code.append((op, labels[arg]))<EOL><DEDENT>elif op in hasjrel:<EOL><INDENT>code.append((op, labels[i + arg]))<EOL><DEDENT>elif op in haslocal:<EOL><INDENT>code.append((op, co.co_varnames[arg]))<EOL><DEDENT>elif op in hascompare:<EOL><INDENT>code.append((op, cmp_op[arg]))<EOL><DEDENT>elif op in hasfree:<EOL><INDENT>code.append((op, cellfree[arg]))<EOL><DEDENT>else:<EOL><INDENT>code.append((op, arg))<EOL><DEDENT><DEDENT><DEDENT>varargs = bool(co.co_flags & CO_VARARGS)<EOL>varkwargs = bool(co.co_flags & CO_VARKEYWORDS)<EOL>newlocals = bool(co.co_flags & CO_NEWLOCALS)<EOL>args = co.co_varnames[:co.co_argcount + varargs + varkwargs]<EOL>if co.co_consts and isinstance(co.co_consts[<NUM_LIT:0>], str):<EOL><INDENT>docstring = co.co_consts[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>docstring = None<EOL><DEDENT>return cls(code = code,<EOL>freevars = co.co_freevars,<EOL>args = args,<EOL>varargs = varargs,<EOL>varkwargs = varkwargs,<EOL>newlocals = newlocals,<EOL>name = co.co_name,<EOL>filename = co.co_filename,<EOL>firstlineno = co.co_firstlineno,<EOL>docstring = docstring,<EOL>)<EOL>
Disassemble a Python code object into a Code object.