1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_abstract.h" // _PyNumber_Index()
10 #include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
11
12 PyDoc_STRVAR(_sre_getcodesize__doc__,
13 "getcodesize($module, /)\n"
14 "--\n"
15 "\n");
16
17 #define _SRE_GETCODESIZE_METHODDEF \
18 {"getcodesize", (PyCFunction)_sre_getcodesize, METH_NOARGS, _sre_getcodesize__doc__},
19
20 static int
21 _sre_getcodesize_impl(PyObject *module);
22
23 static PyObject *
_sre_getcodesize(PyObject * module,PyObject * Py_UNUSED (ignored))24 _sre_getcodesize(PyObject *module, PyObject *Py_UNUSED(ignored))
25 {
26 PyObject *return_value = NULL;
27 int _return_value;
28
29 _return_value = _sre_getcodesize_impl(module);
30 if ((_return_value == -1) && PyErr_Occurred()) {
31 goto exit;
32 }
33 return_value = PyLong_FromLong((long)_return_value);
34
35 exit:
36 return return_value;
37 }
38
39 PyDoc_STRVAR(_sre_ascii_iscased__doc__,
40 "ascii_iscased($module, character, /)\n"
41 "--\n"
42 "\n");
43
44 #define _SRE_ASCII_ISCASED_METHODDEF \
45 {"ascii_iscased", (PyCFunction)_sre_ascii_iscased, METH_O, _sre_ascii_iscased__doc__},
46
47 static int
48 _sre_ascii_iscased_impl(PyObject *module, int character);
49
50 static PyObject *
_sre_ascii_iscased(PyObject * module,PyObject * arg)51 _sre_ascii_iscased(PyObject *module, PyObject *arg)
52 {
53 PyObject *return_value = NULL;
54 int character;
55 int _return_value;
56
57 character = PyLong_AsInt(arg);
58 if (character == -1 && PyErr_Occurred()) {
59 goto exit;
60 }
61 _return_value = _sre_ascii_iscased_impl(module, character);
62 if ((_return_value == -1) && PyErr_Occurred()) {
63 goto exit;
64 }
65 return_value = PyBool_FromLong((long)_return_value);
66
67 exit:
68 return return_value;
69 }
70
71 PyDoc_STRVAR(_sre_unicode_iscased__doc__,
72 "unicode_iscased($module, character, /)\n"
73 "--\n"
74 "\n");
75
76 #define _SRE_UNICODE_ISCASED_METHODDEF \
77 {"unicode_iscased", (PyCFunction)_sre_unicode_iscased, METH_O, _sre_unicode_iscased__doc__},
78
79 static int
80 _sre_unicode_iscased_impl(PyObject *module, int character);
81
82 static PyObject *
_sre_unicode_iscased(PyObject * module,PyObject * arg)83 _sre_unicode_iscased(PyObject *module, PyObject *arg)
84 {
85 PyObject *return_value = NULL;
86 int character;
87 int _return_value;
88
89 character = PyLong_AsInt(arg);
90 if (character == -1 && PyErr_Occurred()) {
91 goto exit;
92 }
93 _return_value = _sre_unicode_iscased_impl(module, character);
94 if ((_return_value == -1) && PyErr_Occurred()) {
95 goto exit;
96 }
97 return_value = PyBool_FromLong((long)_return_value);
98
99 exit:
100 return return_value;
101 }
102
103 PyDoc_STRVAR(_sre_ascii_tolower__doc__,
104 "ascii_tolower($module, character, /)\n"
105 "--\n"
106 "\n");
107
108 #define _SRE_ASCII_TOLOWER_METHODDEF \
109 {"ascii_tolower", (PyCFunction)_sre_ascii_tolower, METH_O, _sre_ascii_tolower__doc__},
110
111 static int
112 _sre_ascii_tolower_impl(PyObject *module, int character);
113
114 static PyObject *
_sre_ascii_tolower(PyObject * module,PyObject * arg)115 _sre_ascii_tolower(PyObject *module, PyObject *arg)
116 {
117 PyObject *return_value = NULL;
118 int character;
119 int _return_value;
120
121 character = PyLong_AsInt(arg);
122 if (character == -1 && PyErr_Occurred()) {
123 goto exit;
124 }
125 _return_value = _sre_ascii_tolower_impl(module, character);
126 if ((_return_value == -1) && PyErr_Occurred()) {
127 goto exit;
128 }
129 return_value = PyLong_FromLong((long)_return_value);
130
131 exit:
132 return return_value;
133 }
134
135 PyDoc_STRVAR(_sre_unicode_tolower__doc__,
136 "unicode_tolower($module, character, /)\n"
137 "--\n"
138 "\n");
139
140 #define _SRE_UNICODE_TOLOWER_METHODDEF \
141 {"unicode_tolower", (PyCFunction)_sre_unicode_tolower, METH_O, _sre_unicode_tolower__doc__},
142
143 static int
144 _sre_unicode_tolower_impl(PyObject *module, int character);
145
146 static PyObject *
_sre_unicode_tolower(PyObject * module,PyObject * arg)147 _sre_unicode_tolower(PyObject *module, PyObject *arg)
148 {
149 PyObject *return_value = NULL;
150 int character;
151 int _return_value;
152
153 character = PyLong_AsInt(arg);
154 if (character == -1 && PyErr_Occurred()) {
155 goto exit;
156 }
157 _return_value = _sre_unicode_tolower_impl(module, character);
158 if ((_return_value == -1) && PyErr_Occurred()) {
159 goto exit;
160 }
161 return_value = PyLong_FromLong((long)_return_value);
162
163 exit:
164 return return_value;
165 }
166
167 PyDoc_STRVAR(_sre_SRE_Pattern_match__doc__,
168 "match($self, /, string, pos=0, endpos=sys.maxsize)\n"
169 "--\n"
170 "\n"
171 "Matches zero or more characters at the beginning of the string.");
172
173 #define _SRE_SRE_PATTERN_MATCH_METHODDEF \
174 {"match", _PyCFunction_CAST(_sre_SRE_Pattern_match), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_match__doc__},
175
176 static PyObject *
177 _sre_SRE_Pattern_match_impl(PatternObject *self, PyTypeObject *cls,
178 PyObject *string, Py_ssize_t pos,
179 Py_ssize_t endpos);
180
181 static PyObject *
_sre_SRE_Pattern_match(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)182 _sre_SRE_Pattern_match(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
183 {
184 PyObject *return_value = NULL;
185 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
186
187 #define NUM_KEYWORDS 3
188 static struct {
189 PyGC_Head _this_is_not_used;
190 PyObject_VAR_HEAD
191 PyObject *ob_item[NUM_KEYWORDS];
192 } _kwtuple = {
193 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
194 .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
195 };
196 #undef NUM_KEYWORDS
197 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
198
199 #else // !Py_BUILD_CORE
200 # define KWTUPLE NULL
201 #endif // !Py_BUILD_CORE
202
203 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
204 static _PyArg_Parser _parser = {
205 .keywords = _keywords,
206 .fname = "match",
207 .kwtuple = KWTUPLE,
208 };
209 #undef KWTUPLE
210 PyObject *argsbuf[3];
211 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
212 PyObject *string;
213 Py_ssize_t pos = 0;
214 Py_ssize_t endpos = PY_SSIZE_T_MAX;
215
216 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
217 if (!args) {
218 goto exit;
219 }
220 string = args[0];
221 if (!noptargs) {
222 goto skip_optional_pos;
223 }
224 if (args[1]) {
225 {
226 Py_ssize_t ival = -1;
227 PyObject *iobj = _PyNumber_Index(args[1]);
228 if (iobj != NULL) {
229 ival = PyLong_AsSsize_t(iobj);
230 Py_DECREF(iobj);
231 }
232 if (ival == -1 && PyErr_Occurred()) {
233 goto exit;
234 }
235 pos = ival;
236 }
237 if (!--noptargs) {
238 goto skip_optional_pos;
239 }
240 }
241 {
242 Py_ssize_t ival = -1;
243 PyObject *iobj = _PyNumber_Index(args[2]);
244 if (iobj != NULL) {
245 ival = PyLong_AsSsize_t(iobj);
246 Py_DECREF(iobj);
247 }
248 if (ival == -1 && PyErr_Occurred()) {
249 goto exit;
250 }
251 endpos = ival;
252 }
253 skip_optional_pos:
254 return_value = _sre_SRE_Pattern_match_impl(self, cls, string, pos, endpos);
255
256 exit:
257 return return_value;
258 }
259
260 PyDoc_STRVAR(_sre_SRE_Pattern_fullmatch__doc__,
261 "fullmatch($self, /, string, pos=0, endpos=sys.maxsize)\n"
262 "--\n"
263 "\n"
264 "Matches against all of the string.");
265
266 #define _SRE_SRE_PATTERN_FULLMATCH_METHODDEF \
267 {"fullmatch", _PyCFunction_CAST(_sre_SRE_Pattern_fullmatch), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_fullmatch__doc__},
268
269 static PyObject *
270 _sre_SRE_Pattern_fullmatch_impl(PatternObject *self, PyTypeObject *cls,
271 PyObject *string, Py_ssize_t pos,
272 Py_ssize_t endpos);
273
274 static PyObject *
_sre_SRE_Pattern_fullmatch(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)275 _sre_SRE_Pattern_fullmatch(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
276 {
277 PyObject *return_value = NULL;
278 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
279
280 #define NUM_KEYWORDS 3
281 static struct {
282 PyGC_Head _this_is_not_used;
283 PyObject_VAR_HEAD
284 PyObject *ob_item[NUM_KEYWORDS];
285 } _kwtuple = {
286 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
287 .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
288 };
289 #undef NUM_KEYWORDS
290 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
291
292 #else // !Py_BUILD_CORE
293 # define KWTUPLE NULL
294 #endif // !Py_BUILD_CORE
295
296 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
297 static _PyArg_Parser _parser = {
298 .keywords = _keywords,
299 .fname = "fullmatch",
300 .kwtuple = KWTUPLE,
301 };
302 #undef KWTUPLE
303 PyObject *argsbuf[3];
304 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
305 PyObject *string;
306 Py_ssize_t pos = 0;
307 Py_ssize_t endpos = PY_SSIZE_T_MAX;
308
309 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
310 if (!args) {
311 goto exit;
312 }
313 string = args[0];
314 if (!noptargs) {
315 goto skip_optional_pos;
316 }
317 if (args[1]) {
318 {
319 Py_ssize_t ival = -1;
320 PyObject *iobj = _PyNumber_Index(args[1]);
321 if (iobj != NULL) {
322 ival = PyLong_AsSsize_t(iobj);
323 Py_DECREF(iobj);
324 }
325 if (ival == -1 && PyErr_Occurred()) {
326 goto exit;
327 }
328 pos = ival;
329 }
330 if (!--noptargs) {
331 goto skip_optional_pos;
332 }
333 }
334 {
335 Py_ssize_t ival = -1;
336 PyObject *iobj = _PyNumber_Index(args[2]);
337 if (iobj != NULL) {
338 ival = PyLong_AsSsize_t(iobj);
339 Py_DECREF(iobj);
340 }
341 if (ival == -1 && PyErr_Occurred()) {
342 goto exit;
343 }
344 endpos = ival;
345 }
346 skip_optional_pos:
347 return_value = _sre_SRE_Pattern_fullmatch_impl(self, cls, string, pos, endpos);
348
349 exit:
350 return return_value;
351 }
352
353 PyDoc_STRVAR(_sre_SRE_Pattern_search__doc__,
354 "search($self, /, string, pos=0, endpos=sys.maxsize)\n"
355 "--\n"
356 "\n"
357 "Scan through string looking for a match, and return a corresponding match object instance.\n"
358 "\n"
359 "Return None if no position in the string matches.");
360
361 #define _SRE_SRE_PATTERN_SEARCH_METHODDEF \
362 {"search", _PyCFunction_CAST(_sre_SRE_Pattern_search), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_search__doc__},
363
364 static PyObject *
365 _sre_SRE_Pattern_search_impl(PatternObject *self, PyTypeObject *cls,
366 PyObject *string, Py_ssize_t pos,
367 Py_ssize_t endpos);
368
369 static PyObject *
_sre_SRE_Pattern_search(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)370 _sre_SRE_Pattern_search(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
371 {
372 PyObject *return_value = NULL;
373 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
374
375 #define NUM_KEYWORDS 3
376 static struct {
377 PyGC_Head _this_is_not_used;
378 PyObject_VAR_HEAD
379 PyObject *ob_item[NUM_KEYWORDS];
380 } _kwtuple = {
381 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
382 .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
383 };
384 #undef NUM_KEYWORDS
385 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
386
387 #else // !Py_BUILD_CORE
388 # define KWTUPLE NULL
389 #endif // !Py_BUILD_CORE
390
391 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
392 static _PyArg_Parser _parser = {
393 .keywords = _keywords,
394 .fname = "search",
395 .kwtuple = KWTUPLE,
396 };
397 #undef KWTUPLE
398 PyObject *argsbuf[3];
399 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
400 PyObject *string;
401 Py_ssize_t pos = 0;
402 Py_ssize_t endpos = PY_SSIZE_T_MAX;
403
404 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
405 if (!args) {
406 goto exit;
407 }
408 string = args[0];
409 if (!noptargs) {
410 goto skip_optional_pos;
411 }
412 if (args[1]) {
413 {
414 Py_ssize_t ival = -1;
415 PyObject *iobj = _PyNumber_Index(args[1]);
416 if (iobj != NULL) {
417 ival = PyLong_AsSsize_t(iobj);
418 Py_DECREF(iobj);
419 }
420 if (ival == -1 && PyErr_Occurred()) {
421 goto exit;
422 }
423 pos = ival;
424 }
425 if (!--noptargs) {
426 goto skip_optional_pos;
427 }
428 }
429 {
430 Py_ssize_t ival = -1;
431 PyObject *iobj = _PyNumber_Index(args[2]);
432 if (iobj != NULL) {
433 ival = PyLong_AsSsize_t(iobj);
434 Py_DECREF(iobj);
435 }
436 if (ival == -1 && PyErr_Occurred()) {
437 goto exit;
438 }
439 endpos = ival;
440 }
441 skip_optional_pos:
442 return_value = _sre_SRE_Pattern_search_impl(self, cls, string, pos, endpos);
443
444 exit:
445 return return_value;
446 }
447
448 PyDoc_STRVAR(_sre_SRE_Pattern_findall__doc__,
449 "findall($self, /, string, pos=0, endpos=sys.maxsize)\n"
450 "--\n"
451 "\n"
452 "Return a list of all non-overlapping matches of pattern in string.");
453
454 #define _SRE_SRE_PATTERN_FINDALL_METHODDEF \
455 {"findall", _PyCFunction_CAST(_sre_SRE_Pattern_findall), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_findall__doc__},
456
457 static PyObject *
458 _sre_SRE_Pattern_findall_impl(PatternObject *self, PyObject *string,
459 Py_ssize_t pos, Py_ssize_t endpos);
460
461 static PyObject *
_sre_SRE_Pattern_findall(PatternObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)462 _sre_SRE_Pattern_findall(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
463 {
464 PyObject *return_value = NULL;
465 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
466
467 #define NUM_KEYWORDS 3
468 static struct {
469 PyGC_Head _this_is_not_used;
470 PyObject_VAR_HEAD
471 PyObject *ob_item[NUM_KEYWORDS];
472 } _kwtuple = {
473 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
474 .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
475 };
476 #undef NUM_KEYWORDS
477 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
478
479 #else // !Py_BUILD_CORE
480 # define KWTUPLE NULL
481 #endif // !Py_BUILD_CORE
482
483 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
484 static _PyArg_Parser _parser = {
485 .keywords = _keywords,
486 .fname = "findall",
487 .kwtuple = KWTUPLE,
488 };
489 #undef KWTUPLE
490 PyObject *argsbuf[3];
491 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
492 PyObject *string;
493 Py_ssize_t pos = 0;
494 Py_ssize_t endpos = PY_SSIZE_T_MAX;
495
496 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
497 if (!args) {
498 goto exit;
499 }
500 string = args[0];
501 if (!noptargs) {
502 goto skip_optional_pos;
503 }
504 if (args[1]) {
505 {
506 Py_ssize_t ival = -1;
507 PyObject *iobj = _PyNumber_Index(args[1]);
508 if (iobj != NULL) {
509 ival = PyLong_AsSsize_t(iobj);
510 Py_DECREF(iobj);
511 }
512 if (ival == -1 && PyErr_Occurred()) {
513 goto exit;
514 }
515 pos = ival;
516 }
517 if (!--noptargs) {
518 goto skip_optional_pos;
519 }
520 }
521 {
522 Py_ssize_t ival = -1;
523 PyObject *iobj = _PyNumber_Index(args[2]);
524 if (iobj != NULL) {
525 ival = PyLong_AsSsize_t(iobj);
526 Py_DECREF(iobj);
527 }
528 if (ival == -1 && PyErr_Occurred()) {
529 goto exit;
530 }
531 endpos = ival;
532 }
533 skip_optional_pos:
534 return_value = _sre_SRE_Pattern_findall_impl(self, string, pos, endpos);
535
536 exit:
537 return return_value;
538 }
539
540 PyDoc_STRVAR(_sre_SRE_Pattern_finditer__doc__,
541 "finditer($self, /, string, pos=0, endpos=sys.maxsize)\n"
542 "--\n"
543 "\n"
544 "Return an iterator over all non-overlapping matches for the RE pattern in string.\n"
545 "\n"
546 "For each match, the iterator returns a match object.");
547
548 #define _SRE_SRE_PATTERN_FINDITER_METHODDEF \
549 {"finditer", _PyCFunction_CAST(_sre_SRE_Pattern_finditer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_finditer__doc__},
550
551 static PyObject *
552 _sre_SRE_Pattern_finditer_impl(PatternObject *self, PyTypeObject *cls,
553 PyObject *string, Py_ssize_t pos,
554 Py_ssize_t endpos);
555
556 static PyObject *
_sre_SRE_Pattern_finditer(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)557 _sre_SRE_Pattern_finditer(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
558 {
559 PyObject *return_value = NULL;
560 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
561
562 #define NUM_KEYWORDS 3
563 static struct {
564 PyGC_Head _this_is_not_used;
565 PyObject_VAR_HEAD
566 PyObject *ob_item[NUM_KEYWORDS];
567 } _kwtuple = {
568 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
569 .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
570 };
571 #undef NUM_KEYWORDS
572 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
573
574 #else // !Py_BUILD_CORE
575 # define KWTUPLE NULL
576 #endif // !Py_BUILD_CORE
577
578 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
579 static _PyArg_Parser _parser = {
580 .keywords = _keywords,
581 .fname = "finditer",
582 .kwtuple = KWTUPLE,
583 };
584 #undef KWTUPLE
585 PyObject *argsbuf[3];
586 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
587 PyObject *string;
588 Py_ssize_t pos = 0;
589 Py_ssize_t endpos = PY_SSIZE_T_MAX;
590
591 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
592 if (!args) {
593 goto exit;
594 }
595 string = args[0];
596 if (!noptargs) {
597 goto skip_optional_pos;
598 }
599 if (args[1]) {
600 {
601 Py_ssize_t ival = -1;
602 PyObject *iobj = _PyNumber_Index(args[1]);
603 if (iobj != NULL) {
604 ival = PyLong_AsSsize_t(iobj);
605 Py_DECREF(iobj);
606 }
607 if (ival == -1 && PyErr_Occurred()) {
608 goto exit;
609 }
610 pos = ival;
611 }
612 if (!--noptargs) {
613 goto skip_optional_pos;
614 }
615 }
616 {
617 Py_ssize_t ival = -1;
618 PyObject *iobj = _PyNumber_Index(args[2]);
619 if (iobj != NULL) {
620 ival = PyLong_AsSsize_t(iobj);
621 Py_DECREF(iobj);
622 }
623 if (ival == -1 && PyErr_Occurred()) {
624 goto exit;
625 }
626 endpos = ival;
627 }
628 skip_optional_pos:
629 return_value = _sre_SRE_Pattern_finditer_impl(self, cls, string, pos, endpos);
630
631 exit:
632 return return_value;
633 }
634
635 PyDoc_STRVAR(_sre_SRE_Pattern_scanner__doc__,
636 "scanner($self, /, string, pos=0, endpos=sys.maxsize)\n"
637 "--\n"
638 "\n");
639
640 #define _SRE_SRE_PATTERN_SCANNER_METHODDEF \
641 {"scanner", _PyCFunction_CAST(_sre_SRE_Pattern_scanner), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_scanner__doc__},
642
643 static PyObject *
644 _sre_SRE_Pattern_scanner_impl(PatternObject *self, PyTypeObject *cls,
645 PyObject *string, Py_ssize_t pos,
646 Py_ssize_t endpos);
647
648 static PyObject *
_sre_SRE_Pattern_scanner(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)649 _sre_SRE_Pattern_scanner(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
650 {
651 PyObject *return_value = NULL;
652 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
653
654 #define NUM_KEYWORDS 3
655 static struct {
656 PyGC_Head _this_is_not_used;
657 PyObject_VAR_HEAD
658 PyObject *ob_item[NUM_KEYWORDS];
659 } _kwtuple = {
660 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
661 .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
662 };
663 #undef NUM_KEYWORDS
664 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
665
666 #else // !Py_BUILD_CORE
667 # define KWTUPLE NULL
668 #endif // !Py_BUILD_CORE
669
670 static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
671 static _PyArg_Parser _parser = {
672 .keywords = _keywords,
673 .fname = "scanner",
674 .kwtuple = KWTUPLE,
675 };
676 #undef KWTUPLE
677 PyObject *argsbuf[3];
678 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
679 PyObject *string;
680 Py_ssize_t pos = 0;
681 Py_ssize_t endpos = PY_SSIZE_T_MAX;
682
683 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
684 if (!args) {
685 goto exit;
686 }
687 string = args[0];
688 if (!noptargs) {
689 goto skip_optional_pos;
690 }
691 if (args[1]) {
692 {
693 Py_ssize_t ival = -1;
694 PyObject *iobj = _PyNumber_Index(args[1]);
695 if (iobj != NULL) {
696 ival = PyLong_AsSsize_t(iobj);
697 Py_DECREF(iobj);
698 }
699 if (ival == -1 && PyErr_Occurred()) {
700 goto exit;
701 }
702 pos = ival;
703 }
704 if (!--noptargs) {
705 goto skip_optional_pos;
706 }
707 }
708 {
709 Py_ssize_t ival = -1;
710 PyObject *iobj = _PyNumber_Index(args[2]);
711 if (iobj != NULL) {
712 ival = PyLong_AsSsize_t(iobj);
713 Py_DECREF(iobj);
714 }
715 if (ival == -1 && PyErr_Occurred()) {
716 goto exit;
717 }
718 endpos = ival;
719 }
720 skip_optional_pos:
721 return_value = _sre_SRE_Pattern_scanner_impl(self, cls, string, pos, endpos);
722
723 exit:
724 return return_value;
725 }
726
727 PyDoc_STRVAR(_sre_SRE_Pattern_split__doc__,
728 "split($self, /, string, maxsplit=0)\n"
729 "--\n"
730 "\n"
731 "Split string by the occurrences of pattern.");
732
733 #define _SRE_SRE_PATTERN_SPLIT_METHODDEF \
734 {"split", _PyCFunction_CAST(_sre_SRE_Pattern_split), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_split__doc__},
735
736 static PyObject *
737 _sre_SRE_Pattern_split_impl(PatternObject *self, PyObject *string,
738 Py_ssize_t maxsplit);
739
740 static PyObject *
_sre_SRE_Pattern_split(PatternObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)741 _sre_SRE_Pattern_split(PatternObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
742 {
743 PyObject *return_value = NULL;
744 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
745
746 #define NUM_KEYWORDS 2
747 static struct {
748 PyGC_Head _this_is_not_used;
749 PyObject_VAR_HEAD
750 PyObject *ob_item[NUM_KEYWORDS];
751 } _kwtuple = {
752 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
753 .ob_item = { &_Py_ID(string), &_Py_ID(maxsplit), },
754 };
755 #undef NUM_KEYWORDS
756 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
757
758 #else // !Py_BUILD_CORE
759 # define KWTUPLE NULL
760 #endif // !Py_BUILD_CORE
761
762 static const char * const _keywords[] = {"string", "maxsplit", NULL};
763 static _PyArg_Parser _parser = {
764 .keywords = _keywords,
765 .fname = "split",
766 .kwtuple = KWTUPLE,
767 };
768 #undef KWTUPLE
769 PyObject *argsbuf[2];
770 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
771 PyObject *string;
772 Py_ssize_t maxsplit = 0;
773
774 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
775 if (!args) {
776 goto exit;
777 }
778 string = args[0];
779 if (!noptargs) {
780 goto skip_optional_pos;
781 }
782 {
783 Py_ssize_t ival = -1;
784 PyObject *iobj = _PyNumber_Index(args[1]);
785 if (iobj != NULL) {
786 ival = PyLong_AsSsize_t(iobj);
787 Py_DECREF(iobj);
788 }
789 if (ival == -1 && PyErr_Occurred()) {
790 goto exit;
791 }
792 maxsplit = ival;
793 }
794 skip_optional_pos:
795 return_value = _sre_SRE_Pattern_split_impl(self, string, maxsplit);
796
797 exit:
798 return return_value;
799 }
800
801 PyDoc_STRVAR(_sre_SRE_Pattern_sub__doc__,
802 "sub($self, /, repl, string, count=0)\n"
803 "--\n"
804 "\n"
805 "Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl.");
806
807 #define _SRE_SRE_PATTERN_SUB_METHODDEF \
808 {"sub", _PyCFunction_CAST(_sre_SRE_Pattern_sub), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_sub__doc__},
809
810 static PyObject *
811 _sre_SRE_Pattern_sub_impl(PatternObject *self, PyTypeObject *cls,
812 PyObject *repl, PyObject *string, Py_ssize_t count);
813
814 static PyObject *
_sre_SRE_Pattern_sub(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)815 _sre_SRE_Pattern_sub(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
816 {
817 PyObject *return_value = NULL;
818 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
819
820 #define NUM_KEYWORDS 3
821 static struct {
822 PyGC_Head _this_is_not_used;
823 PyObject_VAR_HEAD
824 PyObject *ob_item[NUM_KEYWORDS];
825 } _kwtuple = {
826 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
827 .ob_item = { &_Py_ID(repl), &_Py_ID(string), &_Py_ID(count), },
828 };
829 #undef NUM_KEYWORDS
830 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
831
832 #else // !Py_BUILD_CORE
833 # define KWTUPLE NULL
834 #endif // !Py_BUILD_CORE
835
836 static const char * const _keywords[] = {"repl", "string", "count", NULL};
837 static _PyArg_Parser _parser = {
838 .keywords = _keywords,
839 .fname = "sub",
840 .kwtuple = KWTUPLE,
841 };
842 #undef KWTUPLE
843 PyObject *argsbuf[3];
844 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
845 PyObject *repl;
846 PyObject *string;
847 Py_ssize_t count = 0;
848
849 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
850 if (!args) {
851 goto exit;
852 }
853 repl = args[0];
854 string = args[1];
855 if (!noptargs) {
856 goto skip_optional_pos;
857 }
858 {
859 Py_ssize_t ival = -1;
860 PyObject *iobj = _PyNumber_Index(args[2]);
861 if (iobj != NULL) {
862 ival = PyLong_AsSsize_t(iobj);
863 Py_DECREF(iobj);
864 }
865 if (ival == -1 && PyErr_Occurred()) {
866 goto exit;
867 }
868 count = ival;
869 }
870 skip_optional_pos:
871 return_value = _sre_SRE_Pattern_sub_impl(self, cls, repl, string, count);
872
873 exit:
874 return return_value;
875 }
876
877 PyDoc_STRVAR(_sre_SRE_Pattern_subn__doc__,
878 "subn($self, /, repl, string, count=0)\n"
879 "--\n"
880 "\n"
881 "Return the tuple (new_string, number_of_subs_made) found by replacing the leftmost non-overlapping occurrences of pattern with the replacement repl.");
882
883 #define _SRE_SRE_PATTERN_SUBN_METHODDEF \
884 {"subn", _PyCFunction_CAST(_sre_SRE_Pattern_subn), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Pattern_subn__doc__},
885
886 static PyObject *
887 _sre_SRE_Pattern_subn_impl(PatternObject *self, PyTypeObject *cls,
888 PyObject *repl, PyObject *string,
889 Py_ssize_t count);
890
891 static PyObject *
_sre_SRE_Pattern_subn(PatternObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)892 _sre_SRE_Pattern_subn(PatternObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
893 {
894 PyObject *return_value = NULL;
895 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
896
897 #define NUM_KEYWORDS 3
898 static struct {
899 PyGC_Head _this_is_not_used;
900 PyObject_VAR_HEAD
901 PyObject *ob_item[NUM_KEYWORDS];
902 } _kwtuple = {
903 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
904 .ob_item = { &_Py_ID(repl), &_Py_ID(string), &_Py_ID(count), },
905 };
906 #undef NUM_KEYWORDS
907 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
908
909 #else // !Py_BUILD_CORE
910 # define KWTUPLE NULL
911 #endif // !Py_BUILD_CORE
912
913 static const char * const _keywords[] = {"repl", "string", "count", NULL};
914 static _PyArg_Parser _parser = {
915 .keywords = _keywords,
916 .fname = "subn",
917 .kwtuple = KWTUPLE,
918 };
919 #undef KWTUPLE
920 PyObject *argsbuf[3];
921 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
922 PyObject *repl;
923 PyObject *string;
924 Py_ssize_t count = 0;
925
926 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
927 if (!args) {
928 goto exit;
929 }
930 repl = args[0];
931 string = args[1];
932 if (!noptargs) {
933 goto skip_optional_pos;
934 }
935 {
936 Py_ssize_t ival = -1;
937 PyObject *iobj = _PyNumber_Index(args[2]);
938 if (iobj != NULL) {
939 ival = PyLong_AsSsize_t(iobj);
940 Py_DECREF(iobj);
941 }
942 if (ival == -1 && PyErr_Occurred()) {
943 goto exit;
944 }
945 count = ival;
946 }
947 skip_optional_pos:
948 return_value = _sre_SRE_Pattern_subn_impl(self, cls, repl, string, count);
949
950 exit:
951 return return_value;
952 }
953
954 PyDoc_STRVAR(_sre_SRE_Pattern___copy____doc__,
955 "__copy__($self, /)\n"
956 "--\n"
957 "\n");
958
959 #define _SRE_SRE_PATTERN___COPY___METHODDEF \
960 {"__copy__", (PyCFunction)_sre_SRE_Pattern___copy__, METH_NOARGS, _sre_SRE_Pattern___copy____doc__},
961
962 static PyObject *
963 _sre_SRE_Pattern___copy___impl(PatternObject *self);
964
965 static PyObject *
_sre_SRE_Pattern___copy__(PatternObject * self,PyObject * Py_UNUSED (ignored))966 _sre_SRE_Pattern___copy__(PatternObject *self, PyObject *Py_UNUSED(ignored))
967 {
968 return _sre_SRE_Pattern___copy___impl(self);
969 }
970
971 PyDoc_STRVAR(_sre_SRE_Pattern___deepcopy____doc__,
972 "__deepcopy__($self, memo, /)\n"
973 "--\n"
974 "\n");
975
976 #define _SRE_SRE_PATTERN___DEEPCOPY___METHODDEF \
977 {"__deepcopy__", (PyCFunction)_sre_SRE_Pattern___deepcopy__, METH_O, _sre_SRE_Pattern___deepcopy____doc__},
978
979 #if defined(Py_DEBUG)
980
981 PyDoc_STRVAR(_sre_SRE_Pattern__fail_after__doc__,
982 "_fail_after($self, count, exception, /)\n"
983 "--\n"
984 "\n"
985 "For debugging.");
986
987 #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF \
988 {"_fail_after", _PyCFunction_CAST(_sre_SRE_Pattern__fail_after), METH_FASTCALL, _sre_SRE_Pattern__fail_after__doc__},
989
990 static PyObject *
991 _sre_SRE_Pattern__fail_after_impl(PatternObject *self, int count,
992 PyObject *exception);
993
994 static PyObject *
_sre_SRE_Pattern__fail_after(PatternObject * self,PyObject * const * args,Py_ssize_t nargs)995 _sre_SRE_Pattern__fail_after(PatternObject *self, PyObject *const *args, Py_ssize_t nargs)
996 {
997 PyObject *return_value = NULL;
998 int count;
999 PyObject *exception;
1000
1001 if (!_PyArg_CheckPositional("_fail_after", nargs, 2, 2)) {
1002 goto exit;
1003 }
1004 count = PyLong_AsInt(args[0]);
1005 if (count == -1 && PyErr_Occurred()) {
1006 goto exit;
1007 }
1008 exception = args[1];
1009 return_value = _sre_SRE_Pattern__fail_after_impl(self, count, exception);
1010
1011 exit:
1012 return return_value;
1013 }
1014
1015 #endif /* defined(Py_DEBUG) */
1016
1017 PyDoc_STRVAR(_sre_compile__doc__,
1018 "compile($module, /, pattern, flags, code, groups, groupindex,\n"
1019 " indexgroup)\n"
1020 "--\n"
1021 "\n");
1022
1023 #define _SRE_COMPILE_METHODDEF \
1024 {"compile", _PyCFunction_CAST(_sre_compile), METH_FASTCALL|METH_KEYWORDS, _sre_compile__doc__},
1025
1026 static PyObject *
1027 _sre_compile_impl(PyObject *module, PyObject *pattern, int flags,
1028 PyObject *code, Py_ssize_t groups, PyObject *groupindex,
1029 PyObject *indexgroup);
1030
1031 static PyObject *
_sre_compile(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1032 _sre_compile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1033 {
1034 PyObject *return_value = NULL;
1035 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1036
1037 #define NUM_KEYWORDS 6
1038 static struct {
1039 PyGC_Head _this_is_not_used;
1040 PyObject_VAR_HEAD
1041 PyObject *ob_item[NUM_KEYWORDS];
1042 } _kwtuple = {
1043 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1044 .ob_item = { &_Py_ID(pattern), &_Py_ID(flags), &_Py_ID(code), &_Py_ID(groups), &_Py_ID(groupindex), &_Py_ID(indexgroup), },
1045 };
1046 #undef NUM_KEYWORDS
1047 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1048
1049 #else // !Py_BUILD_CORE
1050 # define KWTUPLE NULL
1051 #endif // !Py_BUILD_CORE
1052
1053 static const char * const _keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
1054 static _PyArg_Parser _parser = {
1055 .keywords = _keywords,
1056 .fname = "compile",
1057 .kwtuple = KWTUPLE,
1058 };
1059 #undef KWTUPLE
1060 PyObject *argsbuf[6];
1061 PyObject *pattern;
1062 int flags;
1063 PyObject *code;
1064 Py_ssize_t groups;
1065 PyObject *groupindex;
1066 PyObject *indexgroup;
1067
1068 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 6, 6, 0, argsbuf);
1069 if (!args) {
1070 goto exit;
1071 }
1072 pattern = args[0];
1073 flags = PyLong_AsInt(args[1]);
1074 if (flags == -1 && PyErr_Occurred()) {
1075 goto exit;
1076 }
1077 if (!PyList_Check(args[2])) {
1078 _PyArg_BadArgument("compile", "argument 'code'", "list", args[2]);
1079 goto exit;
1080 }
1081 code = args[2];
1082 {
1083 Py_ssize_t ival = -1;
1084 PyObject *iobj = _PyNumber_Index(args[3]);
1085 if (iobj != NULL) {
1086 ival = PyLong_AsSsize_t(iobj);
1087 Py_DECREF(iobj);
1088 }
1089 if (ival == -1 && PyErr_Occurred()) {
1090 goto exit;
1091 }
1092 groups = ival;
1093 }
1094 if (!PyDict_Check(args[4])) {
1095 _PyArg_BadArgument("compile", "argument 'groupindex'", "dict", args[4]);
1096 goto exit;
1097 }
1098 groupindex = args[4];
1099 if (!PyTuple_Check(args[5])) {
1100 _PyArg_BadArgument("compile", "argument 'indexgroup'", "tuple", args[5]);
1101 goto exit;
1102 }
1103 indexgroup = args[5];
1104 return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
1105
1106 exit:
1107 return return_value;
1108 }
1109
1110 PyDoc_STRVAR(_sre_template__doc__,
1111 "template($module, pattern, template, /)\n"
1112 "--\n"
1113 "\n"
1114 "\n"
1115 "\n"
1116 " template\n"
1117 " A list containing interleaved literal strings (str or bytes) and group\n"
1118 " indices (int), as returned by re._parser.parse_template():\n"
1119 " [literal1, group1, ..., literalN, groupN]");
1120
1121 #define _SRE_TEMPLATE_METHODDEF \
1122 {"template", _PyCFunction_CAST(_sre_template), METH_FASTCALL, _sre_template__doc__},
1123
1124 static PyObject *
1125 _sre_template_impl(PyObject *module, PyObject *pattern, PyObject *template);
1126
1127 static PyObject *
_sre_template(PyObject * module,PyObject * const * args,Py_ssize_t nargs)1128 _sre_template(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
1129 {
1130 PyObject *return_value = NULL;
1131 PyObject *pattern;
1132 PyObject *template;
1133
1134 if (!_PyArg_CheckPositional("template", nargs, 2, 2)) {
1135 goto exit;
1136 }
1137 pattern = args[0];
1138 if (!PyList_Check(args[1])) {
1139 _PyArg_BadArgument("template", "argument 2", "list", args[1]);
1140 goto exit;
1141 }
1142 template = args[1];
1143 return_value = _sre_template_impl(module, pattern, template);
1144
1145 exit:
1146 return return_value;
1147 }
1148
1149 PyDoc_STRVAR(_sre_SRE_Match_expand__doc__,
1150 "expand($self, /, template)\n"
1151 "--\n"
1152 "\n"
1153 "Return the string obtained by doing backslash substitution on the string template, as done by the sub() method.");
1154
1155 #define _SRE_SRE_MATCH_EXPAND_METHODDEF \
1156 {"expand", _PyCFunction_CAST(_sre_SRE_Match_expand), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_expand__doc__},
1157
1158 static PyObject *
1159 _sre_SRE_Match_expand_impl(MatchObject *self, PyObject *template);
1160
1161 static PyObject *
_sre_SRE_Match_expand(MatchObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1162 _sre_SRE_Match_expand(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1163 {
1164 PyObject *return_value = NULL;
1165 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1166
1167 #define NUM_KEYWORDS 1
1168 static struct {
1169 PyGC_Head _this_is_not_used;
1170 PyObject_VAR_HEAD
1171 PyObject *ob_item[NUM_KEYWORDS];
1172 } _kwtuple = {
1173 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1174 .ob_item = { &_Py_ID(template), },
1175 };
1176 #undef NUM_KEYWORDS
1177 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1178
1179 #else // !Py_BUILD_CORE
1180 # define KWTUPLE NULL
1181 #endif // !Py_BUILD_CORE
1182
1183 static const char * const _keywords[] = {"template", NULL};
1184 static _PyArg_Parser _parser = {
1185 .keywords = _keywords,
1186 .fname = "expand",
1187 .kwtuple = KWTUPLE,
1188 };
1189 #undef KWTUPLE
1190 PyObject *argsbuf[1];
1191 PyObject *template;
1192
1193 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
1194 if (!args) {
1195 goto exit;
1196 }
1197 template = args[0];
1198 return_value = _sre_SRE_Match_expand_impl(self, template);
1199
1200 exit:
1201 return return_value;
1202 }
1203
1204 PyDoc_STRVAR(_sre_SRE_Match_groups__doc__,
1205 "groups($self, /, default=None)\n"
1206 "--\n"
1207 "\n"
1208 "Return a tuple containing all the subgroups of the match, from 1.\n"
1209 "\n"
1210 " default\n"
1211 " Is used for groups that did not participate in the match.");
1212
1213 #define _SRE_SRE_MATCH_GROUPS_METHODDEF \
1214 {"groups", _PyCFunction_CAST(_sre_SRE_Match_groups), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_groups__doc__},
1215
1216 static PyObject *
1217 _sre_SRE_Match_groups_impl(MatchObject *self, PyObject *default_value);
1218
1219 static PyObject *
_sre_SRE_Match_groups(MatchObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1220 _sre_SRE_Match_groups(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1221 {
1222 PyObject *return_value = NULL;
1223 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1224
1225 #define NUM_KEYWORDS 1
1226 static struct {
1227 PyGC_Head _this_is_not_used;
1228 PyObject_VAR_HEAD
1229 PyObject *ob_item[NUM_KEYWORDS];
1230 } _kwtuple = {
1231 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1232 .ob_item = { &_Py_ID(default), },
1233 };
1234 #undef NUM_KEYWORDS
1235 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1236
1237 #else // !Py_BUILD_CORE
1238 # define KWTUPLE NULL
1239 #endif // !Py_BUILD_CORE
1240
1241 static const char * const _keywords[] = {"default", NULL};
1242 static _PyArg_Parser _parser = {
1243 .keywords = _keywords,
1244 .fname = "groups",
1245 .kwtuple = KWTUPLE,
1246 };
1247 #undef KWTUPLE
1248 PyObject *argsbuf[1];
1249 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1250 PyObject *default_value = Py_None;
1251
1252 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1253 if (!args) {
1254 goto exit;
1255 }
1256 if (!noptargs) {
1257 goto skip_optional_pos;
1258 }
1259 default_value = args[0];
1260 skip_optional_pos:
1261 return_value = _sre_SRE_Match_groups_impl(self, default_value);
1262
1263 exit:
1264 return return_value;
1265 }
1266
1267 PyDoc_STRVAR(_sre_SRE_Match_groupdict__doc__,
1268 "groupdict($self, /, default=None)\n"
1269 "--\n"
1270 "\n"
1271 "Return a dictionary containing all the named subgroups of the match, keyed by the subgroup name.\n"
1272 "\n"
1273 " default\n"
1274 " Is used for groups that did not participate in the match.");
1275
1276 #define _SRE_SRE_MATCH_GROUPDICT_METHODDEF \
1277 {"groupdict", _PyCFunction_CAST(_sre_SRE_Match_groupdict), METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Match_groupdict__doc__},
1278
1279 static PyObject *
1280 _sre_SRE_Match_groupdict_impl(MatchObject *self, PyObject *default_value);
1281
1282 static PyObject *
_sre_SRE_Match_groupdict(MatchObject * self,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1283 _sre_SRE_Match_groupdict(MatchObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1284 {
1285 PyObject *return_value = NULL;
1286 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1287
1288 #define NUM_KEYWORDS 1
1289 static struct {
1290 PyGC_Head _this_is_not_used;
1291 PyObject_VAR_HEAD
1292 PyObject *ob_item[NUM_KEYWORDS];
1293 } _kwtuple = {
1294 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1295 .ob_item = { &_Py_ID(default), },
1296 };
1297 #undef NUM_KEYWORDS
1298 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1299
1300 #else // !Py_BUILD_CORE
1301 # define KWTUPLE NULL
1302 #endif // !Py_BUILD_CORE
1303
1304 static const char * const _keywords[] = {"default", NULL};
1305 static _PyArg_Parser _parser = {
1306 .keywords = _keywords,
1307 .fname = "groupdict",
1308 .kwtuple = KWTUPLE,
1309 };
1310 #undef KWTUPLE
1311 PyObject *argsbuf[1];
1312 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
1313 PyObject *default_value = Py_None;
1314
1315 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
1316 if (!args) {
1317 goto exit;
1318 }
1319 if (!noptargs) {
1320 goto skip_optional_pos;
1321 }
1322 default_value = args[0];
1323 skip_optional_pos:
1324 return_value = _sre_SRE_Match_groupdict_impl(self, default_value);
1325
1326 exit:
1327 return return_value;
1328 }
1329
1330 PyDoc_STRVAR(_sre_SRE_Match_start__doc__,
1331 "start($self, group=0, /)\n"
1332 "--\n"
1333 "\n"
1334 "Return index of the start of the substring matched by group.");
1335
1336 #define _SRE_SRE_MATCH_START_METHODDEF \
1337 {"start", _PyCFunction_CAST(_sre_SRE_Match_start), METH_FASTCALL, _sre_SRE_Match_start__doc__},
1338
1339 static Py_ssize_t
1340 _sre_SRE_Match_start_impl(MatchObject *self, PyObject *group);
1341
1342 static PyObject *
_sre_SRE_Match_start(MatchObject * self,PyObject * const * args,Py_ssize_t nargs)1343 _sre_SRE_Match_start(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
1344 {
1345 PyObject *return_value = NULL;
1346 PyObject *group = NULL;
1347 Py_ssize_t _return_value;
1348
1349 if (!_PyArg_CheckPositional("start", nargs, 0, 1)) {
1350 goto exit;
1351 }
1352 if (nargs < 1) {
1353 goto skip_optional;
1354 }
1355 group = args[0];
1356 skip_optional:
1357 _return_value = _sre_SRE_Match_start_impl(self, group);
1358 if ((_return_value == -1) && PyErr_Occurred()) {
1359 goto exit;
1360 }
1361 return_value = PyLong_FromSsize_t(_return_value);
1362
1363 exit:
1364 return return_value;
1365 }
1366
1367 PyDoc_STRVAR(_sre_SRE_Match_end__doc__,
1368 "end($self, group=0, /)\n"
1369 "--\n"
1370 "\n"
1371 "Return index of the end of the substring matched by group.");
1372
1373 #define _SRE_SRE_MATCH_END_METHODDEF \
1374 {"end", _PyCFunction_CAST(_sre_SRE_Match_end), METH_FASTCALL, _sre_SRE_Match_end__doc__},
1375
1376 static Py_ssize_t
1377 _sre_SRE_Match_end_impl(MatchObject *self, PyObject *group);
1378
1379 static PyObject *
_sre_SRE_Match_end(MatchObject * self,PyObject * const * args,Py_ssize_t nargs)1380 _sre_SRE_Match_end(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
1381 {
1382 PyObject *return_value = NULL;
1383 PyObject *group = NULL;
1384 Py_ssize_t _return_value;
1385
1386 if (!_PyArg_CheckPositional("end", nargs, 0, 1)) {
1387 goto exit;
1388 }
1389 if (nargs < 1) {
1390 goto skip_optional;
1391 }
1392 group = args[0];
1393 skip_optional:
1394 _return_value = _sre_SRE_Match_end_impl(self, group);
1395 if ((_return_value == -1) && PyErr_Occurred()) {
1396 goto exit;
1397 }
1398 return_value = PyLong_FromSsize_t(_return_value);
1399
1400 exit:
1401 return return_value;
1402 }
1403
1404 PyDoc_STRVAR(_sre_SRE_Match_span__doc__,
1405 "span($self, group=0, /)\n"
1406 "--\n"
1407 "\n"
1408 "For match object m, return the 2-tuple (m.start(group), m.end(group)).");
1409
1410 #define _SRE_SRE_MATCH_SPAN_METHODDEF \
1411 {"span", _PyCFunction_CAST(_sre_SRE_Match_span), METH_FASTCALL, _sre_SRE_Match_span__doc__},
1412
1413 static PyObject *
1414 _sre_SRE_Match_span_impl(MatchObject *self, PyObject *group);
1415
1416 static PyObject *
_sre_SRE_Match_span(MatchObject * self,PyObject * const * args,Py_ssize_t nargs)1417 _sre_SRE_Match_span(MatchObject *self, PyObject *const *args, Py_ssize_t nargs)
1418 {
1419 PyObject *return_value = NULL;
1420 PyObject *group = NULL;
1421
1422 if (!_PyArg_CheckPositional("span", nargs, 0, 1)) {
1423 goto exit;
1424 }
1425 if (nargs < 1) {
1426 goto skip_optional;
1427 }
1428 group = args[0];
1429 skip_optional:
1430 return_value = _sre_SRE_Match_span_impl(self, group);
1431
1432 exit:
1433 return return_value;
1434 }
1435
1436 PyDoc_STRVAR(_sre_SRE_Match___copy____doc__,
1437 "__copy__($self, /)\n"
1438 "--\n"
1439 "\n");
1440
1441 #define _SRE_SRE_MATCH___COPY___METHODDEF \
1442 {"__copy__", (PyCFunction)_sre_SRE_Match___copy__, METH_NOARGS, _sre_SRE_Match___copy____doc__},
1443
1444 static PyObject *
1445 _sre_SRE_Match___copy___impl(MatchObject *self);
1446
1447 static PyObject *
_sre_SRE_Match___copy__(MatchObject * self,PyObject * Py_UNUSED (ignored))1448 _sre_SRE_Match___copy__(MatchObject *self, PyObject *Py_UNUSED(ignored))
1449 {
1450 return _sre_SRE_Match___copy___impl(self);
1451 }
1452
1453 PyDoc_STRVAR(_sre_SRE_Match___deepcopy____doc__,
1454 "__deepcopy__($self, memo, /)\n"
1455 "--\n"
1456 "\n");
1457
1458 #define _SRE_SRE_MATCH___DEEPCOPY___METHODDEF \
1459 {"__deepcopy__", (PyCFunction)_sre_SRE_Match___deepcopy__, METH_O, _sre_SRE_Match___deepcopy____doc__},
1460
1461 PyDoc_STRVAR(_sre_SRE_Scanner_match__doc__,
1462 "match($self, /)\n"
1463 "--\n"
1464 "\n");
1465
1466 #define _SRE_SRE_SCANNER_MATCH_METHODDEF \
1467 {"match", _PyCFunction_CAST(_sre_SRE_Scanner_match), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Scanner_match__doc__},
1468
1469 static PyObject *
1470 _sre_SRE_Scanner_match_impl(ScannerObject *self, PyTypeObject *cls);
1471
1472 static PyObject *
_sre_SRE_Scanner_match(ScannerObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1473 _sre_SRE_Scanner_match(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1474 {
1475 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
1476 PyErr_SetString(PyExc_TypeError, "match() takes no arguments");
1477 return NULL;
1478 }
1479 return _sre_SRE_Scanner_match_impl(self, cls);
1480 }
1481
1482 PyDoc_STRVAR(_sre_SRE_Scanner_search__doc__,
1483 "search($self, /)\n"
1484 "--\n"
1485 "\n");
1486
1487 #define _SRE_SRE_SCANNER_SEARCH_METHODDEF \
1488 {"search", _PyCFunction_CAST(_sre_SRE_Scanner_search), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _sre_SRE_Scanner_search__doc__},
1489
1490 static PyObject *
1491 _sre_SRE_Scanner_search_impl(ScannerObject *self, PyTypeObject *cls);
1492
1493 static PyObject *
_sre_SRE_Scanner_search(ScannerObject * self,PyTypeObject * cls,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)1494 _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
1495 {
1496 if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
1497 PyErr_SetString(PyExc_TypeError, "search() takes no arguments");
1498 return NULL;
1499 }
1500 return _sre_SRE_Scanner_search_impl(self, cls);
1501 }
1502
1503 #ifndef _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
1504 #define _SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF
1505 #endif /* !defined(_SRE_SRE_PATTERN__FAIL_AFTER_METHODDEF) */
1506 /*[clinic end generated code: output=32f2528c7b5b6081 input=a9049054013a1b77]*/
1507