Coverage Report

Created: 2025-07-11 06:53

/src/cpython3/Modules/_io/clinic/bufferedio.c.h
Line
Count
Source (jump to first uncovered line)
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
#  include "pycore_gc.h"          // PyGC_Head
7
#  include "pycore_runtime.h"     // _Py_SINGLETON()
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
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
139
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
140
    #else
141
    #  define KWTUPLE NULL
142
    #endif
143
144
0
    static const char * const _keywords[] = {"", NULL};
145
0
    static _PyArg_Parser _parser = {
146
0
        .keywords = _keywords,
147
0
        .fname = "read",
148
0
        .kwtuple = KWTUPLE,
149
0
    };
150
0
    #undef KWTUPLE
151
0
    PyObject *argsbuf[1];
152
0
    int size = -1;
153
154
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
155
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
156
0
    if (!args) {
157
0
        goto exit;
158
0
    }
159
0
    if (nargs < 1) {
160
0
        goto skip_optional_posonly;
161
0
    }
162
0
    size = PyLong_AsInt(args[0]);
163
0
    if (size == -1 && PyErr_Occurred()) {
164
0
        goto exit;
165
0
    }
166
0
skip_optional_posonly:
167
0
    return_value = _io__BufferedIOBase_read_impl(self, cls, size);
168
169
0
exit:
170
0
    return return_value;
171
0
}
172
173
PyDoc_STRVAR(_io__BufferedIOBase_read1__doc__,
174
"read1($self, size=-1, /)\n"
175
"--\n"
176
"\n"
177
"Read and return up to size bytes, with at most one read() call to the underlying raw stream.\n"
178
"\n"
179
"Return an empty bytes object on EOF.\n"
180
"A short result does not imply that EOF is imminent.");
181
182
#define _IO__BUFFEREDIOBASE_READ1_METHODDEF    \
183
    {"read1", _PyCFunction_CAST(_io__BufferedIOBase_read1), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_read1__doc__},
184
185
static PyObject *
186
_io__BufferedIOBase_read1_impl(PyObject *self, PyTypeObject *cls,
187
                               int Py_UNUSED(size));
188
189
static PyObject *
190
_io__BufferedIOBase_read1(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
191
0
{
192
0
    PyObject *return_value = NULL;
193
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
194
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
195
    #else
196
    #  define KWTUPLE NULL
197
    #endif
198
199
0
    static const char * const _keywords[] = {"", NULL};
200
0
    static _PyArg_Parser _parser = {
201
0
        .keywords = _keywords,
202
0
        .fname = "read1",
203
0
        .kwtuple = KWTUPLE,
204
0
    };
205
0
    #undef KWTUPLE
206
0
    PyObject *argsbuf[1];
207
0
    int size = -1;
208
209
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
210
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
211
0
    if (!args) {
212
0
        goto exit;
213
0
    }
214
0
    if (nargs < 1) {
215
0
        goto skip_optional_posonly;
216
0
    }
217
0
    size = PyLong_AsInt(args[0]);
218
0
    if (size == -1 && PyErr_Occurred()) {
219
0
        goto exit;
220
0
    }
221
0
skip_optional_posonly:
222
0
    return_value = _io__BufferedIOBase_read1_impl(self, cls, size);
223
224
0
exit:
225
0
    return return_value;
226
0
}
227
228
PyDoc_STRVAR(_io__BufferedIOBase_write__doc__,
229
"write($self, b, /)\n"
230
"--\n"
231
"\n"
232
"Write buffer b to the IO stream.\n"
233
"\n"
234
"Return the number of bytes written, which is always\n"
235
"the length of b in bytes.\n"
236
"\n"
237
"Raise BlockingIOError if the buffer is full and the\n"
238
"underlying raw stream cannot accept more data at the moment.");
239
240
#define _IO__BUFFEREDIOBASE_WRITE_METHODDEF    \
241
    {"write", _PyCFunction_CAST(_io__BufferedIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_write__doc__},
242
243
static PyObject *
244
_io__BufferedIOBase_write_impl(PyObject *self, PyTypeObject *cls,
245
                               PyObject *Py_UNUSED(b));
246
247
static PyObject *
248
_io__BufferedIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
249
0
{
250
0
    PyObject *return_value = NULL;
251
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
252
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
253
    #else
254
    #  define KWTUPLE NULL
255
    #endif
256
257
0
    static const char * const _keywords[] = {"", NULL};
258
0
    static _PyArg_Parser _parser = {
259
0
        .keywords = _keywords,
260
0
        .fname = "write",
261
0
        .kwtuple = KWTUPLE,
262
0
    };
263
0
    #undef KWTUPLE
264
0
    PyObject *argsbuf[1];
265
0
    PyObject *b;
266
267
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
268
0
            /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
269
0
    if (!args) {
270
0
        goto exit;
271
0
    }
272
0
    b = args[0];
273
0
    return_value = _io__BufferedIOBase_write_impl(self, cls, b);
274
275
0
exit:
276
0
    return return_value;
277
0
}
278
279
PyDoc_STRVAR(_io__Buffered___sizeof____doc__,
280
"__sizeof__($self, /)\n"
281
"--\n"
282
"\n");
283
284
#define _IO__BUFFERED___SIZEOF___METHODDEF    \
285
    {"__sizeof__", (PyCFunction)_io__Buffered___sizeof__, METH_NOARGS, _io__Buffered___sizeof____doc__},
286
287
static PyObject *
288
_io__Buffered___sizeof___impl(buffered *self);
289
290
static PyObject *
291
_io__Buffered___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
292
0
{
293
0
    PyObject *return_value = NULL;
294
295
0
    Py_BEGIN_CRITICAL_SECTION(self);
296
0
    return_value = _io__Buffered___sizeof___impl((buffered *)self);
297
0
    Py_END_CRITICAL_SECTION();
298
299
0
    return return_value;
300
0
}
301
302
PyDoc_STRVAR(_io__Buffered__dealloc_warn__doc__,
303
"_dealloc_warn($self, source, /)\n"
304
"--\n"
305
"\n");
306
307
#define _IO__BUFFERED__DEALLOC_WARN_METHODDEF    \
308
    {"_dealloc_warn", (PyCFunction)_io__Buffered__dealloc_warn, METH_O, _io__Buffered__dealloc_warn__doc__},
309
310
static PyObject *
311
_io__Buffered__dealloc_warn_impl(buffered *self, PyObject *source);
312
313
static PyObject *
314
_io__Buffered__dealloc_warn(PyObject *self, PyObject *source)
315
0
{
316
0
    PyObject *return_value = NULL;
317
318
0
    return_value = _io__Buffered__dealloc_warn_impl((buffered *)self, source);
319
320
0
    return return_value;
321
0
}
322
323
PyDoc_STRVAR(_io__Buffered_simple_flush__doc__,
324
"flush($self, /)\n"
325
"--\n"
326
"\n");
327
328
#define _IO__BUFFERED_SIMPLE_FLUSH_METHODDEF    \
329
    {"flush", (PyCFunction)_io__Buffered_simple_flush, METH_NOARGS, _io__Buffered_simple_flush__doc__},
330
331
static PyObject *
332
_io__Buffered_simple_flush_impl(buffered *self);
333
334
static PyObject *
335
_io__Buffered_simple_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
336
343
{
337
343
    PyObject *return_value = NULL;
338
339
343
    Py_BEGIN_CRITICAL_SECTION(self);
340
343
    return_value = _io__Buffered_simple_flush_impl((buffered *)self);
341
343
    Py_END_CRITICAL_SECTION();
342
343
343
    return return_value;
344
343
}
345
346
#if !defined(_io__Buffered_closed_DOCSTR)
347
#  define _io__Buffered_closed_DOCSTR NULL
348
#endif
349
#if defined(_IO__BUFFERED_CLOSED_GETSETDEF)
350
#  undef _IO__BUFFERED_CLOSED_GETSETDEF
351
#  define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, (setter)_io__Buffered_closed_set, _io__Buffered_closed_DOCSTR},
352
#else
353
#  define _IO__BUFFERED_CLOSED_GETSETDEF {"closed", (getter)_io__Buffered_closed_get, NULL, _io__Buffered_closed_DOCSTR},
354
#endif
355
356
static PyObject *
357
_io__Buffered_closed_get_impl(buffered *self);
358
359
static PyObject *
360
_io__Buffered_closed_get(PyObject *self, void *Py_UNUSED(context))
361
686
{
362
686
    PyObject *return_value = NULL;
363
364
686
    Py_BEGIN_CRITICAL_SECTION(self);
365
686
    return_value = _io__Buffered_closed_get_impl((buffered *)self);
366
686
    Py_END_CRITICAL_SECTION();
367
368
686
    return return_value;
369
686
}
370
371
PyDoc_STRVAR(_io__Buffered_close__doc__,
372
"close($self, /)\n"
373
"--\n"
374
"\n");
375
376
#define _IO__BUFFERED_CLOSE_METHODDEF    \
377
    {"close", (PyCFunction)_io__Buffered_close, METH_NOARGS, _io__Buffered_close__doc__},
378
379
static PyObject *
380
_io__Buffered_close_impl(buffered *self);
381
382
static PyObject *
383
_io__Buffered_close(PyObject *self, PyObject *Py_UNUSED(ignored))
384
343
{
385
343
    PyObject *return_value = NULL;
386
387
343
    Py_BEGIN_CRITICAL_SECTION(self);
388
343
    return_value = _io__Buffered_close_impl((buffered *)self);
389
343
    Py_END_CRITICAL_SECTION();
390
391
343
    return return_value;
392
343
}
393
394
PyDoc_STRVAR(_io__Buffered_detach__doc__,
395
"detach($self, /)\n"
396
"--\n"
397
"\n");
398
399
#define _IO__BUFFERED_DETACH_METHODDEF    \
400
    {"detach", (PyCFunction)_io__Buffered_detach, METH_NOARGS, _io__Buffered_detach__doc__},
401
402
static PyObject *
403
_io__Buffered_detach_impl(buffered *self);
404
405
static PyObject *
406
_io__Buffered_detach(PyObject *self, PyObject *Py_UNUSED(ignored))
407
0
{
408
0
    PyObject *return_value = NULL;
409
410
0
    Py_BEGIN_CRITICAL_SECTION(self);
411
0
    return_value = _io__Buffered_detach_impl((buffered *)self);
412
0
    Py_END_CRITICAL_SECTION();
413
414
0
    return return_value;
415
0
}
416
417
PyDoc_STRVAR(_io__Buffered_seekable__doc__,
418
"seekable($self, /)\n"
419
"--\n"
420
"\n");
421
422
#define _IO__BUFFERED_SEEKABLE_METHODDEF    \
423
    {"seekable", (PyCFunction)_io__Buffered_seekable, METH_NOARGS, _io__Buffered_seekable__doc__},
424
425
static PyObject *
426
_io__Buffered_seekable_impl(buffered *self);
427
428
static PyObject *
429
_io__Buffered_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
430
66
{
431
66
    PyObject *return_value = NULL;
432
433
66
    Py_BEGIN_CRITICAL_SECTION(self);
434
66
    return_value = _io__Buffered_seekable_impl((buffered *)self);
435
66
    Py_END_CRITICAL_SECTION();
436
437
66
    return return_value;
438
66
}
439
440
PyDoc_STRVAR(_io__Buffered_readable__doc__,
441
"readable($self, /)\n"
442
"--\n"
443
"\n");
444
445
#define _IO__BUFFERED_READABLE_METHODDEF    \
446
    {"readable", (PyCFunction)_io__Buffered_readable, METH_NOARGS, _io__Buffered_readable__doc__},
447
448
static PyObject *
449
_io__Buffered_readable_impl(buffered *self);
450
451
static PyObject *
452
_io__Buffered_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
453
22
{
454
22
    PyObject *return_value = NULL;
455
456
22
    Py_BEGIN_CRITICAL_SECTION(self);
457
22
    return_value = _io__Buffered_readable_impl((buffered *)self);
458
22
    Py_END_CRITICAL_SECTION();
459
460
22
    return return_value;
461
22
}
462
463
PyDoc_STRVAR(_io__Buffered_writable__doc__,
464
"writable($self, /)\n"
465
"--\n"
466
"\n");
467
468
#define _IO__BUFFERED_WRITABLE_METHODDEF    \
469
    {"writable", (PyCFunction)_io__Buffered_writable, METH_NOARGS, _io__Buffered_writable__doc__},
470
471
static PyObject *
472
_io__Buffered_writable_impl(buffered *self);
473
474
static PyObject *
475
_io__Buffered_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
476
44
{
477
44
    PyObject *return_value = NULL;
478
479
44
    Py_BEGIN_CRITICAL_SECTION(self);
480
44
    return_value = _io__Buffered_writable_impl((buffered *)self);
481
44
    Py_END_CRITICAL_SECTION();
482
483
44
    return return_value;
484
44
}
485
486
#if !defined(_io__Buffered_name_DOCSTR)
487
#  define _io__Buffered_name_DOCSTR NULL
488
#endif
489
#if defined(_IO__BUFFERED_NAME_GETSETDEF)
490
#  undef _IO__BUFFERED_NAME_GETSETDEF
491
#  define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, (setter)_io__Buffered_name_set, _io__Buffered_name_DOCSTR},
492
#else
493
#  define _IO__BUFFERED_NAME_GETSETDEF {"name", (getter)_io__Buffered_name_get, NULL, _io__Buffered_name_DOCSTR},
494
#endif
495
496
static PyObject *
497
_io__Buffered_name_get_impl(buffered *self);
498
499
static PyObject *
500
_io__Buffered_name_get(PyObject *self, void *Py_UNUSED(context))
501
0
{
502
0
    PyObject *return_value = NULL;
503
504
0
    Py_BEGIN_CRITICAL_SECTION(self);
505
0
    return_value = _io__Buffered_name_get_impl((buffered *)self);
506
0
    Py_END_CRITICAL_SECTION();
507
508
0
    return return_value;
509
0
}
510
511
#if !defined(_io__Buffered_mode_DOCSTR)
512
#  define _io__Buffered_mode_DOCSTR NULL
513
#endif
514
#if defined(_IO__BUFFERED_MODE_GETSETDEF)
515
#  undef _IO__BUFFERED_MODE_GETSETDEF
516
#  define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, (setter)_io__Buffered_mode_set, _io__Buffered_mode_DOCSTR},
517
#else
518
#  define _IO__BUFFERED_MODE_GETSETDEF {"mode", (getter)_io__Buffered_mode_get, NULL, _io__Buffered_mode_DOCSTR},
519
#endif
520
521
static PyObject *
522
_io__Buffered_mode_get_impl(buffered *self);
523
524
static PyObject *
525
_io__Buffered_mode_get(PyObject *self, void *Py_UNUSED(context))
526
0
{
527
0
    PyObject *return_value = NULL;
528
529
0
    Py_BEGIN_CRITICAL_SECTION(self);
530
0
    return_value = _io__Buffered_mode_get_impl((buffered *)self);
531
0
    Py_END_CRITICAL_SECTION();
532
533
0
    return return_value;
534
0
}
535
536
PyDoc_STRVAR(_io__Buffered_fileno__doc__,
537
"fileno($self, /)\n"
538
"--\n"
539
"\n");
540
541
#define _IO__BUFFERED_FILENO_METHODDEF    \
542
    {"fileno", (PyCFunction)_io__Buffered_fileno, METH_NOARGS, _io__Buffered_fileno__doc__},
543
544
static PyObject *
545
_io__Buffered_fileno_impl(buffered *self);
546
547
static PyObject *
548
_io__Buffered_fileno(PyObject *self, PyObject *Py_UNUSED(ignored))
549
0
{
550
0
    PyObject *return_value = NULL;
551
552
0
    Py_BEGIN_CRITICAL_SECTION(self);
553
0
    return_value = _io__Buffered_fileno_impl((buffered *)self);
554
0
    Py_END_CRITICAL_SECTION();
555
556
0
    return return_value;
557
0
}
558
559
PyDoc_STRVAR(_io__Buffered_isatty__doc__,
560
"isatty($self, /)\n"
561
"--\n"
562
"\n");
563
564
#define _IO__BUFFERED_ISATTY_METHODDEF    \
565
    {"isatty", (PyCFunction)_io__Buffered_isatty, METH_NOARGS, _io__Buffered_isatty__doc__},
566
567
static PyObject *
568
_io__Buffered_isatty_impl(buffered *self);
569
570
static PyObject *
571
_io__Buffered_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
572
0
{
573
0
    PyObject *return_value = NULL;
574
575
0
    Py_BEGIN_CRITICAL_SECTION(self);
576
0
    return_value = _io__Buffered_isatty_impl((buffered *)self);
577
0
    Py_END_CRITICAL_SECTION();
578
579
0
    return return_value;
580
0
}
581
582
PyDoc_STRVAR(_io__Buffered_flush__doc__,
583
"flush($self, /)\n"
584
"--\n"
585
"\n");
586
587
#define _IO__BUFFERED_FLUSH_METHODDEF    \
588
    {"flush", (PyCFunction)_io__Buffered_flush, METH_NOARGS, _io__Buffered_flush__doc__},
589
590
static PyObject *
591
_io__Buffered_flush_impl(buffered *self);
592
593
static PyObject *
594
_io__Buffered_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
595
231k
{
596
231k
    PyObject *return_value = NULL;
597
598
231k
    Py_BEGIN_CRITICAL_SECTION(self);
599
231k
    return_value = _io__Buffered_flush_impl((buffered *)self);
600
231k
    Py_END_CRITICAL_SECTION();
601
602
231k
    return return_value;
603
231k
}
604
605
PyDoc_STRVAR(_io__Buffered_peek__doc__,
606
"peek($self, size=0, /)\n"
607
"--\n"
608
"\n");
609
610
#define _IO__BUFFERED_PEEK_METHODDEF    \
611
    {"peek", _PyCFunction_CAST(_io__Buffered_peek), METH_FASTCALL, _io__Buffered_peek__doc__},
612
613
static PyObject *
614
_io__Buffered_peek_impl(buffered *self, Py_ssize_t size);
615
616
static PyObject *
617
_io__Buffered_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
618
0
{
619
0
    PyObject *return_value = NULL;
620
0
    Py_ssize_t size = 0;
621
622
0
    if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
623
0
        goto exit;
624
0
    }
625
0
    if (nargs < 1) {
626
0
        goto skip_optional;
627
0
    }
628
0
    {
629
0
        Py_ssize_t ival = -1;
630
0
        PyObject *iobj = _PyNumber_Index(args[0]);
631
0
        if (iobj != NULL) {
632
0
            ival = PyLong_AsSsize_t(iobj);
633
0
            Py_DECREF(iobj);
634
0
        }
635
0
        if (ival == -1 && PyErr_Occurred()) {
636
0
            goto exit;
637
0
        }
638
0
        size = ival;
639
0
    }
640
0
skip_optional:
641
0
    Py_BEGIN_CRITICAL_SECTION(self);
642
0
    return_value = _io__Buffered_peek_impl((buffered *)self, size);
643
0
    Py_END_CRITICAL_SECTION();
644
645
0
exit:
646
0
    return return_value;
647
0
}
648
649
PyDoc_STRVAR(_io__Buffered_read__doc__,
650
"read($self, size=-1, /)\n"
651
"--\n"
652
"\n");
653
654
#define _IO__BUFFERED_READ_METHODDEF    \
655
    {"read", _PyCFunction_CAST(_io__Buffered_read), METH_FASTCALL, _io__Buffered_read__doc__},
656
657
static PyObject *
658
_io__Buffered_read_impl(buffered *self, Py_ssize_t n);
659
660
static PyObject *
661
_io__Buffered_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
662
343
{
663
343
    PyObject *return_value = NULL;
664
343
    Py_ssize_t n = -1;
665
666
343
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
667
0
        goto exit;
668
0
    }
669
343
    if (nargs < 1) {
670
343
        goto skip_optional;
671
343
    }
672
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
673
0
        goto exit;
674
0
    }
675
343
skip_optional:
676
343
    Py_BEGIN_CRITICAL_SECTION(self);
677
343
    return_value = _io__Buffered_read_impl((buffered *)self, n);
678
343
    Py_END_CRITICAL_SECTION();
679
680
343
exit:
681
343
    return return_value;
682
343
}
683
684
PyDoc_STRVAR(_io__Buffered_read1__doc__,
685
"read1($self, size=-1, /)\n"
686
"--\n"
687
"\n");
688
689
#define _IO__BUFFERED_READ1_METHODDEF    \
690
    {"read1", _PyCFunction_CAST(_io__Buffered_read1), METH_FASTCALL, _io__Buffered_read1__doc__},
691
692
static PyObject *
693
_io__Buffered_read1_impl(buffered *self, Py_ssize_t n);
694
695
static PyObject *
696
_io__Buffered_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
697
0
{
698
0
    PyObject *return_value = NULL;
699
0
    Py_ssize_t n = -1;
700
701
0
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
702
0
        goto exit;
703
0
    }
704
0
    if (nargs < 1) {
705
0
        goto skip_optional;
706
0
    }
707
0
    {
708
0
        Py_ssize_t ival = -1;
709
0
        PyObject *iobj = _PyNumber_Index(args[0]);
710
0
        if (iobj != NULL) {
711
0
            ival = PyLong_AsSsize_t(iobj);
712
0
            Py_DECREF(iobj);
713
0
        }
714
0
        if (ival == -1 && PyErr_Occurred()) {
715
0
            goto exit;
716
0
        }
717
0
        n = ival;
718
0
    }
