Coverage Report

Created: 2025-07-11 06:24

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