summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-03-30 20:20:39 (GMT)
committerGeorg Brandl <georg@python.org>2008-03-30 20:20:39 (GMT)
commite34c21c2a006e4ac950a519e1e662750f3e09e79 (patch)
treeacff8462559760d3928aeb12edc14d6437f63ff8 /Parser
parent1721e757499db93373cba263b0553a64d4c545a3 (diff)
downloadcpython-e34c21c2a006e4ac950a519e1e662750f3e09e79.zip
cpython-e34c21c2a006e4ac950a519e1e662750f3e09e79.tar.gz
cpython-e34c21c2a006e4ac950a519e1e662750f3e09e79.tar.bz2
Make AST nodes pickleable.
Diffstat (limited to 'Parser')
-rwxr-xr-xParser/asdl_c.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py
index 29e2547..7e12ea6 100755
--- a/Parser/asdl_c.py
+++ b/Parser/asdl_c.py
@@ -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 */