Debian Codegraph @

rpython/tool/jitlogparser/module_finder.py

raw symbols SCIP
1
2 import os, sys, marshal, types, struct, imp
3
4 def _all_codes_from(code):
5 res = {}
6 more = [code]
7 while more:
8 next = more.pop()
9 res[(next.co_firstlineno, next.co_name)] = next
10 more += [co for co in next.co_consts
11 if isinstance(co, types.CodeType)]
12 return res
13
14 def gather_all_code_objs(fname):
15 """ Gathers all code objects from a give fname and sorts them by
16 starting lineno
17 """
18 fname = str(fname)
19 if fname.endswith('.pyc'):
20 code = compile(open(fname[:-1]).read(), fname, 'exec')
21 elif fname.endswith('.py'):
22 code = compile(open(fname).read(), fname, 'exec')
23 else:
24 raise Exception("Unknown file extension: %s" % fname)
25 return _all_codes_from(code)