DRY Python3 scanner code. Some cross version handling fixed.

Some Python 3.2 and 3.3 deparse fixes.
This commit is contained in:
rocky
2015-12-27 04:32:46 -05:00
parent 4640e7dece
commit 44cd349cc7
47 changed files with 1016 additions and 953 deletions

View File

@@ -11,7 +11,6 @@ other versions of Python. Also, we save token information for later
use in deparsing.
"""
import inspect
from collections import namedtuple
from array import array
@@ -145,7 +144,11 @@ class Scanner26(scan.Scanner):
continue
if op in hasconst:
const = co.co_consts[oparg]
if inspect.iscode(const):
# We can't use inspect.iscode() because we may be
# using a different version of Python than the
# one that this was byte-compiled on. So the code
# types may mismatch.
if hasattr(const, 'co_name'):
oparg = const
if const.co_name == '<lambda>':
assert op_name == 'LOAD_CONST'
@@ -901,6 +904,7 @@ class Scanner26(scan.Scanner):
return targets
if __name__ == "__main__":
import inspect
co = inspect.currentframe().f_code
tokens, customize = Scanner26().disassemble(co)
for t in tokens: