• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4 
5 PyDoc_STRVAR(_io_FileIO_close__doc__,
6 "close($self, /)\n"
7 "--\n"
8 "\n"
9 "Close the file.\n"
10 "\n"
11 "A closed file cannot be used for further I/O operations.  close() may be\n"
12 "called more than once without error.");
13 
14 #define _IO_FILEIO_CLOSE_METHODDEF    \
15     {"close", (PyCFunction)_io_FileIO_close, METH_NOARGS, _io_FileIO_close__doc__},
16 
17 static PyObject *
18 _io_FileIO_close_impl(fileio *self);
19 
20 static PyObject *
_io_FileIO_close(fileio * self,PyObject * Py_UNUSED (ignored))21 _io_FileIO_close(fileio *self, PyObject *Py_UNUSED(ignored))
22 {
23     return _io_FileIO_close_impl(self);
24 }
25 
26 PyDoc_STRVAR(_io_FileIO___init____doc__,
27 "FileIO(file, mode=\'r\', closefd=True, opener=None)\n"
28 "--\n"
29 "\n"
30 "Open a file.\n"
31 "\n"
32 "The mode can be \'r\' (default), \'w\', \'x\' or \'a\' for reading,\n"
33 "writing, exclusive creation or appending.  The file will be created if it\n"
34 "doesn\'t exist when opened for writing or appending; it will be truncated\n"
35 "when opened for writing.  A FileExistsError will be raised if it already\n"
36 "exists when opened for creating. Opening a file for creating implies\n"
37 "writing so this mode behaves in a similar way to \'w\'.Add a \'+\' to the mode\n"
38 "to allow simultaneous reading and writing. A custom opener can be used by\n"
39 "passing a callable as *opener*. The underlying file descriptor for the file\n"
40 "object is then obtained by calling opener with (*name*, *flags*).\n"
41 "*opener* must return an open file descriptor (passing os.open as *opener*\n"
42 "results in functionality similar to passing None).");
43 
44 static int
45 _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
46                          int closefd, PyObject *opener);
47 
48 static int
_io_FileIO___init__(PyObject * self,PyObject * args,PyObject * kwargs)49 _io_FileIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
50 {
51     int return_value = -1;
52     static const char * const _keywords[] = {"file", "mode", "closefd", "opener", NULL};
53     static _PyArg_Parser _parser = {"O|siO:FileIO", _keywords, 0};
54     PyObject *nameobj;
55     const char *mode = "r";
56     int closefd = 1;
57     PyObject *opener = Py_None;
58 
59     if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
60         &nameobj, &mode, &closefd, &opener)) {
61         goto exit;
62     }
63     return_value = _io_FileIO___init___impl((fileio *)self, nameobj, mode, closefd, opener);
64 
65 exit:
66     return return_value;
67 }
68 
69 PyDoc_STRVAR(_io_FileIO_fileno__doc__,
70 "fileno($self, /)\n"
71 "--\n"
72 "\n"
73 "Return the underlying file descriptor (an integer).");
74 
75 #define _IO_FILEIO_FILENO_METHODDEF    \
76     {"fileno", (PyCFunction)_io_FileIO_fileno, METH_NOARGS, _io_FileIO_fileno__doc__},
77 
78 static PyObject *
79 _io_FileIO_fileno_impl(fileio *self);
80 
81 static PyObject *
_io_FileIO_fileno(fileio * self,PyObject * Py_UNUSED (ignored))82 _io_FileIO_fileno(fileio *self, PyObject *Py_UNUSED(ignored))
83 {
84     return _io_FileIO_fileno_impl(self);
85 }
86 
87 PyDoc_STRVAR(_io_FileIO_readable__doc__,
88 "readable($self, /)\n"
89 "--\n"
90 "\n"
91 "True if file was opened in a read mode.");
92 
93 #define _IO_FILEIO_READABLE_METHODDEF    \
94     {"readable", (PyCFunction)_io_FileIO_readable, METH_NOARGS, _io_FileIO_readable__doc__},
95 
96 static PyObject *
97 _io_FileIO_readable_impl(fileio *self);
98 
99 static PyObject *
_io_FileIO_readable(fileio * self,PyObject * Py_UNUSED (ignored))100 _io_FileIO_readable(fileio *self, PyObject *Py_UNUSED(ignored))
101 {
102     return _io_FileIO_readable_impl(self);
103 }
104 
105 PyDoc_STRVAR(_io_FileIO_writable__doc__,
106 "writable($self, /)\n"
107 "--\n"
108 "\n"
109 "True if file was opened in a write mode.");
110 
111 #define _IO_FILEIO_WRITABLE_METHODDEF    \
112     {"writable", (PyCFunction)_io_FileIO_writable, METH_NOARGS, _io_FileIO_writable__doc__},
113 
114 static PyObject *
115 _io_FileIO_writable_impl(fileio *self);
116 
117 static PyObject *
_io_FileIO_writable(fileio * self,PyObject * Py_UNUSED (ignored))118 _io_FileIO_writable(fileio *self, PyObject *Py_UNUSED(ignored))
119 {
120     return _io_FileIO_writable_impl(self);
121 }
122 
123 PyDoc_STRVAR(_io_FileIO_seekable__doc__,
124 "seekable($self, /)\n"
125 "--\n"
126 "\n"
127 "True if file supports random-access.");
128 
129 #define _IO_FILEIO_SEEKABLE_METHODDEF    \
130     {"seekable", (PyCFunction)_io_FileIO_seekable, METH_NOARGS, _io_FileIO_seekable__doc__},
131 
132 static PyObject *
133 _io_FileIO_seekable_impl(fileio *self);
134 
135 static PyObject *
_io_FileIO_seekable(fileio * self,PyObject * Py_UNUSED (ignored))136 _io_FileIO_seekable(fileio *self, PyObject *Py_UNUSED(ignored))
137 {
138     return _io_FileIO_seekable_impl(self);
139 }
140 
141 PyDoc_STRVAR(_io_FileIO_readinto__doc__,
142 "readinto($self, buffer, /)\n"
143 "--\n"
144 "\n"
145 "Same as RawIOBase.readinto().");
146 
147 #define _IO_FILEIO_READINTO_METHODDEF    \
148     {"readinto", (PyCFunction)_io_FileIO_readinto, METH_O, _io_FileIO_readinto__doc__},
149 
150 static PyObject *
151 _io_FileIO_readinto_impl(fileio *self, Py_buffer *buffer);
152 
153 static PyObject *
_io_FileIO_readinto(fileio * self,PyObject * arg)154 _io_FileIO_readinto(fileio *self, PyObject *arg)
155 {
156     PyObject *return_value = NULL;
157     Py_buffer buffer = {NULL, NULL};
158 
159     if (!PyArg_Parse(arg, "w*:readinto", &buffer)) {
160         goto exit;
161     }
162     return_value = _io_FileIO_readinto_impl(self, &buffer);
163 
164 exit:
165     /* Cleanup for buffer */
166     if (buffer.obj) {
167        PyBuffer_Release(&buffer);
168     }
169 
170     return return_value;
171 }
172 
173 PyDoc_STRVAR(_io_FileIO_readall__doc__,
174 "readall($self, /)\n"
175 "--\n"
176 "\n"
177 "Read all data from the file, returned as bytes.\n"
178 "\n"
179 "In non-blocking mode, returns as much as is immediately available,\n"
180 "or None if no data is available.  Return an empty bytes object at EOF.");
181 
182 #define _IO_FILEIO_READALL_METHODDEF    \
183     {"readall", (PyCFunction)_io_FileIO_readall, METH_NOARGS, _io_FileIO_readall__doc__},
184 
185 static PyObject *
186 _io_FileIO_readall_impl(fileio *self);
187 
188 static PyObject *
_io_FileIO_readall(fileio * self,PyObject * Py_UNUSED (ignored))189 _io_FileIO_readall(fileio *self, PyObject *Py_UNUSED(ignored))
190 {
191     return _io_FileIO_readall_impl(self);
192 }
193 
194 PyDoc_STRVAR(_io_FileIO_read__doc__,
195 "read($self, size=-1, /)\n"
196 "--\n"
197 "\n"
198 "Read at most size bytes, returned as bytes.\n"
199 "\n"
200 "Only makes one system call, so less data may be returned than requested.\n"
201 "In non-blocking mode, returns None if no data is available.\n"
202 "Return an empty bytes object at EOF.");
203 
204 #define _IO_FILEIO_READ_METHODDEF    \
205     {"read", (PyCFunction)_io_FileIO_read, METH_FASTCALL, _io_FileIO_read__doc__},
206 
207 static PyObject *
208 _io_FileIO_read_impl(fileio *self, Py_ssize_t size);
209 
210 static PyObject *
_io_FileIO_read(fileio * self,PyObject * const * args,Py_ssize_t nargs)211 _io_FileIO_read(fileio *self, PyObject *const *args, Py_ssize_t nargs)
212 {
213     PyObject *return_value = NULL;
214     Py_ssize_t size = -1;
215 
216     if (!_PyArg_ParseStack(args, nargs, "|O&:read",
217         _Py_convert_optional_to_ssize_t, &size)) {
218         goto exit;
219     }
220     return_value = _io_FileIO_read_impl(self, size);
221 
222 exit:
223     return return_value;
224 }
225 
226 PyDoc_STRVAR(_io_FileIO_write__doc__,
227 "write($self, b, /)\n"
228 "--\n"
229 "\n"
230 "Write buffer b to file, return number of bytes written.\n"
231 "\n"
232 "Only makes one system call, so not all of the data may be written.\n"
233 "The number of bytes actually written is returned.  In non-blocking mode,\n"
234 "returns None if the write would block.");
235 
236 #define _IO_FILEIO_WRITE_METHODDEF    \
237     {"write", (PyCFunction)_io_FileIO_write, METH_O, _io_FileIO_write__doc__},
238 
239 static PyObject *
240 _io_FileIO_write_impl(fileio *self, Py_buffer *b);
241 
242 static PyObject *
_io_FileIO_write(fileio * self,PyObject * arg)243 _io_FileIO_write(fileio *self, PyObject *arg)
244 {
245     PyObject *return_value = NULL;
246     Py_buffer b = {NULL, NULL};
247 
248     if (!PyArg_Parse(arg, "y*:write", &b)) {
249         goto exit;
250     }
251     return_value = _io_FileIO_write_impl(self, &b);
252 
253 exit:
254     /* Cleanup for b */
255     if (b.obj) {
256        PyBuffer_Release(&b);
257     }
258 
259     return return_value;
260 }
261 
262 PyDoc_STRVAR(_io_FileIO_seek__doc__,
263 "seek($self, pos, whence=0, /)\n"
264 "--\n"
265 "\n"
266 "Move to new file position and return the file position.\n"
267 "\n"
268 "Argument offset is a byte count.  Optional argument whence defaults to\n"
269 "SEEK_SET or 0 (offset from start of file, offset should be >= 0); other values\n"
270 "are SEEK_CUR or 1 (move relative to current position, positive or negative),\n"
271 "and SEEK_END or 2 (move relative to end of file, usually negative, although\n"
272 "many platforms allow seeking beyond the end of a file).\n"
273 "\n"
274 "Note that not all file objects are seekable.");
275 
276 #define _IO_FILEIO_SEEK_METHODDEF    \
277     {"seek", (PyCFunction)_io_FileIO_seek, METH_FASTCALL, _io_FileIO_seek__doc__},
278 
279 static PyObject *
280 _io_FileIO_seek_impl(fileio *self, PyObject *pos, int whence);
281 
282 static PyObject *
_io_FileIO_seek(fileio * self,PyObject * const * args,Py_ssize_t nargs)283 _io_FileIO_seek(fileio *self, PyObject *const *args, Py_ssize_t nargs)
284 {
285     PyObject *return_value = NULL;
286     PyObject *pos;
287     int whence = 0;
288 
289     if (!_PyArg_ParseStack(args, nargs, "O|i:seek",
290         &pos, &whence)) {
291         goto exit;
292     }
293     return_value = _io_FileIO_seek_impl(self, pos, whence);
294 
295 exit:
296     return return_value;
297 }
298 
299 PyDoc_STRVAR(_io_FileIO_tell__doc__,
300 "tell($self, /)\n"
301 "--\n"
302 "\n"
303 "Current file position.\n"
304 "\n"
305 "Can raise OSError for non seekable files.");
306 
307 #define _IO_FILEIO_TELL_METHODDEF    \
308     {"tell", (PyCFunction)_io_FileIO_tell, METH_NOARGS, _io_FileIO_tell__doc__},
309 
310 static PyObject *
311 _io_FileIO_tell_impl(fileio *self);
312 
313 static PyObject *
_io_FileIO_tell(fileio * self,PyObject * Py_UNUSED (ignored))314 _io_FileIO_tell(fileio *self, PyObject *Py_UNUSED(ignored))
315 {
316     return _io_FileIO_tell_impl(self);
317 }
318 
319 #if defined(HAVE_FTRUNCATE)
320 
321 PyDoc_STRVAR(_io_FileIO_truncate__doc__,
322 "truncate($self, size=None, /)\n"
323 "--\n"
324 "\n"
325 "Truncate the file to at most size bytes and return the truncated size.\n"
326 "\n"
327 "Size defaults to the current file position, as returned by tell().\n"
328 "The current file position is changed to the value of size.");
329 
330 #define _IO_FILEIO_TRUNCATE_METHODDEF    \
331     {"truncate", (PyCFunction)_io_FileIO_truncate, METH_FASTCALL, _io_FileIO_truncate__doc__},
332 
333 static PyObject *
334 _io_FileIO_truncate_impl(fileio *self, PyObject *posobj);
335 
336 static PyObject *
_io_FileIO_truncate(fileio * self,PyObject * const * args,Py_ssize_t nargs)337 _io_FileIO_truncate(fileio *self, PyObject *const *args, Py_ssize_t nargs)
338 {
339     PyObject *return_value = NULL;
340     PyObject *posobj = NULL;
341 
342     if (!_PyArg_UnpackStack(args, nargs, "truncate",
343         0, 1,
344         &posobj)) {
345         goto exit;
346     }
347     return_value = _io_FileIO_truncate_impl(self, posobj);
348 
349 exit:
350     return return_value;
351 }
352 
353 #endif /* defined(HAVE_FTRUNCATE) */
354 
355 PyDoc_STRVAR(_io_FileIO_isatty__doc__,
356 "isatty($self, /)\n"
357 "--\n"
358 "\n"
359 "True if the file is connected to a TTY device.");
360 
361 #define _IO_FILEIO_ISATTY_METHODDEF    \
362     {"isatty", (PyCFunction)_io_FileIO_isatty, METH_NOARGS, _io_FileIO_isatty__doc__},
363 
364 static PyObject *
365 _io_FileIO_isatty_impl(fileio *self);
366 
367 static PyObject *
_io_FileIO_isatty(fileio * self,PyObject * Py_UNUSED (ignored))368 _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
369 {
370     return _io_FileIO_isatty_impl(self);
371 }
372 
373 #ifndef _IO_FILEIO_TRUNCATE_METHODDEF
374     #define _IO_FILEIO_TRUNCATE_METHODDEF
375 #endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
376 /*[clinic end generated code: output=a8796438c8b7c49a input=a9049054013a1b77]*/
377