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