How to use the astor.parse_file function in astor

To help you get started, we’ve selected a few astor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coinse / pyggi / pyggi / program.py View on Github external
"""
        assert isinstance(granularity_level, GranularityLevel)
        if granularity_level == GranularityLevel.LINE:
            contents = {}
            for target in target_files:
                with open(os.path.join(path, target), 'r') as target_file:
                    contents[target] = list(
                        map(str.rstrip, target_file.readlines()))
            return contents
        elif granularity_level == GranularityLevel.AST:
            import ast
            import astor
            contents = {}
            for target in target_files:
                if cls.is_python_code(target):
                    root = astor.parse_file(os.path.join(path, target))
                    contents[target] = root
                else:
                    raise Exception('Program', '{} file is not supported'.format(cls.get_file_extension(target)))
            return contents
        return None
github coinse / pyggi / pyggi / tree / engine.py View on Github external
def get_contents(self, file_path):
        return astor.parse_file(file_path)
github coinse / pyggi / pyggi / tree / astor_engine.py View on Github external
def get_contents(cls, file_path):
        return astor.parse_file(file_path)