mirror of
https://github.com/python/cpython.git
synced 2024-12-12 03:04:15 +08:00
gh-101819: Adapt _io.IOBase.seek and _io.IOBase.truncate to Argument Clinic (#104384)
This commit is contained in:
parent
ed41124bb5
commit
e629ab6adf
102
Modules/_io/clinic/iobase.c.h
generated
102
Modules/_io/clinic/iobase.c.h
generated
@ -8,6 +8,59 @@ preserve
|
||||
#endif
|
||||
|
||||
|
||||
PyDoc_STRVAR(_io__IOBase_seek__doc__,
|
||||
"seek($self, /, *args)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Change the stream position to the given byte offset.\n"
|
||||
"\n"
|
||||
"The offset is interpreted relative to the position indicated by whence.\n"
|
||||
"Values for whence are:\n"
|
||||
"\n"
|
||||
"* 0 -- start of stream (the default); offset should be zero or positive\n"
|
||||
"* 1 -- current stream position; offset may be negative\n"
|
||||
"* 2 -- end of stream; offset is usually negative\n"
|
||||
"\n"
|
||||
"Return the new absolute position.");
|
||||
|
||||
#define _IO__IOBASE_SEEK_METHODDEF \
|
||||
{"seek", _PyCFunction_CAST(_io__IOBase_seek), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__IOBase_seek__doc__},
|
||||
|
||||
static PyObject *
|
||||
_io__IOBase_seek_impl(PyObject *self, PyTypeObject *cls, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
_io__IOBase_seek(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
|
||||
#else
|
||||
# define KWTUPLE NULL
|
||||
#endif
|
||||
|
||||
static const char * const _keywords[] = { NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "seek",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
PyObject *__clinic_args = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
__clinic_args = args[0];
|
||||
return_value = _io__IOBase_seek_impl(self, cls, __clinic_args);
|
||||
|
||||
exit:
|
||||
Py_XDECREF(__clinic_args);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_io__IOBase_tell__doc__,
|
||||
"tell($self, /)\n"
|
||||
"--\n"
|
||||
@ -26,6 +79,53 @@ _io__IOBase_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
return _io__IOBase_tell_impl(self);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_io__IOBase_truncate__doc__,
|
||||
"truncate($self, /, *args)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Truncate file to size bytes.\n"
|
||||
"\n"
|
||||
"File pointer is left unchanged. Size defaults to the current IO position\n"
|
||||
"as reported by tell(). Return the new size.");
|
||||
|
||||
#define _IO__IOBASE_TRUNCATE_METHODDEF \
|
||||
{"truncate", _PyCFunction_CAST(_io__IOBase_truncate), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io__IOBase_truncate__doc__},
|
||||
|
||||
static PyObject *
|
||||
_io__IOBase_truncate_impl(PyObject *self, PyTypeObject *cls, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
_io__IOBase_truncate(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
|
||||
# define KWTUPLE (PyObject *)&_Py_SINGLETON(tuple_empty)
|
||||
#else
|
||||
# define KWTUPLE NULL
|
||||
#endif
|
||||
|
||||
static const char * const _keywords[] = { NULL};
|
||||
static _PyArg_Parser _parser = {
|
||||
.keywords = _keywords,
|
||||
.fname = "truncate",
|
||||
.kwtuple = KWTUPLE,
|
||||
};
|
||||
#undef KWTUPLE
|
||||
PyObject *argsbuf[1];
|
||||
PyObject *__clinic_args = NULL;
|
||||
|
||||
args = _PyArg_UnpackKeywordsWithVararg(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, 0, argsbuf);
|
||||
if (!args) {
|
||||
goto exit;
|
||||
}
|
||||
__clinic_args = args[0];
|
||||
return_value = _io__IOBase_truncate_impl(self, cls, __clinic_args);
|
||||
|
||||
exit:
|
||||
Py_XDECREF(__clinic_args);
|
||||
return return_value;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(_io__IOBase_flush__doc__,
|
||||
"flush($self, /)\n"
|
||||
"--\n"
|
||||
@ -316,4 +416,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return _io__RawIOBase_readall_impl(self);
|
||||
}
|
||||
/*[clinic end generated code: output=b7246a2087eb966b input=a9049054013a1b77]*/
|
||||
/*[clinic end generated code: output=b6d4845254da1da2 input=a9049054013a1b77]*/
|
||||
|
@ -79,21 +79,27 @@ iobase_unsupported(_PyIO_State *state, const char *message)
|
||||
|
||||
/* Positioning */
|
||||
|
||||
PyDoc_STRVAR(iobase_seek_doc,
|
||||
"Change stream position.\n"
|
||||
"\n"
|
||||
"Change the stream position to the given byte offset. The offset is\n"
|
||||
"interpreted relative to the position indicated by whence. Values\n"
|
||||
"for whence are:\n"
|
||||
"\n"
|
||||
"* 0 -- start of stream (the default); offset should be zero or positive\n"
|
||||
"* 1 -- current stream position; offset may be negative\n"
|
||||
"* 2 -- end of stream; offset is usually negative\n"
|
||||
"\n"
|
||||
"Return the new absolute position.");
|
||||
/*[clinic input]
|
||||
_io._IOBase.seek
|
||||
cls: defining_class
|
||||
/
|
||||
*args: object
|
||||
|
||||
Change the stream position to the given byte offset.
|
||||
|
||||
The offset is interpreted relative to the position indicated by whence.
|
||||
Values for whence are:
|
||||
|
||||
* 0 -- start of stream (the default); offset should be zero or positive
|
||||
* 1 -- current stream position; offset may be negative
|
||||
* 2 -- end of stream; offset is usually negative
|
||||
|
||||
Return the new absolute position.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
iobase_seek(PyObject *self, PyObject *args)
|
||||
_io__IOBase_seek_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
|
||||
/*[clinic end generated code: output=1dd694ac9de260fa input=ebb5476eb22fc5d4]*/
|
||||
{
|
||||
_PyIO_State *state = IO_STATE();
|
||||
return iobase_unsupported(state, "seek");
|
||||
@ -112,14 +118,21 @@ _io__IOBase_tell_impl(PyObject *self)
|
||||
return _PyObject_CallMethod(self, &_Py_ID(seek), "ii", 0, 1);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(iobase_truncate_doc,
|
||||
"Truncate file to size bytes.\n"
|
||||
"\n"
|
||||
"File pointer is left unchanged. Size defaults to the current IO\n"
|
||||
"position as reported by tell(). Returns the new size.");
|
||||
/*[clinic input]
|
||||
_io._IOBase.truncate
|
||||
cls: defining_class
|
||||
/
|
||||
*args: object
|
||||
|
||||
Truncate file to size bytes.
|
||||
|
||||
File pointer is left unchanged. Size defaults to the current IO position
|
||||
as reported by tell(). Return the new size.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
iobase_truncate(PyObject *self, PyObject *args)
|
||||
_io__IOBase_truncate_impl(PyObject *self, PyTypeObject *cls, PyObject *args)
|
||||
/*[clinic end generated code: output=b7eed4649cbe22c1 input=ad90582a1d8b5cc9]*/
|
||||
{
|
||||
_PyIO_State *state = IO_STATE();
|
||||
return iobase_unsupported(state, "truncate");
|
||||
@ -809,9 +822,9 @@ _io__IOBase_writelines(PyObject *self, PyObject *lines)
|
||||
#include "clinic/iobase.c.h"
|
||||
|
||||
static PyMethodDef iobase_methods[] = {
|
||||
{"seek", iobase_seek, METH_VARARGS, iobase_seek_doc},
|
||||
_IO__IOBASE_SEEK_METHODDEF
|
||||
_IO__IOBASE_TELL_METHODDEF
|
||||
{"truncate", iobase_truncate, METH_VARARGS, iobase_truncate_doc},
|
||||
_IO__IOBASE_TRUNCATE_METHODDEF
|
||||
_IO__IOBASE_FLUSH_METHODDEF
|
||||
_IO__IOBASE_CLOSE_METHODDEF
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user