160 re.VERBOSE | re.DOTALL | re.MULTILINE, |
160 re.VERBOSE | re.DOTALL | re.MULTILINE, |
161 ).search |
161 ).search |
162 |
162 |
163 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub |
163 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub |
164 |
164 |
165 _modules = {} # cache of modules we've seen |
|
166 |
|
167 |
|
168 def clearModulesCache(): |
|
169 """ |
|
170 Function to clear the cached modules. |
|
171 """ |
|
172 _modules.clear() |
|
173 |
|
174 |
165 |
175 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): |
166 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): |
176 """ |
167 """ |
177 Mixin class implementing the notion of visibility. |
168 Mixin class implementing the notion of visibility. |
178 """ |
169 """ |
273 @param isTypeFile flag indicating a file of this type |
264 @param isTypeFile flag indicating a file of this type |
274 @type bool |
265 @type bool |
275 @return the resulting dictionary |
266 @return the resulting dictionary |
276 @rtype dict |
267 @rtype dict |
277 """ |
268 """ |
278 global _modules |
|
279 |
|
280 if module in _modules: |
|
281 # we've seen this file before... |
|
282 return _modules[module] |
|
283 |
|
284 # search the path for the file |
269 # search the path for the file |
285 f = None |
270 f = None |
286 fullpath = [] if path is None else path[:] |
271 fullpath = [] if path is None else path[:] |
287 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) |
272 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) |
288 if f: |
273 if f: |
289 f.close() |
274 f.close() |
290 if type not in SUPPORTED_TYPES: |
275 if type not in SUPPORTED_TYPES: |
291 # not Ruby source, can't do anything with this module |
276 # not Ruby source, can't do anything with this module |
292 _modules[module] = {} |
|
293 return {} |
277 return {} |
294 |
278 |
295 try: |
279 try: |
296 src = Utilities.readEncodedFile(file)[0] |
280 src = Utilities.readEncodedFile(file)[0] |
297 except (UnicodeError, OSError): |
281 except (UnicodeError, OSError): |
298 # can't do anything with this module |
282 # can't do anything with this module |
299 _modules[module] = {} |
|
300 return {} |
283 return {} |
301 |
284 |
302 _modules[module] = scan(src, file, module) |
285 return scan(src, file, module) |
303 return _modules[module] |
|
304 |
286 |
305 |
287 |
306 def scan(src, file, module): |
288 def scan(src, file, module): |
307 """ |
289 """ |
308 Public method to scan the given source text. |
290 Public method to scan the given source text. |