Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
e34c21c2
Kaydet (Commit)
e34c21c2
authored
Mar 30, 2008
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make AST nodes pickleable.
üst
1721e757
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
4 deletions
+68
-4
test_ast.py
Lib/test/test_ast.py
+14
-0
asdl_c.py
Parser/asdl_c.py
+27
-2
Python-ast.c
Python/Python-ast.c
+27
-2
No files found.
Lib/test/test_ast.py
Dosyayı görüntüle @
e34c21c2
...
...
@@ -166,6 +166,20 @@ class AST_Tests(unittest.TestCase):
# this used to fail because Sub._fields was None
x
=
_ast
.
Sub
()
def
test_pickling
(
self
):
import
pickle
mods
=
[
pickle
]
try
:
import
cPickle
mods
.
append
(
cPickle
)
except
ImportError
:
pass
protocols
=
[
0
,
1
,
2
]
for
mod
in
mods
:
for
protocol
in
protocols
:
for
ast
in
(
compile
(
i
,
"?"
,
"exec"
,
0x400
)
for
i
in
exec_tests
):
ast2
=
mod
.
loads
(
mod
.
dumps
(
ast
,
protocol
))
self
.
assertEquals
(
to_tuple
(
ast2
),
to_tuple
(
ast
))
def
test_main
():
test_support
.
run_unittest
(
AST_Tests
)
...
...
Parser/asdl_c.py
Dosyayı görüntüle @
e34c21c2
...
...
@@ -629,9 +629,34 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
return res;
}
/* Pickling support */
static PyObject *
ast_type_reduce(PyObject *self, PyObject *unused)
{
PyObject *res;
PyObject *dict = PyObject_GetAttrString(self, "__dict__");
if (dict == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError))
PyErr_Clear();
else
return NULL;
}
if (dict) {
res = Py_BuildValue("O()O", Py_TYPE(self), dict);
Py_DECREF(dict);
return res;
}
return Py_BuildValue("O()", Py_TYPE(self));
}
static PyMethodDef ast_type_methods[] = {
{"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
{NULL}
};
static PyTypeObject AST_type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"AST",
"
_ast.
AST",
sizeof(PyObject),
0,
0, /* tp_dealloc */
...
...
@@ -657,7 +682,7 @@ static PyTypeObject AST_type = {
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
0,
/* tp_methods */
ast_type_methods,
/* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
...
...
Python/Python-ast.c
Dosyayı görüntüle @
e34c21c2
...
...
@@ -420,9 +420,34 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
return
res
;
}
/* Pickling support */
static
PyObject
*
ast_type_reduce
(
PyObject
*
self
,
PyObject
*
unused
)
{
PyObject
*
res
;
PyObject
*
dict
=
PyObject_GetAttrString
(
self
,
"__dict__"
);
if
(
dict
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
PyErr_Clear
();
else
return
NULL
;
}
if
(
dict
)
{
res
=
Py_BuildValue
(
"O()O"
,
Py_TYPE
(
self
),
dict
);
Py_DECREF
(
dict
);
return
res
;
}
return
Py_BuildValue
(
"O()"
,
Py_TYPE
(
self
));
}
static
PyMethodDef
ast_type_methods
[]
=
{
{
"__reduce__"
,
ast_type_reduce
,
METH_NOARGS
,
NULL
},
{
NULL
}
};
static
PyTypeObject
AST_type
=
{
PyVarObject_HEAD_INIT
(
&
PyType_Type
,
0
)
"AST"
,
"
_ast.
AST"
,
sizeof
(
PyObject
),
0
,
0
,
/* tp_dealloc */
...
...
@@ -448,7 +473,7 @@ static PyTypeObject AST_type = {
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_methods */
ast_type_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_base */
...
...
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