FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pyt/pyt/module_definitions.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
/
pyt
/
module_definitions.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
94 lines (68 loc) · 2.79 KB
Breadcrumbs
pyt
/
pyt
/
module_definitions.py
Copy path
File metadata and controls
94 lines (68 loc) · 2.79 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""This module handles module definitions which basically is a list of module definition."""
project_definitions
=
dict
()
# Contains all project definitions for a program run
class
ModuleDefinition
():
"""Handling of a definition."""
name
=
None
node
=
None
path
=
None
module_definitions
=
None
def
__init__
(
self
,
local_module_definitions
,
name
,
parent_module_name
,
path
):
if
parent_module_name
:
self
.
name
=
parent_module_name
+
'.'
+
name
else
:
self
.
name
=
name
self
.
path
=
path
self
.
module_definitions
=
local_module_definitions
def
__str__
(
self
):
name
=
'NoName'
node
=
'NoNode'
if
self
.
name
:
name
=
self
.
name
if
self
.
node
:
node
=
str
(
self
.
node
)
return
self
.
__class__
.
__name__
+
': '
+
';'
.
join
((
name
,
node
))
class
LocalModuleDefinition
(
ModuleDefinition
):
"""A local definition."""
pass
class
ModuleDefinitions
():
"""A collection of module definition.
Adds to the project definitions list.
"""
def
__init__
(
self
,
import_names
=
None
,
module_name
=
None
):
"""Optionally set import names and module name.
Module name should only be set when it is a normal import statement.
"""
self
.
definitions
=
list
()
self
.
module_name
=
module_name
self
.
classes
=
list
()
self
.
import_names
=
import_names
def
append
(
self
,
definition
):
"""Add definition to list.
Handles localdefinitions and adds to project_definitions.
"""
if
isinstance
(
definition
,
LocalModuleDefinition
):
self
.
definitions
.
append
(
definition
)
elif
self
.
import_names
and
definition
.
name
in
self
.
import_names
:
self
.
definitions
.
append
(
definition
)
if
not
definition
.
node
in
project_definitions
:
project_definitions
[
definition
.
node
]
=
definition
def
is_import
(
self
):
"""Return whether it is a normal import statement and not a from import.
This can be checked by checking the module name as it is only set when it is a normal import.
"""
return
self
.
module_name
def
get_definition
(
self
,
name
):
"""Get definitions by name."""
for
definition
in
self
.
definitions
:
if
definition
.
name
==
name
:
return
definition
def
set_defintion_node
(
self
,
node
,
name
):
"""Set definition by name."""
definition
=
self
.
get_definition
(
name
)
if
definition
:
definition
.
node
=
node
def
__str__
(
self
):
module
=
'NoModuleName'
if
self
.
module_name
:
module
=
self
.
module_name
return
'Definitions: '
+
' '
.
join
([
str
(
definition
)
for
definition
in
self
.
definitions
])
+
'
\n
module_name: '
+
module
+
'
\n
'
Back
|
FazBrowse Home
|
New Git URL