Debian Codegraph @

Modules/_io/clinic/iobase.c.h

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