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