Skip to content

Commit 184cdd3

Browse files
authored
Merge pull request python-security#98 from python-security/stmt_and_expr_visitors
Make stmt_visitor and expr_visitor
2 parents 90a6d09 + 435463a commit 184cdd3

20 files changed

+538
-545
lines changed

.coveragerc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
[report]
22
exclude_lines =
3-
if __name__ == .__main__.:
4-
raise NotImplementedError
5-
pass
63
def print_lattice
4+
def print_report
75
def print_table
6+
def valid_date
87
def __repr__
98
def __str__
9+
if __name__ == .__main__.:
10+
pass
11+
pragma: no cover
12+
raise NotImplementedError
1013

1114
[run]
1215
source = ./pyt
@@ -15,6 +18,6 @@ omit =
1518
pyt/definition_chains.py
1619
pyt/draw.py
1720
pyt/github_search.py
18-
pyt/intraprocedural_cfg.py
21+
pyt/liveness.py
1922
pyt/repo_runner.py
2023
pyt/save.py

.pre-commit-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
hooks:
44
- id: trailing-whitespace
55
- id: end-of-file-fixer
6-
- id: autopep8-wrapper
76
- id: check-docstring-first
87
- id: debug-statements
98
- id: check-ast
109
- id: check-symlinks
11-
- id: name-tests-test
12-
exclude: tests/util
1310
- id: flake8
1411
args: ['--ignore=E501']

pyt/__main__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
print_table
2020
)
2121
from .draw import draw_cfgs, draw_lattices
22+
from .expr_visitor import make_cfg
2223
from .fixed_point import analyse
2324
from .framework_adaptor import FrameworkAdaptor
2425
from .framework_helper import (
@@ -28,7 +29,6 @@
2829
is_function_without_leading_
2930
)
3031
from .github_search import scan_github, set_github_api_token
31-
from .interprocedural_cfg import interprocedural
3232
from .lattice import print_lattice
3333
from .liveness import LivenessAnalysis
3434
from .project_handler import get_directory_modules, get_modules
@@ -183,13 +183,13 @@ def analyse_repo(github_repo, analysis_type, ui_mode):
183183
project_modules = get_modules(directory)
184184
local_modules = get_directory_modules(directory)
185185
tree = generate_ast(github_repo.path)
186-
interprocedural_cfg = interprocedural(
186+
cfg = make_cfg(
187187
tree,
188188
project_modules,
189189
local_modules,
190190
github_repo.path
191191
)
192-
cfg_list.append(interprocedural_cfg)
192+
cfg_list.append(cfg)
193193

194194
initialize_constraint_table(cfg_list)
195195
analyse(cfg_list, analysis_type=analysis_type)
@@ -256,14 +256,13 @@ def main(command_line_args=sys.argv[1:]):
256256
tree = generate_ast(path, python_2=args.python_2)
257257

258258
cfg_list = list()
259-
260-
interprocedural_cfg = interprocedural(
259+
cfg = make_cfg(
261260
tree,
262261
project_modules,
263262
local_modules,
264263
path
265264
)
266-
cfg_list.append(interprocedural_cfg)
265+
cfg_list.append(cfg)
267266
framework_route_criteria = is_flask_route_function
268267
if args.adaptor:
269268
if args.adaptor.lower().startswith('e'):

pyt/alias_helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module contains helper functions for the interprocedural_cfg module."""
1+
"""This module contains alias helper functions for the expr_visitor module."""
22

33
def as_alias_handler(alias_list):
44
"""Returns a list of all the names that will be called."""

pyt/analysis_base.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,10 @@ class AnalysisBase(metaclass=ABCMeta):
77

88
annotated_cfg_nodes = dict()
99

10-
def __init__(self, cfg, visitor):
11-
"""Annotate visitor if not None and save visitor."""
12-
if visitor:
13-
self.annotate_cfg(cfg, visitor)
14-
self.visitor = visitor
10+
def __init__(self, cfg):
1511
self.cfg = cfg
1612
self.build_lattice(cfg)
1713

18-
def annotate_cfg(self, cfg, visitor):
19-
"""Add the visitor to the cfg nodes."""
20-
for node in cfg.nodes:
21-
if node.ast_node:
22-
_visitor = visitor()
23-
_visitor.visit(node.ast_node)
24-
self.annotated_cfg_nodes[node] = _visitor.result
25-
2614
@staticmethod
2715
@abstractmethod
2816
def get_lattice_elements(cfg_nodes):

pyt/ast_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
python_2_mode = False
1111

1212

13-
def convert_to_3(path):
13+
def convert_to_3(path): # pragma: no cover
1414
"""Convert python 2 file to python 3."""
1515
try:
1616
print('##### Trying to convert file to Python 3. #####')
@@ -30,13 +30,13 @@ def generate_ast(path, python_2=False):
3030
"""
3131
# If set, it stays set.
3232
global python_2_mode
33-
if python_2:
33+
if python_2: # pragma: no cover
3434
python_2_mode = True
3535
if os.path.isfile(path):
3636
with open(path, 'r') as f:
3737
try:
3838
return ast.parse(f.read())
39-
except SyntaxError:
39+
except SyntaxError: # pragma: no cover
4040
global recursive
4141
if not recursive:
4242
if not python_2_mode:

0 commit comments

Comments
 (0)