1/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
6"readinto($self, buffer, /)\n"
7"--\n"
8"\n");
9
10#define _IO__BUFFEREDIOBASE_READINTO_METHODDEF \
11 {"readinto", (PyCFunction)_io__BufferedIOBase_readinto, METH_O, _io__BufferedIOBase_readinto__doc__},
12
13static PyObject *
14_io__BufferedIOBase_readinto_impl(PyObject *self, Py_buffer *buffer);
15
16static PyObject *
17_io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
18{
19 PyObject *return_value = NULL;
20 Py_buffer buffer = {NULL, NULL};
21
22 if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
23 PyErr_Clear();
24 _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
25 goto exit;
26 }
27 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
28 _PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
29 goto exit;
30 }
31 return_value = _io__BufferedIOBase_readinto_impl(self, &buffer);
32
33exit:
34 /* Cleanup for buffer */
35 if (buffer.obj) {
36 PyBuffer_Release(&buffer);
37 }
38
39 return return_value;
40}
41
42PyDoc_STRVAR(_io__BufferedIOBase_readinto1__doc__,
43"readinto1($self, buffer, /)\n"
44"--\n"
45"\n");
46
47#define _IO__BUFFEREDIOBASE_READINTO1_METHODDEF \
48 {"readinto1", (PyCFunction)_io__BufferedIOBase_readinto1, METH_O, _io__BufferedIOBase_readinto1__doc__},
49
50static PyObject *
51_io__BufferedIOBase_readinto1_impl(PyObject *self, Py_buffer *buffer);
52
53static PyObject *
54_io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
55{
56 PyObject *return_value = NULL;
57 Py_buffer buffer = {NULL, NULL};
58
59 if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
60 PyErr_Clear();
61 _PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
62 goto exit;
63 }
64 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
65 _PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
66 goto exit;
67 }
68 return_value = _io__BufferedIOBase_readinto1_impl(self, &buffer);
69
70exit:
71 /* Cleanup for buffer */
72 if (buffer.obj) {
73 PyBuffer_Release(&buffer);
74 }
75
76 return return_value;
77}
78
79PyDoc_STRVAR(_io__BufferedIOBase_detach__doc__,
80"detach($self, /)\n"
81"--\n"
82"\n"
83"Disconnect this buffer from its underlying raw stream and return it.\n"
84"\n"
85"After the raw stream has been detached, the buffer is in an unusable\n"
86"state.");
87
88#define _IO__BUFFEREDIOBASE_DETACH_METHODDEF \
89 {"detach", (PyCFunction)_io__BufferedIOBase_detach, METH_NOARGS, _io__BufferedIOBase_detach__doc__},
90
91static PyObject *
92_io__BufferedIOBase_detach_impl(PyObject *self);
93
94static PyObject *
95_io__BufferedIOBase_detach(PyObject *self, PyObject *Py_UNUSED(ignored))
96{
97 return _io__BufferedIOBase_detach_impl(self);
98}
99
100PyDoc_STRVAR(_io__Buffered_peek__doc__,
101"peek($self, size=0, /)\n"
102"--\n"
103"\n");
104
105#define _IO__BUFFERED_PEEK_METHODDEF \
106 {"peek", (PyCFunction)(void(*)(void))_io__Buffered_peek, METH_FASTCALL, _io__Buffered_peek__doc__},
107
108static PyObject *
109_io__Buffered_peek_impl(buffered *self, Py_ssize_t size);
110
111static PyObject *
112_io__Buffered_peek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
113{
114 PyObject *return_value = NULL;
115 Py_ssize_t size = 0;
116
117 if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
118 goto exit;
119 }
120 if (nargs < 1) {
121 goto skip_optional;
122 }
123 {
124 Py_ssize_t ival = -1;
125 PyObject *iobj = _PyNumber_Index(args[0]);
126 if (iobj != NULL) {
127 ival = PyLong_AsSsize_t(iobj);
128 Py_DECREF(iobj);
129 }
130 if (ival == -1 && PyErr_Occurred()) {
131 goto exit;
132 }
133 size = ival;
134 }
135skip_optional:
136 return_value = _io__Buffered_peek_impl(self, size);
137
138exit:
139 return return_value;
140}
141
142PyDoc_STRVAR(_io__Buffered_read__doc__,
143"read($self, size=-1, /)\n"
144"--\n"
145"\n");
146
147#define _IO__BUFFERED_READ_METHODDEF \
148 {"read", (PyCFunction)(void(*)(void))_io__Buffered_read, METH_FASTCALL, _io__Buffered_read__doc__},
149
150static PyObject *
151_io__Buffered_read_impl(buffered *self, Py_ssize_t n);
152
153static PyObject *
154_io__Buffered_read(buffered *self, PyObject *const *args, Py_ssize_t nargs)
155{
156 PyObject *return_value = NULL;
157 Py_ssize_t n = -1;
158
159 if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
160 goto exit;
161 }
162 if (nargs < 1) {
163 goto skip_optional;
164 }
165 if (!_Py_convert_optional_to_ssize_t(args[0], &n)) {
166 goto exit;
167 }
168skip_optional:
169 return_value = _io__Buffered_read_impl(self, n);
170
171exit:
172 return return_value;
173}
174
175PyDoc_STRVAR(_io__Buffered_read1__doc__,
176"read1($self, size=-1, /)\n"
177"--\n"
178"\n");
179
180#define _IO__BUFFERED_READ1_METHODDEF \
181 {"read1", (PyCFunction)(void(*)(void))_io__Buffered_read1, METH_FASTCALL, _io__Buffered_read1__doc__},
182
183static PyObject *
184_io__Buffered_read1_impl(buffered *self, Py_ssize_t n);
185
186static PyObject *
187_io__Buffered_read1(buffered *self, PyObject *const *args, Py_ssize_t nargs)
188{
189 PyObject *return_value = NULL;
190 Py_ssize_t n = -1;
191
192 if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
193 goto exit;
194 }
195 if (nargs < 1) {
196 goto skip_optional;
197 }
198 {
199 Py_ssize_t ival = -1;
200 PyObject *iobj = _PyNumber_Index(args[0]);
201 if (iobj != NULL) {
202 ival = PyLong_AsSsize_t(iobj);
203 Py_DECREF(iobj);
204 }
205 if (ival == -1 && PyErr_Occurred()) {
206 goto exit;
207 }
208 n = ival;
209 }
210skip_optional:
211 return_value = _io__Buffered_read1_impl(self, n);
212
213exit:
214 return return_value;
215}
216
217PyDoc_STRVAR(_io__Buffered_readinto__doc__,
218"readinto($self, buffer, /)\n"
219"--\n"
220"\n");
221
222#define _IO__BUFFERED_READINTO_METHODDEF \
223 {"readinto", (PyCFunction)_io__Buffered_readinto, METH_O, _io__Buffered_readinto__doc__},
224
225static PyObject *
226_io__Buffered_readinto_impl(buffered *self, Py_buffer *buffer);
227
228static PyObject *
229_io__Buffered_readinto(buffered *self, PyObject *arg)
230{
231 PyObject *return_value = NULL;
232 Py_buffer buffer = {NULL, NULL};
233
234 if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
235 PyErr_Clear();
236 _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
237 goto exit;
238 }
239 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
240 _PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
241 goto exit;
242 }
243 return_value = _io__Buffered_readinto_impl(self, &buffer);
244
245exit:
246 /* Cleanup for buffer */
247 if (buffer.obj) {
248 PyBuffer_Release(&buffer);
249 }
250
251 return return_value;
252}
253
254PyDoc_STRVAR(_io__Buffered_readinto1__doc__,
255"readinto1($self, buffer, /)\n"
256"--\n"
257"\n");
258
259#define _IO__BUFFERED_READINTO1_METHODDEF \
260 {"readinto1", (PyCFunction)_io__Buffered_readinto1, METH_O, _io__Buffered_readinto1__doc__},
261
262static PyObject *
263_io__Buffered_readinto1_impl(buffered *self, Py_buffer *buffer);
264
265static PyObject *
266_io__Buffered_readinto1(buffered *self, PyObject *arg)
267{
268 PyObject *return_value = NULL;
269 Py_buffer buffer = {NULL, NULL};
270
271 if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
272 PyErr_Clear();
273 _PyArg_BadArgument("readinto1", "argument", "read-write bytes-like object", arg);
274 goto exit;
275 }
276 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
277 _PyArg_BadArgument("readinto1", "argument", "contiguous buffer", arg);
278 goto exit;
279 }
280 return_value = _io__Buffered_readinto1_impl(self, &buffer);
281
282exit:
283 /* Cleanup for buffer */
284 if (buffer.obj) {
285 PyBuffer_Release(&buffer);
286 }
287
288 return return_value;
289}
290
291PyDoc_STRVAR(_io__Buffered_readline__doc__,
292"readline($self, size=-1, /)\n"
293"--\n"
294"\n");
295
296#define _IO__BUFFERED_READLINE_METHODDEF \
297 {"readline", (PyCFunction)(void(*)(void))_io__Buffered_readline, METH_FASTCALL, _io__Buffered_readline__doc__},
298
299static PyObject *
300_io__Buffered_readline_impl(buffered *self, Py_ssize_t size);
301
302static PyObject *
303_io__Buffered_readline(buffered *self, PyObject *const *args, Py_ssize_t nargs)
304{
305 PyObject *return_value = NULL;
306 Py_ssize_t size = -1;
307
308 if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
309 goto exit;
310 }
311 if (nargs < 1) {
312 goto skip_optional;
313 }
314 if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
315 goto exit;
316 }
317skip_optional:
318 return_value = _io__Buffered_readline_impl(self, size);
319
320exit:
321 return return_value;
322}
323
324PyDoc_STRVAR(_io__Buffered_seek__doc__,
325"seek($self, target, whence=0, /)\n"
326"--\n"
327"\n");
328
329#define _IO__BUFFERED_SEEK_METHODDEF \
330 {"seek", (PyCFunction)(void(*)(void))_io__Buffered_seek, METH_FASTCALL, _io__Buffered_seek__doc__},
331
332static PyObject *
333_io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence);
334
335static PyObject *
336_io__Buffered_seek(buffered *self, PyObject *const *args, Py_ssize_t nargs)
337{
338 PyObject *return_value = NULL;
339 PyObject *targetobj;
340 int whence = 0;
341
342 if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
343 goto exit;
344 }
345 targetobj = args[0];
346 if (nargs < 2) {
347 goto skip_optional;
348 }
349 whence = _PyLong_AsInt(args[1]);
350 if (whence == -1 && PyErr_Occurred()) {
351 goto exit;
352 }
353skip_optional:
354 return_value = _io__Buffered_seek_impl(self, targetobj, whence);
355
356exit:
357 return return_value;
358}
359
360PyDoc_STRVAR(_io__Buffered_truncate__doc__,
361"truncate($self, pos=None, /)\n"
362"--\n"
363"\n");
364
365#define _IO__BUFFERED_TRUNCATE_METHODDEF \
366 {"truncate", (PyCFunction)(void(*)(void))_io__Buffered_truncate, METH_FASTCALL, _io__Buffered_truncate__doc__},
367
368static PyObject *
369_io__Buffered_truncate_impl(buffered *self, PyObject *pos);
370
371static PyObject *
372_io__Buffered_truncate(buffered *self, PyObject *const *args, Py_ssize_t nargs)
373{
374 PyObject *return_value = NULL;
375 PyObject *pos = Py_None;
376
377 if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
378 goto exit;
379 }
380 if (nargs < 1) {
381 goto skip_optional;
382 }
383 pos = args[0];
384skip_optional:
385 return_value = _io__Buffered_truncate_impl(self, pos);
386
387exit:
388 return return_value;
389}
390
391PyDoc_STRVAR(_io_BufferedReader___init____doc__,
392"BufferedReader(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
393"--\n"
394"\n"
395"Create a new buffered reader using the given readable raw IO object.");
396
397static int
398_io_BufferedReader___init___impl(buffered *self, PyObject *raw,
399 Py_ssize_t buffer_size);
400
401static int
402_io_BufferedReader___init__(PyObject *self, PyObject *args, PyObject *kwargs)
403{
404 int return_value = -1;
405 static const char * const _keywords[] = {"raw", "buffer_size", NULL};
406 static _PyArg_Parser _parser = {NULL, _keywords, "BufferedReader", 0};
407 PyObject *argsbuf[2];
408 PyObject * const *fastargs;
409 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
410 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
411 PyObject *raw;
412 Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
413
414 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
415 if (!fastargs) {
416 goto exit;
417 }
418 raw = fastargs[0];
419 if (!noptargs) {
420 goto skip_optional_pos;
421 }
422 {
423 Py_ssize_t ival = -1;
424 PyObject *iobj = _PyNumber_Index(fastargs[1]);
425 if (iobj != NULL) {
426 ival = PyLong_AsSsize_t(iobj);
427 Py_DECREF(iobj);
428 }
429 if (ival == -1 && PyErr_Occurred()) {
430 goto exit;
431 }
432 buffer_size = ival;
433 }
434skip_optional_pos:
435 return_value = _io_BufferedReader___init___impl((buffered *)self, raw, buffer_size);
436
437exit:
438 return return_value;
439}
440
441PyDoc_STRVAR(_io_BufferedWriter___init____doc__,
442"BufferedWriter(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
443"--\n"
444"\n"
445"A buffer for a writeable sequential RawIO object.\n"
446"\n"
447"The constructor creates a BufferedWriter for the given writeable raw\n"
448"stream. If the buffer_size is not given, it defaults to\n"
449"DEFAULT_BUFFER_SIZE.");
450
451static int
452_io_BufferedWriter___init___impl(buffered *self, PyObject *raw,
453 Py_ssize_t buffer_size);
454
455static int
456_io_BufferedWriter___init__(PyObject *self, PyObject *args, PyObject *kwargs)
457{
458 int return_value = -1;
459 static const char * const _keywords[] = {"raw", "buffer_size", NULL};
460 static _PyArg_Parser _parser = {NULL, _keywords, "BufferedWriter", 0};
461 PyObject *argsbuf[2];
462 PyObject * const *fastargs;
463 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
464 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
465 PyObject *raw;
466 Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
467
468 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
469 if (!fastargs) {
470 goto exit;
471 }
472 raw = fastargs[0];
473 if (!noptargs) {
474 goto skip_optional_pos;
475 }
476 {
477 Py_ssize_t ival = -1;
478 PyObject *iobj = _PyNumber_Index(fastargs[1]);
479 if (iobj != NULL) {
480 ival = PyLong_AsSsize_t(iobj);
481 Py_DECREF(iobj);
482 }
483 if (ival == -1 && PyErr_Occurred()) {
484 goto exit;
485 }
486 buffer_size = ival;
487 }
488skip_optional_pos:
489 return_value = _io_BufferedWriter___init___impl((buffered *)self, raw, buffer_size);
490
491exit:
492 return return_value;
493}
494
495PyDoc_STRVAR(_io_BufferedWriter_write__doc__,
496"write($self, buffer, /)\n"
497"--\n"
498"\n");
499
500#define _IO_BUFFEREDWRITER_WRITE_METHODDEF \
501 {"write", (PyCFunction)_io_BufferedWriter_write, METH_O, _io_BufferedWriter_write__doc__},
502
503static PyObject *
504_io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer);
505
506static PyObject *
507_io_BufferedWriter_write(buffered *self, PyObject *arg)
508{
509 PyObject *return_value = NULL;
510 Py_buffer buffer = {NULL, NULL};
511
512 if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
513 goto exit;
514 }
515 if (!PyBuffer_IsContiguous(&buffer, 'C')) {
516 _PyArg_BadArgument("write", "argument", "contiguous buffer", arg);
517 goto exit;
518 }
519 return_value = _io_BufferedWriter_write_impl(self, &buffer);
520
521exit:
522 /* Cleanup for buffer */
523 if (buffer.obj) {
524 PyBuffer_Release(&buffer);
525 }
526
527 return return_value;
528}
529
530PyDoc_STRVAR(_io_BufferedRWPair___init____doc__,
531"BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE, /)\n"
532"--\n"
533"\n"
534"A buffered reader and writer object together.\n"
535"\n"
536"A buffered reader object and buffered writer object put together to\n"
537"form a sequential IO object that can read and write. This is typically\n"
538"used with a socket or two-way pipe.\n"
539"\n"
540"reader and writer are RawIOBase objects that are readable and\n"
541"writeable respectively. If the buffer_size is omitted it defaults to\n"
542"DEFAULT_BUFFER_SIZE.");
543
544static int
545_io_BufferedRWPair___init___impl(rwpair *self, PyObject *reader,
546 PyObject *writer, Py_ssize_t buffer_size);
547
548static int
549_io_BufferedRWPair___init__(PyObject *self, PyObject *args, PyObject *kwargs)
550{
551 int return_value = -1;
552 PyObject *reader;
553 PyObject *writer;
554 Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
555
556 if (Py_IS_TYPE(self, &PyBufferedRWPair_Type) &&
557 !_PyArg_NoKeywords("BufferedRWPair", kwargs)) {
558 goto exit;
559 }
560 if (!_PyArg_CheckPositional("BufferedRWPair", PyTuple_GET_SIZE(args), 2, 3)) {
561 goto exit;
562 }
563 reader = PyTuple_GET_ITEM(args, 0);
564 writer = PyTuple_GET_ITEM(args, 1);
565 if (PyTuple_GET_SIZE(args) < 3) {
566 goto skip_optional;
567 }
568 {
569 Py_ssize_t ival = -1;
570 PyObject *iobj = _PyNumber_Index(PyTuple_GET_ITEM(args, 2));
571 if (iobj != NULL) {
572 ival = PyLong_AsSsize_t(iobj);
573 Py_DECREF(iobj);
574 }
575 if (ival == -1 && PyErr_Occurred()) {
576 goto exit;
577 }
578 buffer_size = ival;
579 }
580skip_optional:
581 return_value = _io_BufferedRWPair___init___impl((rwpair *)self, reader, writer, buffer_size);
582
583exit:
584 return return_value;
585}
586
587PyDoc_STRVAR(_io_BufferedRandom___init____doc__,
588"BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)\n"
589"--\n"
590"\n"
591"A buffered interface to random access streams.\n"
592"\n"
593"The constructor creates a reader and writer for a seekable stream,\n"
594"raw, given in the first argument. If the buffer_size is omitted it\n"
595"defaults to DEFAULT_BUFFER_SIZE.");
596
597static int
598_io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
599 Py_ssize_t buffer_size);
600
601static int
602_io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
603{
604 int return_value = -1;
605 static const char * const _keywords[] = {"raw", "buffer_size", NULL};
606 static _PyArg_Parser _parser = {NULL, _keywords, "BufferedRandom", 0};
607 PyObject *argsbuf[2];
608 PyObject * const *fastargs;
609 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
610 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
611 PyObject *raw;
612 Py_ssize_t buffer_size = DEFAULT_BUFFER_SIZE;
613
614 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
615 if (!fastargs) {
616 goto exit;
617 }
618 raw = fastargs[0];
619 if (!noptargs) {
620 goto skip_optional_pos;
621 }
622 {
623 Py_ssize_t ival = -1;
624 PyObject *iobj = _PyNumber_Index(fastargs[1]);
625 if (iobj != NULL) {
626 ival = PyLong_AsSsize_t(iobj);
627 Py_DECREF(iobj);
628 }
629 if (ival == -1 && PyErr_Occurred()) {
630 goto exit;
631 }
632 buffer_size = ival;
633 }
634skip_optional_pos:
635 return_value = _io_BufferedRandom___init___impl((buffered *)self, raw, buffer_size);
636
637exit:
638 return return_value;
639}
640/*[clinic end generated code: output=98ccf7610c0e82ba input=a9049054013a1b77]*/
641