719
0
skip_optional:
720
0
    Py_BEGIN_CRITICAL_SECTION(self);
721
0
    return_value = _io__Buffered_read1_impl((buffered *)self, n);
722
0
    Py_END_CRITICAL_SECTION();
723
724
0
exit:
725
0
    return return_value;
726
0
}
727
728
PyDoc_STRVAR(_io__Buffered_readinto__doc__,
729
"readinto($self, buffer, /)\n"
730
"--\n"
731
"\n");
732
733
#define _IO__BUFFERED_READINTO_METHODDEF    \
734
    {"readinto", (PyCFunction)_io__Buffered_readinto, METH_O, _io__Buffered_readinto__doc__},
735
736
static PyObject *
737
_io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer);
738
739
static PyObject *
740
_io__Buffered_readinto(PyObject *self, PyObject *arg)
741
0
{
742
0
    PyObject *return_value = NULL;
743
0
    Py_buffer buffer = {NULL, NULL};
744
745
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
746
0
        _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
747
0
        goto exit;
748
0
    }
749
0
    Py_BEGIN_CRITICAL_SECTION(self);
750
0
    return_value = _io__Buffered_readinto_impl((buffered *)self, &buffer);
751
0
    Py_END_CRITICAL_SECTION();
752
753
0
exit:
754
    /* Cleanup for buffer */
