Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/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
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
0
{
20
0
    return _io_BytesIO_readable_impl(self);
21
0
}
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
0
{
38
0
    return _io_BytesIO_writable_impl(self);
39
0
}
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
0
{
56
0
    return _io_BytesIO_seekable_impl(self);
57
0
}
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
0
{
74
0
    return _io_BytesIO_flush_impl(self);
75
0
}
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
0
{
92
0
    return _io_BytesIO_getbuffer_impl(self);
93
0
}
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
0
{
110
0
    return _io_BytesIO_getvalue_impl(self);
111
0
}
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
0
{
130
0
    return _io_BytesIO_isatty_impl(self);
131
0
}
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
0
{
148
0
    return _io_BytesIO_tell_impl(self);
149
0
}
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
0
{
169
0
    PyObject *return_value = NULL;
170
0
    Py_ssize_t size = -1;
171
172
0
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
173
0
        goto exit;
174
0
    }
175
0
    if (nargs < 1) {
176
0
        goto skip_optional;
177
0
    }
178
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
179
0
        goto exit;
180
0
    }
181
0
skip_optional:
182
0
    return_value = _io_BytesIO_read_impl(self, size);
183
184
0
exit:
185
0
    return return_value;
186
0
}
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
0
{
206
0
    PyObject *return_value = NULL;
207
0
    Py_ssize_t size = -1;
208
209
0
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
210
0
        goto exit;
211
0
    }
212
0
    if (nargs < 1) {
213
0
        goto skip_optional;
214
0
    }
215
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
216
0
        goto exit;
217
0
    }
218
0
skip_optional:
219
0
    return_value = _io_BytesIO_read1_impl(self, size);
220
221
0
exit:
222
0
    return return_value;
223
0
}
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
0
{
244
0
    PyObject *return_value = NULL;
245
0
    Py_ssize_t size = -1;
246
247
0
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
248
0
        goto exit;
249
0
    }
250
0
    if (nargs < 1) {
251
0
        goto skip_optional;
252
0
    }
253
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
254
0
        goto exit;
255
0
    }
256
0
skip_optional:
257
0
    return_value = _io_BytesIO_readline_impl(self, size);
258
259
0
exit:
260
0
    return return_value;
261
0
}
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
0
{
282
0
    PyObject *return_value = NULL;
283
0
    PyObject *arg = Py_None;
284
285
0
    if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) {
286
0
        goto exit;
287
0
    }
288
0
    if (nargs < 1) {
289
0
        goto skip_optional;
290
0
    }
291
0
    arg = args[0];
292
0
skip_optional:
293
0
    return_value = _io_BytesIO_readlines_impl(self, arg);
294
295
0
exit:
296
0
    return return_value;
297
0
}
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
0
{
317
0
    PyObject *return_value = NULL;
318
0
    Py_buffer buffer = {NULL, NULL};
319
320
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
321
0
        PyErr_Clear();
322
0
        _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
323
0
        goto exit;
324
0
    }
325
0
    if (!PyBuffer_IsContiguous(&buffer, 'C')) {
326
0
        _PyArg_BadArgument("readinto", "argument", "contiguous buffer", arg);
327
0
        goto exit;
328
0
    }
329
0
    return_value = _io_BytesIO_readinto_impl(self, &buffer);
330
331
0
exit:
332
    /* Cleanup for buffer */
333
0
    if (buffer.obj) {
334
0
       PyBuffer_Release(&buffer);
335
0
    }
336
337
0
    return return_value;
338
0
}
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
0
{
358
0
    PyObject *return_value = NULL;
359
0
    Py_ssize_t size = self->pos;
360
361
0
    if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
362
0
        goto exit;
363
0
    }
364
0
    if (nargs < 1) {
365
0
        goto skip_optional;
366
0
    }
367
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
368
0
        goto exit;
369
0
    }
370
0
skip_optional:
371
0
    return_value = _io_BytesIO_truncate_impl(self, size);
372
373
0
exit:
374
0
    return return_value;
375
0
}
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
0
{
398
0
    PyObject *return_value = NULL;
399
0
    Py_ssize_t pos;
400
0
    int whence = 0;
401
402
0
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
403
0
        goto exit;
404
0
    }
405
0
    if (PyFloat_Check(args[0])) {
406
0
        PyErr_SetString(PyExc_TypeError,
407
0
                        "integer argument expected, got float" );
408
0
        goto exit;
409
0
    }
