1 | /*[clinic input] |
2 | preserve |
3 | [clinic start generated code]*/ |
4 | |
5 | PyDoc_STRVAR(_io_BytesIO_readable__doc__, |
6 | "readable($self, /)\n" |
7 | "--\n" |
8 | "\n" |
9 | "Returns True if the IO object can be read." ); |
10 | |
11 | #define _IO_BYTESIO_READABLE_METHODDEF \ |
12 | {"readable", (PyCFunction)_io_BytesIO_readable, METH_NOARGS, _io_BytesIO_readable__doc__}, |
13 | |
14 | static PyObject * |
15 | _io_BytesIO_readable_impl(bytesio *self); |
16 | |
17 | static PyObject * |
18 | _io_BytesIO_readable(bytesio *self, PyObject *Py_UNUSED(ignored)) |
19 | { |
20 | return _io_BytesIO_readable_impl(self); |
21 | } |
22 | |
23 | PyDoc_STRVAR(_io_BytesIO_writable__doc__, |
24 | "writable($self, /)\n" |
25 | "--\n" |
26 | "\n" |
27 | "Returns True if the IO object can be written." ); |
28 | |
29 | #define _IO_BYTESIO_WRITABLE_METHODDEF \ |
30 | {"writable", (PyCFunction)_io_BytesIO_writable, METH_NOARGS, _io_BytesIO_writable__doc__}, |
31 | |
32 | static PyObject * |
33 | _io_BytesIO_writable_impl(bytesio *self); |
34 | |
35 | static PyObject * |
36 | _io_BytesIO_writable(bytesio *self, PyObject *Py_UNUSED(ignored)) |
37 | { |
38 | return _io_BytesIO_writable_impl(self); |
39 | } |
40 | |
41 | PyDoc_STRVAR(_io_BytesIO_seekable__doc__, |
42 | "seekable($self, /)\n" |
43 | "--\n" |
44 | "\n" |
45 | "Returns True if the IO object can be seeked." ); |
46 | |
47 | #define _IO_BYTESIO_SEEKABLE_METHODDEF \ |
48 | {"seekable", (PyCFunction)_io_BytesIO_seekable, METH_NOARGS, _io_BytesIO_seekable__doc__}, |
49 | |
50 | static PyObject * |
51 | _io_BytesIO_seekable_impl(bytesio *self); |
52 | |
53 | static PyObject * |
54 | _io_BytesIO_seekable(bytesio *self, PyObject *Py_UNUSED(ignored)) |
55 | { |
56 | return _io_BytesIO_seekable_impl(self); |
57 | } |
58 | |
59 | PyDoc_STRVAR(_io_BytesIO_flush__doc__, |
60 | "flush($self, /)\n" |
61 | "--\n" |
62 | "\n" |
63 | "Does nothing." ); |
64 | |
65 | #define _IO_BYTESIO_FLUSH_METHODDEF \ |
66 | {"flush", (PyCFunction)_io_BytesIO_flush, METH_NOARGS, _io_BytesIO_flush__doc__}, |
67 | |
68 | static PyObject * |
69 | _io_BytesIO_flush_impl(bytesio *self); |
70 | |
71 | static PyObject * |
72 | _io_BytesIO_flush(bytesio *self, PyObject *Py_UNUSED(ignored)) |
73 | { |
74 | return _io_BytesIO_flush_impl(self); |
75 | } |
76 | |
77 | PyDoc_STRVAR(_io_BytesIO_getbuffer__doc__, |
78 | "getbuffer($self, /)\n" |
79 | "--\n" |
80 | "\n" |
81 | "Get a read-write view over the contents of the BytesIO object." ); |
82 | |
83 | #define _IO_BYTESIO_GETBUFFER_METHODDEF \ |
84 | {"getbuffer", (PyCFunction)_io_BytesIO_getbuffer, METH_NOARGS, _io_BytesIO_getbuffer__doc__}, |
85 | |
86 | static PyObject * |
87 | _io_BytesIO_getbuffer_impl(bytesio *self); |
88 | |
89 | static PyObject * |
90 | _io_BytesIO_getbuffer(bytesio *self, PyObject *Py_UNUSED(ignored)) |
91 | { |
92 | return _io_BytesIO_getbuffer_impl(self); |
93 | } |
94 | |
95 | PyDoc_STRVAR(_io_BytesIO_getvalue__doc__, |
96 | "getvalue($self, /)\n" |
97 | "--\n" |
98 | "\n" |
99 | "Retrieve the entire contents of the BytesIO object." ); |
100 | |
101 | #define _IO_BYTESIO_GETVALUE_METHODDEF \ |
102 | {"getvalue", (PyCFunction)_io_BytesIO_getvalue, METH_NOARGS, _io_BytesIO_getvalue__doc__}, |
103 | |
104 | static PyObject * |
105 | _io_BytesIO_getvalue_impl(bytesio *self); |
106 | |
107 | static PyObject * |
108 | _io_BytesIO_getvalue(bytesio *self, PyObject *Py_UNUSED(ignored)) |
109 | { |
110 | return _io_BytesIO_getvalue_impl(self); |
111 | } |
112 | |
113 | PyDoc_STRVAR(_io_BytesIO_isatty__doc__, |
114 | "isatty($self, /)\n" |
115 | "--\n" |
116 | "\n" |
117 | "Always returns False.\n" |
118 | "\n" |
119 | "BytesIO objects are not connected to a TTY-like device." ); |
120 | |
121 | #define _IO_BYTESIO_ISATTY_METHODDEF \ |
122 | {"isatty", (PyCFunction)_io_BytesIO_isatty, METH_NOARGS, _io_BytesIO_isatty__doc__}, |
123 | |
124 | static PyObject * |
125 | _io_BytesIO_isatty_impl(bytesio *self); |
126 | |
127 | static PyObject * |
128 | _io_BytesIO_isatty(bytesio *self, PyObject *Py_UNUSED(ignored)) |
129 | { |
130 | return _io_BytesIO_isatty_impl(self); |
131 | } |
132 | |
133 | PyDoc_STRVAR(_io_BytesIO_tell__doc__, |
134 | "tell($self, /)\n" |
135 | "--\n" |
136 | "\n" |
137 | "Current file position, an integer." ); |
138 | |
139 | #define _IO_BYTESIO_TELL_METHODDEF \ |
140 | {"tell", (PyCFunction)_io_BytesIO_tell, METH_NOARGS, _io_BytesIO_tell__doc__}, |
141 | |
142 | static PyObject * |
143 | _io_BytesIO_tell_impl(bytesio *self); |
144 | |
145 | static PyObject * |
146 | _io_BytesIO_tell(bytesio *self, PyObject *Py_UNUSED(ignored)) |
147 | { |
148 | return _io_BytesIO_tell_impl(self); |
149 | } |
150 | |
151 | PyDoc_STRVAR(_io_BytesIO_read__doc__, |
152 | "read($self, size=-1, /)\n" |
153 | "--\n" |
154 | "\n" |
155 | "Read at most size bytes, returned as a bytes object.\n" |
156 | "\n" |
157 | "If the size argument is negative, read until EOF is reached.\n" |
158 | "Return an empty bytes object at EOF." ); |
159 | |
160 | #define _IO_BYTESIO_READ_METHODDEF \ |
161 | {"read", (PyCFunction)(void(*)(void))_io_BytesIO_read, METH_FASTCALL, _io_BytesIO_read__doc__}, |
162 | |
163 | static PyObject * |
164 | _io_BytesIO_read_impl(bytesio *self, Py_ssize_t size); |
165 | |
166 | static PyObject * |
167 | _io_BytesIO_read(bytesio *self, PyObject *const *args, Py_ssize_t nargs) |
168 | { |
169 | PyObject *return_value = NULL; |
170 | Py_ssize_t size = -1; |
171 | |
172 | if (!_PyArg_CheckPositional("read" , nargs, 0, 1)) { |
173 | goto exit; |
174 | } |
175 | if (nargs < 1) { |
176 | goto skip_optional; |
177 | } |
178 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
179 | goto exit; |
180 | } |
181 | skip_optional: |
182 | return_value = _io_BytesIO_read_impl(self, size); |
183 | |
184 | exit: |
185 | return return_value; |
186 | } |
187 | |
188 | PyDoc_STRVAR(_io_BytesIO_read1__doc__, |
189 | "read1($self, size=-1, /)\n" |
190 | "--\n" |
191 | "\n" |
192 | "Read at most size bytes, returned as a bytes object.\n" |
193 | "\n" |
194 | "If the size argument is negative or omitted, read until EOF is reached.\n" |
195 | "Return an empty bytes object at EOF." ); |
196 | |
197 | #define _IO_BYTESIO_READ1_METHODDEF \ |
198 | {"read1", (PyCFunction)(void(*)(void))_io_BytesIO_read1, METH_FASTCALL, _io_BytesIO_read1__doc__}, |
199 | |
200 | static PyObject * |
201 | _io_BytesIO_read1_impl(bytesio *self, Py_ssize_t size); |
202 | |
203 | static PyObject * |
204 | _io_BytesIO_read1(bytesio *self, PyObject *const *args, Py_ssize_t nargs) |
205 | { |
206 | PyObject *return_value = NULL; |
207 | Py_ssize_t size = -1; |
208 | |
209 | if (!_PyArg_CheckPositional("read1" , nargs, 0, 1)) { |
210 | goto exit; |
211 | } |
212 | if (nargs < 1) { |
213 | goto skip_optional; |
214 | } |
215 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
216 | goto exit; |
217 | } |
218 | skip_optional: |
219 | return_value = _io_BytesIO_read1_impl(self, size); |
220 | |
221 | exit: |
222 | return return_value; |
223 | } |
224 | |
225 | PyDoc_STRVAR(_io_BytesIO_readline__doc__, |
226 | "readline($self, size=-1, /)\n" |
227 | "--\n" |
228 | "\n" |
229 | "Next line from the file, as a bytes object.\n" |
230 | "\n" |
231 | "Retain newline. A non-negative size argument limits the maximum\n" |
232 | "number of bytes to return (an incomplete line may be returned then).\n" |
233 | "Return an empty bytes object at EOF." ); |
234 | |
235 | #define _IO_BYTESIO_READLINE_METHODDEF \ |
236 | {"readline", (PyCFunction)(void(*)(void))_io_BytesIO_readline, METH_FASTCALL, _io_BytesIO_readline__doc__}, |
237 | |
238 | static PyObject * |
239 | _io_BytesIO_readline_impl(bytesio *self, Py_ssize_t size); |
240 | |
241 | static PyObject * |
242 | _io_BytesIO_readline(bytesio *self, PyObject *const *args, Py_ssize_t nargs) |
243 | { |
244 | PyObject *return_value = NULL; |
245 | Py_ssize_t size = -1; |
246 | |
247 | if (!_PyArg_CheckPositional("readline" , nargs, 0, 1)) { |
248 | goto exit; |
249 | } |
250 | if (nargs < 1) { |
251 | goto skip_optional; |
252 | } |
253 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
254 | goto exit; |
255 | } |
256 | skip_optional: |
257 | return_value = _io_BytesIO_readline_impl(self, size); |
258 | |
259 | exit: |
260 | return return_value; |
261 | } |
262 | |
263 | PyDoc_STRVAR(_io_BytesIO_readlines__doc__, |
264 | "readlines($self, size=None, /)\n" |
265 | "--\n" |
266 | "\n" |
267 | "List of bytes objects, each a line from the file.\n" |
268 | "\n" |
269 | "Call readline() repeatedly and return a list of the lines so read.\n" |
270 | "The optional size argument, if given, is an approximate bound on the\n" |
271 | "total number of bytes in the lines returned." ); |
272 | |
273 | #define _IO_BYTESIO_READLINES_METHODDEF \ |
274 | {"readlines", (PyCFunction)(void(*)(void))_io_BytesIO_readlines, METH_FASTCALL, _io_BytesIO_readlines__doc__}, |
275 | |
276 | static PyObject * |
277 | _io_BytesIO_readlines_impl(bytesio *self, PyObject *arg); |
278 | |
279 | static PyObject * |
280 | _io_BytesIO_readlines(bytesio *self, PyObject *const *args, Py_ssize_t nargs) |
281 | { |
282 | PyObject *return_value = NULL; |
283 | PyObject *arg = Py_None; |
284 | |
285 | if (!_PyArg_CheckPositional("readlines" , nargs, 0, 1)) { |
286 | goto exit; |
287 | } |
288 | if (nargs < 1) { |
289 | goto skip_optional; |
290 | } |
291 | arg = args[0]; |
292 | skip_optional: |
293 | return_value = _io_BytesIO_readlines_impl(self, arg); |
294 | |
295 | exit: |
296 | return return_value; |
297 | } |
298 | |
299 | PyDoc_STRVAR(_io_BytesIO_readinto__doc__, |
300 | "readinto($self, buffer, /)\n" |
301 | "--\n" |
302 | "\n" |
303 | "Read bytes into buffer.\n" |
304 | "\n" |
305 | "Returns number of bytes read (0 for EOF), or None if the object\n" |
306 | "is set not to block and has no data to read." ); |
307 | |
308 | #define _IO_BYTESIO_READINTO_METHODDEF \ |
309 | {"readinto", (PyCFunction)_io_BytesIO_readinto, METH_O, _io_BytesIO_readinto__doc__}, |
310 | |
311 | static PyObject * |
312 | _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer); |
313 | |
314 | static PyObject * |
315 | _io_BytesIO_readinto(bytesio *self, PyObject *arg) |
316 | { |
317 | PyObject *return_value = NULL; |
318 | Py_buffer buffer = {NULL, NULL}; |
319 | |
320 | if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) { |
321 | PyErr_Clear(); |
322 | _PyArg_BadArgument("readinto" , "argument" , "read-write bytes-like object" , arg); |
323 | goto exit; |
324 | } |
325 | if (!PyBuffer_IsContiguous(&buffer, 'C')) { |
326 | _PyArg_BadArgument("readinto" , "argument" , "contiguous buffer" , arg); |
327 | goto exit; |
328 | } |
329 | return_value = _io_BytesIO_readinto_impl(self, &buffer); |
330 | |
331 | exit: |
332 | /* Cleanup for buffer */ |
333 | if (buffer.obj) { |
334 | PyBuffer_Release(&buffer); |
335 | } |
336 | |
337 | return return_value; |
338 | } |
339 | |
340 | PyDoc_STRVAR(_io_BytesIO_truncate__doc__, |
341 | "truncate($self, size=None, /)\n" |
342 | "--\n" |
343 | "\n" |
344 | "Truncate the file to at most size bytes.\n" |
345 | "\n" |
346 | "Size defaults to the current file position, as returned by tell().\n" |
347 | "The current file position is unchanged. Returns the new size." ); |
348 | |
349 | #define _IO_BYTESIO_TRUNCATE_METHODDEF \ |
350 | {"truncate", (PyCFunction)(void(*)(void))_io_BytesIO_truncate, METH_FASTCALL, _io_BytesIO_truncate__doc__}, |
351 | |
352 | static PyObject * |
353 | _io_BytesIO_truncate_impl(bytesio *self, Py_ssize_t size); |
354 | |
355 | static PyObject * |
356 | _io_BytesIO_truncate(bytesio *self, PyObject *const *args, Py_ssize_t nargs) |
357 | { |
358 | PyObject *return_value = NULL; |
359 | Py_ssize_t size = self->pos; |
360 | |
361 | if (!_PyArg_CheckPositional("truncate" , nargs, 0, 1)) { |
362 | goto exit; |
363 | } |
364 | if (nargs < 1) { |
365 | goto skip_optional; |
366 | } |
367 | if (!_Py_convert_optional_to_ssize_t(args[0], &size)) { |
368 | goto exit; |
369 | } |
370 | skip_optional: |
371 | return_value = _io_BytesIO_truncate_impl(self, size); |
372 | |
373 | exit: |
374 | return return_value; |
375 | } |
376 | |
377 | PyDoc_STRVAR(_io_BytesIO_seek__doc__, |
378 | "seek($self, pos, whence=0, /)\n" |
379 | "--\n" |
380 | "\n" |
381 | "Change stream position.\n" |
382 | "\n" |
383 | "Seek to byte offset pos relative to position indicated by whence:\n" |
384 | " 0 Start of stream (the default). pos should be >= 0;\n" |
385 | " 1 Current position - pos may be negative;\n" |
386 | " 2 End of stream - pos usually negative.\n" |
387 | "Returns the new absolute position." ); |
388 | |
389 | #define _IO_BYTESIO_SEEK_METHODDEF \ |
390 | {"seek", (PyCFunction)(void(*)(void))_io_BytesIO_seek, METH_FASTCALL, _io_BytesIO_seek__doc__}, |
391 | |
392 | static PyObject * |
393 | _io_BytesIO_seek_impl(bytesio *self, Py_ssize_t pos, int whence); |
394 | |
395 | static PyObject * |
396 | _io_BytesIO_seek(bytesio *self, PyObject *const *args, Py_ssize_t nargs) |
397 | { |
398 | PyObject *return_value = NULL; |
399 | Py_ssize_t pos; |
400 | int whence = 0; |
401 | |
402 | if (!_PyArg_CheckPositional("seek" , nargs, 1, 2)) { |
403 | goto exit; |
404 | } |
405 | { |
406 | Py_ssize_t ival = -1; |
407 | PyObject *iobj = _PyNumber_Index(args[0]); |
408 | if (iobj != NULL) { |
409 | ival = PyLong_AsSsize_t(iobj); |
410 | Py_DECREF(iobj); |
411 | } |
412 | if (ival == -1 && PyErr_Occurred()) { |
413 | goto exit; |
414 | } |
415 | pos = ival; |
416 | } |
417 | if (nargs < 2) { |
418 | goto skip_optional; |
419 | } |
420 | whence = _PyLong_AsInt(args[1]); |
421 | if (whence == -1 && PyErr_Occurred()) { |
422 | goto exit; |
423 | } |
424 | skip_optional: |
425 | return_value = _io_BytesIO_seek_impl(self, pos, whence); |
426 | |
427 | exit: |
428 | return return_value; |
429 | } |
430 | |
431 | PyDoc_STRVAR(_io_BytesIO_write__doc__, |
432 | "write($self, b, /)\n" |
433 | "--\n" |
434 | "\n" |
435 | "Write bytes to file.\n" |
436 | "\n" |
437 | "Return the number of bytes written." ); |
438 | |
439 | #define _IO_BYTESIO_WRITE_METHODDEF \ |
440 | {"write", (PyCFunction)_io_BytesIO_write, METH_O, _io_BytesIO_write__doc__}, |
441 | |
442 | PyDoc_STRVAR(_io_BytesIO_writelines__doc__, |
443 | "writelines($self, lines, /)\n" |
444 | "--\n" |
445 | "\n" |
446 | "Write lines to the file.\n" |
447 | "\n" |
448 | "Note that newlines are not added. lines can be any iterable object\n" |
449 | "producing bytes-like objects. This is equivalent to calling write() for\n" |
450 | "each element." ); |
451 | |
452 | #define _IO_BYTESIO_WRITELINES_METHODDEF \ |
453 | {"writelines", (PyCFunction)_io_BytesIO_writelines, METH_O, _io_BytesIO_writelines__doc__}, |
454 | |
455 | PyDoc_STRVAR(_io_BytesIO_close__doc__, |
456 | "close($self, /)\n" |
457 | "--\n" |
458 | "\n" |
459 | "Disable all I/O operations." ); |
460 | |
461 | #define _IO_BYTESIO_CLOSE_METHODDEF \ |
462 | {"close", (PyCFunction)_io_BytesIO_close, METH_NOARGS, _io_BytesIO_close__doc__}, |
463 | |
464 | static PyObject * |
465 | _io_BytesIO_close_impl(bytesio *self); |
466 | |
467 | static PyObject * |
468 | _io_BytesIO_close(bytesio *self, PyObject *Py_UNUSED(ignored)) |
469 | { |
470 | return _io_BytesIO_close_impl(self); |
471 | } |
472 | |
473 | PyDoc_STRVAR(_io_BytesIO___init____doc__, |
474 | "BytesIO(initial_bytes=b\'\')\n" |
475 | "--\n" |
476 | "\n" |
477 | "Buffered I/O implementation using an in-memory bytes buffer." ); |
478 | |
479 | static int |
480 | _io_BytesIO___init___impl(bytesio *self, PyObject *initvalue); |
481 | |
482 | static int |
483 | _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) |
484 | { |
485 | int return_value = -1; |
486 | static const char * const _keywords[] = {"initial_bytes" , NULL}; |
487 | static _PyArg_Parser _parser = {NULL, _keywords, "BytesIO" , 0}; |
488 | PyObject *argsbuf[1]; |
489 | PyObject * const *fastargs; |
490 | Py_ssize_t nargs = PyTuple_GET_SIZE(args); |
491 | Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0; |
492 | PyObject *initvalue = NULL; |
493 | |
494 | fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf); |
495 | if (!fastargs) { |
496 | goto exit; |
497 | } |
498 | if (!noptargs) { |
499 | goto skip_optional_pos; |
500 | } |
501 | initvalue = fastargs[0]; |
502 | skip_optional_pos: |
503 | return_value = _io_BytesIO___init___impl((bytesio *)self, initvalue); |
504 | |
505 | exit: |
506 | return return_value; |
507 | } |
508 | /*[clinic end generated code: output=49a32140eb8c5555 input=a9049054013a1b77]*/ |
509 | |