755
0
    if (buffer.obj) {
756
0
       PyBuffer_Release(&buffer);
757
0
    }
758
759
0
    return return_value;
760
0
}
761
762
PyDoc_STRVAR(_io__Buffered_readinto1__doc__,
763
"readinto1($self, buffer, /)\n"
764
"--\n"
765
"\n");
766
767
#define _IO__BUFFERED_READINTO1_METHODDEF    \
768
    {"readinto1", (PyCFunction)_io__Buffered_readinto1, METH_O, _io__Buffered_readinto1__doc__},
769
770
static PyObject *
771
_io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer);
772
773
static PyObject *
774
_io__Buffered_readinto1(PyObject *self, PyObject *arg)
775
0
{
776
0
    PyObject *return_value = NULL;
777
0
    Py_buffer buffer = {NULL, NULL};
778
779
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
780
0
        _PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
781
0
        goto exit;
782
0
    }
783
0
    Py_BEGIN_CRITICAL_SECTION(self);
784
0
    return_value = _io__Buffered_readinto1_impl((buffered *)self, &buffer);
785
0
    Py_END_CRITICAL_SECTION();
786
787
0
exit:
788
    /* Cleanup for buffer */
789
0
    if (buffer.obj) {
790
0
       PyBuffer_Release(&buffer);
791
0
    }
792
793
0
    return return_value;
794
0
}
795
796
PyDoc_STRVAR(_io__Buffered_readline__doc__,
797
"readline($self, size=-1, /)\n"
798
"--\n"
799
"\n");
800
801
#define _IO__BUFFERED_READLINE_METHODDEF    \
802
    {"readline", _PyCFunction_CAST(_io__Buffered_readline), METH_FASTCALL, _io__Buffered_readline__doc__},
803
804
static PyObject *
805
_io__Buffered_readline_impl(buffered *self, Py_ssize_t size);
806
807
static PyObject *
808
_io__Buffered_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
809
0
{
810
0
    PyObject *return_value = NULL;
811
0
    Py_ssize_t size = -1;
812
813
0
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
814
0
        goto exit;
815
0
    }
816
0
    if (nargs < 1) {
817
0
        goto skip_optional;
818
0
    }
819
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
820
0
        goto exit;
821
0
    }
822
0
skip_optional:
823
0
    Py_BEGIN_CRITICAL_SECTION(self);
824
0
    return_value = _io__Buffered_readline_impl((buffered *)self, size);
