Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Modules/_io/clinic/stringio.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_StringIO_getvalue__doc__,
6
"getvalue($self, /)\n"
7
"--\n"
8
"\n"
9
"Retrieve the entire contents of the object.");
10
11
#define _IO_STRINGIO_GETVALUE_METHODDEF    \
12
    {"getvalue", (PyCFunction)_io_StringIO_getvalue, METH_NOARGS, _io_StringIO_getvalue__doc__},
13
14
static PyObject *
15
_io_StringIO_getvalue_impl(stringio *self);
16
17
static PyObject *
18
_io_StringIO_getvalue(stringio *self, PyObject *Py_UNUSED(ignored))
19
14
{
20
14
    return _io_StringIO_getvalue_impl(self);
21
14
}
22
23
PyDoc_STRVAR(_io_StringIO_tell__doc__,
24
"tell($self, /)\n"
25
"--\n"
26
"\n"
27
"Tell the current file position.");
28
29
#define _IO_STRINGIO_TELL_METHODDEF    \
30
    {"tell", (PyCFunction)_io_StringIO_tell, METH_NOARGS, _io_StringIO_tell__doc__},
31
32
static PyObject *
33
_io_StringIO_tell_impl(stringio *self);
34
35
static PyObject *
36
_io_StringIO_tell(stringio *self, PyObject *Py_UNUSED(ignored))
37
0
{
38
0
    return _io_StringIO_tell_impl(self);
39
0
}
40
41
PyDoc_STRVAR(_io_StringIO_read__doc__,
42
"read($self, size=-1, /)\n"
43
"--\n"
44
"\n"
45
"Read at most size characters, returned as a string.\n"
46
"\n"
47
"If the argument is negative or omitted, read until EOF\n"
48
"is reached. Return an empty string at EOF.");
49
50
#define _IO_STRINGIO_READ_METHODDEF    \
51
    {"read", (PyCFunction)(void(*)(void))_io_StringIO_read, METH_FASTCALL, _io_StringIO_read__doc__},
52
53
static PyObject *
54
_io_StringIO_read_impl(stringio *self, Py_ssize_t size);
55
56
static PyObject *
57
_io_StringIO_read(stringio *self, PyObject *const *args, Py_ssize_t nargs)
58
0
{
59
0
    PyObject *return_value = NULL;
60
0
    Py_ssize_t size = -1;
61
62
0
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
63
0
        goto exit;
64
0
    }
65
0
    if (nargs < 1) {
66
0
        goto skip_optional;
67
0
    }
68
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
69
0
        goto exit;
70
0
    }
71
0
skip_optional:
72
0
    return_value = _io_StringIO_read_impl(self, size);
73
74
0
exit:
75
0
    return return_value;
76
0
}
77
78
PyDoc_STRVAR(_io_StringIO_readline__doc__,
79
"readline($self, size=-1, /)\n"
80
"--\n"
81
"\n"
82
"Read until newline or EOF.\n"
83
"\n"
84
"Returns an empty string if EOF is hit immediately.");
85
86
#define _IO_STRINGIO_READLINE_METHODDEF    \
87
    {"readline", (PyCFunction)(void(*)(void))_io_StringIO_readline, METH_FASTCALL, _io_StringIO_readline__doc__},
88
89
static PyObject *
90
_io_StringIO_readline_impl(stringio *self, Py_ssize_t size);
91
92
static PyObject *
93
_io_StringIO_readline(stringio *self, PyObject *const *args, Py_ssize_t nargs)
94
0
{
95
0
    PyObject *return_value = NULL;
96
0
    Py_ssize_t size = -1;
97
98
0
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
99
0
        goto exit;
100
0
    }
101
0
    if (nargs < 1) {
102
0
        goto skip_optional;
103
0
    }
104
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
105
0
        goto exit;
106
0
    }
107
0
skip_optional:
108
0
    return_value = _io_StringIO_readline_impl(self, size);
109
110
0
exit:
111
0
    return return_value;
112
0
}
113
114
PyDoc_STRVAR(_io_StringIO_truncate__doc__,
115
"truncate($self, pos=None, /)\n"
116
"--\n"
117
"\n"
118
"Truncate size to pos.\n"
119
"\n"
120
"The pos argument defaults to the current file position, as\n"
121
"returned by tell().  The current file position is unchanged.\n"
122
"Returns the new absolute position.");
123
124
#define _IO_STRINGIO_TRUNCATE_METHODDEF    \
125
    {"truncate", (PyCFunction)(void(*)(void))_io_StringIO_truncate, METH_FASTCALL, _io_StringIO_truncate__doc__},
