src/eric7/Utilities/ClassBrowsers/pyclbr.py

branch
eric7
changeset 9612
93b496cc3c88
parent 9510
b1c92d588478
child 9653
e67609152c5e
equal deleted inserted replaced
9611:af03537d56b2 9612:93b496cc3c88
138 re.VERBOSE | re.DOTALL | re.MULTILINE, 138 re.VERBOSE | re.DOTALL | re.MULTILINE,
139 ).search 139 ).search
140 140
141 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub 141 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub
142 142
143 _modules = {} # cache of modules we've seen
144
145
146 def clearModulesCache():
147 """
148 Function to clear the cached modules.
149 """
150 _modules.clear()
151
152 143
153 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase): 144 class VisibilityMixin(ClbrBaseClasses.ClbrVisibilityMixinBase):
154 """ 145 """
155 Mixin class implementing the notion of visibility. 146 Mixin class implementing the notion of visibility.
156 """ 147 """
367 @param isTypeFile flag indicating a file of this type 358 @param isTypeFile flag indicating a file of this type
368 @type bool 359 @type bool
369 @return the resulting dictionary 360 @return the resulting dictionary
370 @rtype dict 361 @rtype dict
371 """ 362 """
372 global _modules
373
374 if module in _modules:
375 # we've seen this module before...
376 return _modules[module]
377 if module in sys.builtin_module_names:
378 # this is a built-in module
379 _modules[module] = {}
380 return {}
381
382 # search the path for the module 363 # search the path for the module
383 path = [] if path is None else path[:] 364 path = [] if path is None else path[:]
384 f = None 365 f = None
385 if f is None: 366 if f is None:
386 fullpath = path[:] + sys.path[:] 367 fullpath = path[:] + sys.path[:]
389 ) 370 )
390 if f: 371 if f:
391 f.close() 372 f.close()
392 if type not in SUPPORTED_TYPES: 373 if type not in SUPPORTED_TYPES:
393 # not Python source, can't do anything with this module 374 # not Python source, can't do anything with this module
394 _modules[module] = {}
395 return {} 375 return {}
396 376
397 try: 377 try:
398 src = Utilities.readEncodedFile(file)[0] 378 src = Utilities.readEncodedFile(file)[0]
399 except (UnicodeError, OSError): 379 except (UnicodeError, OSError):
400 # can't do anything with this module 380 # can't do anything with this module
401 _modules[module] = {}
402 return {} 381 return {}
403 382
404 _modules[module] = scan(src, file, module) 383 return scan(src, file, module)
405 return _modules[module]
406 384
407 385
408 def scan(src, file, module): 386 def scan(src, file, module):
409 """ 387 """
410 Public method to scan the given source text. 388 Public method to scan the given source text.
450 src = src.replace("\r\n", "\n").replace("\r", "\n") 428 src = src.replace("\r\n", "\n").replace("\r", "\n")
451 srcLines = src.splitlines() 429 srcLines = src.splitlines()
452 430
453 dictionary = {} 431 dictionary = {}
454 dict_counts = {} 432 dict_counts = {}
433
434 modules = {}
455 435
456 classstack = [] # stack of (class, indent) pairs 436 classstack = [] # stack of (class, indent) pairs
457 conditionalsstack = [] # stack of indents of conditional defines 437 conditionalsstack = [] # stack of indents of conditional defines
458 deltastack = [] 438 deltastack = []
459 deltaindent = 0 439 deltaindent = 0
585 # form module.class: 565 # form module.class:
586 # look in 566 # look in
587 # module for class 567 # module for class
588 m = c[-2] 568 m = c[-2]
589 c = c[-1] 569 c = c[-1]
590 if m in _modules: 570 if m in modules:
591 d = _modules[m] 571 d = modules[m]
592 n = d.get(c, n) 572 n = d.get(c, n)
593 names.append(n) 573 names.append(n)
594 inherit = names 574 inherit = names
595 # modify indentation level for conditional defines 575 # modify indentation level for conditional defines
596 if conditionalsstack: 576 if conditionalsstack:

eric ide

mercurial