Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/setuptools/py33compat.py: 43%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import dis
2import array
3import collections
5try:
6 import html
7except ImportError:
8 html = None
10from setuptools.extern import six
11from setuptools.extern.six.moves import html_parser
13__metaclass__ = type
15OpArg = collections.namedtuple('OpArg', 'opcode arg')
18class Bytecode_compat:
19 def __init__(self, code):
20 self.code = code
22 def __iter__(self):
23 """Yield '(op,arg)' pair for each operation in code object 'code'"""
25 bytes = array.array('b', self.code.co_code)
26 eof = len(self.code.co_code)
28 ptr = 0
29 extended_arg = 0
31 while ptr < eof:
33 op = bytes[ptr]
35 if op >= dis.HAVE_ARGUMENT:
37 arg = bytes[ptr + 1] + bytes[ptr + 2] * 256 + extended_arg
38 ptr += 3
40 if op == dis.EXTENDED_ARG:
41 long_type = six.integer_types[-1]
42 extended_arg = arg * long_type(65536)
43 continue
45 else:
46 arg = None
47 ptr += 1
49 yield OpArg(op, arg)
52Bytecode = getattr(dis, 'Bytecode', Bytecode_compat)
55unescape = getattr(html, 'unescape', None)
56if unescape is None:
57 # HTMLParser.unescape is deprecated since Python 3.4, and will be removed
58 # from 3.9.
59 unescape = html_parser.HTMLParser().unescape