Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Modules/_io/clinic/bufferedio.c.h
12 views
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
# include "pycore_gc.h" // PyGC_Head
7
# include "pycore_runtime.h" // _Py_ID()
8
#endif
9
10
11
PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
12
"readinto($self, buffer, /)\n"
13
"--\n"
14
"\n");
15
16
#define _IO__BUFFEREDIOBASE_READINTO_METHODDEF \
17
{"readinto", (PyCFunction)_io__BufferedIOBase_readinto, METH_O, _io__BufferedIOBase_readinto__doc__},
18
19
static PyObject *
20
_io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer);
21
22
static PyObject *
23
_io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
24
{
25
PyObject *return_value = NULL;
26
Py_buffer buffer = {NULL, NULL};
27
28
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
29
PyErr_Clear();
30
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
31
goto exit;
32
}
33
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
34
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
35
goto exit;
36
}
37
return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
38
39
exit:
40
/* Cleanup for buffer */
41
if (buffer.obj) {
42
PyBuffer_Release(&buffer);
43
}
44
45
return return_value;
46
}
47
48
PyDoc_STRVAR(_io__BufferedIOBase_readinto1__doc__,
49
"readinto1($self, buffer, /)\n"
50
"--\n"
51
"\n");
52
53
#define _IO__BUFFEREDIOBASE_READINTO1_METHODDEF \
54
{"readinto1", (PyCFunction)_io__BufferedIOBase_readinto1, METH_O, _io__BufferedIOBase_readinto1__doc__},
55
56
static PyObject *
57
_io__BufferedIOBase_readinto1_impl(PyObject *self, Py_buffer *buffer);
58
59
static PyObject *
60
_io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
61
{
62
PyObject *return_value = NULL;
63
Py_buffer buffer = {NULL, NULL};
64
65
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
66
PyErr_Clear();
67
_PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
68
goto exit;
69
}
70
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
71
_PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
72
goto exit;
73
}
74
return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
75
76
exit:
77
/* Cleanup for buffer */
78
if (buffer.obj) {
79
PyBuffer_Release(&buffer);
80
}
81
82
return return_value;
83
}
84
85
PyDoc_STRVAR(_io__BufferedIOBase_detach__doc__,
86
"detach($self, /)\n"
87
"--\n"
88
"\n"
89
"Disconnect this buffer from its underlying raw stream and return it.\n"
90
"\n"
91
"After the raw stream has been detached, the buffer is in an unusable\n"
92
"state.");
93
94
#define _IO__BUFFEREDIOBASE_DETACH_METHODDEF \
95
{"detach", _PyCFunction_CAST(_io__BufferedIOBase_detach), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_detach__doc__},
96
97
static PyObject *
98
_io__BufferedIOBase_detach_impl(PyObject *self, PyTypeObject *cls);
99
100
static PyObject *
101
_io__BufferedIOBase_detach(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
102
{
103
if (nargs) {
104
PyErr_SetString(PyExc_TypeError, "detach() takes no arguments");
105
return NULL;
106
}
107
return _io__BufferedIOBase_detach_impl(self, cls);
108
}
109
110
PyDoc_STRVAR(_io__BufferedIOBase_read__doc__,
111
"read($self, size=-1, /)\n"
112
"--\n"
113
"\n"
114
"Read and return up to n bytes.\n"
115
"\n"
116
"If the size argument is omitted, None, or negative, read and\n"
117
"return all data until EOF.\n"
118
"\n"
119
"If the size argument is positive, and the underlying raw stream is\n"
120
"not \'interactive\', multiple raw reads may be issued to satisfy\n"
121
"the byte count (unless EOF is reached first).\n"
122
"However, for interactive raw streams (as well as sockets and pipes),\n"
123
"at most one raw read will be issued, and a short result does not\n"
124
"imply that EOF is imminent.\n"
125
"\n"
126
"Return an empty bytes object on EOF.\n"
127
"\n"
128
"Return None if the underlying raw stream was open in non-blocking\n"
129
"mode and no data is available at the moment.");
130
131
#define _IO__BUFFEREDIOBASE_READ_METHODDEF \
132
{"read", _PyCFunction_CAST(_io__BufferedIOBase_read), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_read__doc__},
133
134
static PyObject *
135
_io__BufferedIOBase_read_impl(PyObject *self, PyTypeObject *cls,
136
int Py_UNUSED(size));
137
138
static PyObject *
139
_io__BufferedIOBase_read(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
140
{
141
PyObject *return_value = NULL;
142
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
143
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
144
#else
145
# define KWTUPLE NULL
146
#endif
147
148
static const char * const _keywords[] = {"", NULL};
149
static _PyArg_Parser _parser = {
150
.keywords = _keywords,
151
.fname = "read",
152
.kwtuple = KWTUPLE,
153
};
154
#undef KWTUPLE
155
PyObject *argsbuf[1];
156
int size = -1;
157
158
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
159
if (!args) {
160
goto exit;
161
}
162
if (nargs < 1) {
163
goto skip_optional_posonly;
164
}
165
size = _PyLong_AsInt(args[0]);
166
if (size == -1 && PyErr_Occurred()) {
167
goto exit;
168
}
169
skip_optional_posonly:
170
return_value = _io__BufferedIOBase_read_impl(self, cls, size);
171
172
exit:
173
return return_value;
174
}
175
176
PyDoc_STRVAR(_io__BufferedIOBase_read1__doc__,
177
"read1($self, size=-1, /)\n"
178
"--\n"
179
"\n"
180
"Read and return up to size bytes, with at most one read() call to the underlying raw stream.\n"
181
"\n"
182
"Return an empty bytes object on EOF.\n"
183
"A short result does not imply that EOF is imminent.");
184
185
#define _IO__BUFFEREDIOBASE_READ1_METHODDEF \
186
{"read1", _PyCFunction_CAST(_io__BufferedIOBase_read1), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_read1__doc__},
187
188
static PyObject *
189
_io__BufferedIOBase_read1_impl(PyObject *self, PyTypeObject *cls,
190
int Py_UNUSED(size));
191
192
static PyObject *
193
_io__BufferedIOBase_read1(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
194
{
195
PyObject *return_value = NULL;
196
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
197
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
198
#else
199
# define KWTUPLE NULL
200
#endif
201
202
static const char * const _keywords[] = {"", NULL};
203
static _PyArg_Parser _parser = {
204
.keywords = _keywords,
205
.fname = "read1",
206
.kwtuple = KWTUPLE,
207
};
208
#undef KWTUPLE
209
PyObject *argsbuf[1];
210
int size = -1;
211
212
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
213
if (!args) {
214
goto exit;
215
}
216
if (nargs < 1) {
217
goto skip_optional_posonly;
218
}
219
size = _PyLong_AsInt(args[0]);
220
if (size == -1 && PyErr_Occurred()) {
221
goto exit;
222
}
223
skip_optional_posonly:
224
return_value = _io__BufferedIOBase_read1_impl(self, cls, size);
225
226
exit:
227
return return_value;
228
}
229
230
PyDoc_STRVAR(_io__BufferedIOBase_write__doc__,
231
"write($self, b, /)\n"
232
"--\n"
233
"\n"
234
"Write buffer b to the IO stream.\n"
235
"\n"
236
"Return the number of bytes written, which is always\n"
237
"the length of b in bytes.\n"
238
"\n"
239
"Raise BlockingIOError if the buffer is full and the\n"
240
"underlying raw stream cannot accept more data at the moment.");
241
242
#define _IO__BUFFEREDIOBASE_WRITE_METHODDEF \
243
{"write", _PyCFunction_CAST(_io__BufferedIOBase_write), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__BufferedIOBase_write__doc__},
244
245
static PyObject *
246
_io__BufferedIOBase_write_impl(PyObject *self, PyTypeObject *cls,
247
PyObject *Py_UNUSED(b));
248
249
static PyObject *
250
_io__BufferedIOBase_write(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
251
{
252
PyObject *return_value = NULL;
253
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
254
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
255
#else
256
# define KWTUPLE NULL
257
#endif
258
259
static const char * const _keywords[] = {"", NULL};
260
static _PyArg_Parser _parser = {
261
.keywords = _keywords,
262
.fname = "write",
263
.kwtuple = KWTUPLE,
264
};
265
#undef KWTUPLE
266
PyObject *argsbuf[1];
267
PyObject *b;
268
269
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
270
if (!args) {
271
goto exit;
272
}
273
b = args[0];
274
return_value = _io__BufferedIOBase_write_impl(self, cls, b);
275
276
exit:
277
return return_value;
278
}
279
280
PyDoc_STRVAR(_io__Buffered___sizeof____doc__,
281
"__sizeof__($self, /)\n"
282
"--\n"
283
"\n");
284
285
#define _IO__BUFFERED___SIZEOF___METHODDEF \
286
{"__sizeof__", (PyCFunction)_io__Buffered___sizeof__, METH_NOARGS, _io__Buffered___sizeof____doc__},
287
288
static PyObject *
289
_io__Buffered___sizeof___impl(buffered *self);
290
291
static PyObject *
292
_io__Buffered___sizeof__(buffered *self, PyObject *Py_UNUSED(ignored))
293
{
294
return _io__Buffered___sizeof___impl(self);
295
}
296
297
PyDoc_STRVAR(_io__Buffered__dealloc_warn__doc__,
298
"_dealloc_warn($self, source, /)\n"
299
"--\n"
300
"\n");
301
302
#define _IO__BUFFERED__DEALLOC_WARN_METHODDEF \
303
{"_dealloc_warn", (PyCFunction)_io__Buffered__dealloc_warn, METH_O, _io__Buffered__dealloc_warn__doc__},
304
305
PyDoc_STRVAR(_io__Buffered_simple_flush__doc__,
306
"flush($self, /)\n"
307
"--\n"
308
"\n");
309
310
#define _IO__BUFFERED_SIMPLE_FLUSH_METHODDEF \
311
{"flush", (PyCFunction)_io__Buffered_simple_flush, METH_NOARGS, _io__Buffered_simple_flush__doc__},
312
313
static PyObject *
314
_io__Buffered_simple_flush_impl(buffered *self);
315
316
static PyObject *
317
_io__Buffered_simple_flush(buffered *self, PyObject *Py_UNUSED(ignored))
318
{
319
return _io__Buffered_simple_flush_impl(self);
320
}
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(buffered *self, PyObject *Py_UNUSED(ignored))
335
{
336
return _io__Buffered_close_impl(self);
337
}
338
339
PyDoc_STRVAR(_io__Buffered_detach__doc__,
340
"detach($self, /)\n"
341
"--\n"
342
"\n");
343
344
#define _IO__BUFFERED_DETACH_METHODDEF \
345
{"detach", (PyCFunction)_io__Buffered_detach, METH_NOARGS, _io__Buffered_detach__doc__},
346
347
static PyObject *
348
_io__Buffered_detach_impl(buffered *self);
349
350
static PyObject *
351
_io__Buffered_detach(buffered *self, PyObject *Py_UNUSED(ignored))
352
{
353
return _io__Buffered_detach_impl(self);
354
}
355
356
PyDoc_STRVAR(_io__Buffered_seekable__doc__,
357
"seekable($self, /)\n"
358
"--\n"
359
"\n");
360
361
#define _IO__BUFFERED_SEEKABLE_METHODDEF \
362
{"seekable", (PyCFunction)_io__Buffered_seekable, METH_NOARGS, _io__Buffered_seekable__doc__},
363
364
static PyObject *
365
_io__Buffered_seekable_impl(buffered *self);
366
367
static PyObject *
368
_io__Buffered_seekable(buffered *self, PyObject *Py_UNUSED(ignored))
369
{
370
return _io__Buffered_seekable_impl(self);
371
}
372
373
PyDoc_STRVAR(_io__Buffered_readable__doc__,
374
"readable($self, /)\n"
375
"--\n"
376
"\n");
377
378
#define _IO__BUFFERED_READABLE_METHODDEF \
379
{"readable", (PyCFunction)_io__Buffered_readable, METH_NOARGS, _io__Buffered_readable__doc__},
380
381
static PyObject *
382
_io__Buffered_readable_impl(buffered *self);
383
384
static PyObject *
385
_io__Buffered_readable(buffered *self, PyObject *Py_UNUSED(ignored))
386
{
387
return _io__Buffered_readable_impl(self);
388
}
389
390
PyDoc_STRVAR(_io__Buffered_writable__doc__,
391
"writable($self, /)\n"
392
"--\n"
393
"\n");
394
395
#define _IO__BUFFERED_WRITABLE_METHODDEF \
396
{"writable", (PyCFunction)_io__Buffered_writable, METH_NOARGS, _io__Buffered_writable__doc__},
397
398
static PyObject *
399
_io__Buffered_writable_impl(buffered *self);
400
401
static PyObject *
402
_io__Buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored))
403
{
404
return _io__Buffered_writable_impl(self);
405
}
406
407
PyDoc_STRVAR(_io__Buffered_fileno__doc__,
408
"fileno($self, /)\n"
409
"--\n"
410
"\n");
411
412
#define _IO__BUFFERED_FILENO_METHODDEF \
413
{"fileno", (PyCFunction)_io__Buffered_fileno, METH_NOARGS, _io__Buffered_fileno__doc__},
414
415
static PyObject *
416
_io__Buffered_fileno_impl(buffered *self);
417
418
static PyObject *
419
_io__Buffered_fileno(buffered *self, PyObject *Py_UNUSED(ignored))
420
{
421
return _io__Buffered_fileno_impl(self);
422
}
423
424
PyDoc_STRVAR(_io__Buffered_isatty__doc__,
425
"isatty($self, /)\n"
426
"--\n"
427
"\n");
428
429
#define _IO__BUFFERED_ISATTY_METHODDEF \
430
{"isatty", (PyCFunction)_io__Buffered_isatty, METH_NOARGS, _io__Buffered_isatty__doc__},
431
432
static PyObject *
433
_io__Buffered_isatty_impl(buffered *self);
434
435
static PyObject *
436
_io__Buffered_isatty(buffered *self, PyObject *Py_UNUSED(ignored))
437
{
438
return _io__Buffered_isatty_impl(self);
439
}
440
441
PyDoc_STRVAR(_io__Buffered_flush__doc__,
442
"flush($self, /)\n"
443
"--\n"
444
"\n");
445
446
#define _IO__BUFFERED_FLUSH_METHODDEF \
447
{"flush", (PyCFunction)_io__Buffered_flush, METH_NOARGS, _io__Buffered_flush__doc__},
448
449
static PyObject *
450
_io__Buffered_flush_impl(buffered *self);
451
452
static PyObject *
453
_io__Buffered_flush(buffered *self, PyObject *Py_UNUSED(ignored))
454
{
455
return _io__Buffered_flush_impl(self);
456
}
457
458
PyDoc_STRVAR(_io__Buffered_peek__doc__,
459
"peek($self, size=0, /)\n"
460
"--\n"
461
"\n");
462
463
#define _IO__BUFFERED_PEEK_METHODDEF \
464
{"peek", _PyCFunction_CAST(_io__Buffered_peek), METH_FASTCALL, _io__Buffered_peek__doc__},
465
466
static PyObject *
467
_io__Buffered_peek_impl(buffered *self, Py_ssize_t size);
468
469
static PyObject *
470
_io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
471
{
472
PyObject *return_value = NULL;
473
Py_ssize_t size = 0;
474
475
if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
476
goto exit;
477
}
478
if (nargs < 1) {
479
goto skip_optional;
480
}
481
{
482
Py_ssize_t ival = -1;
483
PyObject *iobj = _PyNumber_Index(args[0]);
484
if (iobj != NULL) {
485
ival = PyLong_AsSsize_t(iobj);
486
Py_DECREF(iobj);
487
}
488
if (ival == -1 && PyErr_Occurred()) {
489
goto exit;
490
}
491
size = ival;
492
}
493
skip_optional:
494
return_value = _io__Buffered_peek_impl(self, size);
495
496
exit:
497
return return_value;
498
}
499
500
PyDoc_STRVAR(_io__Buffered_read__doc__,
501
"read($self, size=-1, /)\n"
502
"--\n"
503
"\n");
504
505
#define _IO__BUFFERED_READ_METHODDEF \
506
{"read", _PyCFunction_CAST(_io__Buffered_read), METH_FASTCALL, _io__Buffered_read__doc__},
507
508
static PyObject *
509
_io__Buffered_read_impl(buffered *self, Py_ssize_t n);
510
511
static PyObject *
512
_io__Buffered_read(buffered *self, PyObject *const *args, Py_ssize_t nargs)
513
{
514
PyObject *return_value = NULL;
515
Py_ssize_t n = -1;
516
517
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
518
goto exit;
519
}
520
if (nargs < 1) {
521
goto skip_optional;
522
}
523
if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
524
goto exit;
525
}
526
skip_optional:
527
return_value = _io__Buffered_read_impl(self, n);
528
529
exit:
530
return return_value;
531
}
532
533
PyDoc_STRVAR(_io__Buffered_read1__doc__,
534
"read1($self, size=-1, /)\n"
535
"--\n"
536
"\n");
537
538
#define _IO__BUFFERED_READ1_METHODDEF \
539
{"read1", _PyCFunction_CAST(_io__Buffered_read1), METH_FASTCALL, _io__Buffered_read1__doc__},
540
541
static PyObject *
542
_io__Buffered_read1_impl(buffered *self, Py_ssize_t n);
543
544
static PyObject *
545
_io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs)
546
{
547
PyObject *return_value = NULL;
548
Py_ssize_t n = -1;
549
550
if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
551
goto exit;
552
}
553
if (nargs < 1) {
554
goto skip_optional;
555
}
556
{
557
Py_ssize_t ival = -1;
558
PyObject *iobj = _PyNumber_Index(args[0]);
559
if (iobj != NULL) {
560
ival = PyLong_AsSsize_t(iobj);
561
Py_DECREF(iobj);
562
}
563
if (ival == -1 && PyErr_Occurred()) {
564
goto exit;
565
}
566
n = ival;
567
}
568
skip_optional:
569
return_value = _io__Buffered_read1_impl(self, n);
570
571
exit:
572
return return_value;
573
}
574
575
PyDoc_STRVAR(_io__Buffered_readinto__doc__,
576
"readinto($self, buffer, /)\n"
577
"--\n"
578
"\n");
579
580
#define _IO__BUFFERED_READINTO_METHODDEF \
581
{"readinto", (PyCFunction)_io__Buffered_readinto, METH_O, _io__Buffered_readinto__doc__},
582
583
static PyObject *
584
_io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer);
585
586
static PyObject *
587
_io__Buffered_readinto(buffered *self, PyObject *arg)
588
{
589
PyObject *return_value = NULL;
590
Py_buffer buffer = {NULL, NULL};
591
592
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
593
PyErr_Clear();
594
_PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
595
goto exit;
596
}
597
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
598
_PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
599
goto exit;
600
}
601
return_value = _io__Buffered_readinto_impl(self, &buffer);
602
603
exit:
604
/* Cleanup for buffer */
605
if (buffer.obj) {
606
PyBuffer_Release(&buffer);
607
}
608
609
return return_value;
610
}
611
612
PyDoc_STRVAR(_io__Buffered_readinto1__doc__,
613
"readinto1($self, buffer, /)\n"
614
"--\n"
615
"\n");
616
617
#define _IO__BUFFERED_READINTO1_METHODDEF \
618
{"readinto1", (PyCFunction)_io__Buffered_readinto1, METH_O, _io__Buffered_readinto1__doc__},
619
620
static PyObject *
621
_io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer);
622
623
static PyObject *
624
_io__Buffered_readinto1(buffered *self, PyObject *arg)
625
{
626
PyObject *return_value = NULL;
627
Py_buffer buffer = {NULL, NULL};
628
629
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
630
PyErr_Clear();
631
_PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
632
goto exit;
633
}
634
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
635
_PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
636
goto exit;
637
}
638
return_value = _io__Buffered_readinto1_impl(self, &buffer);
639
640
exit:
641
/* Cleanup for buffer */
642
if (buffer.obj) {
643
PyBuffer_Release(&buffer);
644
}
645
646
return return_value;
647
}
648
649
PyDoc_STRVAR(_io__Buffered_readline__doc__,
650
"readline($self, size=-1, /)\n"
651
"--\n"
652
"\n");
653
654
#define _IO__BUFFERED_READLINE_METHODDEF \
655
{"readline", _PyCFunction_CAST(_io__Buffered_readline), METH_FASTCALL, _io__Buffered_readline__doc__},
656
657
static PyObject *
658
_io__Buffered_readline_impl(buffered *self, Py_ssize_t size);
659
660
static PyObject *
661
_io__Buffered_readline(buffered *self, PyObject *const *args, Py_ssize_t nargs)
662
{
663
PyObject *return_value = NULL;
664
Py_ssize_t size = -1;
665
666
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
667
goto exit;
668
}
669
if (nargs < 1) {
670
goto skip_optional;
671
}
672
if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
673
goto exit;
674
}
675
skip_optional:
676
return_value = _io__Buffered_readline_impl(self, size);
677
678
exit:
679
return return_value;
680
}
681
682
PyDoc_STRVAR(_io__Buffered_tell__doc__,
683
"tell($self, /)\n"
684
"--\n"
685
"\n");
686
687
#define _IO__BUFFERED_TELL_METHODDEF \
688
{"tell", (PyCFunction)_io__Buffered_tell, METH_NOARGS, _io__Buffered_tell__doc__},
689
690
static PyObject *
691
_io__Buffered_tell_impl(buffered *self);
692
693
static PyObject *
694
_io__Buffered_tell(buffered *self, PyObject *Py_UNUSED(ignored))
695
{
696
return _io__Buffered_tell_impl(self);
697
}
698
699
PyDoc_STRVAR(_io__Buffered_seek__doc__,
700
"seek($self, target, whence=0, /)\n"
701
"--\n"
702
"\n");
703
704
#define _IO__BUFFERED_SEEK_METHODDEF \
705
{"seek", _PyCFunction_CAST(_io__Buffered_seek), METH_FASTCALL, _io__Buffered_seek__doc__},
706
707
static PyObject *
708
_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence);
709
710
static PyObject *
711
_io__Buffered_seek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
712
{
713
PyObject *return_value = NULL;
714
PyObject *targetobj;
715
int whence = 0;
716
717
if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
718
goto exit;
719
}
720
targetobj = args[0];
721
if (nargs < 2) {
722
goto skip_optional;
723
}
724
whence = _PyLong_AsInt(args[1]);
725
if (whence == -1 && PyErr_Occurred()) {
726
goto exit;
727
}
728
skip_optional:
729
return_value = _io__Buffered_seek_impl(self, targetobj, whence);
730
731
exit:
732
return return_value;
733
}
734
735
PyDoc_STRVAR(_io__Buffered_truncate__doc__,
736
"truncate($self, pos=None, /)\n"
737
"--\n"
738
"\n");
739
740
#define _IO__BUFFERED_TRUNCATE_METHODDEF \
741
{"truncate", _PyCFunction_CAST(_io__Buffered_truncate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__Buffered_truncate__doc__},
742
743
static PyObject *
744
_io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos);
745
746
static PyObject *
747
_io__Buffered_truncate(buffered *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
748
{
749
PyObject *return_value = NULL;
750
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
751
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
752
#else
753
# define KWTUPLE NULL
754
#endif
755
756
static const char * const _keywords[] = {"", NULL};
757
static _PyArg_Parser _parser = {
758
.keywords = _keywords,
759
.fname = "truncate",
760
.kwtuple = KWTUPLE,
761
};
762
#undef KWTUPLE
763
PyObject *argsbuf[1];
764
PyObject *pos = Py_None;
765
766
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
767
if (!args) {
768
goto exit;
769
}
770
if (nargs < 1) {
771
goto skip_optional_posonly;
772
}
773
pos = args[0];
774
skip_optional_posonly:
775
return_value = _io__Buffered_truncate_impl(self, cls, pos);
776
777
exit:
778
return return_value;
779
}
780
781
PyDoc_STRVAR(_io_BufferedReader___init____doc__,
782
"BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
783
"--\n"
784
"\n"
785
"Create a new buffered reader using the given readable raw IO object.");
786
787
static int
788
_io_BufferedReader___init___impl(buffered *self, PyObject *raw,
789
Py_ssize_t buffer_size);
790
791
static int
792
_io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs)
793
{
794
int return_value = -1;
795
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
796
797
#define NUM_KEYWORDS 2
798
static struct {
799
PyGC_Head _this_is_not_used;
800
PyObject_VAR_HEAD
801
PyObject *ob_item[NUM_KEYWORDS];
802
} _kwtuple = {
803
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
804
.ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
805
};
806
#undef NUM_KEYWORDS
807
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
808
809
#else // !Py_BUILD_CORE
810
# define KWTUPLE NULL
811
#endif // !Py_BUILD_CORE
812
813
static const char * const _keywords[] = {"raw", "buffer_size", NULL};
814
static _PyArg_Parser _parser = {
815
.keywords = _keywords,
816
.fname = "BufferedReader",
817
.kwtuple = KWTUPLE,
818
};
819
#undef KWTUPLE
820
PyObject *argsbuf[2];
821
PyObject * const *fastargs;
822
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
823
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
824
PyObject *raw;
825
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
826
827
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
828
if (!fastargs) {
829
goto exit;
830
}
831
raw = fastargs[0];
832
if (!noptargs) {
833
goto skip_optional_pos;
834
}
835
{
836
Py_ssize_t ival = -1;
837
PyObject *iobj = _PyNumber_Index(fastargs[1]);
838
if (iobj != NULL) {
839
ival = PyLong_AsSsize_t(iobj);
840
Py_DECREF(iobj);
841
}
842
if (ival == -1 && PyErr_Occurred()) {
843
goto exit;
844
}
845
buffer_size = ival;
846
}
847
skip_optional_pos:
848
return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size);
849
850
exit:
851
return return_value;
852
}
853
854
PyDoc_STRVAR(_io_BufferedWriter___init____doc__,
855
"BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
856
"--\n"
857
"\n"
858
"A buffer for a writeable sequential RawIO object.\n"
859
"\n"
860
"The constructor creates a BufferedWriter for the given writeable raw\n"
861
"stream. If the buffer_size is not given, it defaults to\n"
862
"DEFAULT_BUFFER_SIZE.");
863
864
static int
865
_io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
866
Py_ssize_t buffer_size);
867
868
static int
869
_io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs)
870
{
871
int return_value = -1;
872
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
873
874
#define NUM_KEYWORDS 2
875
static struct {
876
PyGC_Head _this_is_not_used;
877
PyObject_VAR_HEAD
878
PyObject *ob_item[NUM_KEYWORDS];
879
} _kwtuple = {
880
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
881
.ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
882
};
883
#undef NUM_KEYWORDS
884
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
885
886
#else // !Py_BUILD_CORE
887
# define KWTUPLE NULL
888
#endif // !Py_BUILD_CORE
889
890
static const char * const _keywords[] = {"raw", "buffer_size", NULL};
891
static _PyArg_Parser _parser = {
892
.keywords = _keywords,
893
.fname = "BufferedWriter",
894
.kwtuple = KWTUPLE,
895
};
896
#undef KWTUPLE
897
PyObject *argsbuf[2];
898
PyObject * const *fastargs;
899
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
900
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
901
PyObject *raw;
902
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
903
904
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
905
if (!fastargs) {
906
goto exit;
907
}
908
raw = fastargs[0];
909
if (!noptargs) {
910
goto skip_optional_pos;
911
}
912
{
913
Py_ssize_t ival = -1;
914
PyObject *iobj = _PyNumber_Index(fastargs[1]);
915
if (iobj != NULL) {
916
ival = PyLong_AsSsize_t(iobj);
917
Py_DECREF(iobj);
918
}
919
if (ival == -1 && PyErr_Occurred()) {
920
goto exit;
921
}
922
buffer_size = ival;
923
}
924
skip_optional_pos:
925
return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size);
926
927
exit:
928
return return_value;
929
}
930
931
PyDoc_STRVAR(_io_BufferedWriter_write__doc__,
932
"write($self, buffer, /)\n"
933
"--\n"
934
"\n");
935
936
#define _IO_BUFFEREDWRITER_WRITE_METHODDEF \
937
{"write", (PyCFunction)_io_BufferedWriter_write, METH_O, _io_BufferedWriter_write__doc__},
938
939
static PyObject *
940
_io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer);
941
942
static PyObject *
943
_io_BufferedWriter_write(buffered *self, PyObject *arg)
944
{
945
PyObject *return_value = NULL;
946
Py_buffer buffer = {NULL, NULL};
947
948
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
949
goto exit;
950
}
951
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
952
_PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
953
goto exit;
954
}
955
return_value = _io_BufferedWriter_write_impl(self, &buffer);
956
957
exit:
958
/* Cleanup for buffer */
959
if (buffer.obj) {
960
PyBuffer_Release(&buffer);
961
}
962
963
return return_value;
964
}
965
966
PyDoc_STRVAR(_io_BufferedRWPair___init____doc__,
967
"BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)\n"
968
"--\n"
969
"\n"
970
"A buffered reader and writer object together.\n"
971
"\n"
972
"A buffered reader object and buffered writer object put together to\n"
973
"form a sequential IO object that can read and write. This is typically\n"
974
"used with a socket or two-way pipe.\n"
975
"\n"
976
"reader and writer are RawIOBase objects that are readable and\n"
977
"writeable respectively. If the buffer_size is omitted it defaults to\n"
978
"DEFAULT_BUFFER_SIZE.");
979
980
static int
981
_io_BufferedRWPair___init___impl(rwpair *self, PyObject *reader,
982
PyObject *writer, Py_ssize_t buffer_size);
983
984
static int
985
_io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
986
{
987
int return_value = -1;
988
PyTypeObject *base_tp = clinic_state()->PyBufferedRWPair_Type;
989
PyObject *reader;
990
PyObject *writer;
991
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
992
993
if ((Py_IS_TYPE(self, base_tp) ||
994
Py_TYPE(self)->tp_new == base_tp->tp_new) &&
995
!_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
996
goto exit;
997
}
998
if (!_PyArg_CheckPositional("BufferedRWPair", PyTuple_GET_SIZE(args), 2, 3)) {
999
goto exit;
1000
}
1001
reader = PyTuple_GET_ITEM(args, 0);
1002
writer = PyTuple_GET_ITEM(args, 1);
1003
if (PyTuple_GET_SIZE(args) < 3) {
1004
goto skip_optional;
1005
}
1006
{
1007
Py_ssize_t ival = -1;
1008
PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 2));
1009
if (iobj != NULL) {
1010
ival = PyLong_AsSsize_t(iobj);
1011
Py_DECREF(iobj);
1012
}
1013
if (ival == -1 && PyErr_Occurred()) {
1014
goto exit;
1015
}
1016
buffer_size = ival;
1017
}
1018
skip_optional:
1019
return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size);
1020
1021
exit:
1022
return return_value;
1023
}
1024
1025
PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
1026
"BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
1027
"--\n"
1028
"\n"
1029
"A buffered interface to random access streams.\n"
1030
"\n"
1031
"The constructor creates a reader and writer for a seekable stream,\n"
1032
"raw, given in the first argument. If the buffer_size is omitted it\n"
1033
"defaults to DEFAULT_BUFFER_SIZE.");
1034
1035
static int
1036
_io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
1037
Py_ssize_t buffer_size);
1038
1039
static int
1040
_io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
1041
{
1042
int return_value = -1;
1043
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
1044
1045
#define NUM_KEYWORDS 2
1046
static struct {
1047
PyGC_Head _this_is_not_used;
1048
PyObject_VAR_HEAD
1049
PyObject *ob_item[NUM_KEYWORDS];
1050
} _kwtuple = {
1051
.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
1052
.ob_item = { &_Py_ID(raw), &_Py_ID(buffer_size), },
1053
};
1054
#undef NUM_KEYWORDS
1055
#define KWTUPLE (&_kwtuple.ob_base.ob_base)
1056
1057
#else // !Py_BUILD_CORE
1058
# define KWTUPLE NULL
1059
#endif // !Py_BUILD_CORE
1060
1061
static const char * const _keywords[] = {"raw", "buffer_size", NULL};
1062
static _PyArg_Parser _parser = {
1063
.keywords = _keywords,
1064
.fname = "BufferedRandom",
1065
.kwtuple = KWTUPLE,
1066
};
1067
#undef KWTUPLE
1068
PyObject *argsbuf[2];
1069
PyObject * const *fastargs;
1070
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
1071
Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
1072
PyObject *raw;
1073
Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
1074
1075
fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
1076
if (!fastargs) {
1077
goto exit;
1078
}
1079
raw = fastargs[0];
1080
if (!noptargs) {
1081
goto skip_optional_pos;
1082
}
1083
{
1084
Py_ssize_t ival = -1;
1085
PyObject *iobj = _PyNumber_Index(fastargs[1]);
1086
if (iobj != NULL) {
1087
ival = PyLong_AsSsize_t(iobj);
1088
Py_DECREF(iobj);
1089
}
1090
if (ival == -1 && PyErr_Occurred()) {
1091
goto exit;
1092
}
1093
buffer_size = ival;
1094
}
1095
skip_optional_pos:
1096
return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size);
1097
1098
exit:
1099
return return_value;
1100
}
1101
/*[clinic end generated code: output=b7ddf84a5bc2bf34 input=a9049054013a1b77]*/
1102
1103