Utilities/ModuleParser.py

changeset 5651
982465f8389c
parent 5604
b047181a4a33
child 6048
82ad8ec9548c
equal deleted inserted replaced
5650:4c52f07c186e 5651:982465f8389c
1446 """ 1446 """
1447 if lineno not in self.linenos: 1447 if lineno not in self.linenos:
1448 self.linenos.append(lineno) 1448 self.linenos.append(lineno)
1449 1449
1450 1450
1451 def readModule(module, path=[], inpackage=False, basename="", 1451 def readModule(module, path=None, inpackage=False, basename="",
1452 extensions=None, caching=True): 1452 extensions=None, caching=True):
1453 """ 1453 """
1454 Function to read a module file and parse it. 1454 Function to read a module file and parse it.
1455 1455
1456 The module is searched in path and sys.path, read and parsed. 1456 The module is searched in path and sys.path, read and parsed.
1457 If the module was parsed before, the information is taken 1457 If the module was parsed before, the information is taken
1458 from a cache in order to speed up processing. 1458 from a cache in order to speed up processing.
1459 1459
1460 @param module Name of the module to be parsed (string) 1460 @param module name of the module to be parsed (string)
1461 @param path Searchpath for the module (list of strings) 1461 @param path search path for the module (list of strings)
1462 @param inpackage Flag indicating that module is inside a 1462 @param inpackage flag indicating that module is inside a
1463 package (boolean) 1463 package (boolean)
1464 @param basename a path basename. This basename is deleted from 1464 @param basename a path basename that is deleted from the filename of
1465 the filename of the module file to be read. (string) 1465 the module file to be read (string)
1466 @param extensions list of extensions, which should be considered valid 1466 @param extensions list of extensions, which should be considered valid
1467 source file extensions (list of strings) 1467 source file extensions (list of strings)
1468 @param caching flag indicating that the parsed module should be 1468 @param caching flag indicating that the parsed module should be
1469 cached (boolean) 1469 cached (boolean)
1470 @return reference to a Module object containing the parsed 1470 @return reference to a Module object containing the parsed
1516 if caching: 1516 if caching:
1517 _modules[modname] = mod 1517 _modules[modname] = mod
1518 return mod 1518 return mod
1519 1519
1520 # search the path for the module 1520 # search the path for the module
1521 path = [] if path is None else path[:]
1521 f = None 1522 f = None
1522 if inpackage: 1523 if inpackage:
1523 try: 1524 try:
1524 f, file, (suff, mode, moduleType) = find_module( 1525 f, file, (suff, mode, moduleType) = find_module(
1525 module, path, _extensions) 1526 module, path, _extensions)
1526 except ImportError: 1527 except ImportError:
1527 f = None 1528 f = None
1528 if f is None: 1529 if f is None:
1529 fullpath = list(path) + sys.path 1530 fullpath = path[:] + sys.path[:]
1530 f, file, (suff, mode, moduleType) = find_module( 1531 f, file, (suff, mode, moduleType) = find_module(
1531 module, fullpath, _extensions) 1532 module, fullpath, _extensions)
1532 if f: 1533 if f:
1533 f.close() 1534 f.close()
1534 if moduleType not in SUPPORTED_TYPES: 1535 if moduleType not in SUPPORTED_TYPES:

eric ide

mercurial