Utilities/ClassBrowsers/pyclbr.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 2997
7f0ef975da9e
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
205 self.identifiers = [e.replace('"', '').replace("'", "").strip() \ 205 self.identifiers = [e.replace('"', '').replace("'", "").strip() \
206 for e in idents.split(',')] 206 for e in idents.split(',')]
207 207
208 208
209 def readmodule_ex(module, path=[], inpackage=False, isPyFile=False): 209 def readmodule_ex(module, path=[], inpackage=False, isPyFile=False):
210 ''' 210 """
211 Read a module file and return a dictionary of classes. 211 Read a module file and return a dictionary of classes.
212 212
213 Search for MODULE in PATH and sys.path, read and parse the 213 Search for MODULE in PATH and sys.path, read and parse the
214 module and return a dictionary with one entry for each class 214 module and return a dictionary with one entry for each class
215 found in the module. 215 found in the module.
216 216
217 @param module name of the module file (string) 217 @param module name of the module file (string)
218 @param path path the module should be searched in (list of strings) 218 @param path path the module should be searched in (list of strings)
219 @param inpackage flag indicating a module inside a package is scanned 219 @param inpackage flag indicating a module inside a package is scanned
220 @param isPyFile flag indicating a Python file (boolean)
220 @return the resulting dictionary 221 @return the resulting dictionary
221 ''' 222 """
222 global _modules 223 global _modules
223 224
224 dict = {} 225 dict = {}
225 dict_counts = {} 226 dict_counts = {}
226 227
340 # it's a function 341 # it's a function
341 f = Function(module, meth_name, 342 f = Function(module, meth_name,
342 file, lineno, meth_sig, modifierType=modifier) 343 file, lineno, meth_sig, modifierType=modifier)
343 if meth_name in dict_counts: 344 if meth_name in dict_counts:
344 dict_counts[meth_name] += 1 345 dict_counts[meth_name] += 1
345 meth_name = "{0}_{1:d}".format(meth_name, dict_counts[meth_name]) 346 meth_name = "{0}_{1:d}".format(
347 meth_name, dict_counts[meth_name])
346 else: 348 else:
347 dict_counts[meth_name] = 0 349 dict_counts[meth_name] = 0
348 dict[meth_name] = f 350 dict[meth_name] = f
349 if not classstack: 351 if not classstack:
350 if lastGlobalEntry: 352 if lastGlobalEntry:
406 cur_class = Class(module, class_name, inherit, 408 cur_class = Class(module, class_name, inherit,
407 file, lineno) 409 file, lineno)
408 if not classstack: 410 if not classstack:
409 if class_name in dict_counts: 411 if class_name in dict_counts:
410 dict_counts[class_name] += 1 412 dict_counts[class_name] += 1
411 class_name = "{0}_{1:d}".format(class_name, dict_counts[class_name]) 413 class_name = "{0}_{1:d}".format(
414 class_name, dict_counts[class_name])
412 else: 415 else:
413 dict_counts[class_name] = 0 416 dict_counts[class_name] = 0
414 dict[class_name] = cur_class 417 dict[class_name] = cur_class
415 else: 418 else:
416 classstack[-1][0]._addclass(class_name, cur_class) 419 classstack[-1][0]._addclass(class_name, cur_class)
425 last_lineno_pos = start 428 last_lineno_pos = start
426 index = -1 429 index = -1
427 while index >= -len(classstack): 430 while index >= -len(classstack):
428 if classstack[index][0] is not None and \ 431 if classstack[index][0] is not None and \
429 not isinstance(classstack[index][0], Function): 432 not isinstance(classstack[index][0], Function):
430 attr = Attribute(module, m.group("AttributeName"), file, lineno) 433 attr = Attribute(
434 module, m.group("AttributeName"), file, lineno)
431 classstack[index][0]._addattribute(attr) 435 classstack[index][0]._addattribute(attr)
432 break 436 break
433 else: 437 else:
434 index -= 1 438 index -= 1
435 439
439 lineno = lineno + src.count('\n', last_lineno_pos, start) 443 lineno = lineno + src.count('\n', last_lineno_pos, start)
440 last_lineno_pos = start 444 last_lineno_pos = start
441 if thisindent == 0: 445 if thisindent == 0:
442 # global variable 446 # global variable
443 if "@@Globals@@" not in dict: 447 if "@@Globals@@" not in dict:
444 dict["@@Globals@@"] = \ 448 dict["@@Globals@@"] = ClbrBaseClasses.ClbrBase(
445 ClbrBaseClasses.ClbrBase(module, "Globals", file, lineno) 449 module, "Globals", file, lineno)
446 dict["@@Globals@@"]._addglobal( 450 dict["@@Globals@@"]._addglobal(
447 Attribute(module, variable_name, file, lineno)) 451 Attribute(module, variable_name, file, lineno))
448 if lastGlobalEntry: 452 if lastGlobalEntry:
449 lastGlobalEntry.setEndLine(lineno - 1) 453 lastGlobalEntry.setEndLine(lineno - 1)
450 lastGlobalEntry = None 454 lastGlobalEntry = None
481 # a coding statement 485 # a coding statement
482 coding = m.group("Coding") 486 coding = m.group("Coding")
483 lineno = lineno + src.count('\n', last_lineno_pos, start) 487 lineno = lineno + src.count('\n', last_lineno_pos, start)
484 last_lineno_pos = start 488 last_lineno_pos = start
485 if "@@Coding@@" not in dict: 489 if "@@Coding@@" not in dict:
486 dict["@@Coding@@"] = ClbrBaseClasses.Coding(module, file, lineno, coding) 490 dict["@@Coding@@"] = ClbrBaseClasses.Coding(
491 module, file, lineno, coding)
487 492
488 else: 493 else:
489 assert 0, "regexp _getnext found something unexpected" 494 assert 0, "regexp _getnext found something unexpected"
490 495
491 if '__all__' in dict: 496 if '__all__' in dict:

eric ide

mercurial