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