/src/cpython/Modules/_io/clinic/iobase.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_runtime.h" // _Py_SINGLETON() |
7 | | #endif |
8 | | #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() |
9 | | #include "pycore_modsupport.h" // _PyArg_UnpackKeywords() |
10 | | |
11 | | PyDoc_STRVAR(_io__IOBase_seek__doc__, |
12 | | "seek($self, offset, whence=os.SEEK_SET, /)\n" |
13 | | "--\n" |
14 | | "\n" |
15 | | "Change the stream position to the given byte offset.\n" |
16 | | "\n" |
17 | | " offset\n" |
18 | | " The stream position, relative to \'whence\'.\n" |
19 | | " whence\n" |
20 | | " The relative position to seek from.\n" |
21 | | "\n" |
22 | | "The offset is interpreted relative to the position indicated by whence.\n" |
23 | | "Values for whence are:\n" |
24 | | "\n" |
25 | | "* os.SEEK_SET or 0 -- start of stream (the default); offset should be zero or positive\n" |
26 | | "* os.SEEK_CUR or 1 -- current stream position; offset may be negative\n" |
27 | | "* os.SEEK_END or 2 -- end of stream; offset is usually negative\n" |
28 | | "\n" |
29 | | "Return the new absolute position."); |
30 | | |
31 | | #define _IO__IOBASE_SEEK_METHODDEF \ |
32 | | {"seek", _PyCFunction_CAST(_io__IOBase_seek), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__IOBase_seek__doc__}, |
33 | | |
34 | | static PyObject * |
35 | | _io__IOBase_seek_impl(PyObject *self, PyTypeObject *cls, |
36 | | int Py_UNUSED(offset), int Py_UNUSED(whence)); |
37 | | |
38 | | static PyObject * |
39 | | _io__IOBase_seek(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
40 | 0 | { |
41 | 0 | PyObject *return_value = NULL; |
42 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
43 | 0 | # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
44 | | #else |
45 | | # define KWTUPLE NULL |
46 | | #endif |
47 | |
|
48 | 0 | static const char * const _keywords[] = {"", "", NULL}; |
49 | 0 | static _PyArg_Parser _parser = { |
50 | 0 | .keywords = _keywords, |
51 | 0 | .fname = "seek", |
52 | 0 | .kwtuple = KWTUPLE, |
53 | 0 | }; |
54 | 0 | #undef KWTUPLE |
55 | 0 | PyObject *argsbuf[2]; |
56 | 0 | int offset; |
57 | 0 | int whence = 0; |
58 | |
|
59 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
60 | 0 | /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
61 | 0 | if (!args) { |
62 | 0 | goto exit; |
63 | 0 | } |
64 | 0 | offset = PyLong_AsInt(args[0]); |
65 | 0 | if (offset == -1 && PyErr_Occurred()) { |
66 | 0 | goto exit; |
67 | 0 | } |
68 | 0 | if (nargs < 2) { |
69 | 0 | goto skip_optional_posonly; |
70 | 0 | } |
71 | 0 | whence = PyLong_AsInt(args[1]); |
72 | 0 | if (whence == -1 && PyErr_Occurred()) { |
73 | 0 | goto exit; |
74 | 0 | } |
75 | 0 | skip_optional_posonly: |
76 | 0 | return_value = _io__IOBase_seek_impl(self, cls, offset, whence); |
77 | |
|
78 | 0 | exit: |
79 | 0 | return return_value; |
80 | 0 | } |
81 | | |
82 | | PyDoc_STRVAR(_io__IOBase_tell__doc__, |
83 | | "tell($self, /)\n" |
84 | | "--\n" |
85 | | "\n" |
86 | | "Return current stream position."); |
87 | | |
88 | | #define _IO__IOBASE_TELL_METHODDEF \ |
89 | | {"tell", (PyCFunction)_io__IOBase_tell, METH_NOARGS, _io__IOBase_tell__doc__}, |
90 | | |
91 | | static PyObject * |
92 | | _io__IOBase_tell_impl(PyObject *self); |
93 | | |
94 | | static PyObject * |
95 | | _io__IOBase_tell(PyObject *self, PyObject *Py_UNUSED(ignored)) |
96 | 0 | { |
97 | 0 | return _io__IOBase_tell_impl(self); |
98 | 0 | } |
99 | | |
100 | | PyDoc_STRVAR(_io__IOBase_truncate__doc__, |
101 | | "truncate($self, size=None, /)\n" |
102 | | "--\n" |
103 | | "\n" |
104 | | "Truncate file to size bytes.\n" |
105 | | "\n" |
106 | | "File pointer is left unchanged. Size defaults to the current IO position\n" |
107 | | "as reported by tell(). Return the new size."); |
108 | | |
109 | | #define _IO__IOBASE_TRUNCATE_METHODDEF \ |
110 | | {"truncate", _PyCFunction_CAST(_io__IOBase_truncate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__IOBase_truncate__doc__}, |
111 | | |
112 | | static PyObject * |
113 | | _io__IOBase_truncate_impl(PyObject *self, PyTypeObject *cls, |
114 | | PyObject *Py_UNUSED(size)); |
115 | | |
116 | | static PyObject * |
117 | | _io__IOBase_truncate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
118 | 0 | { |
119 | 0 | PyObject *return_value = NULL; |
120 | 0 | #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
121 | 0 | # define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
122 | | #else |
123 | | # define KWTUPLE NULL |
124 | | #endif |
125 | |
|
126 | 0 | static const char * const _keywords[] = {"", NULL}; |
127 | 0 | static _PyArg_Parser _parser = { |
128 | 0 | .keywords = _keywords, |
129 | 0 | .fname = "truncate", |
130 | 0 | .kwtuple = KWTUPLE, |
131 | 0 | }; |
132 | 0 | #undef KWTUPLE |
133 | 0 | PyObject *argsbuf[1]; |
134 | 0 | PyObject *size = Py_None; |
135 | |
|
136 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
137 | 0 | /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
138 | 0 | if (!args) { |
139 | 0 | goto exit; |
140 | 0 | } |
141 | 0 | if (nargs < 1) { |
142 | 0 | goto skip_optional_posonly; |
143 | 0 | } |
144 | 0 | size = args[0]; |
145 | 0 | skip_optional_posonly: |
146 | 0 | return_value = _io__IOBase_truncate_impl(self, cls, size); |
147 | |
|
148 | 0 | exit: |
149 | 0 | return return_value; |
150 | 0 | } |
151 | | |
152 | | PyDoc_STRVAR(_io__IOBase_flush__doc__, |
153 | | "flush($self, /)\n" |
154 | | "--\n" |
155 | | "\n" |
156 | | "Flush write buffers, if applicable.\n" |
157 | | "\n" |
158 | | "This is not implemented for read-only and non-blocking streams."); |
159 | | |
160 | | #define _IO__IOBASE_FLUSH_METHODDEF \ |
161 | | {"flush", (PyCFunction)_io__IOBase_flush, METH_NOARGS, _io__IOBase_flush__doc__}, |
162 | | |
163 | | static PyObject * |
164 | | _io__IOBase_flush_impl(PyObject *self); |
165 | | |
166 | | static PyObject * |
167 | | _io__IOBase_flush(PyObject *self, PyObject *Py_UNUSED(ignored)) |
168 | 9.79k | { |
169 | 9.79k | return _io__IOBase_flush_impl(self); |
170 | 9.79k | } |
171 | | |
172 | | PyDoc_STRVAR(_io__IOBase_close__doc__, |
173 | | "close($self, /)\n" |
174 | | "--\n" |
175 | | "\n" |
176 | | "Flush and close the IO object.\n" |
177 | | "\n" |
178 | | "This method has no effect if the file is already closed."); |
179 | | |
180 | | #define _IO__IOBASE_CLOSE_METHODDEF \ |
181 | | {"close", (PyCFunction)_io__IOBase_close, METH_NOARGS, _io__IOBase_close__doc__}, |
182 | | |
183 | | static PyObject * |
184 | | _io__IOBase_close_impl(PyObject *self); |
185 | | |
186 | | static PyObject * |
187 | | _io__IOBase_close(PyObject *self, PyObject *Py_UNUSED(ignored)) |
188 | 8.84k | { |
189 | 8.84k | return _io__IOBase_close_impl(self); |
190 | 8.84k | } |
191 | | |
192 | | PyDoc_STRVAR(_io__IOBase_seekable__doc__, |
193 | | "seekable($self, /)\n" |
194 | | "--\n" |
195 | | "\n" |
196 | | "Return whether object supports random access.\n" |
197 | | "\n" |
198 | | "If False, seek(), tell() and truncate() will raise OSError.\n" |
199 | | "This method may need to do a test seek()."); |
200 | | |
201 | | #define _IO__IOBASE_SEEKABLE_METHODDEF \ |
202 | | {"seekable", (PyCFunction)_io__IOBase_seekable, METH_NOARGS, _io__IOBase_seekable__doc__}, |
203 | | |
204 | | static PyObject * |
205 | | _io__IOBase_seekable_impl(PyObject *self); |
206 | | |
207 | | static PyObject * |
208 | | _io__IOBase_seekable(PyObject *self, PyObject *Py_UNUSED(ignored)) |
209 | 0 | { |
210 | 0 | return _io__IOBase_seekable_impl(self); |
211 | 0 | } |
212 | | |
213 | | PyDoc_STRVAR(_io__IOBase_readable__doc__, |
214 | | "readable($self, /)\n" |
215 | | "--\n" |
216 | | "\n" |
217 | | "Return whether object was opened for reading.\n" |
218 | | "\n" |
219 | | "If False, read() will raise OSError."); |
220 | | |
221 | | #define _IO__IOBASE_READABLE_METHODDEF \ |
222 | | {"readable", (PyCFunction)_io__IOBase_readable, METH_NOARGS, _io__IOBase_readable__doc__}, |
223 | | |
224 | | static PyObject * |
225 | | _io__IOBase_readable_impl(PyObject *self); |
226 | | |
227 | | static PyObject * |
228 | | _io__IOBase_readable(PyObject *self, PyObject *Py_UNUSED(ignored)) |
229 | 32 | { |
230 | 32 | return _io__IOBase_readable_impl(self); |
231 | 32 | } |
232 | | |
233 | | PyDoc_STRVAR(_io__IOBase_writable__doc__, |
234 | | "writable($self, /)\n" |
235 | | "--\n" |
236 | | "\n" |
237 | | "Return whether object was opened for writing.\n" |
238 | | "\n" |
239 | | "If False, write() will raise OSError."); |
240 | | |
241 | | #define _IO__IOBASE_WRITABLE_METHODDEF \ |
242 | | {"writable", (PyCFunction)_io__IOBase_writable, METH_NOARGS, _io__IOBase_writable__doc__}, |
243 | | |
244 | | static PyObject * |
245 | | _io__IOBase_writable_impl(PyObject *self); |
246 | | |
247 | | static PyObject * |
248 | | _io__IOBase_writable(PyObject *self, PyObject *Py_UNUSED(ignored)) |
249 | 16 | { |
250 | 16 | return _io__IOBase_writable_impl(self); |
251 | 16 | } |
252 | | |
253 | | PyDoc_STRVAR(_io__IOBase_fileno__doc__, |
254 | | "fileno($self, /)\n" |
255 | | "--\n" |
256 | | "\n" |
257 | | "Return underlying file descriptor if one exists.\n" |
258 | | "\n" |
259 | | "Raise OSError if the IO object does not use a file descriptor."); |
260 | | |
261 | | #define _IO__IOBASE_FILENO_METHODDEF \ |
262 | | {"fileno", _PyCFunction_CAST(_io__IOBase_fileno), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__IOBase_fileno__doc__}, |
263 | | |
264 | | static PyObject * |
265 | | _io__IOBase_fileno_impl(PyObject *self, PyTypeObject *cls); |
266 | | |
267 | | static PyObject * |
268 | | _io__IOBase_fileno(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
269 | 0 | { |
270 | 0 | if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
271 | 0 | PyErr_SetString(PyExc_TypeError, "fileno() takes no arguments"); |
272 | 0 | return NULL; |
273 | 0 | } |
274 | 0 | return _io__IOBase_fileno_impl(self, cls); |
275 | 0 | } |
276 | | |
277 | | PyDoc_STRVAR(_io__IOBase_isatty__doc__, |
278 | | "isatty($self, /)\n" |
279 | | "--\n" |
280 | | "\n" |
281 | | "Return whether this is an \'interactive\' stream.\n" |
282 | | "\n" |
283 | | "Return False if it can\'t be determined."); |
284 | | |
285 | | #define _IO__IOBASE_ISATTY_METHODDEF \ |
286 | | {"isatty", (PyCFunction)_io__IOBase_isatty, METH_NOARGS, _io__IOBase_isatty__doc__}, |
287 | | |
288 | | static PyObject * |
289 | | _io__IOBase_isatty_impl(PyObject *self); |
290 | | |
291 | | static PyObject * |
292 | | _io__IOBase_isatty(PyObject *self, PyObject *Py_UNUSED(ignored)) |
293 | 0 | { |
294 | 0 | return _io__IOBase_isatty_impl(self); |
295 | 0 | } |
296 | | |
297 | | PyDoc_STRVAR(_io__IOBase_readline__doc__, |
298 | | "readline($self, size=-1, /)\n" |
299 | | "--\n" |
300 | | "\n" |
301 | | "Read and return a line from the stream.\n" |
302 | | "\n" |
303 | | "If size is specified, at most size bytes will be read.\n" |
304 | | "\n" |
305 | | "The line terminator is always b\'\\n\' for binary files; for text\n" |
306 | | "files, the newlines argument to open can be used to select the line\n" |
307 | | "terminator(s) recognized."); |
308 | | |
309 | | #define _IO__IOBASE_READLINE_METHODDEF \ |
310 | | {"readline", _PyCFunction_CAST(_io__IOBase_readline), METH_FASTCALL, _io__IOBase_readline__doc__}, |
311 | | |
312 | | static PyObject * |
313 | | _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit); |
314 | | |
315 | | static PyObject * |
316 | | _io__IOBase_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
317 | 0 | { |
318 | 0 | PyObject *return_value = NULL; |
319 | 0 | Py_ssize_t limit = -1; |
320 | |
|
321 | 0 | if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { |
322 | 0 | goto exit; |
323 | 0 | } |
324 | 0 | if (nargs < 1) { |
325 | 0 | goto skip_optional; |
326 | 0 | } |
327 | 0 | if (!_Py_convert_optional_to_ssize_t(args[0], &limit)) { |
328 | 0 | goto exit; |
329 | 0 | } |
330 | 0 | skip_optional: |
331 | 0 | return_value = _io__IOBase_readline_impl(self, limit); |
332 | |
|
333 | 0 | exit: |
334 | 0 | return return_value; |
335 | 0 | } |
336 | | |
337 | | PyDoc_STRVAR(_io__IOBase_readlines__doc__, |
338 | | "readlines($self, hint=-1, /)\n" |
339 | | "--\n" |
340 | | "\n" |
341 | | "Return a list of lines from the stream.\n" |
342 | | "\n" |
343 | | "hint can be specified to control the number of lines read: no more\n" |
344 | | "lines will be read if the total size (in bytes/characters) of all\n" |
345 | | "lines so far exceeds hint."); |
346 | | |
347 | | #define _IO__IOBASE_READLINES_METHODDEF \ |
348 | | {"readlines", _PyCFunction_CAST(_io__IOBase_readlines), METH_FASTCALL, _io__IOBase_readlines__doc__}, |
349 | | |
350 | | static PyObject * |
351 | | _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint); |
352 | | |
353 | | static PyObject * |
354 | | _io__IOBase_readlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
355 | 34.7k | { |
356 | 34.7k | PyObject *return_value = NULL; |
357 | 34.7k | Py_ssize_t hint = -1; |
358 | | |
359 | 34.7k | if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) { |
360 | 0 | goto exit; |
361 | 0 | } |
362 | 34.7k | if (nargs < 1) { |
363 | 34.7k | goto skip_optional; |
364 | 34.7k | } |
365 | 0 | if (!_Py_convert_optional_to_ssize_t(args[0], &hint)) { |
366 | 0 | goto exit; |
367 | 0 | } |
368 | 34.7k | skip_optional: |
369 | 34.7k | return_value = _io__IOBase_readlines_impl(self, hint); |
370 | | |
371 | 34.7k | exit: |
372 | 34.7k | return return_value; |
373 | 34.7k | } |
374 | | |
375 | | PyDoc_STRVAR(_io__IOBase_writelines__doc__, |
376 | | "writelines($self, lines, /)\n" |
377 | | "--\n" |
378 | | "\n" |
379 | | "Write a list of lines to stream.\n" |
380 | | "\n" |
381 | | "Line separators are not added, so it is usual for each of the\n" |
382 | | "lines provided to have a line separator at the end."); |
383 | | |
384 | | #define _IO__IOBASE_WRITELINES_METHODDEF \ |
385 | | {"writelines", (PyCFunction)_io__IOBase_writelines, METH_O, _io__IOBase_writelines__doc__}, |
386 | | |
387 | | PyDoc_STRVAR(_io__RawIOBase_read__doc__, |
388 | | "read($self, size=-1, /)\n" |
389 | | "--\n" |
390 | | "\n"); |
391 | | |
392 | | #define _IO__RAWIOBASE_READ_METHODDEF \ |
393 | | {"read", _PyCFunction_CAST(_io__RawIOBase_read), METH_FASTCALL, _io__RawIOBase_read__doc__}, |
394 | | |
395 | | static PyObject * |
396 | | _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n); |
397 | | |
398 | | static PyObject * |
399 | | _io__RawIOBase_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
400 | 0 | { |
401 | 0 | PyObject *return_value = NULL; |
402 | 0 | Py_ssize_t n = -1; |
403 | |
|
404 | 0 | if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { |
405 | 0 | goto exit; |
406 | 0 | } |
407 | 0 | if (nargs < 1) { |
408 | 0 | goto skip_optional; |
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 | n = ival; |
421 | 0 | } |
422 | 0 | skip_optional: |
423 | 0 | return_value = _io__RawIOBase_read_impl(self, n); |
424 | |
|
425 | 0 | exit: |
426 | 0 | return return_value; |
427 | 0 | } |
428 | | |
429 | | PyDoc_STRVAR(_io__RawIOBase_readall__doc__, |
430 | | "readall($self, /)\n" |
431 | | "--\n" |
432 | | "\n" |
433 | | "Read until EOF, using multiple read() call."); |
434 | | |
435 | | #define _IO__RAWIOBASE_READALL_METHODDEF \ |
436 | | {"readall", (PyCFunction)_io__RawIOBase_readall, METH_NOARGS, _io__RawIOBase_readall__doc__}, |
437 | | |
438 | | static PyObject * |
439 | | _io__RawIOBase_readall_impl(PyObject *self); |
440 | | |
441 | | static PyObject * |
442 | | _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored)) |
443 | 0 | { |
444 | 0 | return _io__RawIOBase_readall_impl(self); |
445 | 0 | } |
446 | | /*[clinic end generated code: output=9359e74d95534bef input=a9049054013a1b77]*/ |