iobase.c.h 12 KB

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