126
127
static PyObject *
128
_io_StringIO_truncate_impl(stringio *self, Py_ssize_t size);
129
130
static PyObject *
131
_io_StringIO_truncate(stringio *self, PyObject *const *args, Py_ssize_t nargs)
132
0
{
133
0
    PyObject *return_value = NULL;
134
0
    Py_ssize_t size = self->pos;
135
136
0
    if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
137
0
        goto exit;
138
0
    }
139
0
    if (nargs < 1) {
140
0
        goto skip_optional;
141
0
    }
142
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
143
0
        goto exit;
144
0
    }
145
0
skip_optional:
146
0
    return_value = _io_StringIO_truncate_impl(self, size);
147
148
0
exit:
149
0
    return return_value;
150
0
}
151
152
PyDoc_STRVAR(_io_StringIO_seek__doc__,
153
"seek($self, pos, whence=0, /)\n"
154
"--\n"
155
"\n"
156
"Change stream position.\n"
157
"\n"
158
"Seek to character offset pos relative to position indicated by whence:\n"
159
"    0  Start of stream (the default).  pos should be >= 0;\n"
160
"    1  Current position - pos must be 0;\n"
161
"    2  End of stream - pos must be 0.\n"
162
"Returns the new absolute position.");
163
164
#define _IO_STRINGIO_SEEK_METHODDEF    \
165
    {"seek", (PyCFunction)(void(*)(void))_io_StringIO_seek, METH_FASTCALL, _io_StringIO_seek__doc__},
166
167
static PyObject *
168
_io_StringIO_seek_impl(stringio *self, Py_ssize_t pos, int whence);
169
170
static PyObject *
171
_io_StringIO_seek(stringio *self, PyObject *const *args, Py_ssize_t nargs)
172
0
{
173
0
    PyObject *return_value = NULL;
174
0
    Py_ssize_t pos;
175
0
    int whence = 0;
176
177
0
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
178
0
        goto exit;
179
0
    }
180
0
    if (PyFloat_Check(args[0])) {
181
0
        PyErr_SetString(PyExc_TypeError,
182
0
                        "integer argument expected, got float" );
183
0
        goto exit;
184
0
    }
185
0
    {
186
0
        Py_ssize_t ival = -1;
187
0
        PyObject *iobj = PyNumber_Index(args[0]);
188
0
        if (iobj != NULL) {
189
0
            ival = PyLong_AsSsize_t(iobj);
190
0
            Py_DECREF(iobj);
191
0
        }
192
0
        if (ival == -1 && PyErr_Occurred()) {
193
0
            goto exit;
194
0
        }
195
0
        pos = ival;
196
0
    }
197
0
    if (nargs < 2) {
198
0
        goto skip_optional;
199
0
    }
200
0
    if (PyFloat_Check(args[1])) {
201
0
        PyErr_SetString(PyExc_TypeError,
202
0
                        "integer argument expected, got float" );
203
0
        goto exit;
204
0
    }
205
0
    whence = _PyLong_AsInt(args[1]);
206
0
    if (whence == -1 && PyErr_Occurred()) {
207
0
        goto exit;
208
0
    }
209
0
skip_optional:
210
0
    return_value = _io_StringIO_seek_impl(self, pos, whence);
211
212
0
exit:
213
0
    return return_value;
214
0
}
215
216
PyDoc_STRVAR(_io_StringIO_write__doc__,
217
"write($self, s, /)\n"
218
"--\n"
219
"\n"
220
"Write string to file.\n"
221
"\n"
222
"Returns the number of characters written, which is always equal to\n"
223
"the length of the string.");
224
225
#define _IO_STRINGIO_WRITE_METHODDEF    \
226
    {"write", (PyCFunction)_io_StringIO_write, METH_O, _io_StringIO_write__doc__},
227
228
PyDoc_STRVAR(_io_StringIO_close__doc__,
229
"close($self, /)\n"
230
"--\n"
231
"\n"
232
"Close the IO object.\n"
233
"\n"
234
"Attempting any further operation after the object is closed\n"
235
"will raise a ValueError.\n"
236
"\n"
237
"This method has no effect if the file is already closed.");
238
239
#define _IO_STRINGIO_CLOSE_METHODDEF    \
240
    {"close", (PyCFunction)_io_StringIO_close, METH_NOARGS, _io_StringIO_close__doc__},
241
242
static PyObject *
243
_io_StringIO_close_impl(stringio *self);
244
245
static PyObject *
246
_io_StringIO_close(stringio *self, PyObject *Py_UNUSED(ignored))
247
14
{
248
14
    return _io_StringIO_close_impl(self);
249
14
}
250
251
PyDoc_STRVAR(_io_StringIO___init____doc__,
252
"StringIO(initial_value=\'\', newline=\'\\n\')\n"
253
"--\n"
254
"\n"
255
"Text I/O implementation using an in-memory buffer.\n"
256
"\n"
257
"The initial_value argument sets the value of object.  The newline\n"
258
"argument is like the one of TextIOWrapper\'s constructor.");
259
260
static int
261
_io_StringIO___init___impl(stringio *self, PyObject *value,
262
                           PyObject *newline_obj);
263
264
static int
265
_io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
266
14
{
267
14
    int return_value = -1;
268
14
    static const char * const _keywords[] = {"initial_value", "newline", NULL};
269
14
    static _PyArg_Parser _parser = {NULL, _keywords, "StringIO", 0};
270
14
    PyObject *argsbuf[2];
271
14
    PyObject * const *fastargs;
272
14
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
273
14
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
274
14
    PyObject *value = NULL;
275
14
    PyObject *newline_obj = NULL;
276
277
14
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 2, 0, argsbuf);
278
14
    if (!fastargs) {
279
0
        goto exit;
280
0
    }
281
14
    if (!noptargs) {
282
14
        goto skip_optional_pos;
283
14
    }
284
0
    if (fastargs[0]) {
285
0
        value = fastargs[0];
286
0
        if (!--noptargs) {
287
0
            goto skip_optional_pos;
288
0
        }
289
0
    }
290
0
    newline_obj = fastargs[1];
291
14
skip_optional_pos:
292
14
    return_value = _io_StringIO___init___impl((stringio *)self, value, newline_obj);
293
294
14
exit:
295
14
    return return_value;
296
14
}
297
298
PyDoc_STRVAR(_io_StringIO_readable__doc__,
299
"readable($self, /)\n"
300
"--\n"
301
"\n"
302
"Returns True if the IO object can be read.");
303
304
#define _IO_STRINGIO_READABLE_METHODDEF    \
305
    {"readable", (PyCFunction)_io_StringIO_readable, METH_NOARGS, _io_StringIO_readable__doc__},
306
307
static PyObject *
308
_io_StringIO_readable_impl(stringio *self);
309
310
static PyObject *
311
_io_StringIO_readable(stringio *self, PyObject *Py_UNUSED(ignored))
312
0
{
313
0
    return _io_StringIO_readable_impl(self);
314
0
}
315
316
PyDoc_STRVAR(_io_StringIO_writable__doc__,
317
"writable($self, /)\n"
318
"--\n"
319
"\n"
320
"Returns True if the IO object can be written.");
321
322
#define _IO_STRINGIO_WRITABLE_METHODDEF    \
323
    {"writable", (PyCFunction)_io_StringIO_writable, METH_NOARGS, _io_StringIO_writable__doc__},
324
325
static PyObject *
326
_io_StringIO_writable_impl(stringio *self);
327
328
static PyObject *
329
_io_StringIO_writable(stringio *self, PyObject *Py_UNUSED(ignored))
330
0
{
331
0
    return _io_StringIO_writable_impl(self);
332
0
}
333
334
PyDoc_STRVAR(_io_StringIO_seekable__doc__,
335
"seekable($self, /)\n"
336
"--\n"
337
"\n"
338
"Returns True if the IO object can be seeked.");
339
340
#define _IO_STRINGIO_SEEKABLE_METHODDEF    \
341
    {"seekable", (PyCFunction)_io_StringIO_seekable, METH_NOARGS, _io_StringIO_seekable__doc__},
342
343
static PyObject *
344
_io_StringIO_seekable_impl(stringio *self);
345
346
static PyObject *
347
_io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
348
0
{
349
0
    return _io_StringIO_seekable_impl(self);
350
0
}
351
/*[clinic end generated code: output=7aad5ab2e64a25b8 input=a9049054013a1b77]*/