Find import statements in the code Generate triplets (name, level, fromlist) where name is the imported module and level, fromlist are the corresponding args to __import__.
(co)
| 993 | return |
| 994 | |
| 995 | def _find_imports(co): |
| 996 | """Find import statements in the code |
| 997 | |
| 998 | Generate triplets (name, level, fromlist) where |
| 999 | name is the imported module and level, fromlist are |
| 1000 | the corresponding args to __import__. |
| 1001 | """ |
| 1002 | IMPORT_NAME = opmap['IMPORT_NAME'] |
| 1003 | |
| 1004 | consts = co.co_consts |
| 1005 | names = co.co_names |
| 1006 | opargs = [(op, arg) for _, _, op, arg in _unpack_opargs(co.co_code) |
| 1007 | if op != EXTENDED_ARG] |
| 1008 | for i, (op, oparg) in enumerate(opargs): |
| 1009 | if op == IMPORT_NAME and i >= 2: |
| 1010 | from_op = opargs[i-1] |
| 1011 | level_op = opargs[i-2] |
| 1012 | if (from_op[0] in hasconst and |
| 1013 | (level_op[0] in hasconst or level_op[0] == LOAD_SMALL_INT)): |
| 1014 | level = _get_const_value(level_op[0], level_op[1], consts) |
| 1015 | fromlist = _get_const_value(from_op[0], from_op[1], consts) |
| 1016 | yield (names[oparg], level, fromlist) |
| 1017 | |
| 1018 | def _find_store_names(co): |
| 1019 | """Find names of variables which are written in the code |
nothing calls this directly
no test coverage detected