diff -r 62a058c76869 Modules/_sre.c --- a/Modules/_sre.c Mon Dec 01 13:10:12 2014 +0200 +++ b/Modules/_sre.c Mon Dec 01 16:07:11 2014 +0200 @@ -258,25 +258,47 @@ data_stack_grow(SRE_STATE* state, Py_ssi /* see sre.h for object declarations */ static PyObject*pattern_new_match(PatternObject*, SRE_STATE*, Py_ssize_t); -static PyObject*pattern_scanner(PatternObject*, PyObject*, PyObject* kw); - -static PyObject * -sre_codesize(PyObject* self, PyObject *unused) +static PyObject *pattern_scanner(PatternObject *, PyObject *, Py_ssize_t, Py_ssize_t); + + +/*[clinic input] +output preset file +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=e88df7cedd7ac4f0]*/ + +/*[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 * -sre_getlower(PyObject* self, PyObject* args) +/*[clinic input] +_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) - return Py_BuildValue("i", sre_lower_locale(character)); + return sre_lower_locale(character); if (flags & SRE_FLAG_UNICODE) - return Py_BuildValue("i", sre_lower_unicode(character)); - return Py_BuildValue("i", sre_lower(character)); + return sre_lower_unicode(character); + return sre_lower(character); } LOCAL(void) @@ -528,51 +550,25 @@ sre_search(SRE_STATE* state, SRE_CODE* p return sre_ucs4_search(state, pattern); } +/*[clinic input] +_sre.SRE_Pattern.match + + string: object + pos: Py_ssize_t = 0 + endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize + +Matches zero or more characters at the beginning of the string. +[clinic start generated code]*/ + static PyObject * -fix_string_param(PyObject *string, PyObject *string2, const char *oldname) +_sre_SRE_Pattern_match_impl(PatternObject *self, PyObject *string, Py_ssize_t pos, Py_ssize_t endpos) +/*[clinic end generated code: output=898dda4b94aa375e input=a2ba191647abebe5]*/ { - if (string2 != NULL) { - if (string != NULL) { - PyErr_Format(PyExc_TypeError, - "Argument given by name ('%s') and position (1)", - oldname); - return NULL; - } - if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, - "The '%s' keyword parameter name is deprecated. " - "Use 'string' instead.", oldname) < 0) - return NULL; - return string2; - } - if (string == NULL) { - PyErr_SetString(PyExc_TypeError, - "Required argument 'string' (pos 1) not found"); - return NULL; - } - return string; -} - -static PyObject * -pattern_match(PatternObject *self, PyObject *args, PyObject *kwargs) -{ - 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; Py_ssize_t status; PyObject *match; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|Onn$O:match", _keywords, - &string, &pos, &endpos, &pattern)) - return NULL; - string = fix_string_param(string, pattern, "pattern"); - if (!string) - return NULL; - string = state_init(&state, (PatternObject *)self, string, pos, endpos); - if (!string) + if (!state_init(&state, self, string, pos, endpos)) return NULL; state.ptr = state.start; @@ -592,27 +588,25 @@ pattern_match(PatternObject *self, PyObj return match; } -static PyObject* -pattern_fullmatch(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_sre.SRE_Pattern.fullmatch + + string: object + pos: Py_ssize_t = 0 + endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize + +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=9f8b3725b4357948 input=a6f640614aaefceb]*/ { SRE_STATE state; Py_ssize_t status; PyObject *match; - PyObject *string = NULL, *string2 = NULL; - 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) - return NULL; - - string = state_init(&state, self, string, start, end); - if (!string) + if (!state_init(&state, self, string, pos, endpos)) return NULL; state.ptr = state.start; @@ -632,27 +626,27 @@ pattern_fullmatch(PatternObject* self, P return match; } -static PyObject* -pattern_search(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_sre.SRE_Pattern.search + + string: object + pos: Py_ssize_t = 0 + endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize + +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) +/*[clinic end generated code: output=f8aed6ac4d544770 input=4ae5cb7dc38fed1b]*/ { SRE_STATE state; Py_ssize_t status; PyObject *match; - PyObject *string = NULL, *string2 = NULL; - 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) - return NULL; - - string = state_init(&state, self, string, start, end); - if (!string) + if (!state_init(&state, self, string, pos, endpos)) return NULL; TRACE(("|%p|%p|SEARCH\n", PatternObject_GetCode(self), state.ptr)); @@ -718,28 +712,26 @@ deepcopy(PyObject** object, PyObject* me } #endif -static PyObject* -pattern_findall(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_sre.SRE_Pattern.findall + + string: object + pos: Py_ssize_t = 0 + endpos: Py_ssize_t(c_default="PY_SSIZE_T_MAX") = sys.maxsize + +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) +/*[clinic end generated code: output=5397c05eb712b177 input=5b6a4ee799741563]*/ { SRE_STATE state; PyObject* list; Py_ssize_t status; Py_ssize_t i, b, e; - 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:findall", kwlist, - &string, &start, &end, &string2)) - return NULL; - - string = fix_string_param(string, string2, "source"); - if (!string) - return NULL; - - string = state_init(&state, self, string, start, end); - if (!string) + if (!state_init(&state, self, string, pos, endpos)) return NULL; list = PyList_New(0); @@ -819,14 +811,27 @@ error: } -static PyObject* -pattern_finditer(PatternObject* pattern, PyObject* args, PyObject* kw) +/*[clinic input] +_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=f7b3c8588adbc437 input=612aab69e9fe08e4]*/ { PyObject* scanner; PyObject* search; PyObject* iterator; - scanner = pattern_scanner(pattern, args, kw); + scanner = pattern_scanner(self, string, pos, endpos); if (!scanner) return NULL; @@ -841,8 +846,34 @@ pattern_finditer(PatternObject* pattern, return iterator; } -static PyObject* -pattern_split(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_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=e10c636bd168c03d input=3aacdbde77a3a637]*/ +{ + return pattern_scanner(self, string, pos, endpos); +} + +/*[clinic input] +_sre.SRE_Pattern.split + + string: object + maxsplit: Py_ssize_t = 0 + +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) +/*[clinic end generated code: output=8f2797b44f75521d input=1eeeb10dafc9947a]*/ { SRE_STATE state; PyObject* list; @@ -852,19 +883,7 @@ pattern_split(PatternObject* self, PyObj Py_ssize_t i; void* last; - PyObject *string = NULL, *string2 = NULL; - 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) - return NULL; - - string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX); - if (!string) + if (!state_init(&state, self, string, 0, PY_SSIZE_T_MAX)) return NULL; list = PyList_New(0); @@ -1008,8 +1027,7 @@ pattern_subx(PatternObject* self, PyObje } } - string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX); - if (!string) { + if (!state_init(&state, self, string, 0, PY_SSIZE_T_MAX)) { Py_DECREF(filter); return NULL; } @@ -1149,36 +1167,48 @@ error: } -static PyObject* -pattern_sub(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_sre.SRE_Pattern.sub + + 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=639479f6d3dee458 input=c53d70be0b3caf86]*/ { - 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); + return pattern_subx(self, repl, string, count, 0); } -static PyObject* -pattern_subn(PatternObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_sre.SRE_Pattern.subn + + 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=2d55e5b45cf7c04f input=e7342d7ce6083577]*/ { - 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); + return pattern_subx(self, repl, string, count, 1); } -static PyObject* -pattern_copy(PatternObject* self, PyObject *unused) +/*[clinic input] +_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 PatternObject* copy; @@ -1205,8 +1235,16 @@ pattern_copy(PatternObject* self, PyObje #endif } -static PyObject* -pattern_deepcopy(PatternObject* self, PyObject* memo) +/*[clinic input] +_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 PatternObject* copy; @@ -1308,68 +1346,9 @@ done: 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"); -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} -}; +static PyMethodDef pattern_methods[]; #define PAT_OFF(x) offsetof(PatternObject, x) static PyMemberDef pattern_members[] = { @@ -1413,26 +1392,27 @@ static PyTypeObject Pattern_Type = { 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 * -_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=1b545192bda1f177 input=7d059ec8ae1edb85]*/ { /* "compile" pattern descriptor to pattern object */ PatternObject* self; 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); /* coverity[ampersand_in_size] */ self = PyObject_NEW_VAR(PatternObject, &Pattern_Type, n); @@ -2045,13 +2025,22 @@ match_getslice(MatchObject* self, PyObje return match_getslice_by_index(self, match_getindex(self, index), def); } -static PyObject* -match_expand(MatchObject* self, PyObject* ptemplate) +/*[clinic input] +_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 */ return call( SRE_PY_MODULE, "_expand", - PyTuple_Pack(3, self->pattern, self, ptemplate) + PyTuple_Pack(3, self->pattern, self, template) ); } @@ -2090,24 +2079,29 @@ match_group(MatchObject* self, PyObject* return result; } -static PyObject* -match_groups(MatchObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_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; 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); if (!result) return NULL; for (index = 1; index < self->groups; index++) { PyObject* item; - item = match_getslice_by_index(self, index, def); + item = match_getslice_by_index(self, index, default_value); if (!item) { Py_DECREF(result); return NULL; @@ -2118,18 +2112,23 @@ match_groups(MatchObject* self, PyObject return result; } -static PyObject* -match_groupdict(MatchObject* self, PyObject* args, PyObject* kw) +/*[clinic input] +_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* keys; 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(); if (!result || !self->pattern->groupindex) return result; @@ -2145,7 +2144,7 @@ match_groupdict(MatchObject* self, PyObj key = PyList_GET_ITEM(keys, index); if (!key) goto failed; - value = match_getslice(self, key, def); + value = match_getslice(self, key, default_value); if (!value) { Py_DECREF(key); goto failed; @@ -2166,50 +2165,58 @@ failed: return NULL; } -static PyObject* -match_start(MatchObject* self, PyObject* args) +/*[clinic input] +_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; - - PyObject* index_ = NULL; - if (!PyArg_UnpackTuple(args, "start", 0, 1, &index_)) - return NULL; - - index = match_getindex(self, index_); + Py_ssize_t index = match_getindex(self, group); if (index < 0 || index >= self->groups) { PyErr_SetString( PyExc_IndexError, "no such group" ); - return NULL; + return -1; } /* mark is -1 if group is undefined */ - return PyLong_FromSsize_t(self->mark[index*2]); + return self->mark[index*2]; } -static PyObject* -match_end(MatchObject* self, PyObject* args) +/*[clinic input] +_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; - - PyObject* index_ = NULL; - if (!PyArg_UnpackTuple(args, "end", 0, 1, &index_)) - return NULL; - - index = match_getindex(self, index_); + Py_ssize_t index = match_getindex(self, group); if (index < 0 || index >= self->groups) { PyErr_SetString( PyExc_IndexError, "no such group" ); - return NULL; + return -1; } /* mark is -1 if group is undefined */ - return PyLong_FromSsize_t(self->mark[index*2+1]); + return self->mark[index*2+1]; } LOCAL(PyObject*) @@ -2239,16 +2246,20 @@ LOCAL(PyObject*) return NULL; } -static PyObject* -match_span(MatchObject* self, PyObject* args) +/*[clinic input] +_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; - - PyObject* index_ = NULL; - if (!PyArg_UnpackTuple(args, "span", 0, 1, &index_)) - return NULL; - - index = match_getindex(self, index_); + Py_ssize_t index = match_getindex(self, group); if (index < 0 || index >= self->groups) { PyErr_SetString( @@ -2288,8 +2299,14 @@ match_regs(MatchObject* self) return regs; } -static PyObject* -match_copy(MatchObject* self, PyObject *unused) +/*[clinic input] +_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 MatchObject* copy; @@ -2319,8 +2336,16 @@ match_copy(MatchObject* self, PyObject * #endif } -static PyObject* -match_deepcopy(MatchObject* self, PyObject* memo) +/*[clinic input] +_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 MatchObject* copy; @@ -2351,49 +2376,7 @@ PyDoc_STRVAR(match_group_doc, Return subgroup(s) of the match by indices or names.\n\ For 0 returns the entire match."); -PyDoc_STRVAR(match_start_doc, -"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 PyMethodDef match_methods[]; static PyObject * match_lastindex_get(MatchObject *self) @@ -2571,8 +2554,14 @@ scanner_dealloc(ScannerObject* self) PyObject_DEL(self); } -static PyObject* -scanner_match(ScannerObject* self, PyObject *unused) +/*[clinic input] +_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; PyObject* match; @@ -2598,8 +2587,14 @@ scanner_match(ScannerObject* self, PyObj } -static PyObject* -scanner_search(ScannerObject* self, PyObject *unused) +/*[clinic input] +_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; PyObject* match; @@ -2624,11 +2619,7 @@ scanner_search(ScannerObject* self, PyOb return match; } -static PyMethodDef scanner_methods[] = { - {"match", (PyCFunction) scanner_match, METH_NOARGS}, - {"search", (PyCFunction) scanner_search, METH_NOARGS}, - {NULL, NULL} -}; +static PyMethodDef scanner_methods[]; #define SCAN_OFF(x) offsetof(ScannerObject, x) static PyMemberDef scanner_members[] = { @@ -2668,47 +2659,69 @@ static PyTypeObject Scanner_Type = { 0, /* tp_getset */ }; -static PyObject* -pattern_scanner(PatternObject* pattern, PyObject* args, PyObject* kw) +static PyObject * +pattern_scanner(PatternObject *self, PyObject *string, Py_ssize_t pos, Py_ssize_t endpos) { + ScannerObject* scanner; + + /* create scanner object */ + scanner = PyObject_NEW(ScannerObject, &Scanner_Type); + if (!scanner) + return NULL; + scanner->pattern = NULL; + /* create search state object */ - - 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 */ - self = PyObject_NEW(ScannerObject, &Scanner_Type); - if (!self) - return NULL; - self->pattern = NULL; - - string = state_init(&self->state, pattern, string, start, end); - if (!string) { - Py_DECREF(self); + if (!state_init(&scanner->state, self, string, pos, endpos)) { + Py_DECREF(scanner); return NULL; } - Py_INCREF(pattern); - self->pattern = (PyObject*) pattern; - - return (PyObject*) self; + Py_INCREF(self); + scanner->pattern = (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[] = { - {"compile", _compile, METH_VARARGS}, - {"getcodesize", sre_codesize, METH_NOARGS}, - {"getlower", sre_getlower, METH_VARARGS}, + _SRE_COMPILE_METHODDEF + _SRE_GETCODESIZE_METHODDEF + _SRE_GETLOWER_METHODDEF {NULL, NULL} }; diff -r 62a058c76869 Modules/clinic/_sre.c.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Modules/clinic/_sre.c.h Mon Dec 01 16:07:11 2014 +0200 @@ -0,0 +1,676 @@ +/*[clinic input] +preserve +[clinic start generated code]*/ + +PyDoc_STRVAR(_sre_getcodesize__doc__, +"getcodesize($module, /)\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" +"--"); + +#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, pos=0, endpos=sys.maxsize)\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); + +static PyObject * +_sre_SRE_Pattern_match(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:match", _keywords, + &string, &pos, &endpos)) + goto exit; + return_value = _sre_SRE_Pattern_match_impl(self, string, pos, endpos); + +exit: + return return_value; +} + +PyDoc_STRVAR(_sre_SRE_Pattern_fullmatch__doc__, +"fullmatch($self, /, string, pos=0, endpos=sys.maxsize)\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); + +static PyObject * +_sre_SRE_Pattern_fullmatch(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:fullmatch", _keywords, + &string, &pos, &endpos)) + goto exit; + return_value = _sre_SRE_Pattern_fullmatch_impl(self, string, pos, endpos); + +exit: + return return_value; +} + +PyDoc_STRVAR(_sre_SRE_Pattern_search__doc__, +"search($self, /, string, pos=0, endpos=sys.maxsize)\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); + +static PyObject * +_sre_SRE_Pattern_search(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:search", _keywords, + &string, &pos, &endpos)) + goto exit; + return_value = _sre_SRE_Pattern_search_impl(self, string, pos, endpos); + +exit: + return return_value; +} + +PyDoc_STRVAR(_sre_SRE_Pattern_findall__doc__, +"findall($self, /, string, pos=0, endpos=sys.maxsize)\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); + +static PyObject * +_sre_SRE_Pattern_findall(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:findall", _keywords, + &string, &pos, &endpos)) + goto exit; + return_value = _sre_SRE_Pattern_findall_impl(self, string, pos, endpos); + +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" +"--"); + +#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, maxsplit=0)\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); + +static PyObject * +_sre_SRE_Pattern_split(PatternObject *self, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"string", "maxsplit", NULL}; + PyObject *string; + Py_ssize_t maxsplit = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O|n:split", _keywords, + &string, &maxsplit)) + goto exit; + return_value = _sre_SRE_Pattern_split_impl(self, string, maxsplit); + +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" +"--"); + +#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" +"--"); + +#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" +"--"); + +#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" +"--"); + +#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" +"--"); + +#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" +"--"); + +#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" +"--"); + +#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=00ac6485259f6919 input=a9049054013a1b77]*/