aboutsummaryrefslogtreecommitdiffstats
path: root/setuptools/py33compat.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-01-07 13:37:37 -0500
committerJason R. Coombs <jaraco@jaraco.com>2017-01-07 13:37:37 -0500
commita0d35d47761a8bd7394cb9f2738169b07be3a005 (patch)
tree375334a5e61eb137b5411f92942b510f6024cea3 /setuptools/py33compat.py
parentbbf6ac250a05fd51aa2a44ed3196837491bc9d60 (diff)
parent3c182f9f1eea89040fbfc88d1ccbed31ece6a00b (diff)
downloadexternal_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.py46
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)