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