Python compiler 模块,parseFile() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用compiler.parseFile()

项目:RSPET    作者:panagiks    | 项目源码 | 文件源码
def installed_plugins(self):
        """List all plugins installed."""
        from os import listdir
        from fnmatch import fnmatch
        import compiler
        import inspect
        files = listdir('Plugins')
        try:
            files.remove('mount.py')
            files.remove('template.py')
        except ValueError:
            pass
        plugins = {}
        for element in files:
            if fnmatch(element, '*.py') and not fnmatch(element, '_*'):
                plug_doc = compiler.parseFile('Plugins/' + element).doc
                plug_doc = inspect.cleandoc(plug_doc)
                plugins[element[:-3]] = plug_doc # Remove .py)
        return plugins
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def parseModule(self, module_name, file_name):

        importing = False
        if file_name not in self.parse_cache:
            importing = True
            mod = compiler.parseFile(file_name)
            self.parse_cache[file_name] = mod
        else:
            mod = self.parse_cache[file_name]

        override = False
        platform_file_name = self.generatePlatformFilename(file_name)
        if self.platform and os.path.isfile(platform_file_name):
            mod = copy.deepcopy(mod)
            mod_override = compiler.parseFile(platform_file_name)
            self.merge(mod, mod_override)
            override = True

        if self.verbose:
            if override:
                print "Importing %s (Platform %s)" % (module_name, self.platform)
            elif importing:
                print "Importing %s" % (module_name)

        return mod, override
项目:snakefood    作者:Shapeways    | 项目源码 | 文件源码
def main():
    import optparse
    parser = optparse.OptionParser(__doc__.strip())
    opts, args = parser.parse_args()

    if not args:
        parser.error("You need to specify the name of Python files to print out.")

    import compiler, traceback
    for fn in args:
        print_('\n\n%s:\n' % fn)
        try:
            printAst(compiler.parseFile(fn), initlevel=1)
        except SyntaxError:
            _, e, _ = sys.exc_info()
            traceback.print_exc()
项目:networking-huawei    作者:openstack    | 项目源码 | 文件源码
def check_i18n(input_file, i18n_msg_predicates, msg_format_checkers, debug):
    input_mod = compiler.parseFile(input_file)
    v = compiler.visitor.walk(input_mod,
                              Visitor(input_file,
                                      i18n_msg_predicates,
                                      msg_format_checkers,
                                      debug),
                              ASTWalker())
    return v.error
项目:grin    作者:rkern    | 项目源码 | 文件源码
def normalize_file(filename, *args):
    """ Import-normalize a file.

    If the file is not parseable, an empty filelike object will be returned.
    """
    try:
        ast = compiler.parseFile(filename)
    except Exception, e:
        return StringIO('')
    ip = ImportPuller()
    walk(ast, ip)
    return StringIO(ip.as_string())
项目:beremiz    作者:nucleron    | 项目源码 | 文件源码
def translate(file_name, module_name, debug=False):
    f = file(file_name, "r")
    src = f.read()
    f.close()
    output = cStringIO.StringIO()
    mod = compiler.parseFile(file_name)
    t = Translator(module_name, module_name, module_name, src, debug, mod, output)
    return output.getvalue()
项目:networking-huawei    作者:libuparayil    | 项目源码 | 文件源码
def check_i18n(input_file, i18n_msg_predicates, msg_format_checkers, debug):
    input_mod = compiler.parseFile(input_file)
    v = compiler.visitor.walk(input_mod,
                              Visitor(input_file,
                                      i18n_msg_predicates,
                                      msg_format_checkers,
                                      debug),
                              ASTWalker())
    return v.error