Utilities/ClassBrowsers/pyclbr.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3039
8dd0165d805d
child 3145
a9de05d4a22f
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
104 ) 104 )
105 105
106 | (?P<CodingLine> 106 | (?P<CodingLine>
107 ^ \# \s* [*_-]* \s* coding[:=] \s* (?P<Coding> [-\w_.]+ ) \s* [*_-]* $ 107 ^ \# \s* [*_-]* \s* coding[:=] \s* (?P<Coding> [-\w_.]+ ) \s* [*_-]* $
108 ) 108 )
109 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search 109 """, re.VERBOSE | re.DOTALL | re.MULTILINE).search # __IGNORE_WARNING__
110 110
111 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub 111 _commentsub = re.compile(r"""#[^\n]*\n|#[^\n]*$""").sub
112 112
113 _modules = {} # cache of modules we've seen 113 _modules = {} # cache of modules we've seen
114 114
201 """ 201 """
202 self.module = module 202 self.module = module
203 self.name = '__all__' 203 self.name = '__all__'
204 self.file = file 204 self.file = file
205 self.lineno = lineno 205 self.lineno = lineno
206 self.identifiers = [e.replace('"', '').replace("'", "").strip() \ 206 self.identifiers = [e.replace('"', '').replace("'", "").strip()
207 for e in idents.split(',')] 207 for e in idents.split(',')]
208 208
209 209
210 def readmodule_ex(module, path=[], inpackage=False, isPyFile=False): 210 def readmodule_ex(module, path=[], inpackage=False, isPyFile=False):
211 """ 211 """
237 # search the path for the module 237 # search the path for the module
238 f = None 238 f = None
239 if inpackage: 239 if inpackage:
240 try: 240 try:
241 f, file, (suff, mode, type) = \ 241 f, file, (suff, mode, type) = \
242 ClassBrowsers.find_module(module, path) 242 ClassBrowsers.find_module(module, path)
243 except ImportError: 243 except ImportError:
244 f = None 244 f = None
245 if f is None: 245 if f is None:
246 fullpath = list(path) + sys.path 246 fullpath = list(path) + sys.path
247 f, file, (suff, mode, type) = \ 247 f, file, (suff, mode, type) = \
251 if type == imp.PKG_DIRECTORY: 251 if type == imp.PKG_DIRECTORY:
252 dict['__path__'] = [file] 252 dict['__path__'] = [file]
253 _modules[module] = dict 253 _modules[module] = dict
254 path = [file] + path 254 path = [file] + path
255 f, file, (suff, mode, type) = \ 255 f, file, (suff, mode, type) = \
256 ClassBrowsers.find_module('__init__', [file]) 256 ClassBrowsers.find_module('__init__', [file])
257 if f: 257 if f:
258 f.close() 258 f.close()
259 if type not in SUPPORTED_TYPES: 259 if type not in SUPPORTED_TYPES:
260 # not Python source, can't do anything with this module 260 # not Python source, can't do anything with this module
261 _modules[module] = dict 261 _modules[module] = dict
316 deltaindent = reduce(lambda x, y: x + y, deltastack) 316 deltaindent = reduce(lambda x, y: x + y, deltastack)
317 deltaindentcalculated = 1 317 deltaindentcalculated = 1
318 thisindent -= deltaindent 318 thisindent -= deltaindent
319 else: 319 else:
320 while conditionalsstack and \ 320 while conditionalsstack and \
321 conditionalsstack[-1] >= thisindent: 321 conditionalsstack[-1] >= thisindent:
322 del conditionalsstack[-1] 322 del conditionalsstack[-1]
323 if deltastack: 323 if deltastack:
324 del deltastack[-1] 324 del deltastack[-1]
325 deltaindentcalculated = 0 325 deltaindentcalculated = 0
326 # close all classes indented at least as much 326 # close all classes indented at least as much
327 while classstack and \ 327 while classstack and \
328 classstack[-1][1] >= thisindent: 328 classstack[-1][1] >= thisindent:
329 if classstack[-1][0] is not None: 329 if classstack[-1][0] is not None:
330 # record the end line 330 # record the end line
331 classstack[-1][0].setEndLine(lineno - 1) 331 classstack[-1][0].setEndLine(lineno - 1)
332 del classstack[-1] 332 del classstack[-1]
333 if classstack: 333 if classstack:
368 elif m.start("Class") >= 0: 368 elif m.start("Class") >= 0:
369 # we found a class definition 369 # we found a class definition
370 thisindent = _indent(m.group("ClassIndent")) 370 thisindent = _indent(m.group("ClassIndent"))
371 # close all classes indented at least as much 371 # close all classes indented at least as much
372 while classstack and \ 372 while classstack and \
373 classstack[-1][1] >= thisindent: 373 classstack[-1][1] >= thisindent:
374 if classstack[-1][0] is not None: 374 if classstack[-1][0] is not None:
375 # record the end line 375 # record the end line
376 classstack[-1][0].setEndLine(lineno - 1) 376 classstack[-1][0].setEndLine(lineno - 1)
377 del classstack[-1] 377 del classstack[-1]
378 lineno = lineno + src.count('\n', last_lineno_pos, start) 378 lineno = lineno + src.count('\n', last_lineno_pos, start)
473 473
474 elif m.start("ConditionalDefine") >= 0: 474 elif m.start("ConditionalDefine") >= 0:
475 # a conditional function/method definition 475 # a conditional function/method definition
476 thisindent = _indent(m.group("ConditionalDefineIndent")) 476 thisindent = _indent(m.group("ConditionalDefineIndent"))
477 while conditionalsstack and \ 477 while conditionalsstack and \
478 conditionalsstack[-1] >= thisindent: 478 conditionalsstack[-1] >= thisindent:
479 del conditionalsstack[-1] 479 del conditionalsstack[-1]
480 if deltastack: 480 if deltastack:
481 del deltastack[-1] 481 del deltastack[-1]
482 conditionalsstack.append(thisindent) 482 conditionalsstack.append(thisindent)
483 deltaindentcalculated = 0 483 deltaindentcalculated = 0

eric ide

mercurial