Debian Codegraph @

Modules/_io/clinic/bufferedio.c.h

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