summaryrefslogtreecommitdiffstats
path: root/Modules/_sre.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-10-04 17:09:49 (GMT)
committerGitHub <noreply@github.com>2017-10-04 17:09:49 (GMT)
commit0b5e61ddca73ad4fe597fb15065115b0285c8849 (patch)
tree67819288e77e0c1835ab7e04af83f741e77cfea8 /Modules/_sre.c
parent8d5a3aad2f805dc0ea40829b751f58aa6c75305d (diff)
downloadcpython-0b5e61ddca73ad4fe597fb15065115b0285c8849.zip
cpython-0b5e61ddca73ad4fe597fb15065115b0285c8849.tar.gz
cpython-0b5e61ddca73ad4fe597fb15065115b0285c8849.tar.bz2
bpo-30397: Add re.Pattern and re.Match. (#1646)
Diffstat (limited to 'Modules/_sre.c')
-rw-r--r--Modules/_sre.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 6873f1d..c42ab26 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -630,13 +630,13 @@ _sre.SRE_Pattern.fullmatch
pos: Py_ssize_t = 0
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
-Matches against all of the string
+Matches against all of the string.
[clinic start generated code]*/
static PyObject *
_sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyObject *string,
Py_ssize_t pos, Py_ssize_t endpos)
-/*[clinic end generated code: output=5833c47782a35f4a input=a6f640614aaefceb]*/
+/*[clinic end generated code: output=5833c47782a35f4a input=d9fb03a7625b5828]*/
{
SRE_STATE state;
Py_ssize_t status;
@@ -1341,7 +1341,7 @@ done:
return result;
}
-PyDoc_STRVAR(pattern_doc, "Compiled regular expression objects");
+PyDoc_STRVAR(pattern_doc, "Compiled regular expression object.");
/* PatternObject's 'groupindex' method. */
static PyObject *
@@ -2221,12 +2221,12 @@ _sre.SRE_Match.span
group: object(c_default="NULL") = 0
/
-For MatchObject m, return the 2-tuple (m.start(group), m.end(group)).
+For match object m, return the 2-tuple (m.start(group), m.end(group)).
[clinic start generated code]*/
static PyObject *
_sre_SRE_Match_span_impl(MatchObject *self, PyObject *group)
-/*[clinic end generated code: output=f02ae40594d14fe6 input=49092b6008d176d3]*/
+/*[clinic end generated code: output=f02ae40594d14fe6 input=8fa6014e982d71d4]*/
{
Py_ssize_t index = match_getindex(self, group);
@@ -2625,15 +2625,18 @@ static PyGetSetDef pattern_getset[] = {
#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},
+ {"pattern", T_OBJECT, PAT_OFF(pattern), READONLY,
+ "The pattern string from which the RE object was compiled."},
+ {"flags", T_INT, PAT_OFF(flags), READONLY,
+ "The regex matching flags."},
+ {"groups", T_PYSSIZET, PAT_OFF(groups), READONLY,
+ "The number of capturing groups in the pattern."},
{NULL} /* Sentinel */
};
static PyTypeObject Pattern_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "_" SRE_MODULE ".SRE_Pattern",
+ "re.Pattern",
sizeof(PatternObject), sizeof(SRE_CODE),
(destructor)pattern_dealloc, /* tp_dealloc */
0, /* tp_print */
@@ -2685,18 +2688,24 @@ static PyMethodDef match_methods[] = {
};
static PyGetSetDef match_getset[] = {
- {"lastindex", (getter)match_lastindex_get, (setter)NULL},
- {"lastgroup", (getter)match_lastgroup_get, (setter)NULL},
+ {"lastindex", (getter)match_lastindex_get, (setter)NULL,
+ "The integer index of the last matched capturing group."},
+ {"lastgroup", (getter)match_lastgroup_get, (setter)NULL,
+ "The name of the last matched capturing group."},
{"regs", (getter)match_regs_get, (setter)NULL},
{NULL}
};
#define MATCH_OFF(x) offsetof(MatchObject, x)
static PyMemberDef match_members[] = {
- {"string", T_OBJECT, MATCH_OFF(string), READONLY},
- {"re", T_OBJECT, MATCH_OFF(pattern), READONLY},
- {"pos", T_PYSSIZET, MATCH_OFF(pos), READONLY},
- {"endpos", T_PYSSIZET, MATCH_OFF(endpos), READONLY},
+ {"string", T_OBJECT, MATCH_OFF(string), READONLY,
+ "The string passed to match() or search()."},
+ {"re", T_OBJECT, MATCH_OFF(pattern), READONLY,
+ "The regular expression object."},
+ {"pos", T_PYSSIZET, MATCH_OFF(pos), READONLY,
+ "The index into the string at which the RE engine started looking for a match."},
+ {"endpos", T_PYSSIZET, MATCH_OFF(endpos), READONLY,
+ "The index into the string beyond which the RE engine will not go."},
{NULL}
};
@@ -2705,7 +2714,7 @@ static PyMemberDef match_members[] = {
static PyTypeObject Match_Type = {
PyVarObject_HEAD_INIT(NULL,0)
- "_" SRE_MODULE ".SRE_Match",
+ "re.Match",
sizeof(MatchObject), sizeof(Py_ssize_t),
(destructor)match_dealloc, /* tp_dealloc */
0, /* tp_print */