360 # search the path for the module |
360 # search the path for the module |
361 path = [] if path is None else path[:] |
361 path = [] if path is None else path[:] |
362 f = None |
362 f = None |
363 if inpackage: |
363 if inpackage: |
364 try: |
364 try: |
365 f, file, (suff, mode, type) = \ |
365 f, file, (suff, mode, type) = ClassBrowsers.find_module( |
366 ClassBrowsers.find_module(module, path) |
366 module, path) |
367 except ImportError: |
367 except ImportError: |
368 f = None |
368 f = None |
369 if f is None: |
369 if f is None: |
370 fullpath = path[:] + sys.path[:] |
370 fullpath = path[:] + sys.path[:] |
371 f, file, (suff, mode, type) = \ |
371 f, file, (suff, mode, type) = ClassBrowsers.find_module( |
372 ClassBrowsers.find_module(module, fullpath, isPyFile) |
372 module, fullpath, isPyFile) |
373 if module.endswith(".py") and type == imp.PKG_DIRECTORY: |
373 if module.endswith(".py") and type == imp.PKG_DIRECTORY: |
374 return dictionary |
374 return dictionary |
375 if type == imp.PKG_DIRECTORY: |
375 if type == imp.PKG_DIRECTORY: |
376 dictionary['__path__'] = [file] |
376 dictionary['__path__'] = [file] |
377 _modules[module] = dictionary |
377 _modules[module] = dictionary |
378 path = [file] + path |
378 path = [file] + path |
379 f, file, (suff, mode, type) = \ |
379 f, file, (suff, mode, type) = ClassBrowsers.find_module( |
380 ClassBrowsers.find_module('__init__', [file]) |
380 '__init__', [file]) |
381 if f: |
381 if f: |
382 f.close() |
382 f.close() |
383 if type not in SUPPORTED_TYPES: |
383 if type not in SUPPORTED_TYPES: |
384 # not Python source, can't do anything with this module |
384 # not Python source, can't do anything with this module |
385 _modules[module] = dictionary |
385 _modules[module] = dictionary |
442 deltastack.append(thisindent - conditionalsstack[-1]) |
442 deltastack.append(thisindent - conditionalsstack[-1]) |
443 deltaindent = reduce(lambda x, y: x + y, deltastack) |
443 deltaindent = reduce(lambda x, y: x + y, deltastack) |
444 deltaindentcalculated = 1 |
444 deltaindentcalculated = 1 |
445 thisindent -= deltaindent |
445 thisindent -= deltaindent |
446 else: |
446 else: |
447 while conditionalsstack and \ |
447 while ( |
448 conditionalsstack[-1] >= thisindent: |
448 conditionalsstack and |
|
449 conditionalsstack[-1] >= thisindent |
|
450 ): |
449 del conditionalsstack[-1] |
451 del conditionalsstack[-1] |
450 if deltastack: |
452 if deltastack: |
451 del deltastack[-1] |
453 del deltastack[-1] |
452 deltaindentcalculated = 0 |
454 deltaindentcalculated = 0 |
453 # close all classes indented at least as much |
455 # close all classes indented at least as much |
454 while classstack and \ |
456 while classstack and classstack[-1][1] >= thisindent: |
455 classstack[-1][1] >= thisindent: |
|
456 if classstack[-1][0] is not None: |
457 if classstack[-1][0] is not None: |
457 # record the end line |
458 # record the end line |
458 classstack[-1][0].setEndLine(lineno - 1) |
459 classstack[-1][0].setEndLine(lineno - 1) |
459 del classstack[-1] |
460 del classstack[-1] |
460 if classstack: |
461 if classstack: |
496 |
497 |
497 elif m.start("Class") >= 0: |
498 elif m.start("Class") >= 0: |
498 # we found a class definition |
499 # we found a class definition |
499 thisindent = _indent(m.group("ClassIndent")) |
500 thisindent = _indent(m.group("ClassIndent")) |
500 # close all classes indented at least as much |
501 # close all classes indented at least as much |
501 while classstack and \ |
502 while classstack and classstack[-1][1] >= thisindent: |
502 classstack[-1][1] >= thisindent: |
|
503 if classstack[-1][0] is not None: |
503 if classstack[-1][0] is not None: |
504 # record the end line |
504 # record the end line |
505 classstack[-1][0].setEndLine(lineno - 1) |
505 classstack[-1][0].setEndLine(lineno - 1) |
506 del classstack[-1] |
506 del classstack[-1] |
507 lineno = lineno + src.count('\n', last_lineno_pos, start) |
507 lineno = lineno + src.count('\n', last_lineno_pos, start) |
556 elif m.start("Attribute") >= 0: |
556 elif m.start("Attribute") >= 0: |
557 lineno = lineno + src.count('\n', last_lineno_pos, start) |
557 lineno = lineno + src.count('\n', last_lineno_pos, start) |
558 last_lineno_pos = start |
558 last_lineno_pos = start |
559 index = -1 |
559 index = -1 |
560 while index >= -len(classstack): |
560 while index >= -len(classstack): |
561 if classstack[index][0] is not None and \ |
561 if ( |
562 not isinstance(classstack[index][0], Function): |
562 classstack[index][0] is not None and |
|
563 not isinstance(classstack[index][0], Function) |
|
564 ): |
563 attr = Attribute( |
565 attr = Attribute( |
564 module, m.group("AttributeName"), file, lineno) |
566 module, m.group("AttributeName"), file, lineno) |
565 classstack[index][0]._addattribute(attr) |
567 classstack[index][0]._addattribute(attr) |
566 break |
568 break |
567 else: |
569 else: |
639 dictionary["@@Import@@"].addImport(mod, names, lineno) |
641 dictionary["@@Import@@"].addImport(mod, names, lineno) |
640 |
642 |
641 elif m.start("ConditionalDefine") >= 0: |
643 elif m.start("ConditionalDefine") >= 0: |
642 # a conditional function/method definition |
644 # a conditional function/method definition |
643 thisindent = _indent(m.group("ConditionalDefineIndent")) |
645 thisindent = _indent(m.group("ConditionalDefineIndent")) |
644 while conditionalsstack and \ |
646 while conditionalsstack and conditionalsstack[-1] >= thisindent: |
645 conditionalsstack[-1] >= thisindent: |
|
646 del conditionalsstack[-1] |
647 del conditionalsstack[-1] |
647 if deltastack: |
648 if deltastack: |
648 del deltastack[-1] |
649 del deltastack[-1] |
649 conditionalsstack.append(thisindent) |
650 conditionalsstack.append(thisindent) |
650 deltaindentcalculated = 0 |
651 deltaindentcalculated = 0 |