Utilities/ClassBrowsers/__init__.py

changeset 5977
8a0ec75b0f73
parent 5651
982465f8389c
child 6048
82ad8ec9548c
equal deleted inserted replaced
5976:549918576245 5977:8a0ec75b0f73
9 Currently it offers class browser support for the following 9 Currently it offers class browser support for the following
10 programming languages. 10 programming languages.
11 11
12 <ul> 12 <ul>
13 <li>CORBA IDL</li> 13 <li>CORBA IDL</li>
14 <li>Python</li> 14 <li>JavaScript</li>
15 <li>ProtoBuf</li>
16 <li>Python 2</li>
17 <li>Python 3</li>
15 <li>Ruby</li> 18 <li>Ruby</li>
16 </ul> 19 </ul>
17 """ 20 """
18 21
19 from __future__ import unicode_literals 22 from __future__ import unicode_literals
27 PY_SOURCE = imp.PY_SOURCE 30 PY_SOURCE = imp.PY_SOURCE
28 PTL_SOURCE = 128 31 PTL_SOURCE = 128
29 RB_SOURCE = 129 32 RB_SOURCE = 129
30 IDL_SOURCE = 130 33 IDL_SOURCE = 130
31 JS_SOURCE = 131 34 JS_SOURCE = 131
35 PROTO_SOURCE = 132
32 36
33 SUPPORTED_TYPES = [PY_SOURCE, PTL_SOURCE, RB_SOURCE, IDL_SOURCE, JS_SOURCE] 37 SUPPORTED_TYPES = [PY_SOURCE, PTL_SOURCE, RB_SOURCE, IDL_SOURCE, JS_SOURCE,
38 PROTO_SOURCE]
34 39
35 __extensions = { 40 __extensions = {
36 "IDL": [".idl"], 41 "IDL": [".idl"],
37 "Python": [".py", ".pyw", ".ptl"], # currently not used 42 "Python": [".py", ".pyw", ".ptl"], # currently not used
38 "Ruby": [".rb"], 43 "Ruby": [".rb"],
39 "JavaScript": [".js"], 44 "JavaScript": [".js"],
45 "ProtoBuf": [".proto"],
40 } 46 }
41 47
42 48
43 def readmodule(module, path=None, isPyFile=False): 49 def readmodule(module, path=None, isPyFile=False):
44 """ 50 """
46 etc. . 52 etc. .
47 53
48 The real work of parsing the source file is delegated to the individual 54 The real work of parsing the source file is delegated to the individual
49 file parsers. 55 file parsers.
50 56
51 @param module name of the source file (string) 57 @param module name of the source file
52 @param path path the file should be searched in (list of strings) 58 @type str
53 @param isPyFile flag indicating a Python file (boolean) 59 @param path list of paths the file should be searched in
60 @type list of str
61 @param isPyFile flag indicating a Python file
62 @type bool
54 @return the resulting dictionary 63 @return the resulting dictionary
64 @rtype dict
55 """ 65 """
56 ext = os.path.splitext(module)[1].lower() 66 ext = os.path.splitext(module)[1].lower()
57 path = [] if path is None else path[:] 67 path = [] if path is None else path[:]
58 68
59 if ext in __extensions["IDL"]: 69 if ext in __extensions["IDL"]:
60 from . import idlclbr 70 from . import idlclbr
61 dictionary = idlclbr.readmodule_ex(module, path) 71 dictionary = idlclbr.readmodule_ex(module, path)
62 idlclbr._modules.clear() 72 idlclbr._modules.clear()
73 elif ext in __extensions["ProtoBuf"]:
74 from . import protoclbr
75 dictionary = protoclbr.readmodule_ex(module, path)
76 protoclbr._modules.clear()
63 elif ext in __extensions["Ruby"]: 77 elif ext in __extensions["Ruby"]:
64 from . import rbclbr 78 from . import rbclbr
65 dictionary = rbclbr.readmodule_ex(module, path) 79 dictionary = rbclbr.readmodule_ex(module, path)
66 rbclbr._modules.clear() 80 rbclbr._modules.clear()
67 elif ext in __extensions["JavaScript"] and sys.version_info[0] == 3: 81 elif ext in __extensions["JavaScript"] and sys.version_info[0] == 3:
85 99
86 def find_module(name, path, isPyFile=False): 100 def find_module(name, path, isPyFile=False):
87 """ 101 """
88 Module function to extend the Python module finding mechanism. 102 Module function to extend the Python module finding mechanism.
89 103
90 This function searches for files in the given path. If the filename 104 This function searches for files in the given list of paths. If the
91 doesn't have an extension or an extension of .py, the normal search 105 file name doesn't have an extension or an extension of .py, the normal
92 implemented in the imp module is used. For all other supported files 106 Python search implemented in the imp module is used. For all other
93 only path is searched. 107 supported files only the paths list is searched.
94 108
95 @param name filename or modulename to search for (string) 109 @param name file name or module name to search for
96 @param path search path (list of strings) 110 @type str
97 @param isPyFile flag indicating a Python file (boolean) 111 @param path search paths
112 @type list of str
113 @param isPyFile flag indicating a Python file
114 @type bool
98 @return tuple of the open file, pathname and description. Description 115 @return tuple of the open file, pathname and description. Description
99 is a tuple of file suffix, file mode and file type) 116 is a tuple of file suffix, file mode and file type)
117 @rtype tuple
100 @exception ImportError The file or module wasn't found. 118 @exception ImportError The file or module wasn't found.
101 """ 119 """
102 ext = os.path.splitext(name)[1].lower() 120 ext = os.path.splitext(name)[1].lower()
103 121
104 if ext in __extensions["Ruby"]: 122 if ext in __extensions["Ruby"]:
111 elif ext in __extensions["IDL"]: 129 elif ext in __extensions["IDL"]:
112 for p in path: # only search in path 130 for p in path: # only search in path
113 pathname = os.path.join(p, name) 131 pathname = os.path.join(p, name)
114 if os.path.exists(pathname): 132 if os.path.exists(pathname):
115 return (open(pathname), pathname, (ext, 'r', IDL_SOURCE)) 133 return (open(pathname), pathname, (ext, 'r', IDL_SOURCE))
134 raise ImportError
135
136 elif ext in __extensions["ProtoBuf"]:
137 for p in path: # only search in path
138 pathname = os.path.join(p, name)
139 if os.path.exists(pathname):
140 return (open(pathname), pathname, (ext, 'r', PROTO_SOURCE))
116 raise ImportError 141 raise ImportError
117 142
118 elif ext in __extensions["JavaScript"]: 143 elif ext in __extensions["JavaScript"]:
119 for p in path: # only search in path 144 for p in path: # only search in path
120 pathname = os.path.join(p, name) 145 pathname = os.path.join(p, name)

eric ide

mercurial