FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/rope/base/ast.py at master · MightyWing/pythonVSCode · GitHub
MightyWing
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
rope
/
base
/
ast.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
76 lines (64 loc) · 2.23 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
rope
/
base
/
ast.py
Copy path
File metadata and controls
76 lines (64 loc) · 2.23 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
import
_ast
from
_ast
import
*
from
rope
.
base
import
fscommands
try
:
unicode
except
NameError
:
unicode
=
str
def
parse
(
source
,
filename
=
'<string>'
):
# NOTE: the raw string should be given to `compile` function
if
isinstance
(
source
,
unicode
):
source
=
fscommands
.
unicode_to_file_data
(
source
)
if
b'
\r
'
in
source
:
source
=
source
.
replace
(
b'
\r
\n
'
,
b'
\n
'
).
replace
(
b'
\r
'
,
b'
\n
'
)
if
not
source
.
endswith
(
b'
\n
'
):
source
+=
b'
\n
'
try
:
return
compile
(
source
,
filename
,
'exec'
,
_ast
.
PyCF_ONLY_AST
)
except
(
TypeError
,
ValueError
)
as
e
:
error
=
SyntaxError
()
error
.
lineno
=
1
error
.
filename
=
filename
error
.
msg
=
str
(
e
)
raise
error
def
walk
(
node
,
walker
):
"""Walk the syntax tree"""
method_name
=
'_'
+
node
.
__class__
.
__name__
method
=
getattr
(
walker
,
method_name
,
None
)
if
method
is
not
None
:
if
isinstance
(
node
,
_ast
.
ImportFrom
)
and
node
.
module
is
None
:
# In python < 2.7 ``node.module == ''`` for relative imports
# but for python 2.7 it is None. Generalizing it to ''.
node
.
module
=
''
return
method
(
node
)
for
child
in
get_child_nodes
(
node
):
walk
(
child
,
walker
)
def
get_child_nodes
(
node
):
if
isinstance
(
node
,
_ast
.
Module
):
return
node
.
body
result
=
[]
if
node
.
_fields
is
not
None
:
for
name
in
node
.
_fields
:
child
=
getattr
(
node
,
name
)
if
isinstance
(
child
,
list
):
for
entry
in
child
:
if
isinstance
(
entry
,
_ast
.
AST
):
result
.
append
(
entry
)
if
isinstance
(
child
,
_ast
.
AST
):
result
.
append
(
child
)
return
result
def
call_for_nodes
(
node
,
callback
,
recursive
=
False
):
"""If callback returns `True` the child nodes are skipped"""
result
=
callback
(
node
)
if
recursive
and
not
result
:
for
child
in
get_child_nodes
(
node
):
call_for_nodes
(
child
,
callback
,
recursive
)
def
get_children
(
node
):
result
=
[]
if
node
.
_fields
is
not
None
:
for
name
in
node
.
_fields
:
if
name
in
[
'lineno'
,
'col_offset'
]:
continue
child
=
getattr
(
node
,
name
)
result
.
append
(
child
)
return
result
Back
|
FazBrowse Home
|
New Git URL