825
0
    Py_END_CRITICAL_SECTION();
826
827
0
exit:
828
0
    return return_value;
829
0
}
830
831
PyDoc_STRVAR(_io__Buffered_tell__doc__,
832
"tell($self, /)\n"
833
"--\n"
834
"\n");
835
836
#define _IO__BUFFERED_TELL_METHODDEF    \
837
    {"tell", (PyCFunction)_io__Buffered_tell, METH_NOARGS, _io__Buffered_tell__doc__},
838
839
static PyObject *
840
_io__Buffered_tell_impl(buffered *self);
841
842
static PyObject *
843
_io__Buffered_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
844
44
{
845
44
    PyObject *return_value = NULL;
846
847
44
    Py_BEGIN_CRITICAL_SECTION(self);
848
44
    return_value = _io__Buffered_tell_impl((buffered *)self);
849
44
    Py_END_CRITICAL_SECTION();
850
851
44
    return return_value;
852
44
}
853
854
PyDoc_STRVAR(_io__Buffered_seek__doc__,
855
"seek($self, target, whence=0, /)\n"
856
"--\n"
857
"\n");
858
859
#define _IO__BUFFERED_SEEK_METHODDEF    \
860
    {"seek", _PyCFunction_CAST(_io__Buffered_seek), METH_FASTCALL, _io__Buffered_seek__doc__},
861
862
static PyObject *
863
_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence);
864
865
static PyObject *
866
_io__Buffered_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
867
0
{
868
0
    PyObject *return_value = NULL;
869
0
    PyObject *targetobj;
870
0
    int whence = 0;
871
872
0
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
873
0
        goto exit;
874
0
    }
875
0
    targetobj = args[0];
876
0
    if (nargs < 2) {
877
0
        goto skip_optional;
878
0
    }
879
0
    whence = PyLong_AsInt(args[1]);
880
0
    if (whence == -1 && PyErr_Occurred()) {
881
0
        goto exit;
882
0
    }
883
0
skip_optional:
884
0
    Py_BEGIN_CRITICAL_SECTION(self);
885
0
    return_value = _io__Buffered_seek_impl((buffered *)self, targetobj, whence);
886
0
    Py_END_CRITICAL_SECTION();
887
888
0
exit:
889
0
    return return_value;
890
0
}
891
892
PyDoc_STRVAR(_io__Buffered_truncate__doc__,
893
"truncate($self, pos=None, /)\n"
894
"--\n"
895
"\n");
896
897
#define _IO__BUFFERED_TRUNCATE_METHODDEF    \
898
    {"truncate", _PyCFunction_CAST(_io__Buffered_truncate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__Buffered_truncate__doc__},
899
900
static PyObject *
901
_io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos);
902
903
static PyObject *
904
_io__Buffered_truncate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
905
0
{
906
0
    PyObject *return_value = NULL;
907
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
908
0
    #  define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
909
    #else
910
    #  define KWTUPLE NULL
911
    #endif
912
913
0
    static const char * const _keywords[] = {"", NULL};
914
0
    static _PyArg_Parser _parser = {
915
0
        .keywords = _keywords,
916
0
        .fname = "truncate",
917
0
        .kwtuple = KWTUPLE,
918
0
    };
919
0
    #undef KWTUPLE
920
0
    PyObject *argsbuf[1];
921
0
    PyObject *pos = Py_None;
922
923
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
924
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
925
0
    if (!args) {
926
0
        goto exit;
927
0
    }
928
0
    if (nargs < 1) {
929
0
        goto skip_optional_posonly;
930
0
    }
931
0
    pos = args[0];
932
0
skip_optional_posonly:
933
0
    Py_BEGIN_CRITICAL_SECTION(self);
934
0
    return_value = _io__Buffered_truncate_impl((buffered *)self, cls, pos);
935
0
    Py_END_CRITICAL_SECTION();
936
937
0
exit:
938
0
    return return_value;
939
0
}
940
941
PyDoc_STRVAR(_io_BufferedReader___init____doc__,
942
"BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
943
"--\n"
944
"\n"
945
"Create a new buffered reader using the given readable raw IO object.");
946
947
static int
948
_io_BufferedReader___init___impl(buffered *self, PyObject *raw,
949
                                 Py_ssize_t buffer_size);
