Issue #20148: Converted the _sre module to Argument Clinic.
This commit is contained in:
parent
5abdf48430
commit
a860aeaf98
708
Modules/_sre.c
708
Modules/_sre.c
|
@ -258,25 +258,46 @@ data_stack_grow(SRE_STATE* state, Py_ssize_t size)
|
||||||
|
|
||||||
/* see sre.h for object declarations */
|
/* see sre.h for object declarations */
|
||||||
static PyObject*pattern_new_match(PatternObject*, SRE_STATE*, Py_ssize_t);
|
static PyObject*pattern_new_match(PatternObject*, SRE_STATE*, Py_ssize_t);
|
||||||
static PyObject*pattern_scanner(PatternObject*, PyObject*, PyObject* kw);
|
static PyObject *pattern_scanner(PatternObject *, PyObject *, Py_ssize_t, Py_ssize_t);
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
sre_codesize(PyObject* self, PyObject *unused)
|
/*[clinic input]
|
||||||
|
module _sre
|
||||||
|
class _sre.SRE_Pattern "PatternObject *" "&Pattern_Type"
|
||||||
|
class _sre.SRE_Match "MatchObject *" "&Match_Type"
|
||||||
|
class _sre.SRE_Scanner "ScannerObject *" "&Scanner_Type"
|
||||||
|
[clinic start generated code]*/
|
||||||
|
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=b0230ec19a0deac8]*/
|
||||||
|
|
||||||
|
/*[clinic input]
|
||||||
|
_sre.getcodesize -> int
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
_sre_getcodesize_impl(PyModuleDef *module)
|
||||||
|
/*[clinic end generated code: output=794f1f98ef4883e5 input=bd6f6ecf4916bb2b]*/
|
||||||
{
|
{
|
||||||
return PyLong_FromSize_t(sizeof(SRE_CODE));
|
return sizeof(SRE_CODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
/*[clinic input]
|
||||||
sre_getlower(PyObject* self, PyObject* args)
|
_sre.getlower -> int
|
||||||
|
|
||||||
|
character: int
|
||||||
|
flags: int
|
||||||
|
/
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
_sre_getlower_impl(PyModuleDef *module, int character, int flags)
|
||||||
|
/*[clinic end generated code: output=5fc3616ae2a4c306 input=087d2f1c44bbca6f]*/
|
||||||
{
|
{
|
||||||
int character, flags;
|
|
||||||
if (!PyArg_ParseTuple(args, "ii", &character, &flags))
|
|
||||||
return NULL;
|
|
||||||
if (flags & SRE_FLAG_LOCALE)
|
if (flags & SRE_FLAG_LOCALE)
|
||||||
return Py_BuildValue("i", sre_lower_locale(character));
|
return sre_lower_locale(character);
|
||||||
if (flags & SRE_FLAG_UNICODE)
|
if (flags & SRE_FLAG_UNICODE)
|
||||||
return Py_BuildValue("i", sre_lower_unicode(character));
|
return sre_lower_unicode(character);
|
||||||
return Py_BuildValue("i", sre_lower(character));
|
return sre_lower(character);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL(void)
|
LOCAL(void)
|
||||||
|
@ -552,27 +573,32 @@ fix_string_param(PyObject *string, PyObject *string2, const char *oldname)
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*[clinic input]
|
||||||
|
_sre.SRE_Pattern.match
|
||||||
|
|
||||||
|
string: object = NULL
|
||||||
|
pos: Py_ssize_t = 0
|
||||||
|
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
|
||||||
|
*
|
||||||
|
pattern: object = NULL
|
||||||
|
|
||||||
|
Matches zero or more characters at the beginning of the string.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
pattern_match(PatternObject *self, PyObject *args, PyObject *kwargs)
|
_sre_SRE_Pattern_match_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *pattern)
|
||||||
|
/*[clinic end generated code: output=74b4b1da3bb2d84e input=3d079aa99979b81d]*/
|
||||||
{
|
{
|
||||||
static char *_keywords[] = {"string", "pos", "endpos", "pattern", NULL};
|
|
||||||
PyObject *string = NULL;
|
|
||||||
Py_ssize_t pos = 0;
|
|
||||||
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
|
||||||
PyObject *pattern = NULL;
|
|
||||||
SRE_STATE state;
|
SRE_STATE state;
|
||||||
Py_ssize_t status;
|
Py_ssize_t status;
|
||||||
PyObject *match;
|
PyObject *match;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
|
|
||||||
"|Onn$O:match", _keywords,
|
|
||||||
&string, &pos, &endpos, &pattern))
|
|
||||||
return NULL;
|
|
||||||
string = fix_string_param(string, pattern, "pattern");
|
string = fix_string_param(string, pattern, "pattern");
|
||||||
if (!string)
|
if (!string)
|
||||||
return NULL;
|
return NULL;
|
||||||
string = state_init(&state, (PatternObject *)self, string, pos, endpos);
|
if (!state_init(&state, (PatternObject *)self, string, pos, endpos))
|
||||||
if (!string)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
state.ptr = state.start;
|
state.ptr = state.start;
|
||||||
|
@ -592,27 +618,33 @@ pattern_match(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_fullmatch(PatternObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.fullmatch
|
||||||
|
|
||||||
|
string: object = NULL
|
||||||
|
pos: Py_ssize_t = 0
|
||||||
|
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
|
||||||
|
*
|
||||||
|
pattern: object = NULL
|
||||||
|
|
||||||
|
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,
|
||||||
|
PyObject *pattern)
|
||||||
|
/*[clinic end generated code: output=1c98bc5da744ea94 input=d4228606cc12580f]*/
|
||||||
{
|
{
|
||||||
SRE_STATE state;
|
SRE_STATE state;
|
||||||
Py_ssize_t status;
|
Py_ssize_t status;
|
||||||
PyObject *match;
|
PyObject *match;
|
||||||
|
|
||||||
PyObject *string = NULL, *string2 = NULL;
|
string = fix_string_param(string, pattern, "pattern");
|
||||||
Py_ssize_t start = 0;
|
|
||||||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
|
||||||
static char* kwlist[] = { "string", "pos", "endpos", "pattern", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|Onn$O:fullmatch", kwlist,
|
|
||||||
&string, &start, &end, &string2))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
string = fix_string_param(string, string2, "pattern");
|
|
||||||
if (!string)
|
if (!string)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
string = state_init(&state, self, string, start, end);
|
if (!state_init(&state, self, string, pos, endpos))
|
||||||
if (!string)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
state.ptr = state.start;
|
state.ptr = state.start;
|
||||||
|
@ -632,27 +664,35 @@ pattern_fullmatch(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_search(PatternObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.search
|
||||||
|
|
||||||
|
string: object = NULL
|
||||||
|
pos: Py_ssize_t = 0
|
||||||
|
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
|
||||||
|
*
|
||||||
|
pattern: object = NULL
|
||||||
|
|
||||||
|
Scan through string looking for a match, and return a corresponding match object instance.
|
||||||
|
|
||||||
|
Return None if no position in the string matches.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_search_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *pattern)
|
||||||
|
/*[clinic end generated code: output=3839394a18e5ea4f input=dab42720f4be3a4b]*/
|
||||||
{
|
{
|
||||||
SRE_STATE state;
|
SRE_STATE state;
|
||||||
Py_ssize_t status;
|
Py_ssize_t status;
|
||||||
PyObject *match;
|
PyObject *match;
|
||||||
|
|
||||||
PyObject *string = NULL, *string2 = NULL;
|
string = fix_string_param(string, pattern, "pattern");
|
||||||
Py_ssize_t start = 0;
|
|
||||||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
|
||||||
static char* kwlist[] = { "string", "pos", "endpos", "pattern", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|Onn$O:search", kwlist,
|
|
||||||
&string, &start, &end, &string2))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
string = fix_string_param(string, string2, "pattern");
|
|
||||||
if (!string)
|
if (!string)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
string = state_init(&state, self, string, start, end);
|
if (!state_init(&state, self, string, pos, endpos))
|
||||||
if (!string)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
TRACE(("|%p|%p|SEARCH\n", PatternObject_GetCode(self), state.ptr));
|
TRACE(("|%p|%p|SEARCH\n", PatternObject_GetCode(self), state.ptr));
|
||||||
|
@ -718,28 +758,34 @@ deepcopy(PyObject** object, PyObject* memo)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_findall(PatternObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.findall
|
||||||
|
|
||||||
|
string: object = NULL
|
||||||
|
pos: Py_ssize_t = 0
|
||||||
|
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
|
||||||
|
*
|
||||||
|
source: object = NULL
|
||||||
|
|
||||||
|
Return a list of all non-overlapping matches of pattern in string.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *source)
|
||||||
|
/*[clinic end generated code: output=51295498b300639d input=df688355c056b9de]*/
|
||||||
{
|
{
|
||||||
SRE_STATE state;
|
SRE_STATE state;
|
||||||
PyObject* list;
|
PyObject* list;
|
||||||
Py_ssize_t status;
|
Py_ssize_t status;
|
||||||
Py_ssize_t i, b, e;
|
Py_ssize_t i, b, e;
|
||||||
|
|
||||||
PyObject *string = NULL, *string2 = NULL;
|
string = fix_string_param(string, source, "source");
|
||||||
Py_ssize_t start = 0;
|
|
||||||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
|
||||||
static char* kwlist[] = { "string", "pos", "endpos", "source", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|Onn$O:findall", kwlist,
|
|
||||||
&string, &start, &end, &string2))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
string = fix_string_param(string, string2, "source");
|
|
||||||
if (!string)
|
if (!string)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
string = state_init(&state, self, string, start, end);
|
if (!state_init(&state, self, string, pos, endpos))
|
||||||
if (!string)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
list = PyList_New(0);
|
list = PyList_New(0);
|
||||||
|
@ -819,14 +865,28 @@ error:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.finditer
|
||||||
|
|
||||||
|
string: object
|
||||||
|
pos: Py_ssize_t = 0
|
||||||
|
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
|
||||||
|
|
||||||
|
Return an iterator over all non-overlapping matches for the RE pattern in string.
|
||||||
|
|
||||||
|
For each match, the iterator returns a match object.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_finditer_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos)
|
||||||
|
/*[clinic end generated code: output=0bbb1a0aeb38bb14 input=612aab69e9fe08e4]*/
|
||||||
{
|
{
|
||||||
PyObject* scanner;
|
PyObject* scanner;
|
||||||
PyObject* search;
|
PyObject* search;
|
||||||
PyObject* iterator;
|
PyObject* iterator;
|
||||||
|
|
||||||
scanner = pattern_scanner(pattern, args, kw);
|
scanner = pattern_scanner(self, string, pos, endpos);
|
||||||
if (!scanner)
|
if (!scanner)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -841,8 +901,38 @@ pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw)
|
||||||
return iterator;
|
return iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.scanner
|
||||||
|
|
||||||
|
string: object
|
||||||
|
pos: Py_ssize_t = 0
|
||||||
|
endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_scanner_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos)
|
||||||
|
/*[clinic end generated code: output=54ea548aed33890b input=3aacdbde77a3a637]*/
|
||||||
|
{
|
||||||
|
return pattern_scanner(self, string, pos, endpos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*[clinic input]
|
||||||
|
_sre.SRE_Pattern.split
|
||||||
|
|
||||||
|
string: object = NULL
|
||||||
|
maxsplit: Py_ssize_t = 0
|
||||||
|
*
|
||||||
|
source: object = NULL
|
||||||
|
|
||||||
|
Split string by the occurrences of pattern.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t maxsplit, PyObject *source)
|
||||||
|
/*[clinic end generated code: output=20bac2ff55b9f84c input=41e0b2e35e599d7b]*/
|
||||||
{
|
{
|
||||||
SRE_STATE state;
|
SRE_STATE state;
|
||||||
PyObject* list;
|
PyObject* list;
|
||||||
|
@ -852,14 +942,7 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
void* last;
|
void* last;
|
||||||
|
|
||||||
PyObject *string = NULL, *string2 = NULL;
|
string = fix_string_param(string, source, "source");
|
||||||
Py_ssize_t maxsplit = 0;
|
|
||||||
static char* kwlist[] = { "string", "maxsplit", "source", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|On$O:split", kwlist,
|
|
||||||
&string, &maxsplit, &string2))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
string = fix_string_param(string, string2, "source");
|
|
||||||
if (!string)
|
if (!string)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -876,8 +959,7 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX);
|
if (!state_init(&state, self, string, 0, PY_SSIZE_T_MAX))
|
||||||
if (!string)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
list = PyList_New(0);
|
list = PyList_New(0);
|
||||||
|
@ -1021,8 +1103,7 @@ pattern_subx(PatternObject* self, PyObject* ptemplate, PyObject* string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX);
|
if (!state_init(&state, self, string, 0, PY_SSIZE_T_MAX)) {
|
||||||
if (!string) {
|
|
||||||
Py_DECREF(filter);
|
Py_DECREF(filter);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1162,36 +1243,50 @@ error:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_sub(PatternObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.sub
|
||||||
{
|
|
||||||
PyObject* ptemplate;
|
|
||||||
PyObject* string;
|
|
||||||
Py_ssize_t count = 0;
|
|
||||||
static char* kwlist[] = { "repl", "string", "count", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|n:sub", kwlist,
|
|
||||||
&ptemplate, &string, &count))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return pattern_subx(self, ptemplate, string, count, 0);
|
repl: object
|
||||||
|
string: object
|
||||||
|
count: Py_ssize_t = 0
|
||||||
|
|
||||||
|
Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_sub_impl(PatternObject *self, PyObject *repl,
|
||||||
|
PyObject *string, Py_ssize_t count)
|
||||||
|
/*[clinic end generated code: output=1dbf2ec3479cba00 input=c53d70be0b3caf86]*/
|
||||||
|
{
|
||||||
|
return pattern_subx(self, repl, string, count, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_subn(PatternObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Pattern.subn
|
||||||
{
|
|
||||||
PyObject* ptemplate;
|
|
||||||
PyObject* string;
|
|
||||||
Py_ssize_t count = 0;
|
|
||||||
static char* kwlist[] = { "repl", "string", "count", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "OO|n:subn", kwlist,
|
|
||||||
&ptemplate, &string, &count))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
return pattern_subx(self, ptemplate, string, count, 1);
|
repl: object
|
||||||
|
string: object
|
||||||
|
count: Py_ssize_t = 0
|
||||||
|
|
||||||
|
Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost non-overlapping occurrences of pattern with the replacement repl.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_subn_impl(PatternObject *self, PyObject *repl,
|
||||||
|
PyObject *string, Py_ssize_t count)
|
||||||
|
/*[clinic end generated code: output=0d9522cd529e9728 input=e7342d7ce6083577]*/
|
||||||
|
{
|
||||||
|
return pattern_subx(self, repl, string, count, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_copy(PatternObject* self, PyObject *unused)
|
_sre.SRE_Pattern.__copy__
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern___copy___impl(PatternObject *self)
|
||||||
|
/*[clinic end generated code: output=85dedc2db1bd8694 input=a730a59d863bc9f5]*/
|
||||||
{
|
{
|
||||||
#ifdef USE_BUILTIN_COPY
|
#ifdef USE_BUILTIN_COPY
|
||||||
PatternObject* copy;
|
PatternObject* copy;
|
||||||
|
@ -1218,8 +1313,16 @@ pattern_copy(PatternObject* self, PyObject *unused)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
pattern_deepcopy(PatternObject* self, PyObject* memo)
|
_sre.SRE_Pattern.__deepcopy__
|
||||||
|
|
||||||
|
memo: object
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern___deepcopy___impl(PatternObject *self, PyObject *memo)
|
||||||
|
/*[clinic end generated code: output=75efe69bd12c5d7d input=3959719482c07f70]*/
|
||||||
{
|
{
|
||||||
#ifdef USE_BUILTIN_COPY
|
#ifdef USE_BUILTIN_COPY
|
||||||
PatternObject* copy;
|
PatternObject* copy;
|
||||||
|
@ -1321,68 +1424,9 @@ done:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_match_doc,
|
|
||||||
"match(string[, pos[, endpos]]) -> match object or None.\n\
|
|
||||||
Matches zero or more characters at the beginning of the string");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_fullmatch_doc,
|
|
||||||
"fullmatch(string[, pos[, endpos]]) -> match object or None.\n\
|
|
||||||
Matches against all of the string");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_search_doc,
|
|
||||||
"search(string[, pos[, endpos]]) -> match object or None.\n\
|
|
||||||
Scan through string looking for a match, and return a corresponding\n\
|
|
||||||
match object instance. Return None if no position in the string matches.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_split_doc,
|
|
||||||
"split(string[, maxsplit = 0]) -> list.\n\
|
|
||||||
Split string by the occurrences of pattern.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_findall_doc,
|
|
||||||
"findall(string[, pos[, endpos]]) -> list.\n\
|
|
||||||
Return a list of all non-overlapping matches of pattern in string.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_finditer_doc,
|
|
||||||
"finditer(string[, pos[, endpos]]) -> iterator.\n\
|
|
||||||
Return an iterator over all non-overlapping matches for the \n\
|
|
||||||
RE pattern in string. For each match, the iterator returns a\n\
|
|
||||||
match object.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_sub_doc,
|
|
||||||
"sub(repl, string[, count = 0]) -> newstring.\n\
|
|
||||||
Return the string obtained by replacing the leftmost non-overlapping\n\
|
|
||||||
occurrences of pattern in string by the replacement repl.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_subn_doc,
|
|
||||||
"subn(repl, string[, count = 0]) -> (newstring, number of subs)\n\
|
|
||||||
Return the tuple (new_string, number_of_subs_made) found by replacing\n\
|
|
||||||
the leftmost non-overlapping occurrences of pattern with the\n\
|
|
||||||
replacement repl.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(pattern_doc, "Compiled regular expression objects");
|
PyDoc_STRVAR(pattern_doc, "Compiled regular expression objects");
|
||||||
|
|
||||||
static PyMethodDef pattern_methods[] = {
|
static PyMethodDef pattern_methods[];
|
||||||
{"match", (PyCFunction) pattern_match, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_match_doc},
|
|
||||||
{"fullmatch", (PyCFunction) pattern_fullmatch, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_fullmatch_doc},
|
|
||||||
{"search", (PyCFunction) pattern_search, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_search_doc},
|
|
||||||
{"sub", (PyCFunction) pattern_sub, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_sub_doc},
|
|
||||||
{"subn", (PyCFunction) pattern_subn, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_subn_doc},
|
|
||||||
{"split", (PyCFunction) pattern_split, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_split_doc},
|
|
||||||
{"findall", (PyCFunction) pattern_findall, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_findall_doc},
|
|
||||||
{"finditer", (PyCFunction) pattern_finditer, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
pattern_finditer_doc},
|
|
||||||
{"scanner", (PyCFunction) pattern_scanner, METH_VARARGS|METH_KEYWORDS},
|
|
||||||
{"__copy__", (PyCFunction) pattern_copy, METH_NOARGS},
|
|
||||||
{"__deepcopy__", (PyCFunction) pattern_deepcopy, METH_O},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* PatternObject's 'groupindex' method. */
|
/* PatternObject's 'groupindex' method. */
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
@ -1439,26 +1483,29 @@ static PyTypeObject Pattern_Type = {
|
||||||
|
|
||||||
static int _validate(PatternObject *self); /* Forward */
|
static int _validate(PatternObject *self); /* Forward */
|
||||||
|
|
||||||
|
/*[clinic input]
|
||||||
|
_sre.compile
|
||||||
|
|
||||||
|
pattern: object
|
||||||
|
flags: int
|
||||||
|
code: object(subclass_of='&PyList_Type')
|
||||||
|
groups: Py_ssize_t
|
||||||
|
groupindex: object
|
||||||
|
indexgroup: object
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_compile(PyObject* self_, PyObject* args)
|
_sre_compile_impl(PyModuleDef *module, PyObject *pattern, int flags,
|
||||||
|
PyObject *code, Py_ssize_t groups, PyObject *groupindex,
|
||||||
|
PyObject *indexgroup)
|
||||||
|
/*[clinic end generated code: output=3004b293730bf309 input=7d059ec8ae1edb85]*/
|
||||||
{
|
{
|
||||||
/* "compile" pattern descriptor to pattern object */
|
/* "compile" pattern descriptor to pattern object */
|
||||||
|
|
||||||
PatternObject* self;
|
PatternObject* self;
|
||||||
Py_ssize_t i, n;
|
Py_ssize_t i, n;
|
||||||
|
|
||||||
PyObject* pattern;
|
|
||||||
int flags = 0;
|
|
||||||
PyObject* code;
|
|
||||||
Py_ssize_t groups = 0;
|
|
||||||
PyObject* groupindex = NULL;
|
|
||||||
PyObject* indexgroup = NULL;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OiO!nOO", &pattern, &flags,
|
|
||||||
&PyList_Type, &code, &groups,
|
|
||||||
&groupindex, &indexgroup))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
n = PyList_GET_SIZE(code);
|
n = PyList_GET_SIZE(code);
|
||||||
/* coverity[ampersand_in_size] */
|
/* coverity[ampersand_in_size] */
|
||||||
self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
|
self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n);
|
||||||
|
@ -2071,13 +2118,22 @@ match_getslice(MatchObject* self, PyObject* index, PyObject* def)
|
||||||
return match_getslice_by_index(self, match_getindex(self, index), def);
|
return match_getslice_by_index(self, match_getindex(self, index), def);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_expand(MatchObject* self, PyObject* ptemplate)
|
_sre.SRE_Match.expand
|
||||||
|
|
||||||
|
template: object
|
||||||
|
|
||||||
|
Return the string obtained by doing backslash substitution on the string template, as done by the sub() method.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template)
|
||||||
|
/*[clinic end generated code: output=931b58ccc323c3a1 input=4bfdb22c2f8b146a]*/
|
||||||
{
|
{
|
||||||
/* delegate to Python code */
|
/* delegate to Python code */
|
||||||
return call(
|
return call(
|
||||||
SRE_PY_MODULE, "_expand",
|
SRE_PY_MODULE, "_expand",
|
||||||
PyTuple_Pack(3, self->pattern, self, ptemplate)
|
PyTuple_Pack(3, self->pattern, self, template)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2116,24 +2172,29 @@ match_group(MatchObject* self, PyObject* args)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_groups(MatchObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Match.groups
|
||||||
|
|
||||||
|
default: object = None
|
||||||
|
Is used for groups that did not participate in the match.
|
||||||
|
|
||||||
|
Return a tuple containing all the subgroups of the match, from 1.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_groups_impl(MatchObject *self, PyObject *default_value)
|
||||||
|
/*[clinic end generated code: output=daf8e2641537238a input=bb069ef55dabca91]*/
|
||||||
{
|
{
|
||||||
PyObject* result;
|
PyObject* result;
|
||||||
Py_ssize_t index;
|
Py_ssize_t index;
|
||||||
|
|
||||||
PyObject* def = Py_None;
|
|
||||||
static char* kwlist[] = { "default", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:groups", kwlist, &def))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
result = PyTuple_New(self->groups-1);
|
result = PyTuple_New(self->groups-1);
|
||||||
if (!result)
|
if (!result)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (index = 1; index < self->groups; index++) {
|
for (index = 1; index < self->groups; index++) {
|
||||||
PyObject* item;
|
PyObject* item;
|
||||||
item = match_getslice_by_index(self, index, def);
|
item = match_getslice_by_index(self, index, default_value);
|
||||||
if (!item) {
|
if (!item) {
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2144,18 +2205,23 @@ match_groups(MatchObject* self, PyObject* args, PyObject* kw)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_groupdict(MatchObject* self, PyObject* args, PyObject* kw)
|
_sre.SRE_Match.groupdict
|
||||||
|
|
||||||
|
default: object = None
|
||||||
|
Is used for groups that did not participate in the match.
|
||||||
|
|
||||||
|
Return a dictionary containing all the named subgroups of the match, keyed by the subgroup name.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value)
|
||||||
|
/*[clinic end generated code: output=29917c9073e41757 input=0ded7960b23780aa]*/
|
||||||
{
|
{
|
||||||
PyObject* result;
|
PyObject* result;
|
||||||
PyObject* keys;
|
PyObject* keys;
|
||||||
Py_ssize_t index;
|
Py_ssize_t index;
|
||||||
|
|
||||||
PyObject* def = Py_None;
|
|
||||||
static char* kwlist[] = { "default", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|O:groupdict", kwlist, &def))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
result = PyDict_New();
|
result = PyDict_New();
|
||||||
if (!result || !self->pattern->groupindex)
|
if (!result || !self->pattern->groupindex)
|
||||||
return result;
|
return result;
|
||||||
|
@ -2171,7 +2237,7 @@ match_groupdict(MatchObject* self, PyObject* args, PyObject* kw)
|
||||||
key = PyList_GET_ITEM(keys, index);
|
key = PyList_GET_ITEM(keys, index);
|
||||||
if (!key)
|
if (!key)
|
||||||
goto failed;
|
goto failed;
|
||||||
value = match_getslice(self, key, def);
|
value = match_getslice(self, key, default_value);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
Py_DECREF(key);
|
Py_DECREF(key);
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -2192,50 +2258,58 @@ failed:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_start(MatchObject* self, PyObject* args)
|
_sre.SRE_Match.start -> Py_ssize_t
|
||||||
|
|
||||||
|
group: object(c_default="NULL") = 0
|
||||||
|
/
|
||||||
|
|
||||||
|
Return index of the start of the substring matched by group.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static Py_ssize_t
|
||||||
|
_sre_SRE_Match_start_impl(MatchObject *self, PyObject *group)
|
||||||
|
/*[clinic end generated code: output=3f6e7f9df2fb5201 input=ced8e4ed4b33ee6c]*/
|
||||||
{
|
{
|
||||||
Py_ssize_t index;
|
Py_ssize_t index = match_getindex(self, group);
|
||||||
|
|
||||||
PyObject* index_ = NULL;
|
|
||||||
if (!PyArg_UnpackTuple(args, "start", 0, 1, &index_))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
index = match_getindex(self, index_);
|
|
||||||
|
|
||||||
if (index < 0 || index >= self->groups) {
|
if (index < 0 || index >= self->groups) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_IndexError,
|
PyExc_IndexError,
|
||||||
"no such group"
|
"no such group"
|
||||||
);
|
);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mark is -1 if group is undefined */
|
/* mark is -1 if group is undefined */
|
||||||
return PyLong_FromSsize_t(self->mark[index*2]);
|
return self->mark[index*2];
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_end(MatchObject* self, PyObject* args)
|
_sre.SRE_Match.end -> Py_ssize_t
|
||||||
|
|
||||||
|
group: object(c_default="NULL") = 0
|
||||||
|
/
|
||||||
|
|
||||||
|
Return index of the end of the substring matched by group.
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static Py_ssize_t
|
||||||
|
_sre_SRE_Match_end_impl(MatchObject *self, PyObject *group)
|
||||||
|
/*[clinic end generated code: output=f4240b09911f7692 input=1b799560c7f3d7e6]*/
|
||||||
{
|
{
|
||||||
Py_ssize_t index;
|
Py_ssize_t index = match_getindex(self, group);
|
||||||
|
|
||||||
PyObject* index_ = NULL;
|
|
||||||
if (!PyArg_UnpackTuple(args, "end", 0, 1, &index_))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
index = match_getindex(self, index_);
|
|
||||||
|
|
||||||
if (index < 0 || index >= self->groups) {
|
if (index < 0 || index >= self->groups) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
PyExc_IndexError,
|
PyExc_IndexError,
|
||||||
"no such group"
|
"no such group"
|
||||||
);
|
);
|
||||||
return NULL;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mark is -1 if group is undefined */
|
/* mark is -1 if group is undefined */
|
||||||
return PyLong_FromSsize_t(self->mark[index*2+1]);
|
return self->mark[index*2+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCAL(PyObject*)
|
LOCAL(PyObject*)
|
||||||
|
@ -2265,16 +2339,20 @@ _pair(Py_ssize_t i1, Py_ssize_t i2)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_span(MatchObject* self, PyObject* args)
|
_sre.SRE_Match.span
|
||||||
|
|
||||||
|
group: object(c_default="NULL") = 0
|
||||||
|
/
|
||||||
|
|
||||||
|
For MatchObject 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]*/
|
||||||
{
|
{
|
||||||
Py_ssize_t index;
|
Py_ssize_t index = match_getindex(self, group);
|
||||||
|
|
||||||
PyObject* index_ = NULL;
|
|
||||||
if (!PyArg_UnpackTuple(args, "span", 0, 1, &index_))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
index = match_getindex(self, index_);
|
|
||||||
|
|
||||||
if (index < 0 || index >= self->groups) {
|
if (index < 0 || index >= self->groups) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
|
@ -2314,8 +2392,14 @@ match_regs(MatchObject* self)
|
||||||
return regs;
|
return regs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_copy(MatchObject* self, PyObject *unused)
|
_sre.SRE_Match.__copy__
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match___copy___impl(MatchObject *self)
|
||||||
|
/*[clinic end generated code: output=a779c5fc8b5b4eb4 input=3bb4d30b6baddb5b]*/
|
||||||
{
|
{
|
||||||
#ifdef USE_BUILTIN_COPY
|
#ifdef USE_BUILTIN_COPY
|
||||||
MatchObject* copy;
|
MatchObject* copy;
|
||||||
|
@ -2345,8 +2429,16 @@ match_copy(MatchObject* self, PyObject *unused)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
match_deepcopy(MatchObject* self, PyObject* memo)
|
_sre.SRE_Match.__deepcopy__
|
||||||
|
|
||||||
|
memo: object
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match___deepcopy___impl(MatchObject *self, PyObject *memo)
|
||||||
|
/*[clinic end generated code: output=2b657578eb03f4a3 input=b65b72489eac64cc]*/
|
||||||
{
|
{
|
||||||
#ifdef USE_BUILTIN_COPY
|
#ifdef USE_BUILTIN_COPY
|
||||||
MatchObject* copy;
|
MatchObject* copy;
|
||||||
|
@ -2377,49 +2469,7 @@ PyDoc_STRVAR(match_group_doc,
|
||||||
Return subgroup(s) of the match by indices or names.\n\
|
Return subgroup(s) of the match by indices or names.\n\
|
||||||
For 0 returns the entire match.");
|
For 0 returns the entire match.");
|
||||||
|
|
||||||
PyDoc_STRVAR(match_start_doc,
|
static PyMethodDef match_methods[];
|
||||||
"start([group=0]) -> int.\n\
|
|
||||||
Return index of the start of the substring matched by group.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(match_end_doc,
|
|
||||||
"end([group=0]) -> int.\n\
|
|
||||||
Return index of the end of the substring matched by group.");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(match_span_doc,
|
|
||||||
"span([group]) -> tuple.\n\
|
|
||||||
For MatchObject m, return the 2-tuple (m.start(group), m.end(group)).");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(match_groups_doc,
|
|
||||||
"groups([default=None]) -> tuple.\n\
|
|
||||||
Return a tuple containing all the subgroups of the match, from 1.\n\
|
|
||||||
The default argument is used for groups\n\
|
|
||||||
that did not participate in the match");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(match_groupdict_doc,
|
|
||||||
"groupdict([default=None]) -> dict.\n\
|
|
||||||
Return a dictionary containing all the named subgroups of the match,\n\
|
|
||||||
keyed by the subgroup name. The default argument is used for groups\n\
|
|
||||||
that did not participate in the match");
|
|
||||||
|
|
||||||
PyDoc_STRVAR(match_expand_doc,
|
|
||||||
"expand(template) -> str.\n\
|
|
||||||
Return the string obtained by doing backslash substitution\n\
|
|
||||||
on the string template, as done by the sub() method.");
|
|
||||||
|
|
||||||
static PyMethodDef match_methods[] = {
|
|
||||||
{"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc},
|
|
||||||
{"start", (PyCFunction) match_start, METH_VARARGS, match_start_doc},
|
|
||||||
{"end", (PyCFunction) match_end, METH_VARARGS, match_end_doc},
|
|
||||||
{"span", (PyCFunction) match_span, METH_VARARGS, match_span_doc},
|
|
||||||
{"groups", (PyCFunction) match_groups, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
match_groups_doc},
|
|
||||||
{"groupdict", (PyCFunction) match_groupdict, METH_VARARGS|METH_KEYWORDS,
|
|
||||||
match_groupdict_doc},
|
|
||||||
{"expand", (PyCFunction) match_expand, METH_O, match_expand_doc},
|
|
||||||
{"__copy__", (PyCFunction) match_copy, METH_NOARGS},
|
|
||||||
{"__deepcopy__", (PyCFunction) match_deepcopy, METH_O},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
match_lastindex_get(MatchObject *self)
|
match_lastindex_get(MatchObject *self)
|
||||||
|
@ -2597,8 +2647,14 @@ scanner_dealloc(ScannerObject* self)
|
||||||
PyObject_DEL(self);
|
PyObject_DEL(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
scanner_match(ScannerObject* self, PyObject *unused)
|
_sre.SRE_Scanner.match
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Scanner_match_impl(ScannerObject *self)
|
||||||
|
/*[clinic end generated code: output=936b30c63d4b81eb input=881a0154f8c13d9a]*/
|
||||||
{
|
{
|
||||||
SRE_STATE* state = &self->state;
|
SRE_STATE* state = &self->state;
|
||||||
PyObject* match;
|
PyObject* match;
|
||||||
|
@ -2624,8 +2680,14 @@ scanner_match(ScannerObject* self, PyObject *unused)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject*
|
/*[clinic input]
|
||||||
scanner_search(ScannerObject* self, PyObject *unused)
|
_sre.SRE_Scanner.search
|
||||||
|
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Scanner_search_impl(ScannerObject *self)
|
||||||
|
/*[clinic end generated code: output=7dc211986088f025 input=161223ee92ef9270]*/
|
||||||
{
|
{
|
||||||
SRE_STATE* state = &self->state;
|
SRE_STATE* state = &self->state;
|
||||||
PyObject* match;
|
PyObject* match;
|
||||||
|
@ -2650,11 +2712,7 @@ scanner_search(ScannerObject* self, PyObject *unused)
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef scanner_methods[] = {
|
static PyMethodDef scanner_methods[];
|
||||||
{"match", (PyCFunction) scanner_match, METH_NOARGS},
|
|
||||||
{"search", (PyCFunction) scanner_search, METH_NOARGS},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
#define SCAN_OFF(x) offsetof(ScannerObject, x)
|
#define SCAN_OFF(x) offsetof(ScannerObject, x)
|
||||||
static PyMemberDef scanner_members[] = {
|
static PyMemberDef scanner_members[] = {
|
||||||
|
@ -2694,47 +2752,69 @@ static PyTypeObject Scanner_Type = {
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyObject*
|
static PyObject *
|
||||||
pattern_scanner(PatternObject* pattern, PyObject* args, PyObject* kw)
|
pattern_scanner(PatternObject *self, PyObject *string, Py_ssize_t pos, Py_ssize_t endpos)
|
||||||
{
|
{
|
||||||
/* create search state object */
|
ScannerObject* scanner;
|
||||||
|
|
||||||
ScannerObject* self;
|
|
||||||
|
|
||||||
PyObject *string = NULL, *string2 = NULL;
|
|
||||||
Py_ssize_t start = 0;
|
|
||||||
Py_ssize_t end = PY_SSIZE_T_MAX;
|
|
||||||
static char* kwlist[] = { "string", "pos", "endpos", "source", NULL };
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|Onn$O:scanner", kwlist,
|
|
||||||
&string, &start, &end, &string2))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
string = fix_string_param(string, string2, "source");
|
|
||||||
if (!string)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
/* create scanner object */
|
/* create scanner object */
|
||||||
self = PyObject_NEW(ScannerObject, &Scanner_Type);
|
scanner = PyObject_NEW(ScannerObject, &Scanner_Type);
|
||||||
if (!self)
|
if (!scanner)
|
||||||
return NULL;
|
return NULL;
|
||||||
self->pattern = NULL;
|
scanner->pattern = NULL;
|
||||||
|
|
||||||
string = state_init(&self->state, pattern, string, start, end);
|
/* create search state object */
|
||||||
if (!string) {
|
if (!state_init(&scanner->state, self, string, pos, endpos)) {
|
||||||
Py_DECREF(self);
|
Py_DECREF(scanner);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Py_INCREF(pattern);
|
Py_INCREF(self);
|
||||||
self->pattern = (PyObject*) pattern;
|
scanner->pattern = (PyObject*) self;
|
||||||
|
|
||||||
return (PyObject*) self;
|
return (PyObject*) scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "clinic/_sre.c.h"
|
||||||
|
|
||||||
|
static PyMethodDef pattern_methods[] = {
|
||||||
|
_SRE_SRE_PATTERN_MATCH_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_FULLMATCH_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_SEARCH_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_SUB_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_SUBN_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_FINDALL_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_SPLIT_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_FINDITER_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN_SCANNER_METHODDEF
|
||||||
|
_SRE_SRE_PATTERN___COPY___METHODDEF
|
||||||
|
_SRE_SRE_PATTERN___DEEPCOPY___METHODDEF
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyMethodDef match_methods[] = {
|
||||||
|
{"group", (PyCFunction) match_group, METH_VARARGS, match_group_doc},
|
||||||
|
_SRE_SRE_MATCH_START_METHODDEF
|
||||||
|
_SRE_SRE_MATCH_END_METHODDEF
|
||||||
|
_SRE_SRE_MATCH_SPAN_METHODDEF
|
||||||
|
_SRE_SRE_MATCH_GROUPS_METHODDEF
|
||||||
|
_SRE_SRE_MATCH_GROUPDICT_METHODDEF
|
||||||
|
_SRE_SRE_MATCH_EXPAND_METHODDEF
|
||||||
|
_SRE_SRE_MATCH___COPY___METHODDEF
|
||||||
|
_SRE_SRE_MATCH___DEEPCOPY___METHODDEF
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyMethodDef scanner_methods[] = {
|
||||||
|
_SRE_SRE_SCANNER_MATCH_METHODDEF
|
||||||
|
_SRE_SRE_SCANNER_SEARCH_METHODDEF
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
static PyMethodDef _functions[] = {
|
static PyMethodDef _functions[] = {
|
||||||
{"compile", _compile, METH_VARARGS},
|
_SRE_COMPILE_METHODDEF
|
||||||
{"getcodesize", sre_codesize, METH_NOARGS},
|
_SRE_GETCODESIZE_METHODDEF
|
||||||
{"getlower", sre_getlower, METH_VARARGS},
|
_SRE_GETLOWER_METHODDEF
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,693 @@
|
||||||
|
/*[clinic input]
|
||||||
|
preserve
|
||||||
|
[clinic start generated code]*/
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_getcodesize__doc__,
|
||||||
|
"getcodesize($module, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_GETCODESIZE_METHODDEF \
|
||||||
|
{"getcodesize", (PyCFunction)_sre_getcodesize, METH_NOARGS, _sre_getcodesize__doc__},
|
||||||
|
|
||||||
|
static int
|
||||||
|
_sre_getcodesize_impl(PyModuleDef *module);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_getcodesize(PyModuleDef *module, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
int _return_value;
|
||||||
|
|
||||||
|
_return_value = _sre_getcodesize_impl(module);
|
||||||
|
if ((_return_value == -1) && PyErr_Occurred())
|
||||||
|
goto exit;
|
||||||
|
return_value = PyLong_FromLong((long)_return_value);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_getlower__doc__,
|
||||||
|
"getlower($module, character, flags, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_GETLOWER_METHODDEF \
|
||||||
|
{"getlower", (PyCFunction)_sre_getlower, METH_VARARGS, _sre_getlower__doc__},
|
||||||
|
|
||||||
|
static int
|
||||||
|
_sre_getlower_impl(PyModuleDef *module, int character, int flags);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_getlower(PyModuleDef *module, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
int character;
|
||||||
|
int flags;
|
||||||
|
int _return_value;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTuple(args, "ii:getlower",
|
||||||
|
&character, &flags))
|
||||||
|
goto exit;
|
||||||
|
_return_value = _sre_getlower_impl(module, character, flags);
|
||||||
|
if ((_return_value == -1) && PyErr_Occurred())
|
||||||
|
goto exit;
|
||||||
|
return_value = PyLong_FromLong((long)_return_value);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_match__doc__,
|
||||||
|
"match($self, /, string=None, pos=0, endpos=sys.maxsize, *, pattern=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Matches zero or more characters at the beginning of the string.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_MATCH_METHODDEF \
|
||||||
|
{"match", (PyCFunction)_sre_SRE_Pattern_match, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_match__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_match_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *pattern);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_match(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "pos", "endpos", "pattern", NULL};
|
||||||
|
PyObject *string = NULL;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
||||||
|
PyObject *pattern = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Onn$O:match", _keywords,
|
||||||
|
&string, &pos, &endpos, &pattern))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_match_impl(self, string, pos, endpos, pattern);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_fullmatch__doc__,
|
||||||
|
"fullmatch($self, /, string=None, pos=0, endpos=sys.maxsize, *,\n"
|
||||||
|
" pattern=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Matches against all of the string");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_FULLMATCH_METHODDEF \
|
||||||
|
{"fullmatch", (PyCFunction)_sre_SRE_Pattern_fullmatch, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_fullmatch__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *pattern);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_fullmatch(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "pos", "endpos", "pattern", NULL};
|
||||||
|
PyObject *string = NULL;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
||||||
|
PyObject *pattern = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Onn$O:fullmatch", _keywords,
|
||||||
|
&string, &pos, &endpos, &pattern))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_fullmatch_impl(self, string, pos, endpos, pattern);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_search__doc__,
|
||||||
|
"search($self, /, string=None, pos=0, endpos=sys.maxsize, *,\n"
|
||||||
|
" pattern=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Scan through string looking for a match, and return a corresponding match object instance.\n"
|
||||||
|
"\n"
|
||||||
|
"Return None if no position in the string matches.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_SEARCH_METHODDEF \
|
||||||
|
{"search", (PyCFunction)_sre_SRE_Pattern_search, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_search__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_search_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *pattern);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_search(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "pos", "endpos", "pattern", NULL};
|
||||||
|
PyObject *string = NULL;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
||||||
|
PyObject *pattern = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Onn$O:search", _keywords,
|
||||||
|
&string, &pos, &endpos, &pattern))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_search_impl(self, string, pos, endpos, pattern);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_findall__doc__,
|
||||||
|
"findall($self, /, string=None, pos=0, endpos=sys.maxsize, *,\n"
|
||||||
|
" source=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return a list of all non-overlapping matches of pattern in string.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_FINDALL_METHODDEF \
|
||||||
|
{"findall", (PyCFunction)_sre_SRE_Pattern_findall, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_findall__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos,
|
||||||
|
PyObject *source);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_findall(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "pos", "endpos", "source", NULL};
|
||||||
|
PyObject *string = NULL;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
||||||
|
PyObject *source = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|Onn$O:findall", _keywords,
|
||||||
|
&string, &pos, &endpos, &source))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_findall_impl(self, string, pos, endpos, source);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_finditer__doc__,
|
||||||
|
"finditer($self, /, string, pos=0, endpos=sys.maxsize)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return an iterator over all non-overlapping matches for the RE pattern in string.\n"
|
||||||
|
"\n"
|
||||||
|
"For each match, the iterator returns a match object.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_FINDITER_METHODDEF \
|
||||||
|
{"finditer", (PyCFunction)_sre_SRE_Pattern_finditer, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_finditer__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_finditer_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_finditer(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "pos", "endpos", NULL};
|
||||||
|
PyObject *string;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nn:finditer", _keywords,
|
||||||
|
&string, &pos, &endpos))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_finditer_impl(self, string, pos, endpos);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_scanner__doc__,
|
||||||
|
"scanner($self, /, string, pos=0, endpos=sys.maxsize)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_SCANNER_METHODDEF \
|
||||||
|
{"scanner", (PyCFunction)_sre_SRE_Pattern_scanner, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_scanner__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_scanner_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t pos, Py_ssize_t endpos);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_scanner(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "pos", "endpos", NULL};
|
||||||
|
PyObject *string;
|
||||||
|
Py_ssize_t pos = 0;
|
||||||
|
Py_ssize_t endpos = PY_SSIZE_T_MAX;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|nn:scanner", _keywords,
|
||||||
|
&string, &pos, &endpos))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_scanner_impl(self, string, pos, endpos);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_split__doc__,
|
||||||
|
"split($self, /, string=None, maxsplit=0, *, source=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Split string by the occurrences of pattern.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_SPLIT_METHODDEF \
|
||||||
|
{"split", (PyCFunction)_sre_SRE_Pattern_split, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_split__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
|
||||||
|
Py_ssize_t maxsplit, PyObject *source);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_split(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"string", "maxsplit", "source", NULL};
|
||||||
|
PyObject *string = NULL;
|
||||||
|
Py_ssize_t maxsplit = 0;
|
||||||
|
PyObject *source = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|On$O:split", _keywords,
|
||||||
|
&string, &maxsplit, &source))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_split_impl(self, string, maxsplit, source);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_sub__doc__,
|
||||||
|
"sub($self, /, repl, string, count=0)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_SUB_METHODDEF \
|
||||||
|
{"sub", (PyCFunction)_sre_SRE_Pattern_sub, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_sub__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_sub_impl(PatternObject *self, PyObject *repl,
|
||||||
|
PyObject *string, Py_ssize_t count);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_sub(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"repl", "string", "count", NULL};
|
||||||
|
PyObject *repl;
|
||||||
|
PyObject *string;
|
||||||
|
Py_ssize_t count = 0;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|n:sub", _keywords,
|
||||||
|
&repl, &string, &count))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_sub_impl(self, repl, string, count);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern_subn__doc__,
|
||||||
|
"subn($self, /, repl, string, count=0)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost non-overlapping occurrences of pattern with the replacement repl.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN_SUBN_METHODDEF \
|
||||||
|
{"subn", (PyCFunction)_sre_SRE_Pattern_subn, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern_subn__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_subn_impl(PatternObject *self, PyObject *repl,
|
||||||
|
PyObject *string, Py_ssize_t count);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern_subn(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"repl", "string", "count", NULL};
|
||||||
|
PyObject *repl;
|
||||||
|
PyObject *string;
|
||||||
|
Py_ssize_t count = 0;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|n:subn", _keywords,
|
||||||
|
&repl, &string, &count))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern_subn_impl(self, repl, string, count);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern___copy____doc__,
|
||||||
|
"__copy__($self, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN___COPY___METHODDEF \
|
||||||
|
{"__copy__", (PyCFunction)_sre_SRE_Pattern___copy__, METH_NOARGS, _sre_SRE_Pattern___copy____doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern___copy___impl(PatternObject *self);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern___copy__(PatternObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
return _sre_SRE_Pattern___copy___impl(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Pattern___deepcopy____doc__,
|
||||||
|
"__deepcopy__($self, /, memo)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_PATTERN___DEEPCOPY___METHODDEF \
|
||||||
|
{"__deepcopy__", (PyCFunction)_sre_SRE_Pattern___deepcopy__, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Pattern___deepcopy____doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern___deepcopy___impl(PatternObject *self, PyObject *memo);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Pattern___deepcopy__(PatternObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"memo", NULL};
|
||||||
|
PyObject *memo;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:__deepcopy__", _keywords,
|
||||||
|
&memo))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Pattern___deepcopy___impl(self, memo);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_compile__doc__,
|
||||||
|
"compile($module, /, pattern, flags, code, groups, groupindex,\n"
|
||||||
|
" indexgroup)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_COMPILE_METHODDEF \
|
||||||
|
{"compile", (PyCFunction)_sre_compile, METH_VARARGS|METH_KEYWORDS, _sre_compile__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_compile_impl(PyModuleDef *module, PyObject *pattern, int flags,
|
||||||
|
PyObject *code, Py_ssize_t groups, PyObject *groupindex,
|
||||||
|
PyObject *indexgroup);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_compile(PyModuleDef *module, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
|
||||||
|
PyObject *pattern;
|
||||||
|
int flags;
|
||||||
|
PyObject *code;
|
||||||
|
Py_ssize_t groups;
|
||||||
|
PyObject *groupindex;
|
||||||
|
PyObject *indexgroup;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OiO!nOO:compile", _keywords,
|
||||||
|
&pattern, &flags, &PyList_Type, &code, &groups, &groupindex, &indexgroup))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match_expand__doc__,
|
||||||
|
"expand($self, /, template)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return the string obtained by doing backslash substitution on the string template, as done by the sub() method.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH_EXPAND_METHODDEF \
|
||||||
|
{"expand", (PyCFunction)_sre_SRE_Match_expand, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Match_expand__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_expand(MatchObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"template", NULL};
|
||||||
|
PyObject *template;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:expand", _keywords,
|
||||||
|
&template))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Match_expand_impl(self, template);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match_groups__doc__,
|
||||||
|
"groups($self, /, default=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return a tuple containing all the subgroups of the match, from 1.\n"
|
||||||
|
"\n"
|
||||||
|
" default\n"
|
||||||
|
" Is used for groups that did not participate in the match.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH_GROUPS_METHODDEF \
|
||||||
|
{"groups", (PyCFunction)_sre_SRE_Match_groups, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Match_groups__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_groups_impl(MatchObject *self, PyObject *default_value);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_groups(MatchObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"default", NULL};
|
||||||
|
PyObject *default_value = Py_None;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:groups", _keywords,
|
||||||
|
&default_value))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Match_groups_impl(self, default_value);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match_groupdict__doc__,
|
||||||
|
"groupdict($self, /, default=None)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return a dictionary containing all the named subgroups of the match, keyed by the subgroup name.\n"
|
||||||
|
"\n"
|
||||||
|
" default\n"
|
||||||
|
" Is used for groups that did not participate in the match.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH_GROUPDICT_METHODDEF \
|
||||||
|
{"groupdict", (PyCFunction)_sre_SRE_Match_groupdict, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Match_groupdict__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_groupdict(MatchObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"default", NULL};
|
||||||
|
PyObject *default_value = Py_None;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|O:groupdict", _keywords,
|
||||||
|
&default_value))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Match_groupdict_impl(self, default_value);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match_start__doc__,
|
||||||
|
"start($self, group=0, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return index of the start of the substring matched by group.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH_START_METHODDEF \
|
||||||
|
{"start", (PyCFunction)_sre_SRE_Match_start, METH_VARARGS, _sre_SRE_Match_start__doc__},
|
||||||
|
|
||||||
|
static Py_ssize_t
|
||||||
|
_sre_SRE_Match_start_impl(MatchObject *self, PyObject *group);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_start(MatchObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
PyObject *group = NULL;
|
||||||
|
Py_ssize_t _return_value;
|
||||||
|
|
||||||
|
if (!PyArg_UnpackTuple(args, "start",
|
||||||
|
0, 1,
|
||||||
|
&group))
|
||||||
|
goto exit;
|
||||||
|
_return_value = _sre_SRE_Match_start_impl(self, group);
|
||||||
|
if ((_return_value == -1) && PyErr_Occurred())
|
||||||
|
goto exit;
|
||||||
|
return_value = PyLong_FromSsize_t(_return_value);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match_end__doc__,
|
||||||
|
"end($self, group=0, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"Return index of the end of the substring matched by group.");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH_END_METHODDEF \
|
||||||
|
{"end", (PyCFunction)_sre_SRE_Match_end, METH_VARARGS, _sre_SRE_Match_end__doc__},
|
||||||
|
|
||||||
|
static Py_ssize_t
|
||||||
|
_sre_SRE_Match_end_impl(MatchObject *self, PyObject *group);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_end(MatchObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
PyObject *group = NULL;
|
||||||
|
Py_ssize_t _return_value;
|
||||||
|
|
||||||
|
if (!PyArg_UnpackTuple(args, "end",
|
||||||
|
0, 1,
|
||||||
|
&group))
|
||||||
|
goto exit;
|
||||||
|
_return_value = _sre_SRE_Match_end_impl(self, group);
|
||||||
|
if ((_return_value == -1) && PyErr_Occurred())
|
||||||
|
goto exit;
|
||||||
|
return_value = PyLong_FromSsize_t(_return_value);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match_span__doc__,
|
||||||
|
"span($self, group=0, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n"
|
||||||
|
"For MatchObject m, return the 2-tuple (m.start(group), m.end(group)).");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH_SPAN_METHODDEF \
|
||||||
|
{"span", (PyCFunction)_sre_SRE_Match_span, METH_VARARGS, _sre_SRE_Match_span__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_span_impl(MatchObject *self, PyObject *group);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match_span(MatchObject *self, PyObject *args)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
PyObject *group = NULL;
|
||||||
|
|
||||||
|
if (!PyArg_UnpackTuple(args, "span",
|
||||||
|
0, 1,
|
||||||
|
&group))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Match_span_impl(self, group);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match___copy____doc__,
|
||||||
|
"__copy__($self, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH___COPY___METHODDEF \
|
||||||
|
{"__copy__", (PyCFunction)_sre_SRE_Match___copy__, METH_NOARGS, _sre_SRE_Match___copy____doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match___copy___impl(MatchObject *self);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match___copy__(MatchObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
return _sre_SRE_Match___copy___impl(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Match___deepcopy____doc__,
|
||||||
|
"__deepcopy__($self, /, memo)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_MATCH___DEEPCOPY___METHODDEF \
|
||||||
|
{"__deepcopy__", (PyCFunction)_sre_SRE_Match___deepcopy__, METH_VARARGS|METH_KEYWORDS, _sre_SRE_Match___deepcopy____doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match___deepcopy___impl(MatchObject *self, PyObject *memo);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Match___deepcopy__(MatchObject *self, PyObject *args, PyObject *kwargs)
|
||||||
|
{
|
||||||
|
PyObject *return_value = NULL;
|
||||||
|
static char *_keywords[] = {"memo", NULL};
|
||||||
|
PyObject *memo;
|
||||||
|
|
||||||
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:__deepcopy__", _keywords,
|
||||||
|
&memo))
|
||||||
|
goto exit;
|
||||||
|
return_value = _sre_SRE_Match___deepcopy___impl(self, memo);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return return_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Scanner_match__doc__,
|
||||||
|
"match($self, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_SCANNER_MATCH_METHODDEF \
|
||||||
|
{"match", (PyCFunction)_sre_SRE_Scanner_match, METH_NOARGS, _sre_SRE_Scanner_match__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Scanner_match_impl(ScannerObject *self);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Scanner_match(ScannerObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
return _sre_SRE_Scanner_match_impl(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
PyDoc_STRVAR(_sre_SRE_Scanner_search__doc__,
|
||||||
|
"search($self, /)\n"
|
||||||
|
"--\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
#define _SRE_SRE_SCANNER_SEARCH_METHODDEF \
|
||||||
|
{"search", (PyCFunction)_sre_SRE_Scanner_search, METH_NOARGS, _sre_SRE_Scanner_search__doc__},
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Scanner_search_impl(ScannerObject *self);
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
_sre_SRE_Scanner_search(ScannerObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
return _sre_SRE_Scanner_search_impl(self);
|
||||||
|
}
|
||||||
|
/*[clinic end generated code: output=d1d73ab2c5008bd4 input=a9049054013a1b77]*/
|
Loading…
Reference in New Issue