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