950
951
static int
952
_io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs)
953
365
{
954
365
    int return_value = -1;
955
365
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
956
957
365
    #define NUM_KEYWORDS 2
958
365
    static struct {
959
365
        PyGC_Head _this_is_not_used;
960
365
        PyObject_VAR_HEAD
961
365
        Py_hash_t ob_hash;
962
365
        PyObject *ob_item[NUM_KEYWORDS];
963
365
    } _kwtuple = {
964
365
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
965
365
        .ob_hash = -1,
966
365
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
967
365
    };
968
365
    #undef NUM_KEYWORDS
969
365
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
970
971
    #else  // !Py_BUILD_CORE
972
    #  define KWTUPLE NULL
973
    #endif  // !Py_BUILD_CORE
974
975
365
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
976
365
    static _PyArg_Parser _parser = {
977
365
        .keywords = _keywords,
978
365
        .fname = "BufferedReader",
979
365
        .kwtuple = KWTUPLE,
980
365
    };
981
365
    #undef KWTUPLE
982
365
    PyObject *argsbuf[2];
983
365
    PyObject * const *fastargs;
984
365
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
985
365
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
986
365
    PyObject *raw;
987
365
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
988
989
365
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
990
365
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
991
365
    if (!fastargs) {
992
0
        goto exit;
993
0
    }
994
365
    raw = fastargs[0];
995
365
    if (!noptargs) {
996
0
        goto skip_optional_pos;
997
0
    }
998
365
    {
999
365
        Py_ssize_t ival = -1;
1000
365
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
1001
365
        if (iobj != NULL) {
1002
365
            ival = PyLong_AsSsize_t(iobj);
1003
365
            Py_DECREF(iobj);
1004
365
        }
1005
365
        if (ival == -1 && PyErr_Occurred()) {
1006
0
            goto exit;
1007
0
        }
1008
365
        buffer_size = ival;
1009
365
    }
1010
365
skip_optional_pos:
1011
365
    return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size);
1012
1013
365
exit:
1014
365
    return return_value;
1015
365
}
1016
1017
PyDoc_STRVAR(_io_BufferedWriter___init____doc__,
1018
"BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
1019
"--\n"
1020
"\n"
1021
"A buffer for a writeable sequential RawIO object.\n"
1022
"\n"
1023
"The constructor creates a BufferedWriter for the given writeable raw\n"
1024
"stream. If the buffer_size is not given, it defaults to\n"
1025
"DEFAULT_BUFFER_SIZE.");
1026
1027
static int
1028
_io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
1029
                                 Py_ssize_t buffer_size);
1030
1031
static int
1032
_io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1033
44
{
1034
44
    int return_value = -1;
1035
44
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1036
1037
44
    #define NUM_KEYWORDS 2
1038
44
    static struct {
1039
44
        PyGC_Head _this_is_not_used;
1040
44
        PyObject_VAR_HEAD
1041
44
        Py_hash_t ob_hash;
1042
44
        PyObject *ob_item[NUM_KEYWORDS];
1043
44
    } _kwtuple = {
1044
44
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1045
44
        .ob_hash = -1,
1046
44
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
1047
44
    };
1048
44
    #undef NUM_KEYWORDS
1049
44
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1050
1051
    #else  // !Py_BUILD_CORE
1052
    #  define KWTUPLE NULL
1053
    #endif  // !Py_BUILD_CORE
1054
1055
44
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
1056
44
    static _PyArg_Parser _parser = {
1057
44
        .keywords = _keywords,
1058
44
        .fname = "BufferedWriter",
1059
44
        .kwtuple = KWTUPLE,
1060
44
    };
1061
44
    #undef KWTUPLE
1062
44
    PyObject *argsbuf[2];
1063
44
    PyObject * const *fastargs;
1064
44
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1065
44
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
1066
44
    PyObject *raw;
1067
44
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1068
1069
44
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1070
44
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1071
44
    if (!fastargs) {
1072
0
        goto exit;
1073
0
    }
1074
44
    raw = fastargs[0];
1075
44
    if (!noptargs) {
1076
0
        goto skip_optional_pos;
1077
0
    }
1078
44
    {
1079
44
        Py_ssize_t ival = -1;
1080
44
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
1081
44
        if (iobj != NULL) {
1082
44
            ival = PyLong_AsSsize_t(iobj);
1083
44
            Py_DECREF(iobj);
1084
44
        }
1085
44
        if (ival == -1 && PyErr_Occurred()) {
1086
0
            goto exit;
1087
0
        }
1088
44
        buffer_size = ival;
1089
44
    }
1090
44
skip_optional_pos:
1091
44
    return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size);
1092
1093
44
exit:
1094
44
    return return_value;
1095
44
}
1096
1097
PyDoc_STRVAR(_io_BufferedWriter_write__doc__,
1098
"write($self, buffer, /)\n"
1099
"--\n"
1100
"\n");
1101
1102
#define _IO_BUFFEREDWRITER_WRITE_METHODDEF    \
1103
    {"write", (PyCFunction)_io_BufferedWriter_write, METH_O, _io_BufferedWriter_write__doc__},
1104
1105
static PyObject *
1106
_io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer);
1107
1108
static PyObject *
1109
_io_BufferedWriter_write(PyObject *self, PyObject *arg)
1110
231k
{
1111
231k
    PyObject *return_value = NULL;
1112
231k
    Py_buffer buffer = {NULL, NULL};
1113
1114
231k
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
1115
0
        goto exit;
1116
0
    }
1117
231k
    Py_BEGIN_CRITICAL_SECTION(self);
1118
231k
    return_value = _io_BufferedWriter_write_impl((buffered *)self, &buffer);
1119
231k
    Py_END_CRITICAL_SECTION();
1120
1121
231k
exit:
1122
    /* Cleanup for buffer */
1123
231k
    if (buffer.obj) {
1124
231k
       PyBuffer_Release(&buffer);
1125
231k
    }
1126
1127
231k
    return return_value;
