Coverage Report

Created: 2026-11-20 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython3/Modules/_io/clinic/bufferedio.c.h
Line
Count
Source
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_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
11
#include "pycore_modsupport.h"    // _PyArg_BadArgument()
12
13
PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
14
"readinto($self, buffer, /)\n"
15
"--\n"
16
"\n");
17
18
#define _IO__BUFFEREDIOBASE_READINTO_METHODDEF    \
19
    {"readinto", (PyCFunction)_io__BufferedIOBase_readinto, METH_O, _io__BufferedIOBase_readinto__doc__},
20
21
static PyObject *
22
_io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer);
23
24
static PyObject *
25
_io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
26
0
{
27
0
    PyObject *return_value = NULL;
28
0
    Py_buffer buffer = {NULL, NULL};
29
30
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
31
0
        _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
32
0
        goto exit;
33
0
    }
34
0
    Py_BEGIN_CRITICAL_SECTION(self);
35
0
    return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
36
0
    Py_END_CRITICAL_SECTION();
37
38
0
exit:
39
    /* Cleanup for buffer */
40
0
    if (buffer.obj) {
41
0
       PyBuffer_Release(&buffer);
42
0
    }
43
44
0
    return return_value;
45
0
}
46
47
PyDoc_STRVAR(_io__BufferedIOBase_readinto1__doc__,
48
"readinto1($self, buffer, /)\n"
49
"--\n"
50
"\n");
51
52
#define _IO__BUFFEREDIOBASE_READINTO1_METHODDEF    \
53
    {"readinto1", (PyCFunction)_io__BufferedIOBase_readinto1, METH_O, _io__BufferedIOBase_readinto1__doc__},
54
55
static PyObject *
56
_io__BufferedIOBase_readinto1_impl(PyObject *self, Py_buffer *buffer);
57
58
static PyObject *
59
_io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
60
0
{
61
0
    PyObject *return_value = NULL;
62
0
    Py_buffer buffer = {NULL, NULL};
63
64
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
65
0
        _PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
66
0
        goto exit;
67
0
    }
68
0
    Py_BEGIN_CRITICAL_SECTION(self);
69
0
    return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
70
0
    Py_END_CRITICAL_SECTION();
71
72
0
exit:
73
    /* Cleanup for buffer */
74
0
    if (buffer.obj) {
75
0
       PyBuffer_Release(&buffer);
76
0
    }
77
78
0
    return return_value;
79
0
}
80
81
PyDoc_STRVAR(_io__BufferedIOBase_detach__doc__,
82
"detach($self, /)\n"
83
"--\n"
84
"\n"
85
"Disconnect this buffer from its underlying raw stream and return it.\n"
86
"\n"
87
"After the raw stream has been detached, the buffer is in an unusable\n"
88
"state.");
89
90
#define _IO__BUFFEREDIOBASE_DETACH_METHODDEF    \
91
    {"detach", _PyCFunction_CAST(_io__BufferedIOBase_detach), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_detach__doc__},
92
93
static PyObject *
94
_io__BufferedIOBase_detach_impl(PyObject *self, PyTypeObject *cls);
95
96
static PyObject *
97
_io__BufferedIOBase_detach(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
98
0
{
99
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
100
0
        PyErr_SetString(PyExc_TypeError, "detach() takes no arguments");
101
0
        return NULL;
102
0
    }
103
0
    return _io__BufferedIOBase_detach_impl(self, cls);
104
0
}
105
106
PyDoc_STRVAR(_io__BufferedIOBase_read__doc__,
107
"read($self, size=-1, /)\n"
108
"--\n"
109
"\n"
110
"Read and return up to n bytes.\n"
111
"\n"
112
"If the size argument is omitted, None, or negative, read and\n"
113
"return all data until EOF.\n"
114
"\n"
115
"If the size argument is positive, and the underlying raw stream is\n"
116
"not \'interactive\', multiple raw reads may be issued to satisfy\n"
117
"the byte count (unless EOF is reached first).\n"
118
"However, for interactive raw streams (as well as sockets and pipes),\n"
119
"at most one raw read will be issued, and a short result does not\n"
120
"imply that EOF is imminent.\n"
121
"\n"
122
"Return an empty bytes object on EOF.\n"
123
"\n"
124
"Return None if the underlying raw stream was open in non-blocking\n"
125
"mode and no data is available at the moment.");
126
127
#define _IO__BUFFEREDIOBASE_READ_METHODDEF    \
128
    {"read", _PyCFunction_CAST(_io__BufferedIOBase_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_read__doc__},
129
130
static PyObject *
131
_io__BufferedIOBase_read_impl(PyObject *self, PyTypeObject *cls,
132
                              int Py_UNUSED(size));
133
134
static PyObject *
135
_io__BufferedIOBase_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
136
0
{
137
0
    PyObject *return_value = NULL;
138
0
    int size = -1;
139
140
0
    if (!_PyArg_NoKwnames("read", kwnames)) {
141
0
        goto exit;
142
0
    }
143
0
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
144
0
        goto exit;
145
0
    }
146
0
    if (nargs < 1) {
147
0
        goto skip_optional;
148
0
    }
149
0
    size = PyLong_AsInt(args[0]);
150
0
    if (size == -1 && PyErr_Occurred()) {
151
0
        goto exit;
152
0
    }
153
0
skip_optional:
154
0
    return_value = _io__BufferedIOBase_read_impl(self, cls, size);
155
156
0
exit:
157
0
    return return_value;
158
0
}
159
160
PyDoc_STRVAR(_io__BufferedIOBase_read1__doc__,
161
"read1($self, size=-1, /)\n"
162
"--\n"
163
"\n"
164
"Read and return up to size bytes, with at most one read() call to the underlying raw stream.\n"
165
"\n"
166
"Return an empty bytes object on EOF.\n"
167
"A short result does not imply that EOF is imminent.");
168
169
#define _IO__BUFFEREDIOBASE_READ1_METHODDEF    \
170
    {"read1", _PyCFunction_CAST(_io__BufferedIOBase_read1), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_read1__doc__},
171
172
static PyObject *
173
_io__BufferedIOBase_read1_impl(PyObject *self, PyTypeObject *cls,
174
                               int Py_UNUSED(size));
175
176
static PyObject *
177
_io__BufferedIOBase_read1(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
178
0
{
179
0
    PyObject *return_value = NULL;
180
0
    int size = -1;
181
182
0
    if (!_PyArg_NoKwnames("read1", kwnames)) {
183
0
        goto exit;
184
0
    }
185
0
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
186
0
        goto exit;
187
0
    }
188
0
    if (nargs < 1) {
189
0
        goto skip_optional;
190
0
    }
191
0
    size = PyLong_AsInt(args[0]);
192
0
    if (size == -1 && PyErr_Occurred()) {
193
0
        goto exit;
194
0
    }
195
0
skip_optional:
196
0
    return_value = _io__BufferedIOBase_read1_impl(self, cls, size);
197
198
0
exit:
199
0
    return return_value;
200
0
}
201
202
PyDoc_STRVAR(_io__BufferedIOBase_write__doc__,
203
"write($self, b, /)\n"
204
"--\n"
205
"\n"
206
"Write buffer b to the IO stream.\n"
207
"\n"
208
"Return the number of bytes written, which is always\n"
209
"the length of b in bytes.\n"
210
"\n"
211
"Raise BlockingIOError if the buffer is full and the\n"
212
"underlying raw stream cannot accept more data at the moment.");
213
214
#define _IO__BUFFEREDIOBASE_WRITE_METHODDEF    \
215
    {"write", _PyCFunction_CAST(_io__BufferedIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_write__doc__},
216
217
static PyObject *
218
_io__BufferedIOBase_write_impl(PyObject *self, PyTypeObject *cls,
219
                               PyObject *Py_UNUSED(b));
220
221
static PyObject *
222
_io__BufferedIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
223
0
{
224
0
    PyObject *return_value = NULL;
225
0
    PyObject *b;
226
227
0
    if (!_PyArg_NoKwnames("write", kwnames)) {
228
0
        goto exit;
229
0
    }
230
0
    if (!_PyArg_CheckPositional("write", nargs, 1, 1)) {
231
0
        goto exit;
232
0
    }
233
0
    b = args[0];
234
0
    return_value = _io__BufferedIOBase_write_impl(self, cls, b);
235
236
0
exit:
237
0
    return return_value;
238
0
}
239
240
PyDoc_STRVAR(_io__Buffered___sizeof____doc__,
241
"__sizeof__($self, /)\n"
242
"--\n"
243
"\n");
244
245
#define _IO__BUFFERED___SIZEOF___METHODDEF    \
246
    {"__sizeof__", (PyCFunction)_io__Buffered___sizeof__, METH_NOARGS, _io__Buffered___sizeof____doc__},
247
248
static PyObject *
249
_io__Buffered___sizeof___impl(buffered *self);
250
251
static PyObject *
252
_io__Buffered___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
253
0
{
254
0
    PyObject *return_value = NULL;
255
256
0
    Py_BEGIN_CRITICAL_SECTION(self);
257
0
    return_value = _io__Buffered___sizeof___impl((buffered *)self);
258
0
    Py_END_CRITICAL_SECTION();
259
260
0
    return return_value;
261
0
}
262
263
PyDoc_STRVAR(_io__Buffered__dealloc_warn__doc__,
264
"_dealloc_warn($self, source, /)\n"
265
"--\n"
266
"\n");
267
268
#define _IO__BUFFERED__DEALLOC_WARN_METHODDEF    \
269
    {"_dealloc_warn", (PyCFunction)_io__Buffered__dealloc_warn, METH_O, _io__Buffered__dealloc_warn__doc__},
270
271
static PyObject *
272
_io__Buffered__dealloc_warn_impl(buffered *self, PyObject *source);
273
274
static PyObject *
275
_io__Buffered__dealloc_warn(PyObject *self, PyObject *source)
276
0
{
277
0
    PyObject *return_value = NULL;
278
279
0
    return_value = _io__Buffered__dealloc_warn_impl((buffered *)self, source);
280
281
0
    return return_value;
282
0
}
283
284
PyDoc_STRVAR(_io__Buffered_simple_flush__doc__,
285
"flush($self, /)\n"
286
"--\n"
287
"\n");
288
289
#define _IO__BUFFERED_SIMPLE_FLUSH_METHODDEF    \
290
    {"flush", (PyCFunction)_io__Buffered_simple_flush, METH_NOARGS, _io__Buffered_simple_flush__doc__},
291
292
static PyObject *
293
_io__Buffered_simple_flush_impl(buffered *self);
294
295
static PyObject *
296
_io__Buffered_simple_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
297
377
{
298
377
    PyObject *return_value = NULL;
299
300
377
    Py_BEGIN_CRITICAL_SECTION(self);
301
377
    return_value = _io__Buffered_simple_flush_impl((buffered *)self);
302
377
    Py_END_CRITICAL_SECTION();
303
304
377
    return return_value;
305
377
}
306
307
static PyObject *
308
_io__Buffered_closed_get_impl(buffered *self);
309
310
static PyObject *
311
_io__Buffered_closed_get(PyObject *self, void *Py_UNUSED(context))
312
754
{
313
754
    PyObject *return_value = NULL;
314
315
754
    Py_BEGIN_CRITICAL_SECTION(self);
316
754
    return_value = _io__Buffered_closed_get_impl((buffered *)self);
317
754
    Py_END_CRITICAL_SECTION();
318
319
754
    return return_value;
320
754
}
321
322
PyDoc_STRVAR(_io__Buffered_close__doc__,
323
"close($self, /)\n"
324
"--\n"
325
"\n");
326
327
#define _IO__BUFFERED_CLOSE_METHODDEF    \
328
    {"close", (PyCFunction)_io__Buffered_close, METH_NOARGS, _io__Buffered_close__doc__},
329
330
static PyObject *
331
_io__Buffered_close_impl(buffered *self);
332
333
static PyObject *
334
_io__Buffered_close(PyObject *self, PyObject *Py_UNUSED(ignored))
335
377
{
336
377
    PyObject *return_value = NULL;
337
338
377
    Py_BEGIN_CRITICAL_SECTION(self);
339
377
    return_value = _io__Buffered_close_impl((buffered *)self);
340
377
    Py_END_CRITICAL_SECTION();
341
342
377
    return return_value;
343
377
}
344
345
PyDoc_STRVAR(_io__Buffered_detach__doc__,
346
"detach($self, /)\n"
347
"--\n"
348
"\n");
349
350
#define _IO__BUFFERED_DETACH_METHODDEF    \
351
    {"detach", (PyCFunction)_io__Buffered_detach, METH_NOARGS, _io__Buffered_detach__doc__},
352
353
static PyObject *
354
_io__Buffered_detach_impl(buffered *self);
355
356
static PyObject *
357
_io__Buffered_detach(PyObject *self, PyObject *Py_UNUSED(ignored))
358
0
{
359
0
    PyObject *return_value = NULL;
360
361
0
    Py_BEGIN_CRITICAL_SECTION(self);
362
0
    return_value = _io__Buffered_detach_impl((buffered *)self);
363
0
    Py_END_CRITICAL_SECTION();
364
365
0
    return return_value;
366
0
}
367
368
PyDoc_STRVAR(_io__Buffered_seekable__doc__,
369
"seekable($self, /)\n"
370
"--\n"
371
"\n");
372
373
#define _IO__BUFFERED_SEEKABLE_METHODDEF    \
374
    {"seekable", (PyCFunction)_io__Buffered_seekable, METH_NOARGS, _io__Buffered_seekable__doc__},
375
376
static PyObject *
377
_io__Buffered_seekable_impl(buffered *self);
378
379
static PyObject *
380
_io__Buffered_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
381
66
{
382
66
    PyObject *return_value = NULL;
383
384
66
    Py_BEGIN_CRITICAL_SECTION(self);
385
66
    return_value = _io__Buffered_seekable_impl((buffered *)self);
386
66
    Py_END_CRITICAL_SECTION();
387
388
66
    return return_value;
389
66
}
390
391
PyDoc_STRVAR(_io__Buffered_readable__doc__,
392
"readable($self, /)\n"
393
"--\n"
394
"\n");
395
396
#define _IO__BUFFERED_READABLE_METHODDEF    \
397
    {"readable", (PyCFunction)_io__Buffered_readable, METH_NOARGS, _io__Buffered_readable__doc__},
398
399
static PyObject *
400
_io__Buffered_readable_impl(buffered *self);
401
402
static PyObject *
403
_io__Buffered_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
404
22
{
405
22
    PyObject *return_value = NULL;
406
407
22
    Py_BEGIN_CRITICAL_SECTION(self);
408
22
    return_value = _io__Buffered_readable_impl((buffered *)self);
409
22
    Py_END_CRITICAL_SECTION();
410
411
22
    return return_value;
412
22
}
413
414
PyDoc_STRVAR(_io__Buffered_writable__doc__,
415
"writable($self, /)\n"
416
"--\n"
417
"\n");
418
419
#define _IO__BUFFERED_WRITABLE_METHODDEF    \
420
    {"writable", (PyCFunction)_io__Buffered_writable, METH_NOARGS, _io__Buffered_writable__doc__},
421
422
static PyObject *
423
_io__Buffered_writable_impl(buffered *self);
424
425
static PyObject *
426
_io__Buffered_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
427
44
{
428
44
    PyObject *return_value = NULL;
429
430
44
    Py_BEGIN_CRITICAL_SECTION(self);
431
44
    return_value = _io__Buffered_writable_impl((buffered *)self);
432
44
    Py_END_CRITICAL_SECTION();
433
434
44
    return return_value;
435
44
}
436
437
static PyObject *
438
_io__Buffered_name_get_impl(buffered *self);
439
440
static PyObject *
441
_io__Buffered_name_get(PyObject *self, void *Py_UNUSED(context))
442
0
{
443
0
    PyObject *return_value = NULL;
444
445
0
    Py_BEGIN_CRITICAL_SECTION(self);
446
0
    return_value = _io__Buffered_name_get_impl((buffered *)self);
447
0
    Py_END_CRITICAL_SECTION();
448
449
0
    return return_value;
450
0
}
451
452
static PyObject *
453
_io__Buffered_mode_get_impl(buffered *self);
454
455
static PyObject *
456
_io__Buffered_mode_get(PyObject *self, void *Py_UNUSED(context))
457
0
{
458
0
    PyObject *return_value = NULL;
459
460
0
    Py_BEGIN_CRITICAL_SECTION(self);
461
0
    return_value = _io__Buffered_mode_get_impl((buffered *)self);
462
0
    Py_END_CRITICAL_SECTION();
463
464
0
    return return_value;
465
0
}
466
467
PyDoc_STRVAR(_io__Buffered_fileno__doc__,
468
"fileno($self, /)\n"
469
"--\n"
470
"\n");
471
472
#define _IO__BUFFERED_FILENO_METHODDEF    \
473
    {"fileno", (PyCFunction)_io__Buffered_fileno, METH_NOARGS, _io__Buffered_fileno__doc__},
474
475
static PyObject *
476
_io__Buffered_fileno_impl(buffered *self);
477
478
static PyObject *
479
_io__Buffered_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
480
0
{
481
0
    PyObject *return_value = NULL;
482
483
0
    Py_BEGIN_CRITICAL_SECTION(self);
484
0
    return_value = _io__Buffered_fileno_impl((buffered *)self);
485
0
    Py_END_CRITICAL_SECTION();
486
487
0
    return return_value;
488
0
}
489
490
PyDoc_STRVAR(_io__Buffered_isatty__doc__,
491
"isatty($self, /)\n"
492
"--\n"
493
"\n");
494
495
#define _IO__BUFFERED_ISATTY_METHODDEF    \
496
    {"isatty", (PyCFunction)_io__Buffered_isatty, METH_NOARGS, _io__Buffered_isatty__doc__},
497
498
static PyObject *
499
_io__Buffered_isatty_impl(buffered *self);
500
501
static PyObject *
502
_io__Buffered_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
503
0
{
504
0
    PyObject *return_value = NULL;
505
506
0
    Py_BEGIN_CRITICAL_SECTION(self);
507
0
    return_value = _io__Buffered_isatty_impl((buffered *)self);
508
0
    Py_END_CRITICAL_SECTION();
509
510
0
    return return_value;
511
0
}
512
513
PyDoc_STRVAR(_io__Buffered_flush__doc__,
514
"flush($self, /)\n"
515
"--\n"
516
"\n");
517
518
#define _IO__BUFFERED_FLUSH_METHODDEF    \
519
    {"flush", (PyCFunction)_io__Buffered_flush, METH_NOARGS, _io__Buffered_flush__doc__},
520
521
static PyObject *
522
_io__Buffered_flush_impl(buffered *self);
523
524
static PyObject *
525
_io__Buffered_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
526
153k
{
527
153k
    PyObject *return_value = NULL;
528
529
153k
    Py_BEGIN_CRITICAL_SECTION(self);
530
153k
    return_value = _io__Buffered_flush_impl((buffered *)self);
531
153k
    Py_END_CRITICAL_SECTION();
532
533
153k
    return return_value;
534
153k
}
535
536
PyDoc_STRVAR(_io__Buffered_peek__doc__,
537
"peek($self, size=0, /)\n"
538
"--\n"
539
"\n");
540
541
#define _IO__BUFFERED_PEEK_METHODDEF    \
542
    {"peek", _PyCFunction_CAST(_io__Buffered_peek), METH_FASTCALL, _io__Buffered_peek__doc__},
543
544
static PyObject *
545
_io__Buffered_peek_impl(buffered *self, Py_ssize_t size);
546
547
static PyObject *
548
_io__Buffered_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
549
0
{
550
0
    PyObject *return_value = NULL;
551
0
    Py_ssize_t size = 0;
552
553
0
    if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
554
0
        goto exit;
555
0
    }
556
0
    if (nargs < 1) {
557
0
        goto skip_optional;
558
0
    }
559
0
    {
560
0
        Py_ssize_t ival = -1;
561
0
        PyObject *iobj = _PyNumber_Index(args[0]);
562
0
        if (iobj != NULL) {
563
0
            ival = PyLong_AsSsize_t(iobj);
564
0
            Py_DECREF(iobj);
565
0
        }
566
0
        if (ival == -1 && PyErr_Occurred()) {
567
0
            goto exit;
568
0
        }
569
0
        size = ival;
570
0
    }
571
0
skip_optional:
572
0
    Py_BEGIN_CRITICAL_SECTION(self);
573
0
    return_value = _io__Buffered_peek_impl((buffered *)self, size);
574
0
    Py_END_CRITICAL_SECTION();
575
576
0
exit:
577
0
    return return_value;
578
0
}
579
580
PyDoc_STRVAR(_io__Buffered_read__doc__,
581
"read($self, size=-1, /)\n"
582
"--\n"
583
"\n");
584
585
#define _IO__BUFFERED_READ_METHODDEF    \
586
    {"read", _PyCFunction_CAST(_io__Buffered_read), METH_FASTCALL, _io__Buffered_read__doc__},
587
588
static PyObject *
589
_io__Buffered_read_impl(buffered *self, Py_ssize_t n);
590
591
static PyObject *
592
_io__Buffered_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
593
377
{
594
377
    PyObject *return_value = NULL;
595
377
    Py_ssize_t n = -1;
596
597
377
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
598
0
        goto exit;
599
0
    }
600
377
    if (nargs < 1) {
601
377
        goto skip_optional;
602
377
    }
603
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
604
0
        goto exit;
605
0
    }
606
377
skip_optional:
607
377
    Py_BEGIN_CRITICAL_SECTION(self);
608
377
    return_value = _io__Buffered_read_impl((buffered *)self, n);
609
377
    Py_END_CRITICAL_SECTION();
610
611
377
exit:
612
377
    return return_value;
613
377
}
614
615
PyDoc_STRVAR(_io__Buffered_read1__doc__,
616
"read1($self, size=-1, /)\n"
617
"--\n"
618
"\n");
619
620
#define _IO__BUFFERED_READ1_METHODDEF    \
621
    {"read1", _PyCFunction_CAST(_io__Buffered_read1), METH_FASTCALL, _io__Buffered_read1__doc__},
622
623
static PyObject *
624
_io__Buffered_read1_impl(buffered *self, Py_ssize_t n);
625
626
static PyObject *
627
_io__Buffered_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
628
0
{
629
0
    PyObject *return_value = NULL;
630
0
    Py_ssize_t n = -1;
631
632
0
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
633
0
        goto exit;
634
0
    }
635
0
    if (nargs < 1) {
636
0
        goto skip_optional;
637
0
    }
638
0
    {
639
0
        Py_ssize_t ival = -1;
640
0
        PyObject *iobj = _PyNumber_Index(args[0]);
641
0
        if (iobj != NULL) {
642
0
            ival = PyLong_AsSsize_t(iobj);
643
0
            Py_DECREF(iobj);
644
0
        }
645
0
        if (ival == -1 && PyErr_Occurred()) {
646
0
            goto exit;
647
0
        }
648
0
        n = ival;
649
0
    }
650
0
skip_optional:
651
0
    Py_BEGIN_CRITICAL_SECTION(self);
652
0
    return_value = _io__Buffered_read1_impl((buffered *)self, n);
653
0
    Py_END_CRITICAL_SECTION();
654
655
0
exit:
656
0
    return return_value;
657
0
}
658
659
PyDoc_STRVAR(_io__Buffered_readinto__doc__,
660
"readinto($self, buffer, /)\n"
661
"--\n"
662
"\n");
663
664
#define _IO__BUFFERED_READINTO_METHODDEF    \
665
    {"readinto", (PyCFunction)_io__Buffered_readinto, METH_O, _io__Buffered_readinto__doc__},
666
667
static PyObject *
668
_io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer);
669
670
static PyObject *
671
_io__Buffered_readinto(PyObject *self, PyObject *arg)
672
0
{
673
0
    PyObject *return_value = NULL;
674
0
    Py_buffer buffer = {NULL, NULL};
675
676
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
677
0
        _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
678
0
        goto exit;
679
0
    }
680
0
    Py_BEGIN_CRITICAL_SECTION(self);
681
0
    return_value = _io__Buffered_readinto_impl((buffered *)self, &buffer);
682
0
    Py_END_CRITICAL_SECTION();
683
684
0
exit:
685
    /* Cleanup for buffer */
686
0
    if (buffer.obj) {
687
0
       PyBuffer_Release(&buffer);
688
0
    }
689
690
0
    return return_value;
691
0
}
692
693
PyDoc_STRVAR(_io__Buffered_readinto1__doc__,
694
"readinto1($self, buffer, /)\n"
695
"--\n"
696
"\n");
697
698
#define _IO__BUFFERED_READINTO1_METHODDEF    \
699
    {"readinto1", (PyCFunction)_io__Buffered_readinto1, METH_O, _io__Buffered_readinto1__doc__},
700
701
static PyObject *
702
_io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer);
703
704
static PyObject *
705
_io__Buffered_readinto1(PyObject *self, PyObject *arg)
706
0
{
707
0
    PyObject *return_value = NULL;
708
0
    Py_buffer buffer = {NULL, NULL};
709
710
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
711
0
        _PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
712
0
        goto exit;
713
0
    }
714
0
    Py_BEGIN_CRITICAL_SECTION(self);
715
0
    return_value = _io__Buffered_readinto1_impl((buffered *)self, &buffer);
716
0
    Py_END_CRITICAL_SECTION();
717
718
0
exit:
719
    /* Cleanup for buffer */
720
0
    if (buffer.obj) {
721
0
       PyBuffer_Release(&buffer);
722
0
    }
723
724
0
    return return_value;
725
0
}
726
727
PyDoc_STRVAR(_io__Buffered_readline__doc__,
728
"readline($self, size=-1, /)\n"
729
"--\n"
730
"\n");
731
732
#define _IO__BUFFERED_READLINE_METHODDEF    \
733
    {"readline", _PyCFunction_CAST(_io__Buffered_readline), METH_FASTCALL, _io__Buffered_readline__doc__},
734
735
static PyObject *
736
_io__Buffered_readline_impl(buffered *self, Py_ssize_t size);
737
738
static PyObject *
739
_io__Buffered_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
740
0
{
741
0
    PyObject *return_value = NULL;
742
0
    Py_ssize_t size = -1;
743
744
0
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
745
0
        goto exit;
746
0
    }
747
0
    if (nargs < 1) {
748
0
        goto skip_optional;
749
0
    }
750
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
751
0
        goto exit;
752
0
    }
753
0
skip_optional:
754
0
    Py_BEGIN_CRITICAL_SECTION(self);
755
0
    return_value = _io__Buffered_readline_impl((buffered *)self, size);
756
0
    Py_END_CRITICAL_SECTION();
757
758
0
exit:
759
0
    return return_value;
760
0
}
761
762
PyDoc_STRVAR(_io__Buffered_tell__doc__,
763
"tell($self, /)\n"
764
"--\n"
765
"\n");
766
767
#define _IO__BUFFERED_TELL_METHODDEF    \
768
    {"tell", (PyCFunction)_io__Buffered_tell, METH_NOARGS, _io__Buffered_tell__doc__},
769
770
static PyObject *
771
_io__Buffered_tell_impl(buffered *self);
772
773
static PyObject *
774
_io__Buffered_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
775
44
{
776
44
    PyObject *return_value = NULL;
777
778
44
    Py_BEGIN_CRITICAL_SECTION(self);
779
44
    return_value = _io__Buffered_tell_impl((buffered *)self);
780
44
    Py_END_CRITICAL_SECTION();
781
782
44
    return return_value;
783
44
}
784
785
PyDoc_STRVAR(_io__Buffered_seek__doc__,
786
"seek($self, target, whence=0, /)\n"
787
"--\n"
788
"\n");
789
790
#define _IO__BUFFERED_SEEK_METHODDEF    \
791
    {"seek", _PyCFunction_CAST(_io__Buffered_seek), METH_FASTCALL, _io__Buffered_seek__doc__},
792
793
static PyObject *
794
_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence);
795
796
static PyObject *
797
_io__Buffered_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
798
0
{
799
0
    PyObject *return_value = NULL;
800
0
    PyObject *targetobj;
801
0
    int whence = 0;
802
803
0
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
804
0
        goto exit;
805
0
    }
806
0
    targetobj = args[0];
807
0
    if (nargs < 2) {
808
0
        goto skip_optional;
809
0
    }
810
0
    whence = PyLong_AsInt(args[1]);
811
0
    if (whence == -1 && PyErr_Occurred()) {
812
0
        goto exit;
813
0
    }
814
0
skip_optional:
815
0
    Py_BEGIN_CRITICAL_SECTION(self);
816
0
    return_value = _io__Buffered_seek_impl((buffered *)self, targetobj, whence);
817
0
    Py_END_CRITICAL_SECTION();
818
819
0
exit:
820
0
    return return_value;
821
0
}
822
823
PyDoc_STRVAR(_io__Buffered_truncate__doc__,
824
"truncate($self, pos=None, /)\n"
825
"--\n"
826
"\n");
827
828
#define _IO__BUFFERED_TRUNCATE_METHODDEF    \
829
    {"truncate", _PyCFunction_CAST(_io__Buffered_truncate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__Buffered_truncate__doc__},
830
831
static PyObject *
832
_io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos);
833
834
static PyObject *
835
_io__Buffered_truncate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
836
0
{
837
0
    PyObject *return_value = NULL;
838
0
    PyObject *pos = Py_None;
839
840
0
    if (!_PyArg_NoKwnames("truncate", kwnames)) {
841
0
        goto exit;
842
0
    }
843
0
    if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
844
0
        goto exit;
845
0
    }
846
0
    if (nargs < 1) {
847
0
        goto skip_optional;
848
0
    }
849
0
    pos = args[0];
850
0
skip_optional:
851
0
    Py_BEGIN_CRITICAL_SECTION(self);
852
0
    return_value = _io__Buffered_truncate_impl((buffered *)self, cls, pos);
853
0
    Py_END_CRITICAL_SECTION();
854
855
0
exit:
856
0
    return return_value;
857
0
}
858
859
PyDoc_STRVAR(_io_BufferedReader___init____doc__,
860
"BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
861
"--\n"
862
"\n"
863
"Create a new buffered reader using the given readable raw IO object.");
864
865
static int
866
_io_BufferedReader___init___impl(buffered *self, PyObject *raw,
867
                                 Py_ssize_t buffer_size);
868
869
static int
870
_io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs)
871
399
{
872
399
    int return_value = -1;
873
399
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
874
875
399
    #define NUM_KEYWORDS 2
876
399
    static struct {
877
399
        PyGC_Head _this_is_not_used;
878
399
        PyObject_VAR_HEAD
879
399
        Py_hash_t ob_hash;
880
399
        PyObject *ob_item[NUM_KEYWORDS];
881
399
    } _kwtuple = {
882
399
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
883
399
        .ob_hash = -1,
884
399
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
885
399
    };
886
399
    #undef NUM_KEYWORDS
887
399
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
888
889
    #else  // !Py_BUILD_CORE
890
    #  define KWTUPLE NULL
891
    #endif  // !Py_BUILD_CORE
892
893
399
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
894
399
    static _PyArg_Parser _parser = {
895
399
        .keywords = _keywords,
896
399
        .fname = "BufferedReader",
897
399
        .kwtuple = KWTUPLE,
898
399
    };
899
399
    #undef KWTUPLE
900
399
    PyObject *argsbuf[2];
901
399
    PyObject * const *fastargs;
902
399
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
903
399
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
904
399
    PyObject *raw;
905
399
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
906
907
399
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
908
399
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
909
399
    if (!fastargs) {
910
0
        goto exit;
911
0
    }
912
399
    raw = fastargs[0];
913
399
    if (!noptargs) {
914
0
        goto skip_optional_pos;
915
0
    }
916
399
    {
917
399
        Py_ssize_t ival = -1;
918
399
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
919
399
        if (iobj != NULL) {
920
399
            ival = PyLong_AsSsize_t(iobj);
921
399
            Py_DECREF(iobj);
922
399
        }
923
399
        if (ival == -1 && PyErr_Occurred()) {
924
0
            goto exit;
925
0
        }
926
399
        buffer_size = ival;
927
399
    }
928
399
skip_optional_pos:
929
399
    return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size);
930
931
399
exit:
932
399
    return return_value;
933
399
}
934
935
PyDoc_STRVAR(_io_BufferedWriter___init____doc__,
936
"BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
937
"--\n"
938
"\n"
939
"A buffer for a writeable sequential RawIO object.\n"
940
"\n"
941
"The constructor creates a BufferedWriter for the given writeable raw\n"
942
"stream. If the buffer_size is not given, it defaults to\n"
943
"DEFAULT_BUFFER_SIZE.");
944
945
static int
946
_io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
947
                                 Py_ssize_t buffer_size);
948
949
static int
950
_io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs)
951
44
{
952
44
    int return_value = -1;
953
44
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
954
955
44
    #define NUM_KEYWORDS 2
956
44
    static struct {
957
44
        PyGC_Head _this_is_not_used;
958
44
        PyObject_VAR_HEAD
959
44
        Py_hash_t ob_hash;
960
44
        PyObject *ob_item[NUM_KEYWORDS];
961
44
    } _kwtuple = {
962
44
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
963
44
        .ob_hash = -1,
964
44
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
965
44
    };
966
44
    #undef NUM_KEYWORDS
967
44
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
968
969
    #else  // !Py_BUILD_CORE
970
    #  define KWTUPLE NULL
971
    #endif  // !Py_BUILD_CORE
972
973
44
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
974
44
    static _PyArg_Parser _parser = {
975
44
        .keywords = _keywords,
976
44
        .fname = "BufferedWriter",
977
44
        .kwtuple = KWTUPLE,
978
44
    };
979
44
    #undef KWTUPLE
980
44
    PyObject *argsbuf[2];
981
44
    PyObject * const *fastargs;
982
44
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
983
44
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
984
44
    PyObject *raw;
985
44
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
986
987
44
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
988
44
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
989
44
    if (!fastargs) {
990
0
        goto exit;
991
0
    }
992
44
    raw = fastargs[0];
993
44
    if (!noptargs) {
994
0
        goto skip_optional_pos;
995
0
    }
996
44
    {
997
44
        Py_ssize_t ival = -1;
998
44
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
999
44
        if (iobj != NULL) {
1000
44
            ival = PyLong_AsSsize_t(iobj);
1001
44
            Py_DECREF(iobj);
1002
44
        }
1003
44
        if (ival == -1 && PyErr_Occurred()) {
1004
0
            goto exit;
1005
0
        }
1006
44
        buffer_size = ival;
1007
44
    }
1008
44
skip_optional_pos:
1009
44
    return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size);
1010
1011
44
exit:
1012
44
    return return_value;
1013
44
}
1014
1015
PyDoc_STRVAR(_io_BufferedWriter_write__doc__,
1016
"write($self, buffer, /)\n"
1017
"--\n"
1018
"\n");
1019
1020
#define _IO_BUFFEREDWRITER_WRITE_METHODDEF    \
1021
    {"write", (PyCFunction)_io_BufferedWriter_write, METH_O, _io_BufferedWriter_write__doc__},
1022
1023
static PyObject *
1024
_io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer);
1025
1026
static PyObject *
1027
_io_BufferedWriter_write(PyObject *self, PyObject *arg)
1028
153k
{
1029
153k
    PyObject *return_value = NULL;
1030
153k
    Py_buffer buffer = {NULL, NULL};
1031
1032
153k
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
1033
0
        goto exit;
1034
0
    }
1035
153k
    Py_BEGIN_CRITICAL_SECTION(self);
1036
153k
    return_value = _io_BufferedWriter_write_impl((buffered *)self, &buffer);
1037
153k
    Py_END_CRITICAL_SECTION();
1038
1039
153k
exit:
1040
    /* Cleanup for buffer */
1041
153k
    if (buffer.obj) {
1042
153k
       PyBuffer_Release(&buffer);
1043
153k
    }
1044
1045
153k
    return return_value;
1046
153k
}
1047
1048
PyDoc_STRVAR(_io_BufferedRWPair___init____doc__,
1049
"BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)\n"
1050
"--\n"
1051
"\n"
1052
"A buffered reader and writer object together.\n"
1053
"\n"
1054
"A buffered reader object and buffered writer object put together to\n"
1055
"form a sequential IO object that can read and write. This is typically\n"
1056
"used with a socket or two-way pipe.\n"
1057
"\n"
1058
"reader and writer are RawIOBase objects that are readable and\n"
1059
"writeable respectively. If the buffer_size is omitted it defaults to\n"
1060
"DEFAULT_BUFFER_SIZE.");
1061
1062
static int
1063
_io_BufferedRWPair___init___impl(rwpair *self, PyObject *reader,
1064
                                 PyObject *writer, Py_ssize_t buffer_size);
1065
1066
static int
1067
_io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1068
0
{
1069
0
    int return_value = -1;
1070
0
    PyTypeObject *base_tp = clinic_state()->PyBufferedRWPair_Type;
1071
0
    PyObject *reader;
1072
0
    PyObject *writer;
1073
0
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1074
1075
0
    if ((Py_IS_TYPE(self, base_tp) ||
1076
0
         Py_TYPE(self)->tp_new == base_tp->tp_new) &&
1077
0
        !_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
1078
0
        goto exit;
1079
0
    }
1080
0
    if (!_PyArg_CheckPositional("BufferedRWPair", PyTuple_GET_SIZE(args), 2, 3)) {
1081
0
        goto exit;
1082
0
    }
1083
0
    reader = PyTuple_GET_ITEM(args, 0);
1084
0
    writer = PyTuple_GET_ITEM(args, 1);
1085
0
    if (PyTuple_GET_SIZE(args) < 3) {
1086
0
        goto skip_optional;
1087
0
    }
1088
0
    {
1089
0
        Py_ssize_t ival = -1;
1090
0
        PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 2));
1091
0
        if (iobj != NULL) {
1092
0
            ival = PyLong_AsSsize_t(iobj);
1093
0
            Py_DECREF(iobj);
1094
0
        }
1095
0
        if (ival == -1 && PyErr_Occurred()) {
1096
0
            goto exit;
1097
0
        }
1098
0
        buffer_size = ival;
1099
0
    }
1100
0
skip_optional:
1101
0
    return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size);
1102
1103
0
exit:
1104
0
    return return_value;
1105
0
}
1106
1107
PyDoc_STRVAR(_io_BufferedRWPair_read__doc__,
1108
"read($self, size=-1, /)\n"
1109
"--\n"
1110
"\n");
1111
1112
#define _IO_BUFFEREDRWPAIR_READ_METHODDEF    \
1113
    {"read", _PyCFunction_CAST(_io_BufferedRWPair_read), METH_FASTCALL, _io_BufferedRWPair_read__doc__},
1114
1115
static PyObject *
1116
_io_BufferedRWPair_read_impl(rwpair *self, PyObject *size);
1117
1118
static PyObject *
1119
_io_BufferedRWPair_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1120
0
{
1121
0
    PyObject *return_value = NULL;
1122
0
    PyObject *size = NULL;
1123
1124
0
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
1125
0
        goto exit;
1126
0
    }
1127
0
    if (nargs < 1) {
1128
0
        goto skip_optional;
1129
0
    }
1130
0
    size = args[0];
1131
0
skip_optional:
1132
0
    return_value = _io_BufferedRWPair_read_impl((rwpair *)self, size);
1133
1134
0
exit:
1135
0
    return return_value;
1136
0
}
1137
1138
PyDoc_STRVAR(_io_BufferedRWPair_peek__doc__,
1139
"peek($self, size=0, /)\n"
1140
"--\n"
1141
"\n");
1142
1143
#define _IO_BUFFEREDRWPAIR_PEEK_METHODDEF    \
1144
    {"peek", _PyCFunction_CAST(_io_BufferedRWPair_peek), METH_FASTCALL, _io_BufferedRWPair_peek__doc__},
1145
1146
static PyObject *
1147
_io_BufferedRWPair_peek_impl(rwpair *self, PyObject *size);
1148
1149
static PyObject *
1150
_io_BufferedRWPair_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1151
0
{
1152
0
    PyObject *return_value = NULL;
1153
0
    PyObject *size = NULL;
1154
1155
0
    if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
1156
0
        goto exit;
1157
0
    }
1158
0
    if (nargs < 1) {
1159
0
        goto skip_optional;
1160
0
    }
1161
0
    size = args[0];
1162
0
skip_optional:
1163
0
    return_value = _io_BufferedRWPair_peek_impl((rwpair *)self, size);
1164
1165
0
exit:
1166
0
    return return_value;
1167
0
}
1168
1169
PyDoc_STRVAR(_io_BufferedRWPair_read1__doc__,
1170
"read1($self, size=-1, /)\n"
1171
"--\n"
1172
"\n");
1173
1174
#define _IO_BUFFEREDRWPAIR_READ1_METHODDEF    \
1175
    {"read1", _PyCFunction_CAST(_io_BufferedRWPair_read1), METH_FASTCALL, _io_BufferedRWPair_read1__doc__},
1176
1177
static PyObject *
1178
_io_BufferedRWPair_read1_impl(rwpair *self, PyObject *size);
1179
1180
static PyObject *
1181
_io_BufferedRWPair_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1182
0
{
1183
0
    PyObject *return_value = NULL;
1184
0
    PyObject *size = NULL;
1185
1186
0
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
1187
0
        goto exit;
1188
0
    }
1189
0
    if (nargs < 1) {
1190
0
        goto skip_optional;
1191
0
    }
1192
0
    size = args[0];
1193
0
skip_optional:
1194
0
    return_value = _io_BufferedRWPair_read1_impl((rwpair *)self, size);
1195
1196
0
exit:
1197
0
    return return_value;
1198
0
}
1199
1200
PyDoc_STRVAR(_io_BufferedRWPair_readline__doc__,
1201
"readline($self, size=-1, /)\n"
1202
"--\n"
1203
"\n"
1204
"Read and return a line from the stream.\n"
1205
"\n"
1206
"If size is specified, at most size bytes will be read.\n"
1207
"\n"
1208
"The line terminator is always b\'\\n\'.");
1209
1210
#define _IO_BUFFEREDRWPAIR_READLINE_METHODDEF    \
1211
    {"readline", _PyCFunction_CAST(_io_BufferedRWPair_readline), METH_FASTCALL, _io_BufferedRWPair_readline__doc__},
1212
1213
static PyObject *
1214
_io_BufferedRWPair_readline_impl(rwpair *self, PyObject *size);
1215
1216
static PyObject *
1217
_io_BufferedRWPair_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
1218
0
{
1219
0
    PyObject *return_value = NULL;
1220
0
    PyObject *size = NULL;
1221
1222
0
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
1223
0
        goto exit;
1224
0
    }
1225
0
    if (nargs < 1) {
1226
0
        goto skip_optional;
1227
0
    }
1228
0
    size = args[0];
1229
0
skip_optional:
1230
0
    return_value = _io_BufferedRWPair_readline_impl((rwpair *)self, size);
1231
1232
0
exit:
1233
0
    return return_value;
1234
0
}
1235
1236
PyDoc_STRVAR(_io_BufferedRWPair_readinto__doc__,
1237
"readinto($self, buffer, /)\n"
1238
"--\n"
1239
"\n");
1240
1241
#define _IO_BUFFEREDRWPAIR_READINTO_METHODDEF    \
1242
    {"readinto", (PyCFunction)_io_BufferedRWPair_readinto, METH_O, _io_BufferedRWPair_readinto__doc__},
1243
1244
static PyObject *
1245
_io_BufferedRWPair_readinto_impl(rwpair *self, PyObject *buffer);
1246
1247
static PyObject *
1248
_io_BufferedRWPair_readinto(PyObject *self, PyObject *buffer)
1249
0
{
1250
0
    PyObject *return_value = NULL;
1251
1252
0
    return_value = _io_BufferedRWPair_readinto_impl((rwpair *)self, buffer);
1253
1254
0
    return return_value;
1255
0
}
1256
1257
PyDoc_STRVAR(_io_BufferedRWPair_readinto1__doc__,
1258
"readinto1($self, buffer, /)\n"
1259
"--\n"
1260
"\n");
1261
1262
#define _IO_BUFFEREDRWPAIR_READINTO1_METHODDEF    \
1263
    {"readinto1", (PyCFunction)_io_BufferedRWPair_readinto1, METH_O, _io_BufferedRWPair_readinto1__doc__},
1264
1265
static PyObject *
1266
_io_BufferedRWPair_readinto1_impl(rwpair *self, PyObject *buffer);
1267
1268
static PyObject *
1269
_io_BufferedRWPair_readinto1(PyObject *self, PyObject *buffer)
1270
0
{
1271
0
    PyObject *return_value = NULL;
1272
1273
0
    return_value = _io_BufferedRWPair_readinto1_impl((rwpair *)self, buffer);
1274
1275
0
    return return_value;
1276
0
}
1277
1278
PyDoc_STRVAR(_io_BufferedRWPair_write__doc__,
1279
"write($self, buffer, /)\n"
1280
"--\n"
1281
"\n");
1282
1283
#define _IO_BUFFEREDRWPAIR_WRITE_METHODDEF    \
1284
    {"write", (PyCFunction)_io_BufferedRWPair_write, METH_O, _io_BufferedRWPair_write__doc__},
1285
1286
static PyObject *
1287
_io_BufferedRWPair_write_impl(rwpair *self, PyObject *buffer);
1288
1289
static PyObject *
1290
_io_BufferedRWPair_write(PyObject *self, PyObject *buffer)
1291
0
{
1292
0
    PyObject *return_value = NULL;
1293
1294
0
    return_value = _io_BufferedRWPair_write_impl((rwpair *)self, buffer);
1295
1296
0
    return return_value;
1297
0
}
1298
1299
PyDoc_STRVAR(_io_BufferedRWPair_flush__doc__,
1300
"flush($self, /)\n"
1301
"--\n"
1302
"\n");
1303
1304
#define _IO_BUFFEREDRWPAIR_FLUSH_METHODDEF    \
1305
    {"flush", (PyCFunction)_io_BufferedRWPair_flush, METH_NOARGS, _io_BufferedRWPair_flush__doc__},
1306
1307
static PyObject *
1308
_io_BufferedRWPair_flush_impl(rwpair *self);
1309
1310
static PyObject *
1311
_io_BufferedRWPair_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
1312
0
{
1313
0
    return _io_BufferedRWPair_flush_impl((rwpair *)self);
1314
0
}
1315
1316
PyDoc_STRVAR(_io_BufferedRWPair_readable__doc__,
1317
"readable($self, /)\n"
1318
"--\n"
1319
"\n");
1320
1321
#define _IO_BUFFEREDRWPAIR_READABLE_METHODDEF    \
1322
    {"readable", (PyCFunction)_io_BufferedRWPair_readable, METH_NOARGS, _io_BufferedRWPair_readable__doc__},
1323
1324
static PyObject *
1325
_io_BufferedRWPair_readable_impl(rwpair *self);
1326
1327
static PyObject *
1328
_io_BufferedRWPair_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
1329
0
{
1330
0
    return _io_BufferedRWPair_readable_impl((rwpair *)self);
1331
0
}
1332
1333
PyDoc_STRVAR(_io_BufferedRWPair_writable__doc__,
1334
"writable($self, /)\n"
1335
"--\n"
1336
"\n");
1337
1338
#define _IO_BUFFEREDRWPAIR_WRITABLE_METHODDEF    \
1339
    {"writable", (PyCFunction)_io_BufferedRWPair_writable, METH_NOARGS, _io_BufferedRWPair_writable__doc__},
1340
1341
static PyObject *
1342
_io_BufferedRWPair_writable_impl(rwpair *self);
1343
1344
static PyObject *
1345
_io_BufferedRWPair_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
1346
0
{
1347
0
    return _io_BufferedRWPair_writable_impl((rwpair *)self);
1348
0
}
1349
1350
PyDoc_STRVAR(_io_BufferedRWPair_close__doc__,
1351
"close($self, /)\n"
1352
"--\n"
1353
"\n");
1354
1355
#define _IO_BUFFEREDRWPAIR_CLOSE_METHODDEF    \
1356
    {"close", (PyCFunction)_io_BufferedRWPair_close, METH_NOARGS, _io_BufferedRWPair_close__doc__},
1357
1358
static PyObject *
1359
_io_BufferedRWPair_close_impl(rwpair *self);
1360
1361
static PyObject *
1362
_io_BufferedRWPair_close(PyObject *self, PyObject *Py_UNUSED(ignored))
1363
0
{
1364
0
    return _io_BufferedRWPair_close_impl((rwpair *)self);
1365
0
}
1366
1367
PyDoc_STRVAR(_io_BufferedRWPair_isatty__doc__,
1368
"isatty($self, /)\n"
1369
"--\n"
1370
"\n");
1371
1372
#define _IO_BUFFEREDRWPAIR_ISATTY_METHODDEF    \
1373
    {"isatty", (PyCFunction)_io_BufferedRWPair_isatty, METH_NOARGS, _io_BufferedRWPair_isatty__doc__},
1374
1375
static PyObject *
1376
_io_BufferedRWPair_isatty_impl(rwpair *self);
1377
1378
static PyObject *
1379
_io_BufferedRWPair_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
1380
0
{
1381
0
    return _io_BufferedRWPair_isatty_impl((rwpair *)self);
1382
0
}
1383
1384
static PyObject *
1385
_io_BufferedRWPair_closed_get_impl(rwpair *self);
1386
1387
static PyObject *
1388
_io_BufferedRWPair_closed_get(PyObject *self, void *Py_UNUSED(context))
1389
0
{
1390
0
    return _io_BufferedRWPair_closed_get_impl((rwpair *)self);
1391
0
}
1392
1393
PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
1394
"BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
1395
"--\n"
1396
"\n"
1397
"A buffered interface to random access streams.\n"
1398
"\n"
1399
"The constructor creates a reader and writer for a seekable stream,\n"
1400
"raw, given in the first argument. If the buffer_size is omitted it\n"
1401
"defaults to DEFAULT_BUFFER_SIZE.");
1402
1403
static int
1404
_io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
1405
                                 Py_ssize_t buffer_size);
1406
1407
static int
1408
_io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1409
0
{
1410
0
    int return_value = -1;
1411
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1412
1413
0
    #define NUM_KEYWORDS 2
1414
0
    static struct {
1415
0
        PyGC_Head _this_is_not_used;
1416
0
        PyObject_VAR_HEAD
1417
0
        Py_hash_t ob_hash;
1418
0
        PyObject *ob_item[NUM_KEYWORDS];
1419
0
    } _kwtuple = {
1420
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1421
0
        .ob_hash = -1,
1422
0
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
1423
0
    };
1424
0
    #undef NUM_KEYWORDS
1425
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1426
1427
    #else  // !Py_BUILD_CORE
1428
    #  define KWTUPLE NULL
1429
    #endif  // !Py_BUILD_CORE
1430
1431
0
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
1432
0
    static _PyArg_Parser _parser = {
1433
0
        .keywords = _keywords,
1434
0
        .fname = "BufferedRandom",
1435
0
        .kwtuple = KWTUPLE,
1436
0
    };
1437
0
    #undef KWTUPLE
1438
0
    PyObject *argsbuf[2];
1439
0
    PyObject * const *fastargs;
1440
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1441
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
1442
0
    PyObject *raw;
1443
0
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1444
1445
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1446
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1447
0
    if (!fastargs) {
1448
0
        goto exit;
1449
0
    }
1450
0
    raw = fastargs[0];
1451
0
    if (!noptargs) {
1452
0
        goto skip_optional_pos;
1453
0
    }
1454
0
    {
1455
0
        Py_ssize_t ival = -1;
1456
0
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
1457
0
        if (iobj != NULL) {
1458
0
            ival = PyLong_AsSsize_t(iobj);
1459
0
            Py_DECREF(iobj);
1460
0
        }
1461
0
        if (ival == -1 && PyErr_Occurred()) {
1462
0
            goto exit;
1463
0
        }
1464
0
        buffer_size = ival;
1465
0
    }
1466
0
skip_optional_pos:
1467
0
    return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size);
1468
1469
0
exit:
1470
0
    return return_value;
1471
0
}
1472
#define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)NULL, NULL},
1473
1474
#define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)NULL, NULL},
1475
1476
#define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)NULL, NULL},
1477
1478
#define _IO_BUFFEREDRWPAIR_CLOSED_GETSETDEF {"closed", (getter)_io_BufferedRWPair_closed_get, (setter)NULL, NULL},
1479
1480
/*[clinic end generated code: output=1596bb353f00a1ea input=a9049054013a1b77]*/