Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_io/clinic/textio.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(_io__TextIOBase_detach__doc__,
12
"detach($self, /)\n"
13
"--\n"
14
"\n"
15
"Separate the underlying buffer from the TextIOBase and return it.\n"
16
"\n"
17
"After the underlying buffer has been detached, the TextIO is in an unusable state.");
18
19
#define _IO__TEXTIOBASE_DETACH_METHODDEF \
20
{"detach", _PyCFunction_CAST(_io__TextIOBase_detach), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_detach__doc__},
21
22
static PyObject *
23
_io__TextIOBase_detach_impl(PyObject *self, PyTypeObject *cls);
24
25
static PyObject *
26
_io__TextIOBase_detach(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
27
{
28
if (nargs) {
29
PyErr_SetString(PyExc_TypeError, "detach() takes no arguments");
30
return NULL;
31
}
32
return _io__TextIOBase_detach_impl(self, cls);
33
}
34
35
PyDoc_STRVAR(_io__TextIOBase_read__doc__,
36
"read($self, size=-1, /)\n"
37
"--\n"
38
"\n"
39
"Read at most size characters from stream.\n"
40
"\n"
41
"Read from underlying buffer until we have size characters or we hit EOF.\n"
42
"If size is negative or omitted, read until EOF.");
43
44
#define _IO__TEXTIOBASE_READ_METHODDEF \
45
{"read", _PyCFunction_CAST(_io__TextIOBase_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_read__doc__},
46
47
static PyObject *
48
_io__TextIOBase_read_impl(PyObject *self, PyTypeObject *cls,
49
int Py_UNUSED(size));
50
51
static PyObject *
52
_io__TextIOBase_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
53
{
54
PyObject *return_value = NULL;
55
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
56
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
57
#else
58
# define KWTUPLE NULL
59
#endif
60
61
static const char * const _keywords[] = {"", NULL};
62
static _PyArg_Parser _parser = {
63
.keywords = _keywords,
64
.fname = "read",
65
.kwtuple = KWTUPLE,
66
};
67
#undef KWTUPLE
68
PyObject *argsbuf[1];
69
int size = -1;
70
71
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
72
if (!args) {
73
goto exit;
74
}
75
if (nargs < 1) {
76
goto skip_optional_posonly;
77
}
78
size = _PyLong_AsInt(args[0]);
79
if (size == -1 && PyErr_Occurred()) {
80
goto exit;
81
}
82
skip_optional_posonly:
83
return_value = _io__TextIOBase_read_impl(self, cls, size);
84
85
exit:
86
return return_value;
87
}
88
89
PyDoc_STRVAR(_io__TextIOBase_readline__doc__,
90
"readline($self, size=-1, /)\n"
91
"--\n"
92
"\n"
93
"Read until newline or EOF.\n"
94
"\n"
95
"Return an empty string if EOF is hit immediately.\n"
96
"If size is specified, at most size characters will be read.");
97
98
#define _IO__TEXTIOBASE_READLINE_METHODDEF \
99
{"readline", _PyCFunction_CAST(_io__TextIOBase_readline), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_readline__doc__},
100
101
static PyObject *
102
_io__TextIOBase_readline_impl(PyObject *self, PyTypeObject *cls,
103
int Py_UNUSED(size));
104
105
static PyObject *
106
_io__TextIOBase_readline(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
107
{
108
PyObject *return_value = NULL;
109
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
110
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
111
#else
112
# define KWTUPLE NULL
113
#endif
114
115
static const char * const _keywords[] = {"", NULL};
116
static _PyArg_Parser _parser = {
117
.keywords = _keywords,
118
.fname = "readline",
119
.kwtuple = KWTUPLE,
120
};
121
#undef KWTUPLE
122
PyObject *argsbuf[1];
123
int size = -1;
124
125
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
126
if (!args) {
127
goto exit;
128
}
129
if (nargs < 1) {
130
goto skip_optional_posonly;
131
}
132
size = _PyLong_AsInt(args[0]);
133
if (size == -1 && PyErr_Occurred()) {
134
goto exit;
135
}
136
skip_optional_posonly:
137
return_value = _io__TextIOBase_readline_impl(self, cls, size);
138
139
exit:
140
return return_value;
141
}
142
143
PyDoc_STRVAR(_io__TextIOBase_write__doc__,
144
"write($self, s, /)\n"
145
"--\n"
146
"\n"
147
"Write string s to stream.\n"
148
"\n"
149
"Return the number of characters written\n"
150
"(which is always equal to the length of the string).");
151
152
#define _IO__TEXTIOBASE_WRITE_METHODDEF \
153
{"write", _PyCFunction_CAST(_io__TextIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__TextIOBase_write__doc__},
154
155
static PyObject *
156
_io__TextIOBase_write_impl(PyObject *self, PyTypeObject *cls,
157
const char *Py_UNUSED(s));
158
159
static PyObject *
160
_io__TextIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
161
{
162
PyObject *return_value = NULL;
163
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
164
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
165
#else
166
# define KWTUPLE NULL
167
#endif
168
169
static const char * const _keywords[] = {"", NULL};
170
static _PyArg_Parser _parser = {
171
.keywords = _keywords,
172
.fname = "write",
173
.kwtuple = KWTUPLE,
174
};
175
#undef KWTUPLE
176
PyObject *argsbuf[1];
177
const char *s;
178
179
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
180
if (!args) {
181
goto exit;
182
}
183
if (!PyUnicode_Check(args[0])) {
184
_PyArg_BadArgument("write", "argument 1", "str", args[0]);
185
goto exit;
186
}
187
Py_ssize_t s_length;
188
s = PyUnicode_AsUTF8AndSize(args[0], &s_length);
189
if (s == NULL) {
190
goto exit;
191
}
192
if (strlen(s) != (size_t)s_length) {
193
PyErr_SetString(PyExc_ValueError, "embedded null character");
194
goto exit;
195
}
196
return_value = _io__TextIOBase_write_impl(self, cls, s);
197
198
exit:
199
return return_value;
200
}
201
202
PyDoc_STRVAR(_io_IncrementalNewlineDecoder___init____doc__,
203
"IncrementalNewlineDecoder(decoder, translate, errors=\'strict\')\n"
204
"--\n"
205
"\n"
206
"Codec used when reading a file in universal newlines mode.\n"
207
"\n"
208
"It wraps another incremental decoder, translating \\r\\n and \\r into \\n.\n"
209
"It also records the types of newlines encountered. When used with\n"
210
"translate=False, it ensures that the newline sequence is returned in\n"
211
"one piece. When used with decoder=None, it expects unicode strings as\n"
212
"decode input and translates newlines without first invoking an external\n"
213
"decoder.");
214
215
static int
216
_io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self,
217
PyObject *decoder, int translate,
218
PyObject *errors);
219
220
static int
221
_io_IncrementalNewlineDecoder___init__(PyObject *self, PyObject *args, PyObject *kwargs)
222
{
223
int return_value = -1;
224
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
225
226
#define NUM_KEYWORDS 3
227
static struct {
228
PyGC_Head _this_is_not_used;
229
PyObject_VAR_HEAD
230
PyObject *ob_item[NUM_KEYWORDS];
231
} _kwtuple = {
232
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
233
.ob_item = { &_Py_ID(decoder), &_Py_ID(translate), &_Py_ID(errors), },
234
};
235
#undef NUM_KEYWORDS
236
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
237
238
#else // !Py_BUILD_CORE
239
# define KWTUPLE NULL
240
#endif // !Py_BUILD_CORE
241
242
static const char * const _keywords[] = {"decoder", "translate", "errors", NULL};
243
static _PyArg_Parser _parser = {
244
.keywords = _keywords,
245
.fname = "IncrementalNewlineDecoder",
246
.kwtuple = KWTUPLE,
247
};
248
#undef KWTUPLE
249
PyObject *argsbuf[3];
250
PyObject * const *fastargs;
251
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
252
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 2;
253
PyObject *decoder;
254
int translate;
255
PyObject *errors = NULL;
256
257
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 2, 3, 0, argsbuf);
258
if (!fastargs) {
259
goto exit;
260
}
261
decoder = fastargs[0];
262
translate = PyObject_IsTrue(fastargs[1]);
263
if (translate < 0) {
264
goto exit;
265
}
266
if (!noptargs) {
267
goto skip_optional_pos;
268
}
269
errors = fastargs[2];
270
skip_optional_pos:
271
return_value = _io_IncrementalNewlineDecoder___init___impl((nldecoder_object *)self, decoder, translate, errors);
272
273
exit:
274
return return_value;
275
}
276
277
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_decode__doc__,
278
"decode($self, /, input, final=False)\n"
279
"--\n"
280
"\n");
281
282
#define _IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF \
283
{"decode", _PyCFunction_CAST(_io_IncrementalNewlineDecoder_decode), METH_FASTCALL|METH_KEYWORDS, _io_IncrementalNewlineDecoder_decode__doc__},
284
285
static PyObject *
286
_io_IncrementalNewlineDecoder_decode_impl(nldecoder_object *self,
287
PyObject *input, int final);
288
289
static PyObject *
290
_io_IncrementalNewlineDecoder_decode(nldecoder_object *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
291
{
292
PyObject *return_value = NULL;
293
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
294
295
#define NUM_KEYWORDS 2
296
static struct {
297
PyGC_Head _this_is_not_used;
298
PyObject_VAR_HEAD
299
PyObject *ob_item[NUM_KEYWORDS];
300
} _kwtuple = {
301
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
302
.ob_item = { &_Py_ID(input), &_Py_ID(final), },
303
};
304
#undef NUM_KEYWORDS
305
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
306
307
#else // !Py_BUILD_CORE
308
# define KWTUPLE NULL
309
#endif // !Py_BUILD_CORE
310
311
static const char * const _keywords[] = {"input", "final", NULL};
312
static _PyArg_Parser _parser = {
313
.keywords = _keywords,
314
.fname = "decode",
315
.kwtuple = KWTUPLE,
316
};
317
#undef KWTUPLE
318
PyObject *argsbuf[2];
319
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
320
PyObject *input;
321
int final = 0;
322
323
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
324
if (!args) {
325
goto exit;
326
}
327
input = args[0];
328
if (!noptargs) {
329
goto skip_optional_pos;
330
}
331
final = PyObject_IsTrue(args[1]);
332
if (final < 0) {
333
goto exit;
334
}
335
skip_optional_pos:
336
return_value = _io_IncrementalNewlineDecoder_decode_impl(self, input, final);
337
338
exit:
339
return return_value;
340
}
341
342
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_getstate__doc__,
343
"getstate($self, /)\n"
344
"--\n"
345
"\n");
346
347
#define _IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF \
348
{"getstate", (PyCFunction)_io_IncrementalNewlineDecoder_getstate, METH_NOARGS, _io_IncrementalNewlineDecoder_getstate__doc__},
349
350
static PyObject *
351
_io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self);
352
353
static PyObject *
354
_io_IncrementalNewlineDecoder_getstate(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
355
{
356
return _io_IncrementalNewlineDecoder_getstate_impl(self);
357
}
358
359
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_setstate__doc__,
360
"setstate($self, state, /)\n"
361
"--\n"
362
"\n");
363
364
#define _IO_INCREMENTALNEWLINEDECODER_SETSTATE_METHODDEF \
365
{"setstate", (PyCFunction)_io_IncrementalNewlineDecoder_setstate, METH_O, _io_IncrementalNewlineDecoder_setstate__doc__},
366
367
PyDoc_STRVAR(_io_IncrementalNewlineDecoder_reset__doc__,
368
"reset($self, /)\n"
369
"--\n"
370
"\n");
371
372
#define _IO_INCREMENTALNEWLINEDECODER_RESET_METHODDEF \
373
{"reset", (PyCFunction)_io_IncrementalNewlineDecoder_reset, METH_NOARGS, _io_IncrementalNewlineDecoder_reset__doc__},
374
375
static PyObject *
376
_io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self);
377
378
static PyObject *
379
_io_IncrementalNewlineDecoder_reset(nldecoder_object *self, PyObject *Py_UNUSED(ignored))
380
{
381
return _io_IncrementalNewlineDecoder_reset_impl(self);
382
}
383
384
PyDoc_STRVAR(_io_TextIOWrapper___init____doc__,
385
"TextIOWrapper(buffer, encoding=None, errors=None, newline=None,\n"
386
" line_buffering=False, write_through=False)\n"
387
"--\n"
388
"\n"
389
"Character and line based layer over a BufferedIOBase object, buffer.\n"
390
"\n"
391
"encoding gives the name of the encoding that the stream will be\n"
392
"decoded or encoded with. It defaults to locale.getencoding().\n"
393
"\n"
394
"errors determines the strictness of encoding and decoding (see\n"
395
"help(codecs.Codec) or the documentation for codecs.register) and\n"
396
"defaults to \"strict\".\n"
397
"\n"
398
"newline controls how line endings are handled. It can be None, \'\',\n"
399
"\'\\n\', \'\\r\', and \'\\r\\n\'. It works as follows:\n"
400
"\n"
401
"* On input, if newline is None, universal newlines mode is\n"
402
" enabled. Lines in the input can end in \'\\n\', \'\\r\', or \'\\r\\n\', and\n"
403
" these are translated into \'\\n\' before being returned to the\n"
404
" caller. If it is \'\', universal newline mode is enabled, but line\n"
405
" endings are returned to the caller untranslated. If it has any of\n"
406
" the other legal values, input lines are only terminated by the given\n"
407
" string, and the line ending is returned to the caller untranslated.\n"
408
"\n"
409
"* On output, if newline is None, any \'\\n\' characters written are\n"
410
" translated to the system default line separator, os.linesep. If\n"
411
" newline is \'\' or \'\\n\', no translation takes place. If newline is any\n"
412
" of the other legal values, any \'\\n\' characters written are translated\n"
413
" to the given string.\n"
414
"\n"
415
"If line_buffering is True, a call to flush is implied when a call to\n"
416
"write contains a newline character.");
417
418
static int
419
_io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
420
const char *encoding, PyObject *errors,
421
const char *newline, int line_buffering,
422
int write_through);
423
424
static int
425
_io_TextIOWrapper___init__(PyObject *self, PyObject *args, PyObject *kwargs)
426
{
427
int return_value = -1;
428
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
429
430
#define NUM_KEYWORDS 6
431
static struct {
432
PyGC_Head _this_is_not_used;
433
PyObject_VAR_HEAD
434
PyObject *ob_item[NUM_KEYWORDS];
435
} _kwtuple = {
436
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
437
.ob_item = { &_Py_ID(buffer), &_Py_ID(encoding), &_Py_ID(errors), &_Py_ID(newline), &_Py_ID(line_buffering), &_Py_ID(write_through), },
438
};
439
#undef NUM_KEYWORDS
440
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
441
442
#else // !Py_BUILD_CORE
443
# define KWTUPLE NULL
444
#endif // !Py_BUILD_CORE
445
446
static const char * const _keywords[] = {"buffer", "encoding", "errors", "newline", "line_buffering", "write_through", NULL};
447
static _PyArg_Parser _parser = {
448
.keywords = _keywords,
449
.fname = "TextIOWrapper",
450
.kwtuple = KWTUPLE,
451
};
452
#undef KWTUPLE
453
PyObject *argsbuf[6];
454
PyObject * const *fastargs;
455
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
456
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
457
PyObject *buffer;
458
const char *encoding = NULL;
459
PyObject *errors = Py_None;
460
const char *newline = NULL;
461
int line_buffering = 0;
462
int write_through = 0;
463
464
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 6, 0, argsbuf);
465
if (!fastargs) {
466
goto exit;
467
}
468
buffer = fastargs[0];
469
if (!noptargs) {
470
goto skip_optional_pos;
471
}
472
if (fastargs[1]) {
473
if (fastargs[1] == Py_None) {
474
encoding = NULL;
475
}
476
else if (PyUnicode_Check(fastargs[1])) {
477
Py_ssize_t encoding_length;
478
encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
479
if (encoding == NULL) {
480
goto exit;
481
}
482
if (strlen(encoding) != (size_t)encoding_length) {
483
PyErr_SetString(PyExc_ValueError, "embedded null character");
484
goto exit;
485
}
486
}
487
else {
488
_PyArg_BadArgument("TextIOWrapper", "argument 'encoding'", "str or None", fastargs[1]);
489
goto exit;
490
}
491
if (!--noptargs) {
492
goto skip_optional_pos;
493
}
494
}
495
if (fastargs[2]) {
496
errors = fastargs[2];
497
if (!--noptargs) {
498
goto skip_optional_pos;
499
}
500
}
501
if (fastargs[3]) {
502
if (fastargs[3] == Py_None) {
503
newline = NULL;
504
}
505
else if (PyUnicode_Check(fastargs[3])) {
506
Py_ssize_t newline_length;
507
newline = PyUnicode_AsUTF8AndSize(fastargs[3], &newline_length);
508
if (newline == NULL) {
509
goto exit;
510
}
511
if (strlen(newline) != (size_t)newline_length) {
512
PyErr_SetString(PyExc_ValueError, "embedded null character");
513
goto exit;
514
}
515
}
516
else {
517
_PyArg_BadArgument("TextIOWrapper", "argument 'newline'", "str or None", fastargs[3]);
518
goto exit;
519
}
520
if (!--noptargs) {
521
goto skip_optional_pos;
522
}
523
}
524
if (fastargs[4]) {
525
line_buffering = PyObject_IsTrue(fastargs[4]);
526
if (line_buffering < 0) {
527
goto exit;
528
}
529
if (!--noptargs) {
530
goto skip_optional_pos;
531
}
532
}
533
write_through = PyObject_IsTrue(fastargs[5]);
534
if (write_through < 0) {
535
goto exit;
536
}
537
skip_optional_pos:
538
return_value = _io_TextIOWrapper___init___impl((textio *)self, buffer, encoding, errors, newline, line_buffering, write_through);
539
540
exit:
541
return return_value;
542
}
543
544
PyDoc_STRVAR(_io_TextIOWrapper_reconfigure__doc__,
545
"reconfigure($self, /, *, encoding=None, errors=None, newline=None,\n"
546
" line_buffering=None, write_through=None)\n"
547
"--\n"
548
"\n"
549
"Reconfigure the text stream with new parameters.\n"
550
"\n"
551
"This also does an implicit stream flush.");
552
553
#define _IO_TEXTIOWRAPPER_RECONFIGURE_METHODDEF \
554
{"reconfigure", _PyCFunction_CAST(_io_TextIOWrapper_reconfigure), METH_FASTCALL|METH_KEYWORDS, _io_TextIOWrapper_reconfigure__doc__},
555
556
static PyObject *
557
_io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
558
PyObject *errors, PyObject *newline_obj,
559
PyObject *line_buffering_obj,
560
PyObject *write_through_obj);
561
562
static PyObject *
563
_io_TextIOWrapper_reconfigure(textio *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
564
{
565
PyObject *return_value = NULL;
566
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
567
568
#define NUM_KEYWORDS 5
569
static struct {
570
PyGC_Head _this_is_not_used;
571
PyObject_VAR_HEAD
572
PyObject *ob_item[NUM_KEYWORDS];
573
} _kwtuple = {
574
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
575
.ob_item = { &_Py_ID(encoding), &_Py_ID(errors), &_Py_ID(newline), &_Py_ID(line_buffering), &_Py_ID(write_through), },
576
};
577
#undef NUM_KEYWORDS
578
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
579
580
#else // !Py_BUILD_CORE
581
# define KWTUPLE NULL
582
#endif // !Py_BUILD_CORE
583
584
static const char * const _keywords[] = {"encoding", "errors", "newline", "line_buffering", "write_through", NULL};
585
static _PyArg_Parser _parser = {
586
.keywords = _keywords,
587
.fname = "reconfigure",
588
.kwtuple = KWTUPLE,
589
};
590
#undef KWTUPLE
591
PyObject *argsbuf[5];
592
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
593
PyObject *encoding = Py_None;
594
PyObject *errors = Py_None;
595
PyObject *newline_obj = NULL;
596
PyObject *line_buffering_obj = Py_None;
597
PyObject *write_through_obj = Py_None;
598
599
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
600
if (!args) {
601
goto exit;
602
}
603
if (!noptargs) {
604
goto skip_optional_kwonly;
605
}
606
if (args[0]) {
607
encoding = args[0];
608
if (!--noptargs) {
609
goto skip_optional_kwonly;
610
}
611
}
612
if (args[1]) {
613
errors = args[1];
614
if (!--noptargs) {
615
goto skip_optional_kwonly;
616
}
617
}
618
if (args[2]) {
619
newline_obj = args[2];
620
if (!--noptargs) {
621
goto skip_optional_kwonly;
622
}
623
}
624
if (args[3]) {
625
line_buffering_obj = args[3];
626
if (!--noptargs) {
627
goto skip_optional_kwonly;
628
}
629
}
630
write_through_obj = args[4];
631
skip_optional_kwonly:
632
return_value = _io_TextIOWrapper_reconfigure_impl(self, encoding, errors, newline_obj, line_buffering_obj, write_through_obj);
633
634
exit:
635
return return_value;
636
}
637
638
PyDoc_STRVAR(_io_TextIOWrapper_detach__doc__,
639
"detach($self, /)\n"
640
"--\n"
641
"\n");
642
643
#define _IO_TEXTIOWRAPPER_DETACH_METHODDEF \
644
{"detach", (PyCFunction)_io_TextIOWrapper_detach, METH_NOARGS, _io_TextIOWrapper_detach__doc__},
645
646
static PyObject *
647
_io_TextIOWrapper_detach_impl(textio *self);
648
649
static PyObject *
650
_io_TextIOWrapper_detach(textio *self, PyObject *Py_UNUSED(ignored))
651
{
652
return _io_TextIOWrapper_detach_impl(self);
653
}
654
655
PyDoc_STRVAR(_io_TextIOWrapper_write__doc__,
656
"write($self, text, /)\n"
657
"--\n"
658
"\n");
659
660
#define _IO_TEXTIOWRAPPER_WRITE_METHODDEF \
661
{"write", (PyCFunction)_io_TextIOWrapper_write, METH_O, _io_TextIOWrapper_write__doc__},
662
663
static PyObject *
664
_io_TextIOWrapper_write_impl(textio *self, PyObject *text);
665
666
static PyObject *
667
_io_TextIOWrapper_write(textio *self, PyObject *arg)
668
{
669
PyObject *return_value = NULL;
670
PyObject *text;
671
672
if (!PyUnicode_Check(arg)) {
673
_PyArg_BadArgument("write", "argument", "str", arg);
674
goto exit;
675
}
676
text = arg;
677
return_value = _io_TextIOWrapper_write_impl(self, text);
678
679
exit:
680
return return_value;
681
}
682
683
PyDoc_STRVAR(_io_TextIOWrapper_read__doc__,
684
"read($self, size=-1, /)\n"
685
"--\n"
686
"\n");
687
688
#define _IO_TEXTIOWRAPPER_READ_METHODDEF \
689
{"read", _PyCFunction_CAST(_io_TextIOWrapper_read), METH_FASTCALL, _io_TextIOWrapper_read__doc__},
690
691
static PyObject *
692
_io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n);
693
694
static PyObject *
695
_io_TextIOWrapper_read(textio *self, PyObject *const *args, Py_ssize_t nargs)
696
{
697
PyObject *return_value = NULL;
698
Py_ssize_t n = -1;
699
700
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
701
goto exit;
702
}
703
if (nargs < 1) {
704
goto skip_optional;
705
}
706
if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
707
goto exit;
708
}
709
skip_optional:
710
return_value = _io_TextIOWrapper_read_impl(self, n);
711
712
exit:
713
return return_value;
714
}
715
716
PyDoc_STRVAR(_io_TextIOWrapper_readline__doc__,
717
"readline($self, size=-1, /)\n"
718
"--\n"
719
"\n");
720
721
#define _IO_TEXTIOWRAPPER_READLINE_METHODDEF \
722
{"readline", _PyCFunction_CAST(_io_TextIOWrapper_readline), METH_FASTCALL, _io_TextIOWrapper_readline__doc__},
723
724
static PyObject *
725
_io_TextIOWrapper_readline_impl(textio *self, Py_ssize_t size);
726
727
static PyObject *
728
_io_TextIOWrapper_readline(textio *self, PyObject *const *args, Py_ssize_t nargs)
729
{
730
PyObject *return_value = NULL;
731
Py_ssize_t size = -1;
732
733
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
734
goto exit;
735
}
736
if (nargs < 1) {
737
goto skip_optional;
738
}
739
{
740
Py_ssize_t ival = -1;
741
PyObject *iobj = _PyNumber_Index(args[0]);
742
if (iobj != NULL) {
743
ival = PyLong_AsSsize_t(iobj);
744
Py_DECREF(iobj);
745
}
746
if (ival == -1 && PyErr_Occurred()) {
747
goto exit;
748
}
749
size = ival;
750
}
751
skip_optional:
752
return_value = _io_TextIOWrapper_readline_impl(self, size);
753
754
exit:
755
return return_value;
756
}
757
758
PyDoc_STRVAR(_io_TextIOWrapper_seek__doc__,
759
"seek($self, cookie, whence=0, /)\n"
760
"--\n"
761
"\n");
762
763
#define _IO_TEXTIOWRAPPER_SEEK_METHODDEF \
764
{"seek", _PyCFunction_CAST(_io_TextIOWrapper_seek), METH_FASTCALL, _io_TextIOWrapper_seek__doc__},
765
766
static PyObject *
767
_io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence);
768
769
static PyObject *
770
_io_TextIOWrapper_seek(textio *self, PyObject *const *args, Py_ssize_t nargs)
771
{
772
PyObject *return_value = NULL;
773
PyObject *cookieObj;
774
int whence = 0;
775
776
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
777
goto exit;
778
}
779
cookieObj = args[0];
780
if (nargs < 2) {
781
goto skip_optional;
782
}
783
whence = _PyLong_AsInt(args[1]);
784
if (whence == -1 && PyErr_Occurred()) {
785
goto exit;
786
}
787
skip_optional:
788
return_value = _io_TextIOWrapper_seek_impl(self, cookieObj, whence);
789
790
exit:
791
return return_value;
792
}
793
794
PyDoc_STRVAR(_io_TextIOWrapper_tell__doc__,
795
"tell($self, /)\n"
796
"--\n"
797
"\n");
798
799
#define _IO_TEXTIOWRAPPER_TELL_METHODDEF \
800
{"tell", (PyCFunction)_io_TextIOWrapper_tell, METH_NOARGS, _io_TextIOWrapper_tell__doc__},
801
802
static PyObject *
803
_io_TextIOWrapper_tell_impl(textio *self);
804
805
static PyObject *
806
_io_TextIOWrapper_tell(textio *self, PyObject *Py_UNUSED(ignored))
807
{
808
return _io_TextIOWrapper_tell_impl(self);
809
}
810
811
PyDoc_STRVAR(_io_TextIOWrapper_truncate__doc__,
812
"truncate($self, pos=None, /)\n"
813
"--\n"
814
"\n");
815
816
#define _IO_TEXTIOWRAPPER_TRUNCATE_METHODDEF \
817
{"truncate", _PyCFunction_CAST(_io_TextIOWrapper_truncate), METH_FASTCALL, _io_TextIOWrapper_truncate__doc__},
818
819
static PyObject *
820
_io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos);
821
822
static PyObject *
823
_io_TextIOWrapper_truncate(textio *self, PyObject *const *args, Py_ssize_t nargs)
824
{
825
PyObject *return_value = NULL;
826
PyObject *pos = Py_None;
827
828
if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
829
goto exit;
830
}
831
if (nargs < 1) {
832
goto skip_optional;
833
}
834
pos = args[0];
835
skip_optional:
836
return_value = _io_TextIOWrapper_truncate_impl(self, pos);
837
838
exit:
839
return return_value;
840
}
841
842
PyDoc_STRVAR(_io_TextIOWrapper_fileno__doc__,
843
"fileno($self, /)\n"
844
"--\n"
845
"\n");
846
847
#define _IO_TEXTIOWRAPPER_FILENO_METHODDEF \
848
{"fileno", (PyCFunction)_io_TextIOWrapper_fileno, METH_NOARGS, _io_TextIOWrapper_fileno__doc__},
849
850
static PyObject *
851
_io_TextIOWrapper_fileno_impl(textio *self);
852
853
static PyObject *
854
_io_TextIOWrapper_fileno(textio *self, PyObject *Py_UNUSED(ignored))
855
{
856
return _io_TextIOWrapper_fileno_impl(self);
857
}
858
859
PyDoc_STRVAR(_io_TextIOWrapper_seekable__doc__,
860
"seekable($self, /)\n"
861
"--\n"
862
"\n");
863
864
#define _IO_TEXTIOWRAPPER_SEEKABLE_METHODDEF \
865
{"seekable", (PyCFunction)_io_TextIOWrapper_seekable, METH_NOARGS, _io_TextIOWrapper_seekable__doc__},
866
867
static PyObject *
868
_io_TextIOWrapper_seekable_impl(textio *self);
869
870
static PyObject *
871
_io_TextIOWrapper_seekable(textio *self, PyObject *Py_UNUSED(ignored))
872
{
873
return _io_TextIOWrapper_seekable_impl(self);
874
}
875
876
PyDoc_STRVAR(_io_TextIOWrapper_readable__doc__,
877
"readable($self, /)\n"
878
"--\n"
879
"\n");
880
881
#define _IO_TEXTIOWRAPPER_READABLE_METHODDEF \
882
{"readable", (PyCFunction)_io_TextIOWrapper_readable, METH_NOARGS, _io_TextIOWrapper_readable__doc__},
883
884
static PyObject *
885
_io_TextIOWrapper_readable_impl(textio *self);
886
887
static PyObject *
888
_io_TextIOWrapper_readable(textio *self, PyObject *Py_UNUSED(ignored))
889
{
890
return _io_TextIOWrapper_readable_impl(self);
891
}
892
893
PyDoc_STRVAR(_io_TextIOWrapper_writable__doc__,
894
"writable($self, /)\n"
895
"--\n"
896
"\n");
897
898
#define _IO_TEXTIOWRAPPER_WRITABLE_METHODDEF \
899
{"writable", (PyCFunction)_io_TextIOWrapper_writable, METH_NOARGS, _io_TextIOWrapper_writable__doc__},
900
901
static PyObject *
902
_io_TextIOWrapper_writable_impl(textio *self);
903
904
static PyObject *
905
_io_TextIOWrapper_writable(textio *self, PyObject *Py_UNUSED(ignored))
906
{
907
return _io_TextIOWrapper_writable_impl(self);
908
}
909
910
PyDoc_STRVAR(_io_TextIOWrapper_isatty__doc__,
911
"isatty($self, /)\n"
912
"--\n"
913
"\n");
914
915
#define _IO_TEXTIOWRAPPER_ISATTY_METHODDEF \
916
{"isatty", (PyCFunction)_io_TextIOWrapper_isatty, METH_NOARGS, _io_TextIOWrapper_isatty__doc__},
917
918
static PyObject *
919
_io_TextIOWrapper_isatty_impl(textio *self);
920
921
static PyObject *
922
_io_TextIOWrapper_isatty(textio *self, PyObject *Py_UNUSED(ignored))
923
{
924
return _io_TextIOWrapper_isatty_impl(self);
925
}
926
927
PyDoc_STRVAR(_io_TextIOWrapper_flush__doc__,
928
"flush($self, /)\n"
929
"--\n"
930
"\n");
931
932
#define _IO_TEXTIOWRAPPER_FLUSH_METHODDEF \
933
{"flush", (PyCFunction)_io_TextIOWrapper_flush, METH_NOARGS, _io_TextIOWrapper_flush__doc__},
934
935
static PyObject *
936
_io_TextIOWrapper_flush_impl(textio *self);
937
938
static PyObject *
939
_io_TextIOWrapper_flush(textio *self, PyObject *Py_UNUSED(ignored))
940
{
941
return _io_TextIOWrapper_flush_impl(self);
942
}
943
944
PyDoc_STRVAR(_io_TextIOWrapper_close__doc__,
945
"close($self, /)\n"
946
"--\n"
947
"\n");
948
949
#define _IO_TEXTIOWRAPPER_CLOSE_METHODDEF \
950
{"close", (PyCFunction)_io_TextIOWrapper_close, METH_NOARGS, _io_TextIOWrapper_close__doc__},
951
952
static PyObject *
953
_io_TextIOWrapper_close_impl(textio *self);
954
955
static PyObject *
956
_io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
957
{
958
return _io_TextIOWrapper_close_impl(self);
959
}
960
/*[clinic end generated code: output=e1060638b65e8a63 input=a9049054013a1b77]*/
961
962