1128
231k
}
1129
1130
PyDoc_STRVAR(_io_BufferedRWPair___init____doc__,
1131
"BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)\n"
1132
"--\n"
1133
"\n"
1134
"A buffered reader and writer object together.\n"
1135
"\n"
1136
"A buffered reader object and buffered writer object put together to\n"
1137
"form a sequential IO object that can read and write. This is typically\n"
1138
"used with a socket or two-way pipe.\n"
1139
"\n"
1140
"reader and writer are RawIOBase objects that are readable and\n"
1141
"writeable respectively. If the buffer_size is omitted it defaults to\n"
1142
"DEFAULT_BUFFER_SIZE.");
1143
1144
static int
1145
_io_BufferedRWPair___init___impl(rwpair *self, PyObject *reader,
1146
                                 PyObject *writer, Py_ssize_t buffer_size);
1147
1148
static int
1149
_io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1150
0
{
1151
0
    int return_value = -1;
1152
0
    PyTypeObject *base_tp = clinic_state()->PyBufferedRWPair_Type;
1153
0
    PyObject *reader;
1154
0
    PyObject *writer;
1155
0
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1156
1157
0
    if ((Py_IS_TYPE(self, base_tp) ||
1158
0
         Py_TYPE(self)->tp_new == base_tp->tp_new) &&
1159
0
        !_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
1160
0
        goto exit;
1161
0
    }
1162
0
    if (!_PyArg_CheckPositional("BufferedRWPair", PyTuple_GET_SIZE(args), 2, 3)) {
1163
0
        goto exit;
1164
0
    }
1165
0
    reader = PyTuple_GET_ITEM(args, 0);
1166
0
    writer = PyTuple_GET_ITEM(args, 1);
1167
0
    if (PyTuple_GET_SIZE(args) < 3) {
1168
0
        goto skip_optional;
1169
0
    }
1170
0
    {
1171
0
        Py_ssize_t ival = -1;
1172
0
        PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 2));
1173
0
        if (iobj != NULL) {
1174
0
            ival = PyLong_AsSsize_t(iobj);
1175
0
            Py_DECREF(iobj);
1176
0
        }
1177
0
        if (ival == -1 && PyErr_Occurred()) {
1178
0
            goto exit;
1179
0
        }
1180
0
        buffer_size = ival;
1181
0
    }
1182
0
skip_optional:
1183
0
    return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size);
1184
1185
0
exit:
1186
0
    return return_value;
1187
0
}
1188
1189
PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
1190
"BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
1191
"--\n"
1192
"\n"
1193
"A buffered interface to random access streams.\n"
1194
"\n"
1195
"The constructor creates a reader and writer for a seekable stream,\n"
1196
"raw, given in the first argument. If the buffer_size is omitted it\n"
1197
"defaults to DEFAULT_BUFFER_SIZE.");
1198
1199
static int
1200
_io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
1201
                                 Py_ssize_t buffer_size);
1202
1203
static int
1204
_io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1205
0
{
1206
0
    int return_value = -1;
1207
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1208
1209
0
    #define NUM_KEYWORDS 2
1210
0
    static struct {
1211
0
        PyGC_Head _this_is_not_used;
1212
0
        PyObject_VAR_HEAD
1213
0
        Py_hash_t ob_hash;
1214
0
        PyObject *ob_item[NUM_KEYWORDS];
1215
0
    } _kwtuple = {
1216
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1217
0
        .ob_hash = -1,
1218
0
        .ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
1219
0
    };
1220
0
    #undef NUM_KEYWORDS
1221
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
1222
1223
    #else  // !Py_BUILD_CORE
1224
    #  define KWTUPLE NULL
1225
    #endif  // !Py_BUILD_CORE
1226
1227
0
    static const char * const _keywords[] = {"raw", "buffer_size", NULL};
1228
0
    static _PyArg_Parser _parser = {
1229
0
        .keywords = _keywords,
1230
0
        .fname = "BufferedRandom",
1231
0
        .kwtuple = KWTUPLE,
1232
0
    };
1233
0
    #undef KWTUPLE
1234
0
    PyObject *argsbuf[2];
1235
0
    PyObject * const *fastargs;
1236
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1237
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
1238
0
    PyObject *raw;
1239
0
    Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1240
1241
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
1242
0
            /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
1243
0
    if (!fastargs) {
1244
0
        goto exit;
1245
0
    }
1246
0
    raw = fastargs[0];
1247
0
    if (!noptargs) {
1248
0
        goto skip_optional_pos;
1249
0
    }
1250
0
    {
1251
0
        Py_ssize_t ival = -1;
1252
0
        PyObject *iobj = _PyNumber_Index(fastargs[1]);
1253
0
        if (iobj != NULL) {
1254
0
            ival = PyLong_AsSsize_t(iobj);
1255
0
            Py_DECREF(iobj);
1256
0
        }
1257
0
        if (ival == -1 && PyErr_Occurred()) {
1258
0
            goto exit;
1259
0
        }
1260
0
        buffer_size = ival;
1261
0
    }
1262
0
skip_optional_pos:
1263
0
    return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size);
1264
1265
0
exit:
1266
0
    return return_value;
1267
0
}
1268
/*[clinic end generated code: output=3ee17211d2010462 input=a9049054013a1b77]*/