eric6/Utilities/ClassBrowsers/protoclbr.py

changeset 7690
a59680062837
parent 7685
0b6e8c0d6403
child 7695
032a0586a349
equal deleted inserted replaced
7689:147236d850a4 7690:a59680062837
188 signature, 188 signature,
189 annotation="-> {0}".format(returns)) 189 annotation="-> {0}".format(returns))
190 VisibilityMixin.__init__(self) 190 VisibilityMixin.__init__(self)
191 191
192 192
193 # TODO: extract scan function (see pyclbr)
194 def readmodule_ex(module, path=None): 193 def readmodule_ex(module, path=None):
195 """ 194 """
196 Read a ProtoBuf protocol file and return a dictionary of messages, enums, 195 Read a ProtoBuf protocol file and return a dictionary of messages, enums,
197 services and rpc methods. 196 services and rpc methods.
198 197
203 @return the resulting dictionary 202 @return the resulting dictionary
204 @rtype dict 203 @rtype dict
205 """ 204 """
206 global _modules 205 global _modules
207 206
208 dictionary = {}
209
210 if module in _modules: 207 if module in _modules:
211 # we've seen this file before... 208 # we've seen this file before...
212 return _modules[module] 209 return _modules[module]
213 210
214 # search the path for the file 211 # search the path for the file
217 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) 214 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath)
218 if f: 215 if f:
219 f.close() 216 f.close()
220 if type not in SUPPORTED_TYPES: 217 if type not in SUPPORTED_TYPES:
221 # not ProtoBuf protocol source, can't do anything with this module 218 # not ProtoBuf protocol source, can't do anything with this module
222 _modules[module] = dictionary 219 _modules[module] = {}
223 return dictionary 220 return {}
224 221
225 _modules[module] = dictionary
226 classstack = [] # stack of (class, indent) pairs
227 indent = 0
228 try: 222 try:
229 src = Utilities.readEncodedFile(file)[0] 223 src = Utilities.readEncodedFile(file)[0]
230 except (UnicodeError, IOError): 224 except (UnicodeError, IOError):
231 # can't do anything with this module 225 # can't do anything with this module
232 _modules[module] = dictionary 226 _modules[module] = {}
233 return dictionary 227 return {}
228
229 _modules[module] = scan(src, file, module)
230 return _modules[module]
231
232
233 def scan(src, file, module):
234 """
235 Public method to scan the given source text.
236
237 @param src source text to be scanned
238 @type str
239 @param file file name associated with the source text
240 @type str
241 @param module module name associated with the source text
242 @type str
243 @return dictionary containing the extracted data
244 @rtype dict
245 """
234 # convert eol markers the Python style 246 # convert eol markers the Python style
235 src = src.replace("\r\n", "\n").replace("\r", "\n") 247 src = src.replace("\r\n", "\n").replace("\r", "\n")
248
249 dictionary = {}
250
251 classstack = [] # stack of (class, indent) pairs
252 indent = 0
236 253
237 lineno, last_lineno_pos = 1, 0 254 lineno, last_lineno_pos = 1, 0
238 lastGlobalEntry = None 255 lastGlobalEntry = None
239 cur_obj = None 256 cur_obj = None
240 i = 0 257 i = 0

eric ide

mercurial