diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2017-01-07 13:37:37 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2017-01-07 13:37:37 -0500 |
commit | a0d35d47761a8bd7394cb9f2738169b07be3a005 (patch) | |
tree | 375334a5e61eb137b5411f92942b510f6024cea3 /setuptools/py33compat.py | |
parent | bbf6ac250a05fd51aa2a44ed3196837491bc9d60 (diff) | |
parent | 3c182f9f1eea89040fbfc88d1ccbed31ece6a00b (diff) | |
download | external_python_setuptools-issue-97.tar.gz external_python_setuptools-issue-97.tar.bz2 external_python_setuptools-issue-97.zip |
Merge branch 'master' into issue-97issue-97
Diffstat (limited to 'setuptools/py33compat.py')
-rw-r--r-- | setuptools/py33compat.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/setuptools/py33compat.py b/setuptools/py33compat.py new file mode 100644 index 00000000..2588d680 --- /dev/null +++ b/setuptools/py33compat.py @@ -0,0 +1,46 @@ +import dis +import code +import array +import collections + +from setuptools.extern import six + + +OpArg = collections.namedtuple('OpArg', 'opcode arg') + + +class Bytecode_compat(object): + def __init__(self, code): + self.code = code + + def __iter__(self): + """Yield '(op,arg)' pair for each operation in code object 'code'""" + + bytes = array.array('b', self.code.co_code) + eof = len(self.code.co_code) + + ptr = 0 + extended_arg = 0 + + while ptr < eof: + + op = bytes[ptr] + + if op >= dis.HAVE_ARGUMENT: + + arg = bytes[ptr + 1] + bytes[ptr + 2] * 256 + extended_arg + ptr += 3 + + if op == dis.EXTENDED_ARG: + long_type = six.integer_types[-1] + extended_arg = arg * long_type(65536) + continue + + else: + arg = None + ptr += 1 + + yield OpArg(op, arg) + + +Bytecode = getattr(dis, 'Bytecode', Bytecode_compat) |