Utilities/ModuleParser.py

changeset 2997
7f0ef975da9e
parent 2965
d133c7edd88a
child 3030
4a0a82ddd9d2
child 3057
10516539f238
equal deleted inserted replaced
2996:c6f16f1b9958 2997:7f0ef975da9e
23 23
24 import Utilities 24 import Utilities
25 from functools import reduce 25 from functools import reduce
26 import Preferences 26 import Preferences
27 27
28 __all__ = ["Module", "Class", "Function", "Attribute", "RbModule", "readModule", 28 __all__ = ["Module", "Class", "Function", "Attribute", "RbModule",
29 "getTypeFromTypeName"] 29 "readModule", "getTypeFromTypeName"]
30 30
31 TABWIDTH = 4 31 TABWIDTH = 4
32 32
33 PTL_SOURCE = 128 33 PTL_SOURCE = 128
34 RB_SOURCE = 129 34 RB_SOURCE = 129
121 (?P<MethodModifierIndent> [ \t]* ) 121 (?P<MethodModifierIndent> [ \t]* )
122 (?P<MethodModifierType> @classmethod | @staticmethod ) 122 (?P<MethodModifierType> @classmethod | @staticmethod )
123 ) 123 )
124 124
125 | (?P<Method> 125 | (?P<Method>
126 (^ [ \t]* @ (?: PyQt4 \. )? (?: QtCore \. )? (?: pyqtSignature | pyqtSlot ) 126 (^ [ \t]* @ (?: PyQt4 \. )? (?: QtCore \. )?
127 (?: pyqtSignature | pyqtSlot )
127 [ \t]* \( 128 [ \t]* \(
128 (?P<MethodPyQtSignature> [^)]* ) 129 (?P<MethodPyQtSignature> [^)]* )
129 \) \s* 130 \) \s*
130 )? 131 )?
131 ^ 132 ^
213 | (?P<Method> 214 | (?P<Method>
214 ^ 215 ^
215 (?P<MethodIndent> [ \t]* ) 216 (?P<MethodIndent> [ \t]* )
216 def [ \t]+ 217 def [ \t]+
217 (?: 218 (?:
218 (?P<MethodName2> [a-zA-Z0-9_]+ (?: \. | :: ) [a-zA-Z_] [a-zA-Z0-9_?!=]* ) 219 (?P<MethodName2> [a-zA-Z0-9_]+ (?: \. | :: )
220 [a-zA-Z_] [a-zA-Z0-9_?!=]* )
219 | 221 |
220 (?P<MethodName> [a-zA-Z_] [a-zA-Z0-9_?!=]* ) 222 (?P<MethodName> [a-zA-Z_] [a-zA-Z0-9_?!=]* )
221 | 223 |
222 (?P<MethodName3> [^( \t]{1,3} ) 224 (?P<MethodName3> [^( \t]{1,3} )
223 ) 225 )
266 ^ 268 ^
267 (?P<AccessControlIndent> [ \t]* ) 269 (?P<AccessControlIndent> [ \t]* )
268 (?: 270 (?:
269 (?P<AccessControlType> private | public | protected ) [^_] 271 (?P<AccessControlType> private | public | protected ) [^_]
270 | 272 |
271 (?P<AccessControlType2> private_class_method | public_class_method ) 273 (?P<AccessControlType2>
274 private_class_method | public_class_method )
272 ) 275 )
273 \(? 276 \(?
274 [ \t]* 277 [ \t]*
275 (?P<AccessControlList> (?: : [a-zA-Z0-9_]+ , \s* )* (?: : [a-zA-Z0-9_]+ )+ )? 278 (?P<AccessControlList> (?: : [a-zA-Z0-9_]+ , \s* )*
279 (?: : [a-zA-Z0-9_]+ )+ )?
276 [ \t]* 280 [ \t]*
277 \)? 281 \)?
278 ) 282 )
279 283
280 | (?P<Attribute> 284 | (?P<Attribute>
289 (?P<AttrIndent> [ \t]* ) 293 (?P<AttrIndent> [ \t]* )
290 attr 294 attr
291 (?P<AttrType> (?: _accessor | _reader | _writer ) )? 295 (?P<AttrType> (?: _accessor | _reader | _writer ) )?
292 \(? 296 \(?
293 [ \t]* 297 [ \t]*
294 (?P<AttrList> (?: : [a-zA-Z0-9_]+ , \s* )* (?: : [a-zA-Z0-9_]+ | true | false )+ ) 298 (?P<AttrList> (?: : [a-zA-Z0-9_]+ , \s* )*
299 (?: : [a-zA-Z0-9_]+ | true | false )+ )
295 [ \t]* 300 [ \t]*
296 \)? 301 \)?
297 ) 302 )
298 303
299 | (?P<Begin> 304 | (?P<Begin>
469 """ 474 """
470 self.description = description 475 self.description = description
471 476
472 def scan(self, src): 477 def scan(self, src):
473 """ 478 """
474 Public method to scan the source text and retrieve the relevant information. 479 Public method to scan the source text and retrieve the relevant
480 information.
475 481
476 @param src the source text to be scanned (string) 482 @param src the source text to be scanned (string)
477 """ 483 """
478 if self.type in [imp.PY_SOURCE, PTL_SOURCE]: 484 if self.type in [imp.PY_SOURCE, PTL_SOURCE]:
479 self.__py_scan(src) 485 self.__py_scan(src)
493 else: 499 else:
494 object.setPublic() 500 object.setPublic()
495 501
496 def __py_scan(self, src): 502 def __py_scan(self, src):
497 """ 503 """
498 Private method to scan the source text of a Python module and retrieve the 504 Private method to scan the source text of a Python module and retrieve
499 relevant information. 505 the relevant information.
500 506
501 @param src the source text to be scanned (string) 507 @param src the source text to be scanned (string)
502 """ 508 """
503 lineno, last_lineno_pos = 1, 0 509 lineno, last_lineno_pos = 1, 0
504 lastGlobalEntry = None 510 lastGlobalEntry = None
549 modifier = Function.General 555 modifier = Function.General
550 # modify indentation level for conditional defines 556 # modify indentation level for conditional defines
551 if conditionalsstack: 557 if conditionalsstack:
552 if thisindent > conditionalsstack[-1]: 558 if thisindent > conditionalsstack[-1]:
553 if not deltaindentcalculated: 559 if not deltaindentcalculated:
554 deltastack.append(thisindent - conditionalsstack[-1]) 560 deltastack.append(
555 deltaindent = reduce(lambda x, y: x + y, deltastack) 561 thisindent - conditionalsstack[-1])
562 deltaindent = reduce(
563 lambda x, y: x + y, deltastack)
556 deltaindentcalculated = 1 564 deltaindentcalculated = 1
557 thisindent -= deltaindent 565 thisindent -= deltaindent
558 else: 566 else:
559 while conditionalsstack and \ 567 while conditionalsstack and \
560 conditionalsstack[-1] >= thisindent: 568 conditionalsstack[-1] >= thisindent:
579 if cur_class is None: 587 if cur_class is None:
580 continue 588 continue
581 589
582 if isinstance(cur_class, Class): 590 if isinstance(cur_class, Class):
583 # it's a class method 591 # it's a class method
584 f = Function(None, meth_name, None, lineno, 592 f = Function(
585 meth_sig, meth_pyqtSig, modifierType=modifier) 593 None, meth_name, None, lineno,
594 meth_sig, meth_pyqtSig, modifierType=modifier)
586 self.__py_setVisibility(f) 595 self.__py_setVisibility(f)
587 cur_class.addMethod(meth_name, f) 596 cur_class.addMethod(meth_name, f)
588 break 597 break
589 else: 598 else:
590 # it's a nested function of a module function 599 # it's a nested function of a module function
591 f = Function(self.name, meth_name, self.file, lineno, 600 f = Function(
592 meth_sig, meth_pyqtSig, modifierType=modifier) 601 self.name, meth_name, self.file, lineno,
602 meth_sig, meth_pyqtSig, modifierType=modifier)
593 self.__py_setVisibility(f) 603 self.__py_setVisibility(f)
594 self.addFunction(meth_name, f) 604 self.addFunction(meth_name, f)
595 else: 605 else:
596 # it's a module function 606 # it's a module function
597 f = Function(self.name, meth_name, self.file, lineno, 607 f = Function(self.name, meth_name, self.file, lineno,
698 last_lineno_pos = start 708 last_lineno_pos = start
699 index = -1 709 index = -1
700 while index >= -len(classstack): 710 while index >= -len(classstack):
701 if classstack[index][0] is not None: 711 if classstack[index][0] is not None:
702 attrName = m.group("AttributeName") 712 attrName = m.group("AttributeName")
703 attr = Attribute(self.name, attrName, self.file, lineno) 713 attr = Attribute(
714 self.name, attrName, self.file, lineno)
704 self.__py_setVisibility(attr) 715 self.__py_setVisibility(attr)
705 classstack[index][0].addAttribute(attrName, attr) 716 classstack[index][0].addAttribute(attrName, attr)
706 break 717 break
707 else: 718 else:
708 index -= 1 719 index -= 1
713 isSignal = m.group("VariableSignal") != "" 724 isSignal = m.group("VariableSignal") != ""
714 lineno = lineno + src.count('\n', last_lineno_pos, start) 725 lineno = lineno + src.count('\n', last_lineno_pos, start)
715 last_lineno_pos = start 726 last_lineno_pos = start
716 if thisindent == 0: 727 if thisindent == 0:
717 # global variable 728 # global variable
718 attr = Attribute(self.name, variable_name, self.file, lineno, 729 attr = Attribute(
719 isSignal=isSignal) 730 self.name, variable_name, self.file, lineno,
731 isSignal=isSignal)
720 self.__py_setVisibility(attr) 732 self.__py_setVisibility(attr)
721 self.addGlobal(variable_name, attr) 733 self.addGlobal(variable_name, attr)
722 if lastGlobalEntry: 734 if lastGlobalEntry:
723 lastGlobalEntry.setEndLine(lineno - 1) 735 lastGlobalEntry.setEndLine(lineno - 1)
724 lastGlobalEntry = None 736 lastGlobalEntry = None
728 if classstack[index][1] >= thisindent: 740 if classstack[index][1] >= thisindent:
729 index -= 1 741 index -= 1
730 else: 742 else:
731 if classstack[index][0] is not None and \ 743 if classstack[index][0] is not None and \
732 isinstance(classstack[index][0], Class): 744 isinstance(classstack[index][0], Class):
733 attr = Attribute(self.name, variable_name, self.file, 745 attr = Attribute(
734 lineno, isSignal=isSignal) 746 self.name, variable_name, self.file,
747 lineno, isSignal=isSignal)
735 self.__py_setVisibility(attr) 748 self.__py_setVisibility(attr)
736 classstack[index][0].addGlobal(variable_name, attr) 749 classstack[index][0].addGlobal(
750 variable_name, attr)
737 break 751 break
738 752
739 elif m.start("Import") >= 0: 753 elif m.start("Import") >= 0:
740 # import module 754 # import module
741 names = [n.strip() for n in "".join( 755 names = [n.strip() for n in
742 m.group("ImportList").splitlines()).replace("\\", "").split(',')] 756 "".join(m.group("ImportList").splitlines())
757 .replace("\\", "").split(',')]
743 for name in names: 758 for name in names:
744 if not name in self.imports: 759 if not name in self.imports:
745 self.imports.append(name) 760 self.imports.append(name)
746 761
747 elif m.start("ImportFrom") >= 0: 762 elif m.start("ImportFrom") >= 0:
748 # from module import stuff 763 # from module import stuff
749 mod = m.group("ImportFromPath") 764 mod = m.group("ImportFromPath")
750 names = [n.strip() for n in "".join( 765 names = [n.strip() for n in
751 m.group("ImportFromList").splitlines()).replace("\\", "").split(',')] 766 "".join(m.group("ImportFromList").splitlines())
767 .replace("\\", "").split(',')]
752 if mod not in self.from_imports: 768 if mod not in self.from_imports:
753 self.from_imports[mod] = [] 769 self.from_imports[mod] = []
754 self.from_imports[mod].extend(names) 770 self.from_imports[mod].extend(names)
755 771
756 elif m.start("ConditionalDefine") >= 0: 772 elif m.start("ConditionalDefine") >= 0:
769 785
770 modulelevel = 0 786 modulelevel = 0
771 787
772 def __rb_scan(self, src): 788 def __rb_scan(self, src):
773 """ 789 """
774 Private method to scan the source text of a Python module and retrieve the 790 Private method to scan the source text of a Python module and retrieve
775 relevant information. 791 the relevant information.
776 792
777 @param src the source text to be scanned (string) 793 @param src the source text to be scanned (string)
778 """ 794 """
779 lineno, last_lineno_pos = 1, 0 795 lineno, last_lineno_pos = 1, 0
780 classstack = [] # stack of (class, indent) pairs 796 classstack = [] # stack of (class, indent) pairs
806 meth_name = meth_name[6:] 822 meth_name = meth_name[6:]
807 # close all classes/modules indented at least as much 823 # close all classes/modules indented at least as much
808 while classstack and \ 824 while classstack and \
809 classstack[-1][1] >= thisindent: 825 classstack[-1][1] >= thisindent:
810 if classstack[-1][0] is not None and \ 826 if classstack[-1][0] is not None and \
811 isinstance(classstack[-1][0], (Class, Function, RbModule)): 827 isinstance(classstack[-1][0],
828 (Class, Function, RbModule)):
812 # record the end line of this class, function or module 829 # record the end line of this class, function or module
813 classstack[-1][0].setEndLine(lineno - 1) 830 classstack[-1][0].setEndLine(lineno - 1)
814 del classstack[-1] 831 del classstack[-1]
815 while acstack and \ 832 while acstack and \
816 acstack[-1][1] >= thisindent: 833 acstack[-1][1] >= thisindent:
831 None, lineno, meth_sig) 848 None, lineno, meth_sig)
832 cur_class.addMethod(meth_name, f) 849 cur_class.addMethod(meth_name, f)
833 break 850 break
834 else: 851 else:
835 # it's a nested function of a module function 852 # it's a nested function of a module function
836 f = Function(self.name, meth_name, self.file, lineno, meth_sig) 853 f = Function(
854 self.name, meth_name, self.file, lineno, meth_sig)
837 self.addFunction(meth_name, f) 855 self.addFunction(meth_name, f)
838 # set access control 856 # set access control
839 if acstack: 857 if acstack:
840 accesscontrol = acstack[-1][0] 858 accesscontrol = acstack[-1][0]
841 if accesscontrol == "private": 859 if accesscontrol == "private":
844 f.setProtected() 862 f.setProtected()
845 elif accesscontrol == "public": 863 elif accesscontrol == "public":
846 f.setPublic() 864 f.setPublic()
847 else: 865 else:
848 # it's a function 866 # it's a function
849 f = Function(self.name, meth_name, self.file, lineno, meth_sig) 867 f = Function(
868 self.name, meth_name, self.file, lineno, meth_sig)
850 self.addFunction(meth_name, f) 869 self.addFunction(meth_name, f)
851 if not classstack: 870 if not classstack:
852 if lastGlobalEntry: 871 if lastGlobalEntry:
853 lastGlobalEntry.setEndLine(lineno - 1) 872 lastGlobalEntry.setEndLine(lineno - 1)
854 lastGlobalEntry = f 873 lastGlobalEntry = f
881 last_lineno_pos = start 900 last_lineno_pos = start
882 # close all classes/modules indented at least as much 901 # close all classes/modules indented at least as much
883 while classstack and \ 902 while classstack and \
884 classstack[-1][1] >= thisindent: 903 classstack[-1][1] >= thisindent:
885 if classstack[-1][0] is not None and \ 904 if classstack[-1][0] is not None and \
886 isinstance(classstack[-1][0], (Class, Function, RbModule)): 905 isinstance(classstack[-1][0],
906 (Class, Function, RbModule)):
887 # record the end line of this class, function or module 907 # record the end line of this class, function or module
888 classstack[-1][0].setEndLine(lineno - 1) 908 classstack[-1][0].setEndLine(lineno - 1)
889 del classstack[-1] 909 del classstack[-1]
890 class_name = m.group("ClassName") or m.group("ClassName2") 910 class_name = m.group("ClassName") or m.group("ClassName2")
891 inherit = m.group("ClassSupers") 911 inherit = m.group("ClassSupers")
929 last_lineno_pos = start 949 last_lineno_pos = start
930 # close all classes/modules indented at least as much 950 # close all classes/modules indented at least as much
931 while classstack and \ 951 while classstack and \
932 classstack[-1][1] >= thisindent: 952 classstack[-1][1] >= thisindent:
933 if classstack[-1][0] is not None and \ 953 if classstack[-1][0] is not None and \
934 isinstance(classstack[-1][0], (Class, Function, RbModule)): 954 isinstance(classstack[-1][0],
955 (Class, Function, RbModule)):
935 # record the end line of this class, function or module 956 # record the end line of this class, function or module
936 classstack[-1][0].setEndLine(lineno - 1) 957 classstack[-1][0].setEndLine(lineno - 1)
937 del classstack[-1] 958 del classstack[-1]
938 module_name = m.group("ModuleName") 959 module_name = m.group("ModuleName")
939 # remember this class 960 # remember this class
960 aclist = m.group("AccessControlList") 981 aclist = m.group("AccessControlList")
961 if aclist is None: 982 if aclist is None:
962 index = -1 983 index = -1
963 while index >= -len(acstack): 984 while index >= -len(acstack):
964 if acstack[index][1] < indent: 985 if acstack[index][1] < indent:
965 actype = m.group("AccessControlType") or \ 986 actype = \
966 m.group("AccessControlType2").split('_')[0] 987 m.group("AccessControlType") or \
988 m.group("AccessControlType2").split('_')[0]
967 acstack[index][0] = actype.lower() 989 acstack[index][0] = actype.lower()
968 break 990 break
969 else: 991 else:
970 index -= 1 992 index -= 1
971 else: 993 else:
973 while index >= -len(classstack): 995 while index >= -len(classstack):
974 if classstack[index][0] is not None and \ 996 if classstack[index][0] is not None and \
975 not isinstance(classstack[index][0], Function) and \ 997 not isinstance(classstack[index][0], Function) and \
976 not classstack[index][1] >= indent: 998 not classstack[index][1] >= indent:
977 parent = classstack[index][0] 999 parent = classstack[index][0]
978 actype = m.group("AccessControlType") or \ 1000 actype = \
979 m.group("AccessControlType2").split('_')[0] 1001 m.group("AccessControlType") or \
1002 m.group("AccessControlType2").split('_')[0]
980 actype = actype.lower() 1003 actype = actype.lower()
981 for name in aclist.split(","): 1004 for name in aclist.split(","):
982 name = name.strip()[1:] # get rid of leading ':' 1005 # get rid of leading ':'
1006 name = name.strip()[1:]
983 acmeth = parent.getMethod(name) 1007 acmeth = parent.getMethod(name)
984 if acmeth is None: 1008 if acmeth is None:
985 continue 1009 continue
986 if actype == "private": 1010 if actype == "private":
987 acmeth.setPrivate() 1011 acmeth.setPrivate()
1000 while index >= -len(classstack): 1024 while index >= -len(classstack):
1001 if classstack[index][0] is not None and \ 1025 if classstack[index][0] is not None and \
1002 not isinstance(classstack[index][0], Function) and \ 1026 not isinstance(classstack[index][0], Function) and \
1003 not classstack[index][1] >= indent: 1027 not classstack[index][1] >= indent:
1004 attrName = m.group("AttributeName") 1028 attrName = m.group("AttributeName")
1005 attr = Attribute(self.name, attrName, self.file, lineno) 1029 attr = Attribute(
1030 self.name, attrName, self.file, lineno)
1006 if attrName.startswith("@@") or attrName[0].isupper(): 1031 if attrName.startswith("@@") or attrName[0].isupper():
1007 classstack[index][0].addGlobal(attrName, attr) 1032 classstack[index][0].addGlobal(attrName, attr)
1008 else: 1033 else:
1009 classstack[index][0].addAttribute(attrName, attr) 1034 classstack[index][0].addAttribute(attrName, attr)
1010 break 1035 break
1011 else: 1036 else:
1012 index -= 1 1037 index -= 1
1013 else: 1038 else:
1014 attrName = m.group("AttributeName") 1039 attrName = m.group("AttributeName")
1015 if attrName[0] != "@": 1040 if attrName[0] != "@":
1016 attr = Attribute(self.name, attrName, self.file, lineno) 1041 attr = Attribute(
1042 self.name, attrName, self.file, lineno)
1017 self.addGlobal(attrName, attr) 1043 self.addGlobal(attrName, attr)
1018 if lastGlobalEntry: 1044 if lastGlobalEntry:
1019 lastGlobalEntry.setEndLine(lineno - 1) 1045 lastGlobalEntry.setEndLine(lineno - 1)
1020 lastGlobalEntry = None 1046 lastGlobalEntry = None
1021 1047
1030 parent = classstack[index][0] 1056 parent = classstack[index][0]
1031 if m.group("AttrType") is None: 1057 if m.group("AttrType") is None:
1032 nv = m.group("AttrList").split(",") 1058 nv = m.group("AttrList").split(",")
1033 if not nv: 1059 if not nv:
1034 break 1060 break
1035 name = nv[0].strip()[1:] # get rid of leading ':' 1061 # get rid of leading ':'
1062 name = nv[0].strip()[1:]
1036 attr = parent.getAttribute("@" + name) or \ 1063 attr = parent.getAttribute("@" + name) or \
1037 parent.getAttribute("@@" + name) or \ 1064 parent.getAttribute("@@" + name) or \
1038 Attribute(self.name, "@" + name, self.file, lineno) 1065 Attribute(
1066 self.name, "@" + name, self.file, lineno)
1039 if len(nv) == 1 or nv[1].strip() == "false": 1067 if len(nv) == 1 or nv[1].strip() == "false":
1040 attr.setProtected() 1068 attr.setProtected()
1041 elif nv[1].strip() == "true": 1069 elif nv[1].strip() == "true":
1042 attr.setPublic() 1070 attr.setPublic()
1043 parent.addAttribute(attr.name, attr) 1071 parent.addAttribute(attr.name, attr)
1044 else: 1072 else:
1045 access = m.group("AttrType") 1073 access = m.group("AttrType")
1046 for name in m.group("AttrList").split(","): 1074 for name in m.group("AttrList").split(","):
1047 name = name.strip()[1:] # get rid of leading ':' 1075 # get rid of leading ':'
1076 name = name.strip()[1:]
1048 attr = parent.getAttribute("@" + name) or \ 1077 attr = parent.getAttribute("@" + name) or \
1049 parent.getAttribute("@@" + name) or \ 1078 parent.getAttribute("@@" + name) or \
1050 Attribute(self.name, "@" + name, self.file, lineno) 1079 Attribute(
1080 self.name, "@" + name, self.file,
1081 lineno)
1051 if access == "_accessor": 1082 if access == "_accessor":
1052 attr.setPublic() 1083 attr.setPublic()
1053 elif access == "_reader" or access == "_writer": 1084 elif access == "_reader" or \
1085 access == "_writer":
1054 if attr.isPrivate(): 1086 if attr.isPrivate():
1055 attr.setProtected() 1087 attr.setProtected()
1056 elif attr.isProtected(): 1088 elif attr.isProtected():
1057 attr.setPublic() 1089 attr.setPublic()
1058 parent.addAttribute(attr.name, attr) 1090 parent.addAttribute(attr.name, attr)
1081 else: 1113 else:
1082 assert 0, "regexp _getnext found something unexpected" 1114 assert 0, "regexp _getnext found something unexpected"
1083 1115
1084 def createHierarchy(self): 1116 def createHierarchy(self):
1085 """ 1117 """
1086 Public method to build the inheritance hierarchy for all classes of this module. 1118 Public method to build the inheritance hierarchy for all classes of
1119 this module.
1087 1120
1088 @return A dictionary with inheritance hierarchies. 1121 @return A dictionary with inheritance hierarchies.
1089 """ 1122 """
1090 hierarchy = {} 1123 hierarchy = {}
1091 for cls in list(list(self.classes.keys())): 1124 for cls in list(list(self.classes.keys())):
1114 for cls in classes[name].super: 1147 for cls in classes[name].super:
1115 if cls not in classes: 1148 if cls not in classes:
1116 rv[cls] = {} 1149 rv[cls] = {}
1117 exhausted = path + [cls] 1150 exhausted = path + [cls]
1118 exhausted.reverse() 1151 exhausted.reverse()
1119 self.addPathToHierarchy(exhausted, result, self.addPathToHierarchy) 1152 self.addPathToHierarchy(
1153 exhausted, result, self.addPathToHierarchy)
1120 else: 1154 else:
1121 rv[cls] = self.assembleHierarchy(cls, 1155 rv[cls] = self.assembleHierarchy(cls,
1122 classes, path + [cls], result) 1156 classes, path + [cls], result)
1123 1157
1124 if len(rv) == 0: 1158 if len(rv) == 0:
1313 """ 1347 """
1314 General = 0 1348 General = 0
1315 Static = 1 1349 Static = 1
1316 Class = 2 1350 Class = 2
1317 1351
1318 def __init__(self, module, name, file, lineno, signature='', pyqtSignature=None, 1352 def __init__(self, module, name, file, lineno, signature='',
1319 modifierType=General): 1353 pyqtSignature=None, modifierType=General):
1320 """ 1354 """
1321 Constructor 1355 Constructor
1322 1356
1323 @param module name of module containing this function (string) 1357 @param module name of module containing this function (string)
1324 @param name name of the function (string) 1358 @param name name of the function (string)
1381 1415
1382 def addAssignment(self, lineno): 1416 def addAssignment(self, lineno):
1383 """ 1417 """
1384 Public method to add another assignment line number. 1418 Public method to add another assignment line number.
1385 1419
1386 @param lineno linenumber of the additional attribute assignment (integer) 1420 @param lineno linenumber of the additional attribute assignment
1421 (integer)
1387 """ 1422 """
1388 if lineno not in self.linenos: 1423 if lineno not in self.linenos:
1389 self.linenos.append(lineno) 1424 self.linenos.append(lineno)
1390 1425
1391 1426
1460 1495
1461 # search the path for the module 1496 # search the path for the module
1462 f = None 1497 f = None
1463 if inpackage: 1498 if inpackage:
1464 try: 1499 try:
1465 f, file, (suff, mode, type) = find_module(module, path, _extensions) 1500 f, file, (suff, mode, type) = find_module(
1501 module, path, _extensions)
1466 except ImportError: 1502 except ImportError:
1467 f = None 1503 f = None
1468 if f is None: 1504 if f is None:
1469 fullpath = list(path) + sys.path 1505 fullpath = list(path) + sys.path
1470 f, file, (suff, mode, type) = find_module(module, fullpath, _extensions) 1506 f, file, (suff, mode, type) = find_module(
1507 module, fullpath, _extensions)
1471 if f: 1508 if f:
1472 f.close() 1509 f.close()
1473 if type not in SUPPORTED_TYPES: 1510 if type not in SUPPORTED_TYPES:
1474 # not supported source, can't do anything with this module 1511 # not supported source, can't do anything with this module
1475 _modules[modname] = Module(modname, None, None) 1512 _modules[modname] = Module(modname, None, None)
1518 for p in path: # only search in path 1555 for p in path: # only search in path
1519 if os.path.exists(os.path.join(p, name)): 1556 if os.path.exists(os.path.join(p, name)):
1520 pathname = os.path.join(p, name) 1557 pathname = os.path.join(p, name)
1521 if ext == '.ptl': 1558 if ext == '.ptl':
1522 # Quixote page template 1559 # Quixote page template
1523 return (open(pathname), pathname, ('.ptl', 'r', PTL_SOURCE)) 1560 return (open(pathname), pathname,
1561 ('.ptl', 'r', PTL_SOURCE))
1524 elif ext == '.rb': 1562 elif ext == '.rb':
1525 # Ruby source file 1563 # Ruby source file
1526 return (open(pathname), pathname, ('.rb', 'r', RB_SOURCE)) 1564 return (open(pathname), pathname,
1565 ('.rb', 'r', RB_SOURCE))
1527 else: 1566 else:
1528 return (open(pathname), pathname, (ext, 'r', imp.PY_SOURCE)) 1567 return (open(pathname), pathname,
1568 (ext, 'r', imp.PY_SOURCE))
1529 raise ImportError 1569 raise ImportError
1530 1570
1531 # standard Python module file 1571 # standard Python module file
1532 if name.lower().endswith('.py'): 1572 if name.lower().endswith('.py'):
1533 name = name[:-3] 1573 name = name[:-3]
1560 if basename: 1600 if basename:
1561 module = module.replace(basename, "") 1601 module = module.replace(basename, "")
1562 modname = module.replace(os.sep, '.') 1602 modname = module.replace(os.sep, '.')
1563 else: 1603 else:
1564 modname = os.path.basename(module) 1604 modname = os.path.basename(module)
1565 if modname.lower().endswith(".ptl") or modname.lower().endswith(".pyw"): 1605 if modname.lower().endswith(".ptl") or \
1606 modname.lower().endswith(".pyw"):
1566 modname = modname[:-4] 1607 modname = modname[:-4]
1567 elif modname.lower().endswith(".rb"): 1608 elif modname.lower().endswith(".rb"):
1568 modname = modname[:-3] 1609 modname = modname[:-3]
1569 module = os.path.basename(module) 1610 module = os.path.basename(module)
1570 1611

eric ide

mercurial