410
0
    {
411
0
        Py_ssize_t ival = -1;
412
0
        PyObject *iobj = PyNumber_Index(args[0]);
413
0
        if (iobj != NULL) {
414
0
            ival = PyLong_AsSsize_t(iobj);
415
0
            Py_DECREF(iobj);
416
0
        }
417
0
        if (ival == -1 && PyErr_Occurred()) {
418
0
            goto exit;
419
0
        }
420
0
        pos = ival;
421
0
    }
422
0
    if (nargs < 2) {
423
0
        goto skip_optional;
424
0
    }
425
0
    if (PyFloat_Check(args[1])) {
426
0
        PyErr_SetString(PyExc_TypeError,
427
0
                        "integer argument expected, got float" );
428
0
        goto exit;
429
0
    }
430
0
    whence = _PyLong_AsInt(args[1]);
431
0
    if (whence == -1 && PyErr_Occurred()) {
432
0
        goto exit;
433
0
    }
434
0
skip_optional:
435
0
    return_value = _io_BytesIO_seek_impl(self, pos, whence);
436
437
0
exit:
438
0
    return return_value;
439
0
}
440
441
PyDoc_STRVAR(_io_BytesIO_write__doc__,
442
"write($self, b, /)\n"
443
"--\n"
444
"\n"
445
"Write bytes to file.\n"
446
"\n"
447
"Return the number of bytes written.");
448
449
#define _IO_BYTESIO_WRITE_METHODDEF    \
450
    {"write", (PyCFunction)_io_BytesIO_write, METH_O, _io_BytesIO_write__doc__},
451
452
PyDoc_STRVAR(_io_BytesIO_writelines__doc__,
453
"writelines($self, lines, /)\n"
454
"--\n"
455
"\n"
456
"Write lines to the file.\n"
457
"\n"
458
"Note that newlines are not added.  lines can be any iterable object\n"
459
"producing bytes-like objects. This is equivalent to calling write() for\n"
460
"each element.");
461
462
#define _IO_BYTESIO_WRITELINES_METHODDEF    \
463
    {"writelines", (PyCFunction)_io_BytesIO_writelines, METH_O, _io_BytesIO_writelines__doc__},
464
465
PyDoc_STRVAR(_io_BytesIO_close__doc__,
466
"close($self, /)\n"
467
"--\n"
468
"\n"
469
"Disable all I/O operations.");
470
471
#define _IO_BYTESIO_CLOSE_METHODDEF    \
472
    {"close", (PyCFunction)_io_BytesIO_close, METH_NOARGS, _io_BytesIO_close__doc__},
473
474
static PyObject *
475
_io_BytesIO_close_impl(bytesio *self);
476
477
static PyObject *
478
_io_BytesIO_close(bytesio *self, PyObject *Py_UNUSED(ignored))
479
0
{
480
0
    return _io_BytesIO_close_impl(self);
481
0
}
482
483
PyDoc_STRVAR(_io_BytesIO___init____doc__,
484
"BytesIO(initial_bytes=b\'\')\n"
485
"--\n"
486
"\n"
487
"Buffered I/O implementation using an in-memory bytes buffer.");
488
489
static int
490
_io_BytesIO___init___impl(bytesio *self, PyObject *initvalue);
491
492
static int
493
_io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
494
0
{
495
0
    int return_value = -1;
496
0
    static const char * const _keywords[] = {"initial_bytes", NULL};
497
0
    static _PyArg_Parser _parser = {NULL, _keywords, "BytesIO", 0};
498
0
    PyObject *argsbuf[1];
499
0
    PyObject * const *fastargs;
500
0
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
501
0
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
502
0
    PyObject *initvalue = NULL;
503
504
0
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 1, 0, argsbuf);
505
0
    if (!fastargs) {
506
0
        goto exit;
507
0
    }
508
0
    if (!noptargs) {
509
0
        goto skip_optional_pos;
510
0
    }
511
0
    initvalue = fastargs[0];
512
0
skip_optional_pos:
513
0
    return_value = _io_BytesIO___init___impl((bytesio *)self, initvalue);
514
515
0
exit:
516
0
    return return_value;
517
0
}
518
/*[clinic end generated code: output=4ec2506def9c8eb9 input=a9049054013a1b77]*/