| 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 |
{ |
| 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, |
| 60 |
/*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 61 |
if (!args) { |
| 62 |
goto exit; |
| 63 |
} |
| 64 |
offset = PyLong_AsInt(args[0]); |
| 65 |
if (offset == -1 && PyErr_Occurred()) { |
| 66 |
goto exit; |
| 67 |
} |
| 68 |
if (nargs < 2) { |
| 69 |
goto skip_optional_posonly; |
| 70 |
} |
| 71 |
whence = PyLong_AsInt(args[1]); |
| 72 |
if (whence == -1 && PyErr_Occurred()) { |
| 73 |
goto exit; |
| 74 |
} |
| 75 |
skip_optional_posonly: |
| 76 |
return_value = _io__IOBase_seek_impl(self, cls, offset, whence); |
| 77 |
|
| 78 |
exit: |
| 79 |
return return_value; |
| 80 |
} |
| 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 |
{ |
| 97 |
return _io__IOBase_tell_impl(self); |
| 98 |
} |
| 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 |
{ |
| 119 |
PyObject *return_value = NULL; |
| 120 |
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) |
| 121 |
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty) |
| 122 |
#else |
| 123 |
# define KWTUPLE NULL |
| 124 |
#endif |
| 125 |
|
| 126 |
static const char * const _keywords[] = {"", NULL}; |
| 127 |
static _PyArg_Parser _parser = { |
| 128 |
.keywords = _keywords, |
| 129 |
.fname = "truncate", |
| 130 |
.kwtuple = KWTUPLE, |
| 131 |
}; |
| 132 |
#undef KWTUPLE |
| 133 |
PyObject *argsbuf[1]; |
| 134 |
PyObject *size = Py_None; |
| 135 |
|
| 136 |
args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, |
| 137 |
/*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf); |
| 138 |
if (!args) { |
| 139 |
goto exit; |
| 140 |
} |
| 141 |
if (nargs < 1) { |
| 142 |
goto skip_optional_posonly; |
| 143 |
} |
| 144 |
size = args[0]; |
| 145 |
skip_optional_posonly: |
| 146 |
return_value = _io__IOBase_truncate_impl(self, cls, size); |
| 147 |
|
| 148 |
exit: |
| 149 |
return return_value; |
| 150 |
} |
| 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 |
{ |
| 169 |
return _io__IOBase_flush_impl(self); |
| 170 |
} |
| 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 |
{ |
| 189 |
return _io__IOBase_close_impl(self); |
| 190 |
} |
| 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 |
{ |
| 210 |
return _io__IOBase_seekable_impl(self); |
| 211 |
} |
| 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 |
{ |
| 230 |
return _io__IOBase_readable_impl(self); |
| 231 |
} |
| 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 |
{ |
| 250 |
return _io__IOBase_writable_impl(self); |
| 251 |
} |
| 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 |
{ |
| 270 |
if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) { |
| 271 |
PyErr_SetString(PyExc_TypeError, "fileno() takes no arguments"); |
| 272 |
return NULL; |
| 273 |
} |
| 274 |
return _io__IOBase_fileno_impl(self, cls); |
| 275 |
} |
| 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 |
{ |
| 294 |
return _io__IOBase_isatty_impl(self); |
| 295 |
} |
| 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 |
{ |
| 318 |
PyObject *return_value = NULL; |
| 319 |
Py_ssize_t limit = -1; |
| 320 |
|
| 321 |
if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) { |
| 322 |
goto exit; |
| 323 |
} |
| 324 |
if (nargs < 1) { |
| 325 |
goto skip_optional; |
| 326 |
} |
| 327 |
if (!_Py_convert_optional_to_ssize_t(args[0], &limit)) { |
| 328 |
goto exit; |
| 329 |
} |
| 330 |
skip_optional: |
| 331 |
return_value = _io__IOBase_readline_impl(self, limit); |
| 332 |
|
| 333 |
exit: |
| 334 |
return return_value; |
| 335 |
} |
| 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 |
{ |
| 356 |
PyObject *return_value = NULL; |
| 357 |
Py_ssize_t hint = -1; |
| 358 |
|
| 359 |
if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) { |
| 360 |
goto exit; |
| 361 |
} |
| 362 |
if (nargs < 1) { |
| 363 |
goto skip_optional; |
| 364 |
} |
| 365 |
if (!_Py_convert_optional_to_ssize_t(args[0], &hint)) { |
| 366 |
goto exit; |
| 367 |
} |
| 368 |
skip_optional: |
| 369 |
return_value = _io__IOBase_readlines_impl(self, hint); |
| 370 |
|
| 371 |
exit: |
| 372 |
return return_value; |
| 373 |
} |
| 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 |
{ |
| 401 |
PyObject *return_value = NULL; |
| 402 |
Py_ssize_t n = -1; |
| 403 |
|
| 404 |
if (!_PyArg_CheckPositional("read", nargs, 0, 1)) { |
| 405 |
goto exit; |
| 406 |
} |
| 407 |
if (nargs < 1) { |
| 408 |
goto skip_optional; |
| 409 |
} |
| 410 |
{ |
| 411 |
Py_ssize_t ival = -1; |
| 412 |
PyObject *iobj = _PyNumber_Index(args[0]); |
| 413 |
if (iobj != NULL) { |
| 414 |
ival = PyLong_AsSsize_t(iobj); |
| 415 |
Py_DECREF(iobj); |
| 416 |
} |
| 417 |
if (ival == -1 && PyErr_Occurred()) { |
| 418 |
goto exit; |
| 419 |
} |
| 420 |
n = ival; |
| 421 |
} |
| 422 |
skip_optional: |
| 423 |
return_value = _io__RawIOBase_read_impl(self, n); |
| 424 |
|
| 425 |
exit: |
| 426 |
return return_value; |
| 427 |
} |
| 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 |
{ |
| 444 |
return _io__RawIOBase_readall_impl(self); |
| 445 |
} |
| 446 |
/*[clinic end generated code: output=9359e74d95534bef input=a9049054013a1b77]*/ |