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