|
|
@ -158,7 +158,7 @@ IMPORT_NAME = dis.opname.index('IMPORT_NAME')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _getarg(nextb, c):
|
|
|
|
def _getarg(nextb, c):
|
|
|
|
if c > dis.HAVE_ARGUMENT:
|
|
|
|
if c >= dis.HAVE_ARGUMENT:
|
|
|
|
return nextb() | (nextb() << 8)
|
|
|
|
return nextb() | (nextb() << 8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -184,9 +184,10 @@ else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def scan_code_imports(co):
|
|
|
|
def scan_code_imports(co):
|
|
|
|
"""Given a code object `co`, scan its bytecode yielding any
|
|
|
|
"""
|
|
|
|
``IMPORT_NAME`` and associated prior ``LOAD_CONST`` instructions
|
|
|
|
Given a code object `co`, scan its bytecode yielding any ``IMPORT_NAME``
|
|
|
|
representing an `Import` statement or `ImportFrom` statement.
|
|
|
|
and associated prior ``LOAD_CONST`` instructions representing an `Import`
|
|
|
|
|
|
|
|
statement or `ImportFrom` statement.
|
|
|
|
|
|
|
|
|
|
|
|
:return:
|
|
|
|
:return:
|
|
|
|
Generator producing `(level, modname, namelist)` tuples, where:
|
|
|
|
Generator producing `(level, modname, namelist)` tuples, where:
|
|
|
@ -200,6 +201,7 @@ def scan_code_imports(co):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
opit = iter_opcodes(co)
|
|
|
|
opit = iter_opcodes(co)
|
|
|
|
opit, opit2, opit3 = itertools.tee(opit, 3)
|
|
|
|
opit, opit2, opit3 = itertools.tee(opit, 3)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
next(opit2)
|
|
|
|
next(opit2)
|
|
|
|
next(opit3)
|
|
|
|
next(opit3)
|
|
|
@ -207,14 +209,22 @@ def scan_code_imports(co):
|
|
|
|
except StopIteration:
|
|
|
|
except StopIteration:
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
for oparg1, oparg2, (op3, arg3) in izip(opit, opit2, opit3):
|
|
|
|
if sys.version_info >= (2, 5):
|
|
|
|
if op3 == IMPORT_NAME:
|
|
|
|
for oparg1, oparg2, (op3, arg3) in izip(opit, opit2, opit3):
|
|
|
|
op2, arg2 = oparg2
|
|
|
|
if op3 == IMPORT_NAME:
|
|
|
|
op1, arg1 = oparg1
|
|
|
|
op2, arg2 = oparg2
|
|
|
|
if op1 == op2 == LOAD_CONST:
|
|
|
|
op1, arg1 = oparg1
|
|
|
|
yield (co.co_consts[arg1],
|
|
|
|
if op1 == op2 == LOAD_CONST:
|
|
|
|
co.co_names[arg3],
|
|
|
|
yield (co.co_consts[arg1],
|
|
|
|
co.co_consts[arg2] or ())
|
|
|
|
co.co_names[arg3],
|
|
|
|
|
|
|
|
co.co_consts[arg2] or ())
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# Python 2.4 did not yet have 'level', so stack format differs.
|
|
|
|
|
|
|
|
for oparg1, (op2, arg2) in izip(opit, opit2):
|
|
|
|
|
|
|
|
if op2 == IMPORT_NAME:
|
|
|
|
|
|
|
|
op1, arg1 = oparg1
|
|
|
|
|
|
|
|
if op1 == LOAD_CONST:
|
|
|
|
|
|
|
|
yield (-1, co.co_names[arg2], co.co_consts[arg1] or ())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ThreadWatcher(object):
|
|
|
|
class ThreadWatcher(object):
|
|
|
|