summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-10-20 10:13:31 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-10-20 10:13:31 (GMT)
commit36af10c1f7e50b257e97854aca594ec988d85c65 (patch)
tree98a269bfdbdb50090d9e09ee0fb80020b8690ea1 /Modules
parentd5fd8df22f4c94714e9fd93db80c3cc3995c44e3 (diff)
downloadcpython-36af10c1f7e50b257e97854aca594ec988d85c65.zip
cpython-36af10c1f7e50b257e97854aca594ec988d85c65.tar.gz
cpython-36af10c1f7e50b257e97854aca594ec988d85c65.tar.bz2
Issue #17087: Improved the repr for regular expression match objects.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sre.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 0db4ebe..84330ef 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -3637,6 +3637,22 @@ match_regs_get(MatchObject *self)
return match_regs(self);
}
+static PyObject *
+match_repr(MatchObject *self)
+{
+ PyObject *result;
+ PyObject *group0 = match_getslice_by_index(self, 0, Py_None);
+ if (group0 == NULL)
+ return NULL;
+ result = PyUnicode_FromFormat(
+ "<%s object; span=(%d, %d), match=%.50R>",
+ Py_TYPE(self)->tp_name,
+ self->mark[0], self->mark[1], group0);
+ Py_DECREF(group0);
+ return result;
+}
+
+
static PyGetSetDef match_getset[] = {
{"lastindex", (getter)match_lastindex_get, (setter)NULL},
{"lastgroup", (getter)match_lastgroup_get, (setter)NULL},
@@ -3665,7 +3681,7 @@ static PyTypeObject Match_Type = {
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
- 0, /* tp_repr */
+ (reprfunc)match_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */