blob: d398a8504ba4180da237b30aad9576faab573903 [file] [log] [blame]
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_sre_getcodesize__doc__,
6"getcodesize($module, /)\n"
7"--\n"
8"\n");
9
10#define _SRE_GETCODESIZE_METHODDEF \
11 {"getcodesize", (PyCFunction)_sre_getcodesize, METH_NOARGS, _sre_getcodesize__doc__},
12
13static int
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030014_sre_getcodesize_impl(PyObject *module);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +030015
16static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +030017_sre_getcodesize(PyObject *module, PyObject *Py_UNUSED(ignored))
Serhiy Storchakaa860aea2015-05-03 15:54:23 +030018{
19 PyObject *return_value = NULL;
20 int _return_value;
21
22 _return_value = _sre_getcodesize_impl(module);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030023 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +030024 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030025 }
Serhiy Storchakaa860aea2015-05-03 15:54:23 +030026 return_value = PyLong_FromLong((long)_return_value);
27
28exit:
29 return return_value;
30}
31
Serhiy Storchaka6d336a02017-05-09 23:37:14 +030032PyDoc_STRVAR(_sre_ascii_iscased__doc__,
33"ascii_iscased($module, character, /)\n"
34"--\n"
35"\n");
36
37#define _SRE_ASCII_ISCASED_METHODDEF \
38 {"ascii_iscased", (PyCFunction)_sre_ascii_iscased, METH_O, _sre_ascii_iscased__doc__},
39
40static int
41_sre_ascii_iscased_impl(PyObject *module, int character);
42
43static PyObject *
44_sre_ascii_iscased(PyObject *module, PyObject *arg)
45{
46 PyObject *return_value = NULL;
47 int character;
48 int _return_value;
49
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020050 if (PyFloat_Check(arg)) {
51 PyErr_SetString(PyExc_TypeError,
52 "integer argument expected, got float" );
53 goto exit;
54 }
55 character = _PyLong_AsInt(arg);
56 if (character == -1 && PyErr_Occurred()) {
Serhiy Storchaka6d336a02017-05-09 23:37:14 +030057 goto exit;
58 }
59 _return_value = _sre_ascii_iscased_impl(module, character);
60 if ((_return_value == -1) && PyErr_Occurred()) {
61 goto exit;
62 }
63 return_value = PyBool_FromLong((long)_return_value);
64
65exit:
66 return return_value;
67}
68
69PyDoc_STRVAR(_sre_unicode_iscased__doc__,
70"unicode_iscased($module, character, /)\n"
71"--\n"
72"\n");
73
74#define _SRE_UNICODE_ISCASED_METHODDEF \
75 {"unicode_iscased", (PyCFunction)_sre_unicode_iscased, METH_O, _sre_unicode_iscased__doc__},
76
77static int
78_sre_unicode_iscased_impl(PyObject *module, int character);
79
80static PyObject *
81_sre_unicode_iscased(PyObject *module, PyObject *arg)
82{
83 PyObject *return_value = NULL;
84 int character;
85 int _return_value;
86
Serhiy Storchaka32d96a22018-12-25 13:23:47 +020087 if (PyFloat_Check(arg)) {
88 PyErr_SetString(PyExc_TypeError,
89 "integer argument expected, got float" );
90 goto exit;
91 }
92 character = _PyLong_AsInt(arg);
93 if (character == -1 && PyErr_Occurred()) {
Serhiy Storchaka6d336a02017-05-09 23:37:14 +030094 goto exit;
95 }
96 _return_value = _sre_unicode_iscased_impl(module, character);
97 if ((_return_value == -1) && PyErr_Occurred()) {
98 goto exit;
99 }
100 return_value = PyBool_FromLong((long)_return_value);
101
102exit:
103 return return_value;
104}
105
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300106PyDoc_STRVAR(_sre_ascii_tolower__doc__,
107"ascii_tolower($module, character, /)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300108"--\n"
109"\n");
110
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300111#define _SRE_ASCII_TOLOWER_METHODDEF \
112 {"ascii_tolower", (PyCFunction)_sre_ascii_tolower, METH_O, _sre_ascii_tolower__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300113
114static int
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300115_sre_ascii_tolower_impl(PyObject *module, int character);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300116
117static PyObject *
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300118_sre_ascii_tolower(PyObject *module, PyObject *arg)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300119{
120 PyObject *return_value = NULL;
121 int character;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300122 int _return_value;
123
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200124 if (PyFloat_Check(arg)) {
125 PyErr_SetString(PyExc_TypeError,
126 "integer argument expected, got float" );
127 goto exit;
128 }
129 character = _PyLong_AsInt(arg);
130 if (character == -1 && PyErr_Occurred()) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300131 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300132 }
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300133 _return_value = _sre_ascii_tolower_impl(module, character);
134 if ((_return_value == -1) && PyErr_Occurred()) {
135 goto exit;
136 }
137 return_value = PyLong_FromLong((long)_return_value);
Victor Stinner259f0e42017-01-17 01:35:17 +0100138
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300139exit:
140 return return_value;
141}
142
143PyDoc_STRVAR(_sre_unicode_tolower__doc__,
144"unicode_tolower($module, character, /)\n"
145"--\n"
146"\n");
147
148#define _SRE_UNICODE_TOLOWER_METHODDEF \
149 {"unicode_tolower", (PyCFunction)_sre_unicode_tolower, METH_O, _sre_unicode_tolower__doc__},
150
151static int
152_sre_unicode_tolower_impl(PyObject *module, int character);
153
154static PyObject *
155_sre_unicode_tolower(PyObject *module, PyObject *arg)
156{
157 PyObject *return_value = NULL;
158 int character;
159 int _return_value;
160
Serhiy Storchaka32d96a22018-12-25 13:23:47 +0200161 if (PyFloat_Check(arg)) {
162 PyErr_SetString(PyExc_TypeError,
163 "integer argument expected, got float" );
164 goto exit;
165 }
166 character = _PyLong_AsInt(arg);
167 if (character == -1 && PyErr_Occurred()) {
Victor Stinner259f0e42017-01-17 01:35:17 +0100168 goto exit;
169 }
Serhiy Storchaka7186cc22017-05-05 10:42:46 +0300170 _return_value = _sre_unicode_tolower_impl(module, character);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300171 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300172 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300173 }
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300174 return_value = PyLong_FromLong((long)_return_value);
175
176exit:
177 return return_value;
178}
179
180PyDoc_STRVAR(_sre_SRE_Pattern_match__doc__,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200181"match($self, /, string, pos=0, endpos=sys.maxsize)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300182"--\n"
183"\n"
184"Matches zero or more characters at the beginning of the string.");
185
186#define _SRE_SRE_PATTERN_MATCH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200187 {"match", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_match, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_match__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300188
189static PyObject *
190_sre_SRE_Pattern_match_impl(PatternObject *self, PyObject *string,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200191 Py_ssize_t pos, Py_ssize_t endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300192
193static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200194_sre_SRE_Pattern_match(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300195{
196 PyObject *return_value = NULL;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200197 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200198 static _PyArg_Parser _parser = {NULL, _keywords, "match", 0};
199 PyObject *argsbuf[3];
200 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200201 PyObject *string;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300202 Py_ssize_t pos = 0;
203 Py_ssize_t endpos = PY_SSIZE_T_MAX;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300204
Serhiy Storchaka31913912019-03-14 10:32:22 +0200205 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
206 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300207 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300208 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200209 string = args[0];
210 if (!noptargs) {
211 goto skip_optional_pos;
212 }
213 if (args[1]) {
214 if (PyFloat_Check(args[1])) {
215 PyErr_SetString(PyExc_TypeError,
216 "integer argument expected, got float" );
217 goto exit;
218 }
219 {
220 Py_ssize_t ival = -1;
221 PyObject *iobj = PyNumber_Index(args[1]);
222 if (iobj != NULL) {
223 ival = PyLong_AsSsize_t(iobj);
224 Py_DECREF(iobj);
225 }
226 if (ival == -1 && PyErr_Occurred()) {
227 goto exit;
228 }
229 pos = ival;
230 }
231 if (!--noptargs) {
232 goto skip_optional_pos;
233 }
234 }
235 if (PyFloat_Check(args[2])) {
236 PyErr_SetString(PyExc_TypeError,
237 "integer argument expected, got float" );
238 goto exit;
239 }
240 {
241 Py_ssize_t ival = -1;
242 PyObject *iobj = PyNumber_Index(args[2]);
243 if (iobj != NULL) {
244 ival = PyLong_AsSsize_t(iobj);
245 Py_DECREF(iobj);
246 }
247 if (ival == -1 && PyErr_Occurred()) {
248 goto exit;
249 }
250 endpos = ival;
251 }
252skip_optional_pos:
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200253 return_value = _sre_SRE_Pattern_match_impl(self, string, pos, endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300254
255exit:
256 return return_value;
257}
258
259PyDoc_STRVAR(_sre_SRE_Pattern_fullmatch__doc__,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200260"fullmatch($self, /, string, pos=0, endpos=sys.maxsize)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300261"--\n"
262"\n"
Serhiy Storchaka0b5e61d2017-10-04 20:09:49 +0300263"Matches against all of the string.");
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300264
265#define _SRE_SRE_PATTERN_FULLMATCH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200266 {"fullmatch", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_fullmatch, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_fullmatch__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300267
268static PyObject *
269_sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyObject *string,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200270 Py_ssize_t pos, Py_ssize_t endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300271
272static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200273_sre_SRE_Pattern_fullmatch(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300274{
275 PyObject *return_value = NULL;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200276 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200277 static _PyArg_Parser _parser = {NULL, _keywords, "fullmatch", 0};
278 PyObject *argsbuf[3];
279 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200280 PyObject *string;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300281 Py_ssize_t pos = 0;
282 Py_ssize_t endpos = PY_SSIZE_T_MAX;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300283
Serhiy Storchaka31913912019-03-14 10:32:22 +0200284 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
285 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300286 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300287 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200288 string = args[0];
289 if (!noptargs) {
290 goto skip_optional_pos;
291 }
292 if (args[1]) {
293 if (PyFloat_Check(args[1])) {
294 PyErr_SetString(PyExc_TypeError,
295 "integer argument expected, got float" );
296 goto exit;
297 }
298 {
299 Py_ssize_t ival = -1;
300 PyObject *iobj = PyNumber_Index(args[1]);
301 if (iobj != NULL) {
302 ival = PyLong_AsSsize_t(iobj);
303 Py_DECREF(iobj);
304 }
305 if (ival == -1 && PyErr_Occurred()) {
306 goto exit;
307 }
308 pos = ival;
309 }
310 if (!--noptargs) {
311 goto skip_optional_pos;
312 }
313 }
314 if (PyFloat_Check(args[2])) {
315 PyErr_SetString(PyExc_TypeError,
316 "integer argument expected, got float" );
317 goto exit;
318 }
319 {
320 Py_ssize_t ival = -1;
321 PyObject *iobj = PyNumber_Index(args[2]);
322 if (iobj != NULL) {
323 ival = PyLong_AsSsize_t(iobj);
324 Py_DECREF(iobj);
325 }
326 if (ival == -1 && PyErr_Occurred()) {
327 goto exit;
328 }
329 endpos = ival;
330 }
331skip_optional_pos:
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200332 return_value = _sre_SRE_Pattern_fullmatch_impl(self, string, pos, endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300333
334exit:
335 return return_value;
336}
337
338PyDoc_STRVAR(_sre_SRE_Pattern_search__doc__,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200339"search($self, /, string, pos=0, endpos=sys.maxsize)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300340"--\n"
341"\n"
342"Scan through string looking for a match, and return a corresponding match object instance.\n"
343"\n"
344"Return None if no position in the string matches.");
345
346#define _SRE_SRE_PATTERN_SEARCH_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200347 {"search", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_search, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_search__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300348
349static PyObject *
350_sre_SRE_Pattern_search_impl(PatternObject *self, PyObject *string,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200351 Py_ssize_t pos, Py_ssize_t endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300352
353static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200354_sre_SRE_Pattern_search(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300355{
356 PyObject *return_value = NULL;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200357 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200358 static _PyArg_Parser _parser = {NULL, _keywords, "search", 0};
359 PyObject *argsbuf[3];
360 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200361 PyObject *string;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300362 Py_ssize_t pos = 0;
363 Py_ssize_t endpos = PY_SSIZE_T_MAX;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300364
Serhiy Storchaka31913912019-03-14 10:32:22 +0200365 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
366 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300367 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300368 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200369 string = args[0];
370 if (!noptargs) {
371 goto skip_optional_pos;
372 }
373 if (args[1]) {
374 if (PyFloat_Check(args[1])) {
375 PyErr_SetString(PyExc_TypeError,
376 "integer argument expected, got float" );
377 goto exit;
378 }
379 {
380 Py_ssize_t ival = -1;
381 PyObject *iobj = PyNumber_Index(args[1]);
382 if (iobj != NULL) {
383 ival = PyLong_AsSsize_t(iobj);
384 Py_DECREF(iobj);
385 }
386 if (ival == -1 && PyErr_Occurred()) {
387 goto exit;
388 }
389 pos = ival;
390 }
391 if (!--noptargs) {
392 goto skip_optional_pos;
393 }
394 }
395 if (PyFloat_Check(args[2])) {
396 PyErr_SetString(PyExc_TypeError,
397 "integer argument expected, got float" );
398 goto exit;
399 }
400 {
401 Py_ssize_t ival = -1;
402 PyObject *iobj = PyNumber_Index(args[2]);
403 if (iobj != NULL) {
404 ival = PyLong_AsSsize_t(iobj);
405 Py_DECREF(iobj);
406 }
407 if (ival == -1 && PyErr_Occurred()) {
408 goto exit;
409 }
410 endpos = ival;
411 }
412skip_optional_pos:
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200413 return_value = _sre_SRE_Pattern_search_impl(self, string, pos, endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300414
415exit:
416 return return_value;
417}
418
419PyDoc_STRVAR(_sre_SRE_Pattern_findall__doc__,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200420"findall($self, /, string, pos=0, endpos=sys.maxsize)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300421"--\n"
422"\n"
423"Return a list of all non-overlapping matches of pattern in string.");
424
425#define _SRE_SRE_PATTERN_FINDALL_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200426 {"findall", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_findall, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_findall__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300427
428static PyObject *
429_sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200430 Py_ssize_t pos, Py_ssize_t endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300431
432static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200433_sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300434{
435 PyObject *return_value = NULL;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200436 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200437 static _PyArg_Parser _parser = {NULL, _keywords, "findall", 0};
438 PyObject *argsbuf[3];
439 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200440 PyObject *string;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300441 Py_ssize_t pos = 0;
442 Py_ssize_t endpos = PY_SSIZE_T_MAX;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300443
Serhiy Storchaka31913912019-03-14 10:32:22 +0200444 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
445 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300446 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300447 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200448 string = args[0];
449 if (!noptargs) {
450 goto skip_optional_pos;
451 }
452 if (args[1]) {
453 if (PyFloat_Check(args[1])) {
454 PyErr_SetString(PyExc_TypeError,
455 "integer argument expected, got float" );
456 goto exit;
457 }
458 {
459 Py_ssize_t ival = -1;
460 PyObject *iobj = PyNumber_Index(args[1]);
461 if (iobj != NULL) {
462 ival = PyLong_AsSsize_t(iobj);
463 Py_DECREF(iobj);
464 }
465 if (ival == -1 && PyErr_Occurred()) {
466 goto exit;
467 }
468 pos = ival;
469 }
470 if (!--noptargs) {
471 goto skip_optional_pos;
472 }
473 }
474 if (PyFloat_Check(args[2])) {
475 PyErr_SetString(PyExc_TypeError,
476 "integer argument expected, got float" );
477 goto exit;
478 }
479 {
480 Py_ssize_t ival = -1;
481 PyObject *iobj = PyNumber_Index(args[2]);
482 if (iobj != NULL) {
483 ival = PyLong_AsSsize_t(iobj);
484 Py_DECREF(iobj);
485 }
486 if (ival == -1 && PyErr_Occurred()) {
487 goto exit;
488 }
489 endpos = ival;
490 }
491skip_optional_pos:
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200492 return_value = _sre_SRE_Pattern_findall_impl(self, string, pos, endpos);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300493
494exit:
495 return return_value;
496}
497
498PyDoc_STRVAR(_sre_SRE_Pattern_finditer__doc__,
499"finditer($self, /, string, pos=0, endpos=sys.maxsize)\n"
500"--\n"
501"\n"
502"Return an iterator over all non-overlapping matches for the RE pattern in string.\n"
503"\n"
504"For each match, the iterator returns a match object.");
505
506#define _SRE_SRE_PATTERN_FINDITER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200507 {"finditer", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_finditer, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_finditer__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300508
509static PyObject *
510_sre_SRE_Pattern_finditer_impl(PatternObject *self, PyObject *string,
511 Py_ssize_t pos, Py_ssize_t endpos);
512
513static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200514_sre_SRE_Pattern_finditer(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300515{
516 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300517 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200518 static _PyArg_Parser _parser = {NULL, _keywords, "finditer", 0};
519 PyObject *argsbuf[3];
520 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300521 PyObject *string;
522 Py_ssize_t pos = 0;
523 Py_ssize_t endpos = PY_SSIZE_T_MAX;
524
Serhiy Storchaka31913912019-03-14 10:32:22 +0200525 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
526 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300527 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300528 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200529 string = args[0];
530 if (!noptargs) {
531 goto skip_optional_pos;
532 }
533 if (args[1]) {
534 if (PyFloat_Check(args[1])) {
535 PyErr_SetString(PyExc_TypeError,
536 "integer argument expected, got float" );
537 goto exit;
538 }
539 {
540 Py_ssize_t ival = -1;
541 PyObject *iobj = PyNumber_Index(args[1]);
542 if (iobj != NULL) {
543 ival = PyLong_AsSsize_t(iobj);
544 Py_DECREF(iobj);
545 }
546 if (ival == -1 && PyErr_Occurred()) {
547 goto exit;
548 }
549 pos = ival;
550 }
551 if (!--noptargs) {
552 goto skip_optional_pos;
553 }
554 }
555 if (PyFloat_Check(args[2])) {
556 PyErr_SetString(PyExc_TypeError,
557 "integer argument expected, got float" );
558 goto exit;
559 }
560 {
561 Py_ssize_t ival = -1;
562 PyObject *iobj = PyNumber_Index(args[2]);
563 if (iobj != NULL) {
564 ival = PyLong_AsSsize_t(iobj);
565 Py_DECREF(iobj);
566 }
567 if (ival == -1 && PyErr_Occurred()) {
568 goto exit;
569 }
570 endpos = ival;
571 }
572skip_optional_pos:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300573 return_value = _sre_SRE_Pattern_finditer_impl(self, string, pos, endpos);
574
575exit:
576 return return_value;
577}
578
579PyDoc_STRVAR(_sre_SRE_Pattern_scanner__doc__,
580"scanner($self, /, string, pos=0, endpos=sys.maxsize)\n"
581"--\n"
582"\n");
583
584#define _SRE_SRE_PATTERN_SCANNER_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200585 {"scanner", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_scanner, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_scanner__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300586
587static PyObject *
588_sre_SRE_Pattern_scanner_impl(PatternObject *self, PyObject *string,
589 Py_ssize_t pos, Py_ssize_t endpos);
590
591static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200592_sre_SRE_Pattern_scanner(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300593{
594 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300595 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200596 static _PyArg_Parser _parser = {NULL, _keywords, "scanner", 0};
597 PyObject *argsbuf[3];
598 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300599 PyObject *string;
600 Py_ssize_t pos = 0;
601 Py_ssize_t endpos = PY_SSIZE_T_MAX;
602
Serhiy Storchaka31913912019-03-14 10:32:22 +0200603 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
604 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300605 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300606 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200607 string = args[0];
608 if (!noptargs) {
609 goto skip_optional_pos;
610 }
611 if (args[1]) {
612 if (PyFloat_Check(args[1])) {
613 PyErr_SetString(PyExc_TypeError,
614 "integer argument expected, got float" );
615 goto exit;
616 }
617 {
618 Py_ssize_t ival = -1;
619 PyObject *iobj = PyNumber_Index(args[1]);
620 if (iobj != NULL) {
621 ival = PyLong_AsSsize_t(iobj);
622 Py_DECREF(iobj);
623 }
624 if (ival == -1 && PyErr_Occurred()) {
625 goto exit;
626 }
627 pos = ival;
628 }
629 if (!--noptargs) {
630 goto skip_optional_pos;
631 }
632 }
633 if (PyFloat_Check(args[2])) {
634 PyErr_SetString(PyExc_TypeError,
635 "integer argument expected, got float" );
636 goto exit;
637 }
638 {
639 Py_ssize_t ival = -1;
640 PyObject *iobj = PyNumber_Index(args[2]);
641 if (iobj != NULL) {
642 ival = PyLong_AsSsize_t(iobj);
643 Py_DECREF(iobj);
644 }
645 if (ival == -1 && PyErr_Occurred()) {
646 goto exit;
647 }
648 endpos = ival;
649 }
650skip_optional_pos:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300651 return_value = _sre_SRE_Pattern_scanner_impl(self, string, pos, endpos);
652
653exit:
654 return return_value;
655}
656
657PyDoc_STRVAR(_sre_SRE_Pattern_split__doc__,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200658"split($self, /, string, maxsplit=0)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300659"--\n"
660"\n"
661"Split string by the occurrences of pattern.");
662
663#define _SRE_SRE_PATTERN_SPLIT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200664 {"split", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_split, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_split__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300665
666static PyObject *
667_sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200668 Py_ssize_t maxsplit);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300669
670static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200671_sre_SRE_Pattern_split(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300672{
673 PyObject *return_value = NULL;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200674 static const char * const _keywords[] = {"string", "maxsplit", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200675 static _PyArg_Parser _parser = {NULL, _keywords, "split", 0};
676 PyObject *argsbuf[2];
677 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200678 PyObject *string;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300679 Py_ssize_t maxsplit = 0;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300680
Serhiy Storchaka31913912019-03-14 10:32:22 +0200681 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
682 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300683 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300684 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200685 string = args[0];
686 if (!noptargs) {
687 goto skip_optional_pos;
688 }
689 if (PyFloat_Check(args[1])) {
690 PyErr_SetString(PyExc_TypeError,
691 "integer argument expected, got float" );
692 goto exit;
693 }
694 {
695 Py_ssize_t ival = -1;
696 PyObject *iobj = PyNumber_Index(args[1]);
697 if (iobj != NULL) {
698 ival = PyLong_AsSsize_t(iobj);
699 Py_DECREF(iobj);
700 }
701 if (ival == -1 && PyErr_Occurred()) {
702 goto exit;
703 }
704 maxsplit = ival;
705 }
706skip_optional_pos:
Serhiy Storchakab37f3f62017-01-13 08:53:58 +0200707 return_value = _sre_SRE_Pattern_split_impl(self, string, maxsplit);
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300708
709exit:
710 return return_value;
711}
712
713PyDoc_STRVAR(_sre_SRE_Pattern_sub__doc__,
714"sub($self, /, repl, string, count=0)\n"
715"--\n"
716"\n"
717"Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.");
718
719#define _SRE_SRE_PATTERN_SUB_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200720 {"sub", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_sub, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_sub__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300721
722static PyObject *
723_sre_SRE_Pattern_sub_impl(PatternObject *self, PyObject *repl,
724 PyObject *string, Py_ssize_t count);
725
726static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200727_sre_SRE_Pattern_sub(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300728{
729 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300730 static const char * const _keywords[] = {"repl", "string", "count", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200731 static _PyArg_Parser _parser = {NULL, _keywords, "sub", 0};
732 PyObject *argsbuf[3];
733 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300734 PyObject *repl;
735 PyObject *string;
736 Py_ssize_t count = 0;
737
Serhiy Storchaka31913912019-03-14 10:32:22 +0200738 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
739 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300740 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300741 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200742 repl = args[0];
743 string = args[1];
744 if (!noptargs) {
745 goto skip_optional_pos;
746 }
747 if (PyFloat_Check(args[2])) {
748 PyErr_SetString(PyExc_TypeError,
749 "integer argument expected, got float" );
750 goto exit;
751 }
752 {
753 Py_ssize_t ival = -1;
754 PyObject *iobj = PyNumber_Index(args[2]);
755 if (iobj != NULL) {
756 ival = PyLong_AsSsize_t(iobj);
757 Py_DECREF(iobj);
758 }
759 if (ival == -1 && PyErr_Occurred()) {
760 goto exit;
761 }
762 count = ival;
763 }
764skip_optional_pos:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300765 return_value = _sre_SRE_Pattern_sub_impl(self, repl, string, count);
766
767exit:
768 return return_value;
769}
770
771PyDoc_STRVAR(_sre_SRE_Pattern_subn__doc__,
772"subn($self, /, repl, string, count=0)\n"
773"--\n"
774"\n"
775"Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost non-overlapping occurrences of pattern with the replacement repl.");
776
777#define _SRE_SRE_PATTERN_SUBN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200778 {"subn", (PyCFunction)(void(*)(void))_sre_SRE_Pattern_subn, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_subn__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300779
780static PyObject *
781_sre_SRE_Pattern_subn_impl(PatternObject *self, PyObject *repl,
782 PyObject *string, Py_ssize_t count);
783
784static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200785_sre_SRE_Pattern_subn(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300786{
787 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300788 static const char * const _keywords[] = {"repl", "string", "count", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200789 static _PyArg_Parser _parser = {NULL, _keywords, "subn", 0};
790 PyObject *argsbuf[3];
791 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300792 PyObject *repl;
793 PyObject *string;
794 Py_ssize_t count = 0;
795
Serhiy Storchaka31913912019-03-14 10:32:22 +0200796 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
797 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300798 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300799 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200800 repl = args[0];
801 string = args[1];
802 if (!noptargs) {
803 goto skip_optional_pos;
804 }
805 if (PyFloat_Check(args[2])) {
806 PyErr_SetString(PyExc_TypeError,
807 "integer argument expected, got float" );
808 goto exit;
809 }
810 {
811 Py_ssize_t ival = -1;
812 PyObject *iobj = PyNumber_Index(args[2]);
813 if (iobj != NULL) {
814 ival = PyLong_AsSsize_t(iobj);
815 Py_DECREF(iobj);
816 }
817 if (ival == -1 && PyErr_Occurred()) {
818 goto exit;
819 }
820 count = ival;
821 }
822skip_optional_pos:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300823 return_value = _sre_SRE_Pattern_subn_impl(self, repl, string, count);
824
825exit:
826 return return_value;
827}
828
829PyDoc_STRVAR(_sre_SRE_Pattern___copy____doc__,
830"__copy__($self, /)\n"
831"--\n"
832"\n");
833
834#define _SRE_SRE_PATTERN___COPY___METHODDEF \
835 {"__copy__", (PyCFunction)_sre_SRE_Pattern___copy__, METH_NOARGS, _sre_SRE_Pattern___copy____doc__},
836
837static PyObject *
838_sre_SRE_Pattern___copy___impl(PatternObject *self);
839
840static PyObject *
841_sre_SRE_Pattern___copy__(PatternObject *self, PyObject *Py_UNUSED(ignored))
842{
843 return _sre_SRE_Pattern___copy___impl(self);
844}
845
846PyDoc_STRVAR(_sre_SRE_Pattern___deepcopy____doc__,
Serhiy Storchakafdbd0112017-04-16 10:16:03 +0300847"__deepcopy__($self, memo, /)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300848"--\n"
849"\n");
850
851#define _SRE_SRE_PATTERN___DEEPCOPY___METHODDEF \
Serhiy Storchakafdbd0112017-04-16 10:16:03 +0300852 {"__deepcopy__", (PyCFunction)_sre_SRE_Pattern___deepcopy__, METH_O, _sre_SRE_Pattern___deepcopy____doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300853
854PyDoc_STRVAR(_sre_compile__doc__,
855"compile($module, /, pattern, flags, code, groups, groupindex,\n"
856" indexgroup)\n"
857"--\n"
858"\n");
859
860#define _SRE_COMPILE_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200861 {"compile", (PyCFunction)(void(*)(void))_sre_compile, METH_FASTCALL|METH_KEYWORDS, _sre_compile__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300862
863static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300864_sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300865 PyObject *code, Py_ssize_t groups, PyObject *groupindex,
866 PyObject *indexgroup);
867
868static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200869_sre_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300870{
871 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300872 static const char * const _keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200873 static _PyArg_Parser _parser = {NULL, _keywords, "compile", 0};
874 PyObject *argsbuf[6];
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300875 PyObject *pattern;
876 int flags;
877 PyObject *code;
878 Py_ssize_t groups;
879 PyObject *groupindex;
880 PyObject *indexgroup;
881
Serhiy Storchaka31913912019-03-14 10:32:22 +0200882 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 6, 6, 0, argsbuf);
883 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300884 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300885 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200886 pattern = args[0];
887 if (PyFloat_Check(args[1])) {
888 PyErr_SetString(PyExc_TypeError,
889 "integer argument expected, got float" );
890 goto exit;
891 }
892 flags = _PyLong_AsInt(args[1]);
893 if (flags == -1 && PyErr_Occurred()) {
894 goto exit;
895 }
896 if (!PyList_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200897 _PyArg_BadArgument("compile", "argument 'code'", "list", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200898 goto exit;
899 }
900 code = args[2];
901 if (PyFloat_Check(args[3])) {
902 PyErr_SetString(PyExc_TypeError,
903 "integer argument expected, got float" );
904 goto exit;
905 }
906 {
907 Py_ssize_t ival = -1;
908 PyObject *iobj = PyNumber_Index(args[3]);
909 if (iobj != NULL) {
910 ival = PyLong_AsSsize_t(iobj);
911 Py_DECREF(iobj);
912 }
913 if (ival == -1 && PyErr_Occurred()) {
914 goto exit;
915 }
916 groups = ival;
917 }
918 if (!PyDict_Check(args[4])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200919 _PyArg_BadArgument("compile", "argument 'groupindex'", "dict", args[4]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200920 goto exit;
921 }
922 groupindex = args[4];
923 if (!PyTuple_Check(args[5])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200924 _PyArg_BadArgument("compile", "argument 'indexgroup'", "tuple", args[5]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200925 goto exit;
926 }
927 indexgroup = args[5];
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300928 return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
929
930exit:
931 return return_value;
932}
933
934PyDoc_STRVAR(_sre_SRE_Match_expand__doc__,
935"expand($self, /, template)\n"
936"--\n"
937"\n"
938"Return the string obtained by doing backslash substitution on the string template, as done by the sub() method.");
939
940#define _SRE_SRE_MATCH_EXPAND_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200941 {"expand", (PyCFunction)(void(*)(void))_sre_SRE_Match_expand, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_expand__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300942
943static PyObject *
944_sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template);
945
946static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200947_sre_SRE_Match_expand(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300948{
949 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300950 static const char * const _keywords[] = {"template", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200951 static _PyArg_Parser _parser = {NULL, _keywords, "expand", 0};
952 PyObject *argsbuf[1];
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300953 PyObject *template;
954
Serhiy Storchaka31913912019-03-14 10:32:22 +0200955 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
956 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300957 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300958 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200959 template = args[0];
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300960 return_value = _sre_SRE_Match_expand_impl(self, template);
961
962exit:
963 return return_value;
964}
965
966PyDoc_STRVAR(_sre_SRE_Match_groups__doc__,
967"groups($self, /, default=None)\n"
968"--\n"
969"\n"
970"Return a tuple containing all the subgroups of the match, from 1.\n"
971"\n"
972" default\n"
973" Is used for groups that did not participate in the match.");
974
975#define _SRE_SRE_MATCH_GROUPS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200976 {"groups", (PyCFunction)(void(*)(void))_sre_SRE_Match_groups, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_groups__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300977
978static PyObject *
979_sre_SRE_Match_groups_impl(MatchObject *self, PyObject *default_value);
980
981static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200982_sre_SRE_Match_groups(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300983{
984 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +0300985 static const char * const _keywords[] = {"default", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200986 static _PyArg_Parser _parser = {NULL, _keywords, "groups", 0};
987 PyObject *argsbuf[1];
988 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300989 PyObject *default_value = Py_None;
990
Serhiy Storchaka31913912019-03-14 10:32:22 +0200991 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
992 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +0300993 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300994 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200995 if (!noptargs) {
996 goto skip_optional_pos;
997 }
998 default_value = args[0];
999skip_optional_pos:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001000 return_value = _sre_SRE_Match_groups_impl(self, default_value);
1001
1002exit:
1003 return return_value;
1004}
1005
1006PyDoc_STRVAR(_sre_SRE_Match_groupdict__doc__,
1007"groupdict($self, /, default=None)\n"
1008"--\n"
1009"\n"
1010"Return a dictionary containing all the named subgroups of the match, keyed by the subgroup name.\n"
1011"\n"
1012" default\n"
1013" Is used for groups that did not participate in the match.");
1014
1015#define _SRE_SRE_MATCH_GROUPDICT_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001016 {"groupdict", (PyCFunction)(void(*)(void))_sre_SRE_Match_groupdict, METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_groupdict__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001017
1018static PyObject *
1019_sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value);
1020
1021static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001022_sre_SRE_Match_groupdict(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001023{
1024 PyObject *return_value = NULL;
Serhiy Storchaka9171a8b2016-08-14 10:52:18 +03001025 static const char * const _keywords[] = {"default", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +02001026 static _PyArg_Parser _parser = {NULL, _keywords, "groupdict", 0};
1027 PyObject *argsbuf[1];
1028 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001029 PyObject *default_value = Py_None;
1030
Serhiy Storchaka31913912019-03-14 10:32:22 +02001031 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1032 if (!args) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001033 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001034 }
Serhiy Storchaka31913912019-03-14 10:32:22 +02001035 if (!noptargs) {
1036 goto skip_optional_pos;
1037 }
1038 default_value = args[0];
1039skip_optional_pos:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001040 return_value = _sre_SRE_Match_groupdict_impl(self, default_value);
1041
1042exit:
1043 return return_value;
1044}
1045
1046PyDoc_STRVAR(_sre_SRE_Match_start__doc__,
1047"start($self, group=0, /)\n"
1048"--\n"
1049"\n"
1050"Return index of the start of the substring matched by group.");
1051
1052#define _SRE_SRE_MATCH_START_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001053 {"start", (PyCFunction)(void(*)(void))_sre_SRE_Match_start, METH_FASTCALL, _sre_SRE_Match_start__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001054
1055static Py_ssize_t
1056_sre_SRE_Match_start_impl(MatchObject *self, PyObject *group);
1057
1058static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001059_sre_SRE_Match_start(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001060{
1061 PyObject *return_value = NULL;
1062 PyObject *group = NULL;
1063 Py_ssize_t _return_value;
1064
Serhiy Storchaka2a39d252019-01-11 18:01:42 +02001065 if (!_PyArg_CheckPositional("start", nargs, 0, 1)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +01001066 goto exit;
1067 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +02001068 if (nargs < 1) {
1069 goto skip_optional;
1070 }
1071 group = args[0];
1072skip_optional:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001073 _return_value = _sre_SRE_Match_start_impl(self, group);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001074 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001075 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001076 }
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001077 return_value = PyLong_FromSsize_t(_return_value);
1078
1079exit:
1080 return return_value;
1081}
1082
1083PyDoc_STRVAR(_sre_SRE_Match_end__doc__,
1084"end($self, group=0, /)\n"
1085"--\n"
1086"\n"
1087"Return index of the end of the substring matched by group.");
1088
1089#define _SRE_SRE_MATCH_END_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001090 {"end", (PyCFunction)(void(*)(void))_sre_SRE_Match_end, METH_FASTCALL, _sre_SRE_Match_end__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001091
1092static Py_ssize_t
1093_sre_SRE_Match_end_impl(MatchObject *self, PyObject *group);
1094
1095static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001096_sre_SRE_Match_end(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001097{
1098 PyObject *return_value = NULL;
1099 PyObject *group = NULL;
1100 Py_ssize_t _return_value;
1101
Serhiy Storchaka2a39d252019-01-11 18:01:42 +02001102 if (!_PyArg_CheckPositional("end", nargs, 0, 1)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +01001103 goto exit;
1104 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +02001105 if (nargs < 1) {
1106 goto skip_optional;
1107 }
1108 group = args[0];
1109skip_optional:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001110 _return_value = _sre_SRE_Match_end_impl(self, group);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001111 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001112 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +03001113 }
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001114 return_value = PyLong_FromSsize_t(_return_value);
1115
1116exit:
1117 return return_value;
1118}
1119
1120PyDoc_STRVAR(_sre_SRE_Match_span__doc__,
1121"span($self, group=0, /)\n"
1122"--\n"
1123"\n"
Serhiy Storchaka0b5e61d2017-10-04 20:09:49 +03001124"For match object m, return the 2-tuple (m.start(group), m.end(group)).");
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001125
1126#define _SRE_SRE_MATCH_SPAN_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +02001127 {"span", (PyCFunction)(void(*)(void))_sre_SRE_Match_span, METH_FASTCALL, _sre_SRE_Match_span__doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001128
1129static PyObject *
1130_sre_SRE_Match_span_impl(MatchObject *self, PyObject *group);
1131
1132static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +02001133_sre_SRE_Match_span(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001134{
1135 PyObject *return_value = NULL;
1136 PyObject *group = NULL;
1137
Serhiy Storchaka2a39d252019-01-11 18:01:42 +02001138 if (!_PyArg_CheckPositional("span", nargs, 0, 1)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +01001139 goto exit;
1140 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +02001141 if (nargs < 1) {
1142 goto skip_optional;
1143 }
1144 group = args[0];
1145skip_optional:
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001146 return_value = _sre_SRE_Match_span_impl(self, group);
1147
1148exit:
1149 return return_value;
1150}
1151
1152PyDoc_STRVAR(_sre_SRE_Match___copy____doc__,
1153"__copy__($self, /)\n"
1154"--\n"
1155"\n");
1156
1157#define _SRE_SRE_MATCH___COPY___METHODDEF \
1158 {"__copy__", (PyCFunction)_sre_SRE_Match___copy__, METH_NOARGS, _sre_SRE_Match___copy____doc__},
1159
1160static PyObject *
1161_sre_SRE_Match___copy___impl(MatchObject *self);
1162
1163static PyObject *
1164_sre_SRE_Match___copy__(MatchObject *self, PyObject *Py_UNUSED(ignored))
1165{
1166 return _sre_SRE_Match___copy___impl(self);
1167}
1168
1169PyDoc_STRVAR(_sre_SRE_Match___deepcopy____doc__,
Serhiy Storchakafdbd0112017-04-16 10:16:03 +03001170"__deepcopy__($self, memo, /)\n"
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001171"--\n"
1172"\n");
1173
1174#define _SRE_SRE_MATCH___DEEPCOPY___METHODDEF \
Serhiy Storchakafdbd0112017-04-16 10:16:03 +03001175 {"__deepcopy__", (PyCFunction)_sre_SRE_Match___deepcopy__, METH_O, _sre_SRE_Match___deepcopy____doc__},
Serhiy Storchakaa860aea2015-05-03 15:54:23 +03001176
1177PyDoc_STRVAR(_sre_SRE_Scanner_match__doc__,
1178"match($self, /)\n"
1179"--\n"
1180"\n");
1181
1182#define _SRE_SRE_SCANNER_MATCH_METHODDEF \
1183 {"match", (PyCFunction)_sre_SRE_Scanner_match, METH_NOARGS, _sre_SRE_Scanner_match__doc__},
1184
1185static PyObject *
1186_sre_SRE_Scanner_match_impl(ScannerObject *self);
1187
1188static PyObject *
1189_sre_SRE_Scanner_match(ScannerObject *self, PyObject *Py_UNUSED(ignored))
1190{
1191 return _sre_SRE_Scanner_match_impl(self);
1192}
1193
1194PyDoc_STRVAR(_sre_SRE_Scanner_search__doc__,
1195"search($self, /)\n"
1196"--\n"
1197"\n");
1198
1199#define _SRE_SRE_SCANNER_SEARCH_METHODDEF \
1200 {"search", (PyCFunction)_sre_SRE_Scanner_search, METH_NOARGS, _sre_SRE_Scanner_search__doc__},
1201
1202static PyObject *
1203_sre_SRE_Scanner_search_impl(ScannerObject *self);
1204
1205static PyObject *
1206_sre_SRE_Scanner_search(ScannerObject *self, PyObject *Py_UNUSED(ignored))
1207{
1208 return _sre_SRE_Scanner_search_impl(self);
1209}
Rémi Lapeyre4901fe22019-08-29 16:49:08 +02001210/*[clinic end generated code: output=1adeddce58ae284c input=a9049054013a1b77]*/