Coverage Report

Created: 2025-07-04 06:49

/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
96.0M
{
184
96.0M
    PyObject *return_value = NULL;
185
96.0M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
186
187
96.0M
    #define NUM_KEYWORDS 3
188
96.0M
    static struct {
189
96.0M
        PyGC_Head _this_is_not_used;
190
96.0M
        PyObject_VAR_HEAD
191
96.0M
        Py_hash_t ob_hash;
192
96.0M
        PyObject *ob_item[NUM_KEYWORDS];
193
96.0M
    } _kwtuple = {
194
96.0M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
195
96.0M
        .ob_hash = -1,
196
96.0M
        .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
197
96.0M
    };
198
96.0M
    #undef NUM_KEYWORDS
199
96.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
96.0M
    static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
206
96.0M
    static _PyArg_Parser _parser = {
207
96.0M
        .keywords = _keywords,
208
96.0M
        .fname = "match",
209
96.0M
        .kwtuple = KWTUPLE,
210
96.0M
    };
211
96.0M
    #undef KWTUPLE
212
96.0M
    PyObject *argsbuf[3];
213
96.0M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
214
96.0M
    PyObject *string;
215
96.0M
    Py_ssize_t pos = 0;
216
96.0M
    Py_ssize_t endpos = PY_SSIZE_T_MAX;
217
218
96.0M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
219
96.0M
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
220
96.0M
    if (!args) {
221
0
        goto exit;
222
0
    }
223
96.0M
    string = args[0];
224
96.0M
    if (!noptargs) {
225
31.5M
        goto skip_optional_pos;
226
31.5M
    }
227
64.4M
    if (args[1]) {
228
64.4M
        {
229
64.4M
            Py_ssize_t ival = -1;
230
64.4M
            PyObject *iobj = _PyNumber_Index(args[1]);
231
64.4M
            if (iobj != NULL) {
232
64.4M
                ival = PyLong_AsSsize_t(iobj);
233
64.4M
                Py_DECREF(iobj);
234
64.4M
            }
235
64.4M
            if (ival == -1 && PyErr_Occurred()) {
236
0
                goto exit;
237
0
            }
238
64.4M
            pos = ival;
239
64.4M
        }
240
64.4M
        if (!--noptargs) {
241
64.4M
            goto skip_optional_pos;
242
64.4M
        }
243
64.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
96.0M
skip_optional_pos:
257
96.0M
    return_value = _sre_SRE_Pattern_match_impl((PatternObject *)self, cls, string, pos, endpos);
258
259
96.0M
exit:
260
96.0M
    return return_value;
261
96.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
508k
{
378
508k
    PyObject *return_value = NULL;
379
508k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
380
381
508k
    #define NUM_KEYWORDS 3
382
508k
    static struct {
383
508k
        PyGC_Head _this_is_not_used;
384
508k
        PyObject_VAR_HEAD
385
508k
        Py_hash_t ob_hash;
386
508k
        PyObject *ob_item[NUM_KEYWORDS];
387
508k
    } _kwtuple = {
388
508k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
389
508k
        .ob_hash = -1,
390
508k
        .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
391
508k
    };
392
508k
    #undef NUM_KEYWORDS
393
508k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
394
395
    #else  // !Py_BUILD_CORE
396
    #  define KWTUPLE NULL
397
    #endif  // !Py_BUILD_CORE
398
399
508k
    static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
400
508k
    static _PyArg_Parser _parser = {
401
508k
        .keywords = _keywords,
402
508k
        .fname = "search",
403
508k
        .kwtuple = KWTUPLE,
404
508k
    };
405
508k
    #undef KWTUPLE
406
508k
    PyObject *argsbuf[3];
407
508k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
408
508k
    PyObject *string;
409
508k
    Py_ssize_t pos = 0;
410
508k
    Py_ssize_t endpos = PY_SSIZE_T_MAX;
411
412
508k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
413
508k
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
414
508k
    if (!args) {
415
0
        goto exit;
416
0
    }
417
508k
    string = args[0];
418
508k
    if (!noptargs) {
419
8.85k
        goto skip_optional_pos;
420
8.85k
    }
421
499k
    if (args[1]) {
422
499k
        {
423
499k
            Py_ssize_t ival = -1;
424
499k
            PyObject *iobj = _PyNumber_Index(args[1]);
425
499k
            if (iobj != NULL) {
426
499k
                ival = PyLong_AsSsize_t(iobj);
427
499k
                Py_DECREF(iobj);
428
499k
            }
429
499k
            if (ival == -1 && PyErr_Occurred()) {
430
0
                goto exit;
431
0
            }
432
499k
            pos = ival;
433
499k
        }
434
499k
        if (!--noptargs) {
435
499k
            goto skip_optional_pos;
436
499k
        }
437
499k
    }
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
508k
skip_optional_pos:
451
508k
    return_value = _sre_SRE_Pattern_search_impl((PatternObject *)self, cls, string, pos, endpos);
452
453
508k
exit:
454
508k
    return return_value;
455
508k
}
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
4.03M
{
473
4.03M
    PyObject *return_value = NULL;
474
4.03M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
475
476
4.03M
    #define NUM_KEYWORDS 3
477
4.03M
    static struct {
478
4.03M
        PyGC_Head _this_is_not_used;
479
4.03M
        PyObject_VAR_HEAD
480
4.03M
        Py_hash_t ob_hash;
481
4.03M
        PyObject *ob_item[NUM_KEYWORDS];
482
4.03M
    } _kwtuple = {
483
4.03M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
484
4.03M
        .ob_hash = -1,
485
4.03M
        .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
486
4.03M
    };
487
4.03M
    #undef NUM_KEYWORDS
488
4.03M
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
489
490
    #else  // !Py_BUILD_CORE
491
    #  define KWTUPLE NULL
492
    #endif  // !Py_BUILD_CORE
493
494
4.03M
    static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
495
4.03M
    static _PyArg_Parser _parser = {
496
4.03M
        .keywords = _keywords,
497
4.03M
        .fname = "findall",
498
4.03M
        .kwtuple = KWTUPLE,
499
4.03M
    };
500
4.03M
    #undef KWTUPLE
501
4.03M
    PyObject *argsbuf[3];
502
4.03M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
503
4.03M
    PyObject *string;
504
4.03M
    Py_ssize_t pos = 0;
505
4.03M
    Py_ssize_t endpos = PY_SSIZE_T_MAX;
506
507
4.03M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
508
4.03M
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
509
4.03M
    if (!args) {
510
0
        goto exit;
511
0
    }
512
4.03M
    string = args[0];
513
4.03M
    if (!noptargs) {
514
4.03M
        goto skip_optional_pos;
515
4.03M
    }
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
4.03M
skip_optional_pos:
546
4.03M
    return_value = _sre_SRE_Pattern_findall_impl((PatternObject *)self, string, pos, endpos);
547
548
4.03M
exit:
549
4.03M
    return return_value;
550
4.03M
}
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
338k
{
571
338k
    PyObject *return_value = NULL;
572
338k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
573
574
338k
    #define NUM_KEYWORDS 3
575
338k
    static struct {
576
338k
        PyGC_Head _this_is_not_used;
577
338k
        PyObject_VAR_HEAD
578
338k
        Py_hash_t ob_hash;
579
338k
        PyObject *ob_item[NUM_KEYWORDS];
580
338k
    } _kwtuple = {
581
338k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
582
338k
        .ob_hash = -1,
583
338k
        .ob_item = { &_Py_ID(string), &_Py_ID(pos), &_Py_ID(endpos), },
584
338k
    };
585
338k
    #undef NUM_KEYWORDS
586
338k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
587
588
    #else  // !Py_BUILD_CORE
589
    #  define KWTUPLE NULL
590
    #endif  // !Py_BUILD_CORE
591
592
338k
    static const char * const _keywords[] = {"string", "pos", "endpos", NULL};
593
338k
    static _PyArg_Parser _parser = {
594
338k
        .keywords = _keywords,
595
338k
        .fname = "finditer",
596
338k
        .kwtuple = KWTUPLE,
597
338k
    };
598
338k
    #undef KWTUPLE
599
338k
    PyObject *argsbuf[3];
600
338k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
601
338k
    PyObject *string;
602
338k
    Py_ssize_t pos = 0;
603
338k
    Py_ssize_t endpos = PY_SSIZE_T_MAX;
604
605
338k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
606
338k
            /*minpos*/ 1, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
607
338k
    if (!args) {
608
0
        goto exit;
609
0
    }
610
338k
    string = args[0];
611
338k
    if (!noptargs) {
612
338k
        goto skip_optional_pos;
613
338k
    }
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
338k
skip_optional_pos:
644
338k
    return_value = _sre_SRE_Pattern_finditer_impl((PatternObject *)self, cls, string, pos, endpos);
645
646
338k
exit:
647
338k
    return return_value;
648
338k
}
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.51M
{
761
1.51M
    PyObject *return_value = NULL;
762
1.51M
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
763
764
1.51M
    #define NUM_KEYWORDS 2
765
1.51M
    static struct {
766
1.51M
        PyGC_Head _this_is_not_used;
767
1.51M
        PyObject_VAR_HEAD
768
1.51M
        Py_hash_t ob_hash;
769
1.51M
        PyObject *ob_item[NUM_KEYWORDS];
770
1.51M
    } _kwtuple = {
771
1.51M
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
772
1.51M
        .ob_hash = -1,
773
1.51M
        .ob_item = { &_Py_ID(string), &_Py_ID(maxsplit), },
774
1.51M
    };
775
1.51M
    #undef NUM_KEYWORDS
776
1.51M
    #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.51M
    static const char * const _keywords[] = {"string", "maxsplit", NULL};
783
1.51M
    static _PyArg_Parser _parser = {
784
1.51M
        .keywords = _keywords,
785
1.51M
        .fname = "split",
786
1.51M
        .kwtuple = KWTUPLE,
787
1.51M
    };
788
1.51M
    #undef KWTUPLE
789
1.51M
    PyObject *argsbuf[2];
790
1.51M
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
791
1.51M
    PyObject *string;
792
1.51M
    Py_ssize_t maxsplit = 0;
793
794
1.51M
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
795
1.51M
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
796
1.51M
    if (!args) {
797
0
        goto exit;
798
0
    }
799
1.51M
    string = args[0];
800
1.51M
    if (!noptargs) {
801
240k
        goto skip_optional_pos;
802
240k
    }
803
1.27M
    {
804
1.27M
        Py_ssize_t ival = -1;
805
1.27M
        PyObject *iobj = _PyNumber_Index(args[1]);
806
1.27M
        if (iobj != NULL) {
807
1.27M
            ival = PyLong_AsSsize_t(iobj);
808
1.27M
            Py_DECREF(iobj);
809
1.27M
        }
810
1.27M
        if (ival == -1 && PyErr_Occurred()) {
811
0
            goto exit;
812
0
        }
813
1.27M
        maxsplit = ival;
814
1.27M
    }
815
1.51M
skip_optional_pos:
816
1.51M
    return_value = _sre_SRE_Pattern_split_impl((PatternObject *)self, string, maxsplit);
817
818
1.51M
exit:
819
1.51M
    return return_value;
820
1.51M
}
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
889k
{
838
889k
    PyObject *return_value = NULL;
839
889k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
840
841
889k
    #define NUM_KEYWORDS 3
842
889k
    static struct {
843
889k
        PyGC_Head _this_is_not_used;
844
889k
        PyObject_VAR_HEAD
845
889k
        Py_hash_t ob_hash;
846
889k
        PyObject *ob_item[NUM_KEYWORDS];
847
889k
    } _kwtuple = {
848
889k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
849
889k
        .ob_hash = -1,
850
889k
        .ob_item = { &_Py_ID(repl), &_Py_ID(string), &_Py_ID(count), },
851
889k
    };
852
889k
    #undef NUM_KEYWORDS
853
889k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
854
855
    #else  // !Py_BUILD_CORE
856
    #  define KWTUPLE NULL
857
    #endif  // !Py_BUILD_CORE
858
859
889k
    static const char * const _keywords[] = {"repl", "string", "count", NULL};
860
889k
    static _PyArg_Parser _parser = {
861
889k
        .keywords = _keywords,
862
889k
        .fname = "sub",
863
889k
        .kwtuple = KWTUPLE,
864
889k
    };
865
889k
    #undef KWTUPLE
866
889k
    PyObject *argsbuf[3];
867
889k
    Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
868
889k
    PyObject *repl;
869
889k
    PyObject *string;
870
889k
    Py_ssize_t count = 0;
871
872
889k
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
873
889k
            /*minpos*/ 2, /*maxpos*/ 3, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
874
889k
    if (!args) {
875
0
        goto exit;
876
0
    }
877
889k
    repl = args[0];
878
889k
    string = args[1];
879
889k
    if (!noptargs) {
880
889k
        goto skip_optional_pos;
881
889k
    }
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
889k
skip_optional_pos:
895
889k
    return_value = _sre_SRE_Pattern_sub_impl((PatternObject *)self, cls, repl, string, count);
896
897
889k
exit:
898
889k
    return return_value;
899
889k
}
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
208
{
1074
208
    PyObject *return_value = NULL;
1075
208
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1076
1077
208
    #define NUM_KEYWORDS 6
1078
208
    static struct {
1079
208
        PyGC_Head _this_is_not_used;
1080
208
        PyObject_VAR_HEAD
1081
208
        Py_hash_t ob_hash;
1082
208
        PyObject *ob_item[NUM_KEYWORDS];
1083
208
    } _kwtuple = {
1084
208
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1085
208
        .ob_hash = -1,
1086
208
        .ob_item = { &_Py_ID(pattern), &_Py_ID(flags), &_Py_ID(code), &_Py_ID(groups), &_Py_ID(groupindex), &_Py_ID(indexgroup), },
1087
208
    };
1088
208
    #undef NUM_KEYWORDS
1089
208
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1090
1091
    #else  // !Py_BUILD_CORE
1092
    #  define KWTUPLE NULL
1093
    #endif  // !Py_BUILD_CORE
1094
1095
208
    static const char * const _keywords[] = {"pattern", "flags", "code", "groups", "groupindex", "indexgroup", NULL};
1096
208
    static _PyArg_Parser _parser = {
1097
208
        .keywords = _keywords,
1098
208
        .fname = "compile",
1099
208
        .kwtuple = KWTUPLE,
1100
208
    };
1101
208
    #undef KWTUPLE
1102
208
    PyObject *argsbuf[6];
1103
208
    PyObject *pattern;
1104
208
    int flags;
1105
208
    PyObject *code;
1106
208
    Py_ssize_t groups;
1107
208
    PyObject *groupindex;
1108
208
    PyObject *indexgroup;
1109
1110
208
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
1111
208
            /*minpos*/ 6, /*maxpos*/ 6, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1112
208
    if (!args) {
1113
0
        goto exit;
1114
0
    }
1115
208
    pattern = args[0];
1116
208
    flags = PyLong_AsInt(args[1]);
1117
208
    if (flags == -1 && PyErr_Occurred()) {
1118
0
        goto exit;
1119
0
    }
1120
208
    if (!PyList_Check(args[2])) {
1121
0
        _PyArg_BadArgument("compile", "argument 'code'", "list", args[2]);
1122
0
        goto exit;
1123
0
    }
1124
208
    code = args[2];
1125
208
    {
1126
208
        Py_ssize_t ival = -1;
1127
208
        PyObject *iobj = _PyNumber_Index(args[3]);
1128
208
        if (iobj != NULL) {
1129
208
            ival = PyLong_AsSsize_t(iobj);
1130
208
            Py_DECREF(iobj);
1131
208
        }
1132
208
        if (ival == -1 && PyErr_Occurred()) {
1133
0
            goto exit;
1134
0
        }
1135
208
        groups = ival;
1136
208
    }
1137
208
    if (!PyDict_Check(args[4])) {
1138
0
        _PyArg_BadArgument("compile", "argument 'groupindex'", "dict", args[4]);
1139
0
        goto exit;
1140
0
    }
1141
208
    groupindex = args[4];
1142
208
    if (!PyTuple_Check(args[5])) {
1143
0
        _PyArg_BadArgument("compile", "argument 'indexgroup'", "tuple", args[5]);
1144
0
        goto exit;
1145
0
    }
1146
208
    indexgroup = args[5];
1147
208
    return_value = _sre_compile_impl(module, pattern, flags, code, groups, groupindex, indexgroup);
1148
1149
208
exit:
1150
208
    return return_value;
1151
208
}
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
498k
{
1397
498k
    PyObject *return_value = NULL;
1398
498k
    PyObject *group = NULL;
1399
498k
    Py_ssize_t _return_value;
1400
1401
498k
    if (!_PyArg_CheckPositional("start", nargs, 0, 1)) {
1402
0
        goto exit;
1403
0
    }
1404
498k
    if (nargs < 1) {
1405
468k
        goto skip_optional;
1406
468k
    }
1407
29.9k
    group = args[0];
1408
498k
skip_optional:
1409
498k
    _return_value = _sre_SRE_Match_start_impl((MatchObject *)self, group);
1410
498k
    if ((_return_value == -1) && PyErr_Occurred()) {
1411
0
        goto exit;
1412
0
    }
1413
498k
    return_value = PyLong_FromSsize_t(_return_value);
1414
1415
498k
exit:
1416
498k
    return return_value;
1417
498k
}
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
58.5M
{
1434
58.5M
    PyObject *return_value = NULL;
1435
58.5M
    PyObject *group = NULL;
1436
58.5M
    Py_ssize_t _return_value;
1437
1438
58.5M
    if (!_PyArg_CheckPositional("end", nargs, 0, 1)) {
1439
0
        goto exit;
1440
0
    }
1441
58.5M
    if (nargs < 1) {
1442
58.5M
        goto skip_optional;
1443
58.5M
    }
1444
29.9k
    group = args[0];
1445
58.5M
skip_optional:
1446
58.5M
    _return_value = _sre_SRE_Match_end_impl((MatchObject *)self, group);
1447
58.5M
    if ((_return_value == -1) && PyErr_Occurred()) {
1448
0
        goto exit;
1449
0
    }
1450
58.5M
    return_value = PyLong_FromSsize_t(_return_value);
1451
1452
58.5M
exit:
1453
58.5M
    return return_value;
1454
58.5M
}
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
2.53M
{
1471
2.53M
    PyObject *return_value = NULL;
1472
2.53M
    PyObject *group = NULL;
1473
1474
2.53M
    if (!_PyArg_CheckPositional("span", nargs, 0, 1)) {
1475
0
        goto exit;
1476
0
    }
1477
2.53M
    if (nargs < 1) {
1478
2.53M
        goto skip_optional;
1479
2.53M
    }
1480
0
    group = args[0];
1481
2.53M
skip_optional:
1482
2.53M
    return_value = _sre_SRE_Match_span_impl((MatchObject *)self, group);
1483
1484
2.53M
exit:
1485
2.53M
    return return_value;
1486
2.53M
}
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.73M
{
1561
2.73M
    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.73M
    return _sre_SRE_Scanner_search_impl((ScannerObject *)self, cls);
1566
2.73M
}
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]*/