Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
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
def get_contents(self, file_path):
return astor.parse_file(file_path)
def get_contents(cls, file_path):
return astor.parse_file(file_path)