Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Side by Side Diff: third_party/google-endpoints/setuptools/py33compat.py

Issue 2666783008: Add google-endpoints to third_party/. (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 import dis
2 import array
3 import collections
4
5 import six
6
7
8 OpArg = collections.namedtuple('OpArg', 'opcode arg')
9
10
11 class Bytecode_compat(object):
12 def __init__(self, code):
13 self.code = code
14
15 def __iter__(self):
16 """Yield '(op,arg)' pair for each operation in code object 'code'"""
17
18 bytes = array.array('b', self.code.co_code)
19 eof = len(self.code.co_code)
20
21 ptr = 0
22 extended_arg = 0
23
24 while ptr < eof:
25
26 op = bytes[ptr]
27
28 if op >= dis.HAVE_ARGUMENT:
29
30 arg = bytes[ptr + 1] + bytes[ptr + 2] * 256 + extended_arg
31 ptr += 3
32
33 if op == dis.EXTENDED_ARG:
34 long_type = six.integer_types[-1]
35 extended_arg = arg * long_type(65536)
36 continue
37
38 else:
39 arg = None
40 ptr += 1
41
42 yield OpArg(op, arg)
43
44
45 Bytecode = getattr(dis, 'Bytecode', Bytecode_compat)
OLDNEW
« no previous file with comments | « third_party/google-endpoints/setuptools/py31compat.py ('k') | third_party/google-endpoints/setuptools/py36compat.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698