FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pyt/func_counter.py at 8githubScanRefactor · python-security/pyt · GitHub
python-security
pyt
Repository navigation
Code
Issues
26
(26)
Pull requests
2
(2)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pyt
/
func_counter.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (39 loc) · 1.37 KB
Breadcrumbs
pyt
/
func_counter.py
Copy path
File metadata and controls
49 lines (39 loc) · 1.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Module used for counting number of functions
to get an estimate og how big the CFG should be"""
import
ast
from
pyt
.
cfg
import
get_call_names_as_string
,
generate_ast
from
pyt
.
project_handler
import
get_python_modules
function_calls
=
list
()
functions
=
dict
()
classes
=
dict
()
class
Counter
(
ast
.
NodeVisitor
):
def
visit_Call
(
self
,
node
):
n
=
get_call_names_as_string
(
node
.
func
)
function_calls
.
append
(
n
)
self
.
generic_visit
(
node
)
# Husk return, save vars overhead
def
visit_FunctionDef
(
self
,
node
):
if
node
.
name
in
functions
:
node
.
name
+=
'¤'
functions
[
node
.
name
]
=
len
(
node
.
body
)
for
n
in
node
.
body
:
self
.
visit
(
n
)
def
visit_ClassDef
(
self
,
node
):
if
node
.
name
in
classes
:
node
.
name
+=
'¤'
classes
[
node
.
name
]
=
len
(
node
.
body
)
for
n
in
node
.
body
:
self
.
visit
(
n
)
if
__name__
==
'__main__'
:
module_paths
=
(
m
[
1
]
for
m
in
get_python_modules
(
'../flaskbb/flaskbb'
))
for
p
in
module_paths
:
print
(
p
)
t
=
generate_ast
(
p
)
c
=
Counter
()
c
.
visit
(
t
)
max_func_len
=
max
(
functions
.
values
())
max_class_len
=
max
(
classes
.
values
())
restore_stuff
=
6
# varies
print
(
len
(
function_calls
))
print
(
'estimate stuff: '
,
max_func_len
*
len
(
function_calls
))
print
(
'estimate stuff: '
,
max_class_len
*
len
(
function_calls
))
Back
|
FazBrowse Home
|
New Git URL