390 |
390 |
391 class Module(object): |
391 class Module(object): |
392 """ |
392 """ |
393 Class to represent a Python module. |
393 Class to represent a Python module. |
394 """ |
394 """ |
395 def __init__(self, name, file=None, type=None): |
395 def __init__(self, name, file=None, moduleType=None): |
396 """ |
396 """ |
397 Constructor |
397 Constructor |
398 |
398 |
399 @param name name of this module (string) |
399 @param name name of this module (string) |
400 @param file filename of file containing this module (string) |
400 @param file filename of file containing this module (string) |
401 @param type type of this module |
401 @param moduleType type of this module |
402 """ |
402 """ |
403 self.name = name |
403 self.name = name |
404 self.file = file |
404 self.file = file |
405 self.modules = {} |
405 self.modules = {} |
406 self.modules_counts = {} |
406 self.modules_counts = {} |
411 self.description = "" |
411 self.description = "" |
412 self.globals = {} |
412 self.globals = {} |
413 self.imports = [] |
413 self.imports = [] |
414 self.from_imports = {} |
414 self.from_imports = {} |
415 self.package = '.'.join(name.split('.')[:-1]) |
415 self.package = '.'.join(name.split('.')[:-1]) |
416 self.type = type |
416 self.type = moduleType |
417 if type in [imp.PY_SOURCE, PTL_SOURCE]: |
417 if moduleType in [imp.PY_SOURCE, PTL_SOURCE]: |
418 self._getnext = _py_getnext |
418 self._getnext = _py_getnext |
419 elif type == RB_SOURCE: |
419 elif moduleType == RB_SOURCE: |
420 self._getnext = _rb_getnext |
420 self._getnext = _rb_getnext |
421 else: |
421 else: |
422 self._getnext = None |
422 self._getnext = None |
423 |
423 |
424 def addClass(self, name, _class): |
424 def addClass(self, name, _class): |
493 if self.type in [imp.PY_SOURCE, PTL_SOURCE]: |
493 if self.type in [imp.PY_SOURCE, PTL_SOURCE]: |
494 self.__py_scan(src) |
494 self.__py_scan(src) |
495 elif self.type == RB_SOURCE: |
495 elif self.type == RB_SOURCE: |
496 self.__rb_scan(src) |
496 self.__rb_scan(src) |
497 |
497 |
498 def __py_setVisibility(self, object): |
498 def __py_setVisibility(self, objectRef): |
499 """ |
499 """ |
500 Private method to set the visibility of an object. |
500 Private method to set the visibility of an object. |
501 |
501 |
502 @param object reference to the object (Attribute, Class or Function) |
502 @param objectRef reference to the object (Attribute, Class or Function) |
503 """ |
503 """ |
504 if object.name.startswith('__'): |
504 if objectRef.name.startswith('__'): |
505 object.setPrivate() |
505 objectRef.setPrivate() |
506 elif object.name.startswith('_'): |
506 elif objectRef.name.startswith('_'): |
507 object.setProtected() |
507 objectRef.setProtected() |
508 else: |
508 else: |
509 object.setPublic() |
509 objectRef.setPublic() |
510 |
510 |
511 def __py_scan(self, src): |
511 def __py_scan(self, src): |
512 """ |
512 """ |
513 Private method to scan the source text of a Python module and retrieve |
513 Private method to scan the source text of a Python module and retrieve |
514 the relevant information. |
514 the relevant information. |
1222 @return type of the modules's source (string) |
1222 @return type of the modules's source (string) |
1223 """ |
1223 """ |
1224 if self.type in [imp.PY_SOURCE, PTL_SOURCE]: |
1224 if self.type in [imp.PY_SOURCE, PTL_SOURCE]: |
1225 py3ExtList = Preferences.getDebugger("Python3Extensions").split() |
1225 py3ExtList = Preferences.getDebugger("Python3Extensions").split() |
1226 if self.file.endswith(tuple(py3ExtList)): |
1226 if self.file.endswith(tuple(py3ExtList)): |
1227 type = "Python3" |
1227 moduleType = "Python3" |
1228 else: |
1228 else: |
1229 type = "Python2" |
1229 moduleType = "Python2" |
1230 elif self.type == RB_SOURCE: |
1230 elif self.type == RB_SOURCE: |
1231 type = "Ruby" |
1231 moduleType = "Ruby" |
1232 else: |
1232 else: |
1233 type = "" |
1233 moduleType = "" |
1234 return type |
1234 return moduleType |
1235 |
1235 |
1236 |
1236 |
1237 class Class(VisibilityBase): |
1237 class Class(VisibilityBase): |
1238 """ |
1238 """ |
1239 Class to represent a Python class. |
1239 Class to represent a Python class. |
1240 """ |
1240 """ |
1241 def __init__(self, module, name, super, file, lineno): |
1241 def __init__(self, module, name, superClasses, file, lineno): |
1242 """ |
1242 """ |
1243 Constructor |
1243 Constructor |
1244 |
1244 |
1245 @param module name of module containing this class (string) |
1245 @param module name of module containing this class (string) |
1246 @param name name of the class (string) |
1246 @param name name of the class (string) |
1247 @param super list of classnames this class is inherited from |
1247 @param superClasses list of classnames this class is inherited from |
1248 (list of strings) |
1248 (list of strings) |
1249 @param file name of file containing this class (string) |
1249 @param file name of file containing this class (string) |
1250 @param lineno linenumber of the class definition (integer) |
1250 @param lineno linenumber of the class definition (integer) |
1251 """ |
1251 """ |
1252 self.module = module |
1252 self.module = module |
1253 self.name = name |
1253 self.name = name |
1254 if super is None: |
1254 if superClasses is None: |
1255 super = [] |
1255 superClasses = [] |
1256 self.super = super |
1256 self.super = superClasses |
1257 self.methods = {} |
1257 self.methods = {} |
1258 self.attributes = {} |
1258 self.attributes = {} |
1259 self.globals = {} |
1259 self.globals = {} |
1260 self.file = file |
1260 self.file = file |
1261 self.lineno = lineno |
1261 self.lineno = lineno |
1519 |
1519 |
1520 # search the path for the module |
1520 # search the path for the module |
1521 f = None |
1521 f = None |
1522 if inpackage: |
1522 if inpackage: |
1523 try: |
1523 try: |
1524 f, file, (suff, mode, type) = find_module( |
1524 f, file, (suff, mode, moduleType) = find_module( |
1525 module, path, _extensions) |
1525 module, path, _extensions) |
1526 except ImportError: |
1526 except ImportError: |
1527 f = None |
1527 f = None |
1528 if f is None: |
1528 if f is None: |
1529 fullpath = list(path) + sys.path |
1529 fullpath = list(path) + sys.path |
1530 f, file, (suff, mode, type) = find_module( |
1530 f, file, (suff, mode, moduleType) = find_module( |
1531 module, fullpath, _extensions) |
1531 module, fullpath, _extensions) |
1532 if f: |
1532 if f: |
1533 f.close() |
1533 f.close() |
1534 if type not in SUPPORTED_TYPES: |
1534 if moduleType not in SUPPORTED_TYPES: |
1535 # not supported source, can't do anything with this module |
1535 # not supported source, can't do anything with this module |
1536 _modules[modname] = Module(modname, None, None) |
1536 _modules[modname] = Module(modname, None, None) |
1537 return _modules[modname] |
1537 return _modules[modname] |
1538 |
1538 |
1539 mod = Module(modname, file, type) |
1539 mod = Module(modname, file, moduleType) |
1540 try: |
1540 try: |
1541 src = Utilities.readEncodedFile(file)[0] |
1541 src = Utilities.readEncodedFile(file)[0] |
1542 mod.scan(src) |
1542 mod.scan(src) |
1543 except (UnicodeError, IOError): |
1543 except (UnicodeError, IOError): |
1544 pass |
1544 pass |