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