Lines Matching +full:helper +full:- +full:module +full:- +full:imports
1 """Parse a Python module and describe its classes and methods.
3 Parse enough of a Python file to recognize imports and class and
7 readmodule_ex(module [, path])
8 where module is the name of a Python module, and path is an optional
9 list of directories where the module is to be searched. If present,
12 the classes defined in the module (including classes that are defined
18 A class is described by the class Class in this module. Instances
20 module -- the module name
21 name -- the name of the class
22 super -- a list of super classes (Class instances)
23 methods -- a dictionary of methods
24 file -- the file in which the class was defined
25 lineno -- the line in the file on which the class statement occurred
34 A function is described by the class Function in this module.
36 module -- the module name
37 name -- the name of the class
38 file -- the file in which the class was defined
39 lineno -- the line in the file on which the class statement occurred
55 def __init__(self, module, name, super, file, lineno): argument
56 self.module = module
69 '''Class to represent a top-level Python function'''
70 def __init__(self, module, name, file, lineno): argument
71 self.module = module
76 def readmodule(module, path=None): argument
83 for key, value in _readmodule(module, path or []).items():
88 def readmodule_ex(module, path=None): argument
89 '''Read a module file and return a dictionary of classes.
91 Search for MODULE in PATH and sys.path, read and parse the
92 module and return a dictionary with one entry for each class
93 found in the module.
95 return _readmodule(module, path or [])
97 def _readmodule(module, path, inpackage=None): argument
102 package search path; otherwise, we are searching for a top-level
103 module, and PATH is combined with sys.path.
105 # Compute the full module name (prepending inpackage if set)
107 fullmodule = "%s.%s" % (inpackage, module)
109 fullmodule = module
115 # Initialize the dict for this module's contents
118 # Check if it is a built-in module; we don't do much for these
119 if module in sys.builtin_module_names and inpackage is None:
120 _modules[module] = dict
123 # Check for a dotted module name
124 i = module.rfind('.')
126 package = module[:i]
127 submodule = module[i+1:]
135 # Search the path for the module
138 f, fname, (_s, _m, ty) = imp.find_module(module, path)
140 f, fname, (_s, _m, ty) = imp.find_module(module, path + sys.path)
147 # not Python source, can't do anything with this module
159 while stack and stack[-1][1] >= thisindent:
160 del stack[-1]
164 while stack and stack[-1][1] >= thisindent:
165 del stack[-1]
170 cur_class = stack[-1][0]
183 while stack and stack[-1][1] >= thisindent:
184 del stack[-1]
207 # module.class: look in module for
209 m = c[-2]
210 c = c[-1]
220 level -= 1
239 # Recursively read the imported module
248 # If we can't find or parse the imported module,
249 # too bad -- don't die here.
257 # Recursively read the imported module
260 # If we can't find or parse the imported module,
261 # too bad -- don't die here.
263 # add any classes that were defined in the imported module
280 # Helper to get a comma-separated list of dotted names plus 'as'
300 # Helper to get a dotted name, return a pair (name, token) where
326 mod = mod[:-3]