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