summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-29 22:01:48 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-29 22:01:48 (GMT)
commit07360df481adeacfc2b7a1a7f89ae9a76e86b725 (patch)
tree1d111118cafc0117d3cd68fdfa7397e68dd25191 /Modules/_sre.c
parent1813c1701f8e7e9287bccf66d1b4b8348c432168 (diff)
downloadcpython-07360df481adeacfc2b7a1a7f89ae9a76e86b725.zip
cpython-07360df481adeacfc2b7a1a7f89ae9a76e86b725.tar.gz
cpython-07360df481adeacfc2b7a1a7f89ae9a76e86b725.tar.bz2
Issue #14260: The groupindex attribute of regular expression pattern object
now is non-modifiable mapping.
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 83eb963..8cad1ac 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -1384,12 +1384,24 @@ static PyMethodDef pattern_methods[] = {
{NULL, NULL}
};
+/* PatternObject's 'groupindex' method. */
+static PyObject *
+pattern_groupindex(PatternObject *self)
+{
+ return PyDictProxy_New(self->groupindex);
+}
+
+static PyGetSetDef pattern_getset[] = {
+ {"groupindex", (getter)pattern_groupindex, (setter)NULL,
+ "A dictionary mapping group names to group numbers."},
+ {NULL} /* Sentinel */
+};
+
#define PAT_OFF(x) offsetof(PatternObject, x)
static PyMemberDef pattern_members[] = {
{"pattern", T_OBJECT, PAT_OFF(pattern), READONLY},
{"flags", T_INT, PAT_OFF(flags), READONLY},
{"groups", T_PYSSIZET, PAT_OFF(groups), READONLY},
- {"groupindex", T_OBJECT, PAT_OFF(groupindex), READONLY},
{NULL} /* Sentinel */
};
@@ -1422,6 +1434,7 @@ static PyTypeObject Pattern_Type = {
0, /* tp_iternext */
pattern_methods, /* tp_methods */
pattern_members, /* tp_members */
+ pattern_getset, /* tp_getset */
};
static int _validate(PatternObject *self); /* Forward */