Home | History | Annotate | Download | only in clinic
      1 /*[clinic input]
      2 preserve
      3 [clinic start generated code]*/
      4 
      5 PyDoc_STRVAR(_io_BytesIO_readable__doc__,
      6 "readable($self, /)\n"
      7 "--\n"
      8 "\n"
      9 "Returns True if the IO object can be read.");
     10 
     11 #define _IO_BYTESIO_READABLE_METHODDEF    \
     12     {"readable", (PyCFunction)_io_BytesIO_readable, METH_NOARGS, _io_BytesIO_readable__doc__},
     13 
     14 static PyObject *
     15 _io_BytesIO_readable_impl(bytesio *self);
     16 
     17 static PyObject *
     18 _io_BytesIO_readable(bytesio *self, PyObject *Py_UNUSED(ignored))
     19 {
     20     return _io_BytesIO_readable_impl(self);
     21 }
     22 
     23 PyDoc_STRVAR(_io_BytesIO_writable__doc__,
     24 "writable($self, /)\n"
     25 "--\n"
     26 "\n"
     27 "Returns True if the IO object can be written.");
     28 
     29 #define _IO_BYTESIO_WRITABLE_METHODDEF    \
     30     {"writable", (PyCFunction)_io_BytesIO_writable, METH_NOARGS, _io_BytesIO_writable__doc__},
     31 
     32 static PyObject *
     33 _io_BytesIO_writable_impl(bytesio *self);
     34 
     35 static PyObject *
     36 _io_BytesIO_writable(bytesio *self, PyObject *Py_UNUSED(ignored))
     37 {
     38     return _io_BytesIO_writable_impl(self);
     39 }
     40 
     41 PyDoc_STRVAR(_io_BytesIO_seekable__doc__,
     42 "seekable($self, /)\n"
     43 "--\n"
     44 "\n"
     45 "Returns True if the IO object can be seeked.");
     46 
     47 #define _IO_BYTESIO_SEEKABLE_METHODDEF    \
     48     {"seekable", (PyCFunction)_io_BytesIO_seekable, METH_NOARGS, _io_BytesIO_seekable__doc__},
     49 
     50 static PyObject *
     51 _io_BytesIO_seekable_impl(bytesio *self);
     52 
     53 static PyObject *
     54 _io_BytesIO_seekable(bytesio *self, PyObject *Py_UNUSED(ignored))
     55 {
     56     return _io_BytesIO_seekable_impl(self);
     57 }
     58 
     59 PyDoc_STRVAR(_io_BytesIO_flush__doc__,
     60 "flush($self, /)\n"
     61 "--\n"
     62 "\n"
     63 "Does nothing.");
     64 
     65 #define _IO_BYTESIO_FLUSH_METHODDEF    \
     66     {"flush", (PyCFunction)_io_BytesIO_flush, METH_NOARGS, _io_BytesIO_flush__doc__},
     67 
     68 static PyObject *
     69 _io_BytesIO_flush_impl(bytesio *self);
     70 
     71 static PyObject *
     72 _io_BytesIO_flush(bytesio *self, PyObject *Py_UNUSED(ignored))
     73 {
     74     return _io_BytesIO_flush_impl(self);
     75 }
     76 
     77 PyDoc_STRVAR(_io_BytesIO_getbuffer__doc__,
     78 "getbuffer($self, /)\n"
     79 "--\n"
     80 "\n"
     81 "Get a read-write view over the contents of the BytesIO object.");
     82 
     83 #define _IO_BYTESIO_GETBUFFER_METHODDEF    \
     84     {"getbuffer", (PyCFunction)_io_BytesIO_getbuffer, METH_NOARGS, _io_BytesIO_getbuffer__doc__},
     85 
     86 static PyObject *
     87 _io_BytesIO_getbuffer_impl(bytesio *self);
     88 
     89 static PyObject *
     90 _io_BytesIO_getbuffer(bytesio *self, PyObject *Py_UNUSED(ignored))
     91 {
     92     return _io_BytesIO_getbuffer_impl(self);
     93 }
     94 
     95 PyDoc_STRVAR(_io_BytesIO_getvalue__doc__,
     96 "getvalue($self, /)\n"
     97 "--\n"
     98 "\n"
     99 "Retrieve the entire contents of the BytesIO object.");
    100 
    101 #define _IO_BYTESIO_GETVALUE_METHODDEF    \
    102     {"getvalue", (PyCFunction)_io_BytesIO_getvalue, METH_NOARGS, _io_BytesIO_getvalue__doc__},
    103 
    104 static PyObject *
    105 _io_BytesIO_getvalue_impl(bytesio *self);
    106 
    107 static PyObject *
    108 _io_BytesIO_getvalue(bytesio *self, PyObject *Py_UNUSED(ignored))
    109 {
    110     return _io_BytesIO_getvalue_impl(self);
    111 }
    112 
    113 PyDoc_STRVAR(_io_BytesIO_isatty__doc__,
    114 "isatty($self, /)\n"
    115 "--\n"
    116 "\n"
    117 "Always returns False.\n"
    118 "\n"
    119 "BytesIO objects are not connected to a TTY-like device.");
    120 
    121 #define _IO_BYTESIO_ISATTY_METHODDEF    \
    122     {"isatty", (PyCFunction)_io_BytesIO_isatty, METH_NOARGS, _io_BytesIO_isatty__doc__},
    123 
    124 static PyObject *
    125 _io_BytesIO_isatty_impl(bytesio *self);
    126 
    127 static PyObject *
    128 _io_BytesIO_isatty(bytesio *self, PyObject *Py_UNUSED(ignored))
    129 {
    130     return _io_BytesIO_isatty_impl(self);
    131 }
    132 
    133 PyDoc_STRVAR(_io_BytesIO_tell__doc__,
    134 "tell($self, /)\n"
    135 "--\n"
    136 "\n"
    137 "Current file position, an integer.");
    138 
    139 #define _IO_BYTESIO_TELL_METHODDEF    \
    140     {"tell", (PyCFunction)_io_BytesIO_tell, METH_NOARGS, _io_BytesIO_tell__doc__},
    141 
    142 static PyObject *
    143 _io_BytesIO_tell_impl(bytesio *self);
    144 
    145 static PyObject *
    146 _io_BytesIO_tell(bytesio *self, PyObject *Py_UNUSED(ignored))
    147 {
    148     return _io_BytesIO_tell_impl(self);
    149 }
    150 
    151 PyDoc_STRVAR(_io_BytesIO_read__doc__,
    152 "read($self, size=None, /)\n"
    153 "--\n"
    154 "\n"
    155 "Read at most size bytes, returned as a bytes object.\n"
    156 "\n"
    157 "If the size argument is negative, read until EOF is reached.\n"
    158 "Return an empty bytes object at EOF.");
    159 
    160 #define _IO_BYTESIO_READ_METHODDEF    \
    161     {"read", (PyCFunction)_io_BytesIO_read, METH_VARARGS, _io_BytesIO_read__doc__},
    162 
    163 static PyObject *
    164 _io_BytesIO_read_impl(bytesio *self, PyObject *arg);
    165 
    166 static PyObject *
    167 _io_BytesIO_read(bytesio *self, PyObject *args)
    168 {
    169     PyObject *return_value = NULL;
    170     PyObject *arg = Py_None;
    171 
    172     if (!PyArg_UnpackTuple(args, "read",
    173         0, 1,
    174         &arg)) {
    175         goto exit;
    176     }
    177     return_value = _io_BytesIO_read_impl(self, arg);
    178 
    179 exit:
    180     return return_value;
    181 }
    182 
    183 PyDoc_STRVAR(_io_BytesIO_read1__doc__,
    184 "read1($self, size, /)\n"
    185 "--\n"
    186 "\n"
    187 "Read at most size bytes, returned as a bytes object.\n"
    188 "\n"
    189 "If the size argument is negative or omitted, read until EOF is reached.\n"
    190 "Return an empty bytes object at EOF.");
    191 
    192 #define _IO_BYTESIO_READ1_METHODDEF    \
    193     {"read1", (PyCFunction)_io_BytesIO_read1, METH_O, _io_BytesIO_read1__doc__},
    194 
    195 PyDoc_STRVAR(_io_BytesIO_readline__doc__,
    196 "readline($self, size=None, /)\n"
    197 "--\n"
    198 "\n"
    199 "Next line from the file, as a bytes object.\n"
    200 "\n"
    201 "Retain newline.  A non-negative size argument limits the maximum\n"
    202 "number of bytes to return (an incomplete line may be returned then).\n"
    203 "Return an empty bytes object at EOF.");
    204 
    205 #define _IO_BYTESIO_READLINE_METHODDEF    \
    206     {"readline", (PyCFunction)_io_BytesIO_readline, METH_VARARGS, _io_BytesIO_readline__doc__},
    207 
    208 static PyObject *
    209 _io_BytesIO_readline_impl(bytesio *self, PyObject *arg);
    210 
    211 static PyObject *
    212 _io_BytesIO_readline(bytesio *self, PyObject *args)
    213 {
    214     PyObject *return_value = NULL;
    215     PyObject *arg = Py_None;
    216 
    217     if (!PyArg_UnpackTuple(args, "readline",
    218         0, 1,
    219         &arg)) {
    220         goto exit;
    221     }
    222     return_value = _io_BytesIO_readline_impl(self, arg);
    223 
    224 exit:
    225     return return_value;
    226 }
    227 
    228 PyDoc_STRVAR(_io_BytesIO_readlines__doc__,
    229 "readlines($self, size=None, /)\n"
    230 "--\n"
    231 "\n"
    232 "List of bytes objects, each a line from the file.\n"
    233 "\n"
    234 "Call readline() repeatedly and return a list of the lines so read.\n"
    235 "The optional size argument, if given, is an approximate bound on the\n"
    236 "total number of bytes in the lines returned.");
    237 
    238 #define _IO_BYTESIO_READLINES_METHODDEF    \
    239     {"readlines", (PyCFunction)_io_BytesIO_readlines, METH_VARARGS, _io_BytesIO_readlines__doc__},
    240 
    241 static PyObject *
    242 _io_BytesIO_readlines_impl(bytesio *self, PyObject *arg);
    243 
    244 static PyObject *
    245 _io_BytesIO_readlines(bytesio *self, PyObject *args)
    246 {
    247     PyObject *return_value = NULL;
    248     PyObject *arg = Py_None;
    249 
    250     if (!PyArg_UnpackTuple(args, "readlines",
    251         0, 1,
    252         &arg)) {
    253         goto exit;
    254     }
    255     return_value = _io_BytesIO_readlines_impl(self, arg);
    256 
    257 exit:
    258     return return_value;
    259 }
    260 
    261 PyDoc_STRVAR(_io_BytesIO_readinto__doc__,
    262 "readinto($self, buffer, /)\n"
    263 "--\n"
    264 "\n"
    265 "Read bytes into buffer.\n"
    266 "\n"
    267 "Returns number of bytes read (0 for EOF), or None if the object\n"
    268 "is set not to block and has no data to read.");
    269 
    270 #define _IO_BYTESIO_READINTO_METHODDEF    \
    271     {"readinto", (PyCFunction)_io_BytesIO_readinto, METH_O, _io_BytesIO_readinto__doc__},
    272 
    273 static PyObject *
    274 _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer);
    275 
    276 static PyObject *
    277 _io_BytesIO_readinto(bytesio *self, PyObject *arg)
    278 {
    279     PyObject *return_value = NULL;
    280     Py_buffer buffer = {NULL, NULL};
    281 
    282     if (!PyArg_Parse(arg, "w*:readinto", &buffer)) {
    283         goto exit;
    284     }
    285     return_value = _io_BytesIO_readinto_impl(self, &buffer);
    286 
    287 exit:
    288     /* Cleanup for buffer */
    289     if (buffer.obj) {
    290        PyBuffer_Release(&buffer);
    291     }
    292 
    293     return return_value;
    294 }
    295 
    296 PyDoc_STRVAR(_io_BytesIO_truncate__doc__,
    297 "truncate($self, size=None, /)\n"
    298 "--\n"
    299 "\n"
    300 "Truncate the file to at most size bytes.\n"
    301 "\n"
    302 "Size defaults to the current file position, as returned by tell().\n"
    303 "The current file position is unchanged.  Returns the new size.");
    304 
    305 #define _IO_BYTESIO_TRUNCATE_METHODDEF    \
    306     {"truncate", (PyCFunction)_io_BytesIO_truncate, METH_VARARGS, _io_BytesIO_truncate__doc__},
    307 
    308 static PyObject *
    309 _io_BytesIO_truncate_impl(bytesio *self, PyObject *arg);
    310 
    311 static PyObject *
    312 _io_BytesIO_truncate(bytesio *self, PyObject *args)
    313 {
    314     PyObject *return_value = NULL;
    315     PyObject *arg = Py_None;
    316 
    317     if (!PyArg_UnpackTuple(args, "truncate",
    318         0, 1,
    319         &arg)) {
    320         goto exit;
    321     }
    322     return_value = _io_BytesIO_truncate_impl(self, arg);
    323 
    324 exit:
    325     return return_value;
    326 }
    327 
    328 PyDoc_STRVAR(_io_BytesIO_seek__doc__,
    329 "seek($self, pos, whence=0, /)\n"
    330 "--\n"
    331 "\n"
    332 "Change stream position.\n"
    333 "\n"
    334 "Seek to byte offset pos relative to position indicated by whence:\n"
    335 "     0  Start of stream (the default).  pos should be >= 0;\n"
    336 "     1  Current position - pos may be negative;\n"
    337 "     2  End of stream - pos usually negative.\n"
    338 "Returns the new absolute position.");
    339 
    340 #define _IO_BYTESIO_SEEK_METHODDEF    \
    341     {"seek", (PyCFunction)_io_BytesIO_seek, METH_VARARGS, _io_BytesIO_seek__doc__},
    342 
    343 static PyObject *
    344 _io_BytesIO_seek_impl(bytesio *self, Py_ssize_t pos, int whence);
    345 
    346 static PyObject *
    347 _io_BytesIO_seek(bytesio *self, PyObject *args)
    348 {
    349     PyObject *return_value = NULL;
    350     Py_ssize_t pos;
    351     int whence = 0;
    352 
    353     if (!PyArg_ParseTuple(args, "n|i:seek",
    354         &pos, &whence)) {
    355         goto exit;
    356     }
    357     return_value = _io_BytesIO_seek_impl(self, pos, whence);
    358 
    359 exit:
    360     return return_value;
    361 }
    362 
    363 PyDoc_STRVAR(_io_BytesIO_write__doc__,
    364 "write($self, b, /)\n"
    365 "--\n"
    366 "\n"
    367 "Write bytes to file.\n"
    368 "\n"
    369 "Return the number of bytes written.");
    370 
    371 #define _IO_BYTESIO_WRITE_METHODDEF    \
    372     {"write", (PyCFunction)_io_BytesIO_write, METH_O, _io_BytesIO_write__doc__},
    373 
    374 PyDoc_STRVAR(_io_BytesIO_writelines__doc__,
    375 "writelines($self, lines, /)\n"
    376 "--\n"
    377 "\n"
    378 "Write lines to the file.\n"
    379 "\n"
    380 "Note that newlines are not added.  lines can be any iterable object\n"
    381 "producing bytes-like objects. This is equivalent to calling write() for\n"
    382 "each element.");
    383 
    384 #define _IO_BYTESIO_WRITELINES_METHODDEF    \
    385     {"writelines", (PyCFunction)_io_BytesIO_writelines, METH_O, _io_BytesIO_writelines__doc__},
    386 
    387 PyDoc_STRVAR(_io_BytesIO_close__doc__,
    388 "close($self, /)\n"
    389 "--\n"
    390 "\n"
    391 "Disable all I/O operations.");
    392 
    393 #define _IO_BYTESIO_CLOSE_METHODDEF    \
    394     {"close", (PyCFunction)_io_BytesIO_close, METH_NOARGS, _io_BytesIO_close__doc__},
    395 
    396 static PyObject *
    397 _io_BytesIO_close_impl(bytesio *self);
    398 
    399 static PyObject *
    400 _io_BytesIO_close(bytesio *self, PyObject *Py_UNUSED(ignored))
    401 {
    402     return _io_BytesIO_close_impl(self);
    403 }
    404 
    405 PyDoc_STRVAR(_io_BytesIO___init____doc__,
    406 "BytesIO(initial_bytes=b\'\')\n"
    407 "--\n"
    408 "\n"
    409 "Buffered I/O implementation using an in-memory bytes buffer.");
    410 
    411 static int
    412 _io_BytesIO___init___impl(bytesio *self, PyObject *initvalue);
    413 
    414 static int
    415 _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
    416 {
    417     int return_value = -1;
    418     static const char * const _keywords[] = {"initial_bytes", NULL};
    419     static _PyArg_Parser _parser = {"|O:BytesIO", _keywords, 0};
    420     PyObject *initvalue = NULL;
    421 
    422     if (!_PyArg_ParseTupleAndKeywordsFast(args, kwargs, &_parser,
    423         &initvalue)) {
    424         goto exit;
    425     }
    426     return_value = _io_BytesIO___init___impl((bytesio *)self, initvalue);
    427 
    428 exit:
    429     return return_value;
    430 }
    431 /*[clinic end generated code: output=6382e8eb578eea64 input=a9049054013a1b77]*/
    432