Commit a29c9a4d authored by Jason R. Coombs's avatar Jason R. Coombs

Use dis module rather than manually disassembling the bytecode. Fixes #866.

parent b911a237
import sys import sys
import imp import imp
import marshal import marshal
import dis
from distutils.version import StrictVersion from distutils.version import StrictVersion
from imp import PKG_DIRECTORY, PY_COMPILED, PY_SOURCE, PY_FROZEN from imp import PKG_DIRECTORY, PY_COMPILED, PY_SOURCE, PY_FROZEN
from setuptools.extern import six
__all__ = [ __all__ = [
'Require', 'find_module', 'get_module_constant', 'extract_constant' 'Require', 'find_module', 'get_module_constant', 'extract_constant'
] ]
...@@ -80,35 +79,10 @@ class Require: ...@@ -80,35 +79,10 @@ class Require:
def _iter_code(code): def _iter_code(code):
"""Yield '(op,arg)' pair for each operation in code object 'code'""" """Yield '(op,arg)' pair for each operation in code object 'code'"""
return (
from array import array (op.opcode, op.arg)
from dis import HAVE_ARGUMENT, EXTENDED_ARG for op in dis.Bytecode(code)
)
bytes = array('b', code.co_code)
eof = len(code.co_code)
ptr = 0
extended_arg = 0
while ptr < eof:
op = bytes[ptr]
if op >= HAVE_ARGUMENT:
arg = bytes[ptr + 1] + bytes[ptr + 2] * 256 + extended_arg
ptr += 3
if op == EXTENDED_ARG:
long_type = six.integer_types[-1]
extended_arg = arg * long_type(65536)
continue
else:
arg = None
ptr += 1
yield op, arg
def find_module(module, paths=None): def find_module(module, paths=None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment