Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
A
astor
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
astor
Commits
87c12c79
Kaydet (Commit)
87c12c79
authored
Eyl 20, 2012
tarafından
Patrick Maupin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Made codegen work with Python 3
üst
8d1b3b61
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
13 deletions
+41
-13
codegen.py
astor/codegen.py
+39
-10
test_codegen.py
test/test_codegen.py
+2
-3
No files found.
astor/codegen.py
Dosyayı görüntüle @
87c12c79
...
@@ -99,13 +99,17 @@ class SourceGenerator(ExplicitNodeVisitor):
...
@@ -99,13 +99,17 @@ class SourceGenerator(ExplicitNodeVisitor):
else
:
else
:
want_comma
.
append
(
True
)
want_comma
.
append
(
True
)
padding
=
[
None
]
*
(
len
(
node
.
args
)
-
len
(
node
.
defaults
))
def
loop_args
(
args
,
defaults
):
for
arg
,
default
in
zip
(
node
.
args
,
padding
+
node
.
defaults
):
padding
=
[
None
]
*
(
len
(
args
)
-
len
(
defaults
))
write_comma
()
for
arg
,
default
in
zip
(
args
,
padding
+
defaults
):
self
.
visit
(
arg
)
write_comma
()
if
default
is
not
None
:
self
.
visit
(
arg
)
self
.
write
(
'='
)
if
default
is
not
None
:
self
.
visit
(
default
)
self
.
write
(
'='
)
self
.
visit
(
default
)
loop_args
(
node
.
args
,
node
.
defaults
)
if
node
.
vararg
is
not
None
:
if
node
.
vararg
is
not
None
:
write_comma
()
write_comma
()
self
.
write
(
'*'
+
node
.
vararg
)
self
.
write
(
'*'
+
node
.
vararg
)
...
@@ -113,6 +117,15 @@ class SourceGenerator(ExplicitNodeVisitor):
...
@@ -113,6 +117,15 @@ class SourceGenerator(ExplicitNodeVisitor):
write_comma
()
write_comma
()
self
.
write
(
'**'
+
node
.
kwarg
)
self
.
write
(
'**'
+
node
.
kwarg
)
kwonlyargs
=
getattr
(
node
,
'kwonlyargs'
,
None
)
if
not
kwonlyargs
:
return
if
node
.
vararg
is
None
:
write_comma
()
self
.
write
(
'*'
)
loop_args
(
kwonlyargs
,
node
.
kw_defaults
)
def
decorators
(
self
,
node
):
def
decorators
(
self
,
node
):
for
decorator
in
node
.
decorator_list
:
for
decorator
in
node
.
decorator_list
:
self
.
newline
(
decorator
)
self
.
newline
(
decorator
)
...
@@ -160,7 +173,13 @@ class SourceGenerator(ExplicitNodeVisitor):
...
@@ -160,7 +173,13 @@ class SourceGenerator(ExplicitNodeVisitor):
self
.
newline
(
node
)
self
.
newline
(
node
)
self
.
write
(
'def
%
s('
%
node
.
name
)
self
.
write
(
'def
%
s('
%
node
.
name
)
self
.
signature
(
node
.
args
)
self
.
signature
(
node
.
args
)
self
.
write
(
'):'
)
returns
=
getattr
(
node
,
'returns'
,
None
)
if
returns
is
None
:
self
.
write
(
'):'
)
else
:
self
.
write
(
') ->'
)
self
.
visit
(
returns
)
self
.
write
(
':'
)
self
.
body
(
node
.
body
)
self
.
body
(
node
.
body
)
def
visit_ClassDef
(
self
,
node
):
def
visit_ClassDef
(
self
,
node
):
...
@@ -536,6 +555,12 @@ class SourceGenerator(ExplicitNodeVisitor):
...
@@ -536,6 +555,12 @@ class SourceGenerator(ExplicitNodeVisitor):
# Helper Nodes
# Helper Nodes
def
visit_arg
(
self
,
node
):
self
.
write
(
node
.
arg
)
if
node
.
annotation
is
not
None
:
self
.
write
(
': '
)
self
.
visit
(
node
.
annotation
)
def
visit_alias
(
self
,
node
):
def
visit_alias
(
self
,
node
):
self
.
write
(
node
.
name
)
self
.
write
(
node
.
name
)
if
node
.
asname
is
not
None
:
if
node
.
asname
is
not
None
:
...
@@ -557,8 +582,12 @@ class SourceGenerator(ExplicitNodeVisitor):
...
@@ -557,8 +582,12 @@ class SourceGenerator(ExplicitNodeVisitor):
if
node
.
type
is
not
None
:
if
node
.
type
is
not
None
:
self
.
write
(
' '
)
self
.
write
(
' '
)
self
.
visit
(
node
.
type
)
self
.
visit
(
node
.
type
)
if
node
.
name
is
not
None
:
name
=
node
.
name
if
name
is
not
None
:
self
.
write
(
' as '
)
self
.
write
(
' as '
)
self
.
visit
(
node
.
name
)
if
isinstance
(
name
,
str
):
self
.
write
(
name
)
else
:
self
.
visit
(
name
)
self
.
write
(
':'
)
self
.
write
(
':'
)
self
.
body
(
node
.
body
)
self
.
body
(
node
.
body
)
test/test_codegen.py
Dosyayı görüntüle @
87c12c79
...
@@ -38,8 +38,7 @@ def findpy(root):
...
@@ -38,8 +38,7 @@ def findpy(root):
def
testone
(
fname
,
f1
=
None
,
f2
=
None
):
def
testone
(
fname
,
f1
=
None
,
f2
=
None
):
try
:
try
:
ast1
=
astor
.
parsefile
(
fname
)
ast1
=
astor
.
parsefile
(
fname
)
except
SyntaxError
:
except
(
SyntaxError
,
UnicodeDecodeError
):
raise
print
(
"IGNORED
%
s"
%
fname
)
print
(
"IGNORED
%
s"
%
fname
)
return
return
dump1
=
astor
.
dump
(
ast1
)
dump1
=
astor
.
dump
(
ast1
)
...
@@ -51,7 +50,7 @@ def testone(fname, f1=None, f2=None):
...
@@ -51,7 +50,7 @@ def testone(fname, f1=None, f2=None):
if
not
ok
and
f1
is
not
None
and
f2
is
not
None
:
if
not
ok
and
f1
is
not
None
and
f2
is
not
None
:
f1
.
write
(
'
\n\n
***************************************
\n
%
s
\n
***************************************
\n\n\n
'
%
fname
)
f1
.
write
(
'
\n\n
***************************************
\n
%
s
\n
***************************************
\n\n\n
'
%
fname
)
f2
.
write
(
'
\n\n
***************************************
\n
%
s
\n
***************************************
\n\n\n
'
%
fname
)
f2
.
write
(
'
\n\n
***************************************
\n
%
s
\n
***************************************
\n\n\n
'
%
fname
)
f
2
.
write
(
dump1
)
f
1
.
write
(
dump1
)
f2
.
write
(
dump2
)
f2
.
write
(
dump2
)
f
=
open
(
'bad.txt'
,
'w'
)
f
=
open
(
'bad.txt'
,
'w'
)
f
.
write
(
reconstitute
)
f
.
write
(
reconstitute
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment