Coverage Report

Created: 2026-10-17 06:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/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
1.38M
{
298
1.38M
    PyObject *return_value = NULL;
299
300
1.38M
    Py_BEGIN_CRITICAL_SECTION(self);
301
1.38M
    return_value = _io__Buffered_simple_flush_impl((buffered *)self);
302
1.38M
    Py_END_CRITICAL_SECTION();
303
304
1.38M
    return return_value;
305
1.38M
}
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
56.7k
{
313
56.7k
    PyObject *return_value = NULL;
314
315
56.7k
    Py_BEGIN_CRITICAL_SECTION(self);
316
56.7k
    return_value = _io__Buffered_closed_get_impl((buffered *)self);
317
56.7k
    Py_END_CRITICAL_SECTION();
318
319
56.7k
    return return_value;
320
56.7k
}
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
29.4k
{
336
29.4k
    PyObject *return_value = NULL;
337
338
29.4k
    Py_BEGIN_CRITICAL_SECTION(self);
339
29.4k
    return_value = _io__Buffered_close_impl((buffered *)self);
340
29.4k
    Py_END_CRITICAL_SECTION();
341
342
29.4k
    return return_value;
343
29.4k
}
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
132
{
382
132
    PyObject *return_value = NULL;
383
384
132
    Py_BEGIN_CRITICAL_SECTION(self);
385
132
    return_value = _io__Buffered_seekable_impl((buffered *)self);
386
132
    Py_END_CRITICAL_SECTION();
387
388
132
    return return_value;
389
132
}
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
55
{
405
55
    PyObject *return_value = NULL;
406
407
55
    Py_BEGIN_CRITICAL_SECTION(self);
408
55
    return_value = _io__Buffered_readable_impl((buffered *)self);
409
55
    Py_END_CRITICAL_SECTION();
410
411
55
    return return_value;
412
55
}
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
75
{
428
75
    PyObject *return_value = NULL;
429
430
75
    Py_BEGIN_CRITICAL_SECTION(self);
431
75
    return_value = _io__Buffered_writable_impl((buffered *)self);
432
75
    Py_END_CRITICAL_SECTION();
433
434
75
    return return_value;
435
75
}
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
10
{
443
10
    PyObject *return_value = NULL;
444
445
10
    Py_BEGIN_CRITICAL_SECTION(self);
446
10
    return_value = _io__Buffered_name_get_impl((buffered *)self);
447
10
    Py_END_CRITICAL_SECTION();
448
449
10
    return return_value;
450
10
}
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
3
{
458
3
    PyObject *return_value = NULL;
459
460
3
    Py_BEGIN_CRITICAL_SECTION(self);
461
3
    return_value = _io__Buffered_mode_get_impl((buffered *)self);
462
3
    Py_END_CRITICAL_SECTION();
463
464
3
    return return_value;
465
3
}
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
240k
{
527
240k
    PyObject *return_value = NULL;
528
529
240k
    Py_BEGIN_CRITICAL_SECTION(self);
530
240k
    return_value = _io__Buffered_flush_impl((buffered *)self);
531
240k
    Py_END_CRITICAL_SECTION();
532
533
240k
    return return_value;
534
240k
}
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
5.67M
{
594
5.67M
    PyObject *return_value = NULL;
595
5.67M
    Py_ssize_t n = -1;
596
597
5.67M
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
598
0
        goto exit;
599
0
    }
600
5.67M
    if (nargs < 1) {
601
5.77k
        goto skip_optional;
602
5.77k
    }
603
5.67M
    if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
604
0
        goto exit;
605
0
    }
606
5.67M
skip_optional:
607
5.67M
    Py_BEGIN_CRITICAL_SECTION(self);
608
5.67M
    return_value = _io__Buffered_read_impl((buffered *)self, n);
609
5.67M
    Py_END_CRITICAL_SECTION();
610
611
5.67M
exit:
612
5.67M
    return return_value;
613
5.67M
}
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
130
{
629
130
    PyObject *return_value = NULL;
630
130
    Py_ssize_t n = -1;
631
632
130
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
633
0
        goto exit;
634
0
    }
635
130
    if (nargs < 1) {
636
0
        goto skip_optional;
637
0
    }
638
130
    {
639
130
        Py_ssize_t ival = -1;
640
130
        PyObject *iobj = _PyNumber_Index(args[0]);
641
130
        if (iobj != NULL) {
642
130
            ival = PyLong_AsSsize_t(iobj);
643
130
            Py_DECREF(iobj);
644
130
        }
645
130
        if (ival == -1 && PyErr_Occurred()) {
646
0
            goto exit;
647
0
        }
648
130
        n = ival;
649
130
    }
650
130
skip_optional:
651
130
    Py_BEGIN_CRITICAL_SECTION(self);
652
130
    return_value = _io__Buffered_read1_impl((buffered *)self, n);
653
130
    Py_END_CRITICAL_SECTION();
654
655
130
exit:
656
130
    return return_value;
657
130
}
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
18
{
741
18
    PyObject *return_value = NULL;
742
18
    Py_ssize_t size = -1;
743
744
18
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
745
0
        goto exit;
746
0
    }
747
18
    if (nargs < 1) {
748
18
        goto skip_optional;
749
18
    }
750
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
751
0
        goto exit;
752
0
    }
753
18
skip_optional:
754
18
    Py_BEGIN_CRITICAL_SECTION(self);
755
18
    return_value = _io__Buffered_readline_impl((buffered *)self, size);
756
18
    Py_END_CRITICAL_SECTION();
757
758
18
exit:
759
18
    return return_value;
760
18
}
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
4.58k
{
776
4.58k
    PyObject *return_value = NULL;
777
778
4.58k
    Py_BEGIN_CRITICAL_SECTION(self);
779
4.58k
    return_value = _io__Buffered_tell_impl((buffered *)self);
780
4.58k
    Py_END_CRITICAL_SECTION();
781
782
4.58k
    return return_value;
783
4.58k
}
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
1.37M
{
799
1.37M
    PyObject *return_value = NULL;
800
1.37M
    PyObject *targetobj;
801
1.37M
    int whence = 0;
802
803
1.37M
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
804
0
        goto exit;
805
0
    }
806
1.37M
    targetobj = args[0];
807
1.37M
    if (nargs < 2) {
808
10
        goto skip_optional;
809
10
    }
810
1.37M
    whence = PyLong_AsInt(args[1]);
811
1.37M
    if (whence == -1 && PyErr_Occurred()) {
812
0
        goto exit;
813
0
    }
814
1.37M
skip_optional:
815
1.37M
    Py_BEGIN_CRITICAL_SECTION(self);
816
1.37M
    return_value = _io__Buffered_seek_impl((buffered *)self, targetobj, whence);
817
1.37M
    Py_END_CRITICAL_SECTION();
818
819
1.37M
exit:
820
1.37M
    return return_value;
821
1.37M
}
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
10.6k
{
872
10.6k
    int return_value = -1;
873
10.6k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
874
875
10.6k
    #define NUM_KEYWORDS 2
876
10.6k
    static struct {
877
10.6k
        PyGC_Head _this_is_not_used;
878
10.6k
        PyObject_VAR_HEAD
879
10.6k
        Py_hash_t ob_hash;
880
10.6k
        PyObject *ob_item[NUM_KEYWORDS];
881
10.6k
    } _kwtuple = {
882
10.6k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
883
10.6k
        .ob_hash = -1,
884
10.6k
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
885
10.6k
    };
886
10.6k
    #undef NUM_KEYWORDS
887
10.6k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
888
889
    #else  // !Py_BUILD_CORE
890
    #  define KWTUPLE NULL
891
    #endif  // !Py_BUILD_CORE
892
893
10.6k
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
894
10.6k
    static _PyArg_Parser _parser = {
895
10.6k
        .keywords = _keywords,
896
10.6k
        .fname = "BufferedReader",
897
10.6k
        .kwtuple = KWTUPLE,
898
10.6k
    };
899
10.6k
    #undef KWTUPLE
900
10.6k
    PyObject *argsbuf[2];
901
10.6k
    PyObject * const *fastargs;
902
10.6k
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
903
10.6k
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
904
10.6k
    PyObject *raw;
905
10.6k
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
906
907
10.6k
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
908
10.6k
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
909
10.6k
    if (!fastargs) {
910
0
        goto exit;
911
0
    }
912
10.6k
    raw = fastargs[0];
913
10.6k
    if (!noptargs) {
914
4.85k
        goto skip_optional_pos;
915
4.85k
    }
916
5.83k
    {
917
5.83k
        Py_ssize_t ival = -1;
918
5.83k
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
919
5.83k
        if (iobj != NULL) {
920
5.83k
            ival = PyLong_AsSsize_t(iobj);
921
5.83k
            Py_DECREF(iobj);
922
5.83k
        }
923
5.83k
        if (ival == -1 && PyErr_Occurred()) {
924
0
            goto exit;
925
0
        }
926
5.83k
        buffer_size = ival;
927
5.83k
    }
928
10.6k
skip_optional_pos:
929
10.6k
    return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size);
930
931
10.6k
exit:
932
10.6k
    return return_value;
933
10.6k
}
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
18.8k
{
952
18.8k
    int return_value = -1;
953
18.8k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
954
955
18.8k
    #define NUM_KEYWORDS 2
956
18.8k
    static struct {
957
18.8k
        PyGC_Head _this_is_not_used;
958
18.8k
        PyObject_VAR_HEAD
959
18.8k
        Py_hash_t ob_hash;
960
18.8k
        PyObject *ob_item[NUM_KEYWORDS];
961
18.8k
    } _kwtuple = {
962
18.8k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
963
18.8k
        .ob_hash = -1,
964
18.8k
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
965
18.8k
    };
966
18.8k
    #undef NUM_KEYWORDS
967
18.8k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
968
969
    #else  // !Py_BUILD_CORE
970
    #  define KWTUPLE NULL
971
    #endif  // !Py_BUILD_CORE
972
973
18.8k
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
974
18.8k
    static _PyArg_Parser _parser = {
975
18.8k
        .keywords = _keywords,
976
18.8k
        .fname = "BufferedWriter",
977
18.8k
        .kwtuple = KWTUPLE,
978
18.8k
    };
979
18.8k
    #undef KWTUPLE
980
18.8k
    PyObject *argsbuf[2];
981
18.8k
    PyObject * const *fastargs;
982
18.8k
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
983
18.8k
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
984
18.8k
    PyObject *raw;
985
18.8k
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
986
987
18.8k
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
988
18.8k
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
989
18.8k
    if (!fastargs) {
990
0
        goto exit;
991
0
    }
992
18.8k
    raw = fastargs[0];
993
18.8k
    if (!noptargs) {
994
0
        goto skip_optional_pos;
995
0
    }
996
18.8k
    {
997
18.8k
        Py_ssize_t ival = -1;
998
18.8k
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
999
18.8k
        if (iobj != NULL) {
1000
18.8k
            ival = PyLong_AsSsize_t(iobj);
1001
18.8k
            Py_DECREF(iobj);
1002
18.8k
        }
1003
18.8k
        if (ival == -1 && PyErr_Occurred()) {
1004
0
            goto exit;
1005
0
        }
1006
18.8k
        buffer_size = ival;
1007
18.8k
    }
1008
18.8k
skip_optional_pos:
1009
18.8k
    return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size);
1010
1011
18.8k
exit:
1012
18.8k
    return return_value;
1013
18.8k
}
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
240k
{
1029
240k
    PyObject *return_value = NULL;
1030
240k
    Py_buffer buffer = {NULL, NULL};
1031
1032
240k
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
1033
0
        goto exit;
1034
0
    }
1035
240k
    Py_BEGIN_CRITICAL_SECTION(self);
1036
240k
    return_value = _io_BufferedWriter_write_impl((buffered *)self, &buffer);
1037
240k
    Py_END_CRITICAL_SECTION();
1038
1039
240k
exit:
1040
    /* Cleanup for buffer */
1041
240k
    if (buffer.obj) {
1042
240k
       PyBuffer_Release(&buffer);
1043
240k
    }
1044
1045
240k
    return return_value;
1046
240k
}
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_readinto__doc__,
1201
"readinto($self, buffer, /)\n"
1202
"--\n"
1203
"\n");
1204
1205
#define _IO_BUFFEREDRWPAIR_READINTO_METHODDEF    \
1206
    {"readinto", (PyCFunction)_io_BufferedRWPair_readinto, METH_O, _io_BufferedRWPair_readinto__doc__},
1207
1208
static PyObject *
1209
_io_BufferedRWPair_readinto_impl(rwpair *self, PyObject *buffer);
1210
1211
static PyObject *
1212
_io_BufferedRWPair_readinto(PyObject *self, PyObject *buffer)
1213
0
{
1214
0
    PyObject *return_value = NULL;
1215
1216
0
    return_value = _io_BufferedRWPair_readinto_impl((rwpair *)self, buffer);
1217
1218
0
    return return_value;
1219
0
}
1220
1221
PyDoc_STRVAR(_io_BufferedRWPair_readinto1__doc__,
1222
"readinto1($self, buffer, /)\n"
1223
"--\n"
1224
"\n");
1225
1226
#define _IO_BUFFEREDRWPAIR_READINTO1_METHODDEF    \
1227
    {"readinto1", (PyCFunction)_io_BufferedRWPair_readinto1, METH_O, _io_BufferedRWPair_readinto1__doc__},
1228
1229
static PyObject *
1230
_io_BufferedRWPair_readinto1_impl(rwpair *self, PyObject *buffer);
1231
1232
static PyObject *
1233
_io_BufferedRWPair_readinto1(PyObject *self, PyObject *buffer)
1234
0
{
1235
0
    PyObject *return_value = NULL;
1236
1237
0
    return_value = _io_BufferedRWPair_readinto1_impl((rwpair *)self, buffer);
1238
1239
0
    return return_value;
1240
0
}
1241
1242
PyDoc_STRVAR(_io_BufferedRWPair_write__doc__,
1243
"write($self, buffer, /)\n"
1244
"--\n"
1245
"\n");
1246
1247
#define _IO_BUFFEREDRWPAIR_WRITE_METHODDEF    \
1248
    {"write", (PyCFunction)_io_BufferedRWPair_write, METH_O, _io_BufferedRWPair_write__doc__},
1249
1250
static PyObject *
1251
_io_BufferedRWPair_write_impl(rwpair *self, PyObject *buffer);
1252
1253
static PyObject *
1254
_io_BufferedRWPair_write(PyObject *self, PyObject *buffer)
1255
0
{
1256
0
    PyObject *return_value = NULL;
1257
1258
0
    return_value = _io_BufferedRWPair_write_impl((rwpair *)self, buffer);
1259
1260
0
    return return_value;
1261
0
}
1262
1263
PyDoc_STRVAR(_io_BufferedRWPair_flush__doc__,
1264
"flush($self, /)\n"
1265
"--\n"
1266
"\n");
1267
1268
#define _IO_BUFFEREDRWPAIR_FLUSH_METHODDEF    \
1269
    {"flush", (PyCFunction)_io_BufferedRWPair_flush, METH_NOARGS, _io_BufferedRWPair_flush__doc__},
1270
1271
static PyObject *
1272
_io_BufferedRWPair_flush_impl(rwpair *self);
1273
1274
static PyObject *
1275
_io_BufferedRWPair_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
1276
0
{
1277
0
    return _io_BufferedRWPair_flush_impl((rwpair *)self);
1278
0
}
1279
1280
PyDoc_STRVAR(_io_BufferedRWPair_readable__doc__,
1281
"readable($self, /)\n"
1282
"--\n"
1283
"\n");
1284
1285
#define _IO_BUFFEREDRWPAIR_READABLE_METHODDEF    \
1286
    {"readable", (PyCFunction)_io_BufferedRWPair_readable, METH_NOARGS, _io_BufferedRWPair_readable__doc__},
1287
1288
static PyObject *
1289
_io_BufferedRWPair_readable_impl(rwpair *self);
1290
1291
static PyObject *
1292
_io_BufferedRWPair_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
1293
0
{
1294
0
    return _io_BufferedRWPair_readable_impl((rwpair *)self);
1295
0
}
1296
1297
PyDoc_STRVAR(_io_BufferedRWPair_writable__doc__,
1298
"writable($self, /)\n"
1299
"--\n"
1300
"\n");
1301
1302
#define _IO_BUFFEREDRWPAIR_WRITABLE_METHODDEF    \
1303
    {"writable", (PyCFunction)_io_BufferedRWPair_writable, METH_NOARGS, _io_BufferedRWPair_writable__doc__},
1304
1305
static PyObject *
1306
_io_BufferedRWPair_writable_impl(rwpair *self);
1307
1308
static PyObject *
1309
_io_BufferedRWPair_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
1310
0
{
1311
0
    return _io_BufferedRWPair_writable_impl((rwpair *)self);
1312
0
}
1313
1314
PyDoc_STRVAR(_io_BufferedRWPair_close__doc__,
1315
"close($self, /)\n"
1316
"--\n"
1317
"\n");
1318
1319
#define _IO_BUFFEREDRWPAIR_CLOSE_METHODDEF    \
1320
    {"close", (PyCFunction)_io_BufferedRWPair_close, METH_NOARGS, _io_BufferedRWPair_close__doc__},
1321
1322
static PyObject *
1323
_io_BufferedRWPair_close_impl(rwpair *self);
1324
1325
static PyObject *
1326
_io_BufferedRWPair_close(PyObject *self, PyObject *Py_UNUSED(ignored))
1327
0
{
1328
0
    return _io_BufferedRWPair_close_impl((rwpair *)self);
1329
0
}
1330
1331
PyDoc_STRVAR(_io_BufferedRWPair_isatty__doc__,
1332
"isatty($self, /)\n"
1333
"--\n"
1334
"\n");
1335
1336
#define _IO_BUFFEREDRWPAIR_ISATTY_METHODDEF    \
1337
    {"isatty", (PyCFunction)_io_BufferedRWPair_isatty, METH_NOARGS, _io_BufferedRWPair_isatty__doc__},
1338
1339
static PyObject *
1340
_io_BufferedRWPair_isatty_impl(rwpair *self);
1341
1342
static PyObject *
1343
_io_BufferedRWPair_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
1344
0
{
1345
0
    return _io_BufferedRWPair_isatty_impl((rwpair *)self);
1346
0
}
1347
1348
static PyObject *
1349
_io_BufferedRWPair_closed_get_impl(rwpair *self);
1350
1351
static PyObject *
1352
_io_BufferedRWPair_closed_get(PyObject *self, void *Py_UNUSED(context))
1353
0
{
1354
0
    return _io_BufferedRWPair_closed_get_impl((rwpair *)self);
1355
0
}
1356
1357
PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
1358
"BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
1359
"--\n"
1360
"\n"
1361
"A buffered interface to random access streams.\n"
1362
"\n"
1363
"The constructor creates a reader and writer for a seekable stream,\n"
1364
"raw, given in the first argument. If the buffer_size is omitted it\n"
1365
"defaults to DEFAULT_BUFFER_SIZE.");
1366
1367
static int
1368
_io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
1369
                                 Py_ssize_t buffer_size);
1370
1371
static int
1372
_io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1373
0
{
1374
0
    int return_value = -1;
1375
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1376
1377
0
    #define NUM_KEYWORDS 2
1378
0
    static struct {
1379
0
        PyGC_Head _this_is_not_used;
1380
0
        PyObject_VAR_HEAD
1381
0
        Py_hash_t ob_hash;
1382
0
        PyObject *ob_item[NUM_KEYWORDS];
1383
0
    } _kwtuple = {
1384
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1385
0
        .ob_hash = -1,
1386
0
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
1387
0
    };
1388
0
    #undef NUM_KEYWORDS
1389
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1390
1391
    #else  // !Py_BUILD_CORE
1392
    #  define KWTUPLE NULL
1393
    #endif  // !Py_BUILD_CORE
1394
1395
0
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
1396
0
    static _PyArg_Parser _parser = {
1397
0
        .keywords = _keywords,
1398
0
        .fname = "BufferedRandom",
1399
0
        .kwtuple = KWTUPLE,
1400
0
    };
1401
0
    #undef KWTUPLE
1402
0
    PyObject *argsbuf[2];
1403
0
    PyObject * const *fastargs;
1404
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1405
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
1406
0
    PyObject *raw;
1407
0
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1408
1409
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1410
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1411
0
    if (!fastargs) {
1412
0
        goto exit;
1413
0
    }
1414
0
    raw = fastargs[0];
1415
0
    if (!noptargs) {
1416
0
        goto skip_optional_pos;
1417
0
    }
1418
0
    {
1419
0
        Py_ssize_t ival = -1;
1420
0
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
1421
0
        if (iobj != NULL) {
1422
0
            ival = PyLong_AsSsize_t(iobj);
1423
0
            Py_DECREF(iobj);
1424
0
        }
1425
0
        if (ival == -1 && PyErr_Occurred()) {
1426
0
            goto exit;
1427
0
        }
1428
0
        buffer_size = ival;
1429
0
    }
1430
0
skip_optional_pos:
1431
0
    return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size);
1432
1433
0
exit:
1434
0
    return return_value;
1435
0
}
1436
#define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)NULL, NULL},
1437
1438
#define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)NULL, NULL},
1439
1440
#define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)NULL, NULL},
1441
1442
#define _IO_BUFFEREDRWPAIR_CLOSED_GETSETDEF {"closed", (getter)_io_BufferedRWPair_closed_get, (setter)NULL, NULL},
1443
1444
/*[clinic end generated code: output=d9e1eb0efa4a2431 input=a9049054013a1b77]*/