bpo-38378: Rename parameters "out" and "in" of os.sendfile(). (GH-16742)

They conflicted with keyword "in".

Also rename positional-only parameters of private os._fcopyfile()
for consistency.
This commit is contained in:
Serhiy Storchaka 2019-10-13 11:59:31 +03:00 committed by GitHub
parent 46113e0cf3
commit 140a7d1f35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 34 deletions

View file

@ -1251,27 +1251,27 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
:exc:`InterruptedError` exception (see :pep:`475` for the rationale). :exc:`InterruptedError` exception (see :pep:`475` for the rationale).
.. function:: sendfile(out, in, offset, count) .. function:: sendfile(out_fd, in_fd, offset, count)
sendfile(out, in, offset, count, [headers], [trailers], flags=0) sendfile(out_fd, in_fd, offset, count, [headers], [trailers], flags=0)
Copy *count* bytes from file descriptor *in* to file descriptor *out* Copy *count* bytes from file descriptor *in_fd* to file descriptor *out_fd*
starting at *offset*. starting at *offset*.
Return the number of bytes sent. When EOF is reached return 0. Return the number of bytes sent. When EOF is reached return ``0``.
The first function notation is supported by all platforms that define The first function notation is supported by all platforms that define
:func:`sendfile`. :func:`sendfile`.
On Linux, if *offset* is given as ``None``, the bytes are read from the On Linux, if *offset* is given as ``None``, the bytes are read from the
current position of *in* and the position of *in* is updated. current position of *in_fd* and the position of *in_fd* is updated.
The second case may be used on Mac OS X and FreeBSD where *headers* and The second case may be used on Mac OS X and FreeBSD where *headers* and
*trailers* are arbitrary sequences of buffers that are written before and *trailers* are arbitrary sequences of buffers that are written before and
after the data from *in* is written. It returns the same as the first case. after the data from *in_fd* is written. It returns the same as the first case.
On Mac OS X and FreeBSD, a value of 0 for *count* specifies to send until On Mac OS X and FreeBSD, a value of ``0`` for *count* specifies to send until
the end of *in* is reached. the end of *in_fd* is reached.
All platforms support sockets as *out* file descriptor, and some platforms All platforms support sockets as *out_fd* file descriptor, and some platforms
allow other types (e.g. regular file, pipe) as well. allow other types (e.g. regular file, pipe) as well.
Cross-platform applications should not use *headers*, *trailers* and *flags* Cross-platform applications should not use *headers*, *trailers* and *flags*
@ -1286,6 +1286,9 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
.. versionadded:: 3.3 .. versionadded:: 3.3
.. versionchanged:: 3.9
Parameters *out* and *in* was renamed to *out_fd* and *in_fd*.
.. function:: set_blocking(fd, blocking) .. function:: set_blocking(fd, blocking)

View file

@ -3110,11 +3110,12 @@ class TestSendfile(unittest.TestCase):
def test_keywords(self): def test_keywords(self):
# Keyword arguments should be supported # Keyword arguments should be supported
os.sendfile(out=self.sockno, offset=0, count=4096, os.sendfile(out_fd=self.sockno, in_fd=self.fileno,
**{'in': self.fileno}) offset=0, count=4096)
if self.SUPPORT_HEADERS_TRAILERS: if self.SUPPORT_HEADERS_TRAILERS:
os.sendfile(self.sockno, self.fileno, offset=0, count=4096, os.sendfile(out_fd=self.sockno, in_fd=self.fileno,
headers=(), trailers=(), flags=0) offset=0, count=4096,
headers=(), trailers=(), flags=0)
# --- headers / trailers tests # --- headers / trailers tests

View file

@ -0,0 +1,2 @@
Parameters *out* and *in* of :func:`os.sendfile` was renamed to *out_fd* and
*in_fd*.

View file

@ -4986,7 +4986,7 @@ exit:
#if defined(__APPLE__) #if defined(__APPLE__)
PyDoc_STRVAR(os__fcopyfile__doc__, PyDoc_STRVAR(os__fcopyfile__doc__,
"_fcopyfile($module, infd, outfd, flags, /)\n" "_fcopyfile($module, in_fd, out_fd, flags, /)\n"
"--\n" "--\n"
"\n" "\n"
"Efficiently copy content or metadata of 2 regular file descriptors (macOS)."); "Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
@ -4995,14 +4995,14 @@ PyDoc_STRVAR(os__fcopyfile__doc__,
{"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__}, {"_fcopyfile", (PyCFunction)(void(*)(void))os__fcopyfile, METH_FASTCALL, os__fcopyfile__doc__},
static PyObject * static PyObject *
os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags); os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
static PyObject * static PyObject *
os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs) os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{ {
PyObject *return_value = NULL; PyObject *return_value = NULL;
int infd; int in_fd;
int outfd; int out_fd;
int flags; int flags;
if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) { if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
@ -5013,8 +5013,8 @@ os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
"integer argument expected, got float" ); "integer argument expected, got float" );
goto exit; goto exit;
} }
infd = _PyLong_AsInt(args[0]); in_fd = _PyLong_AsInt(args[0]);
if (infd == -1 && PyErr_Occurred()) { if (in_fd == -1 && PyErr_Occurred()) {
goto exit; goto exit;
} }
if (PyFloat_Check(args[1])) { if (PyFloat_Check(args[1])) {
@ -5022,8 +5022,8 @@ os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
"integer argument expected, got float" ); "integer argument expected, got float" );
goto exit; goto exit;
} }
outfd = _PyLong_AsInt(args[1]); out_fd = _PyLong_AsInt(args[1]);
if (outfd == -1 && PyErr_Occurred()) { if (out_fd == -1 && PyErr_Occurred()) {
goto exit; goto exit;
} }
if (PyFloat_Check(args[2])) { if (PyFloat_Check(args[2])) {
@ -5035,7 +5035,7 @@ os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
if (flags == -1 && PyErr_Occurred()) { if (flags == -1 && PyErr_Occurred()) {
goto exit; goto exit;
} }
return_value = os__fcopyfile_impl(module, infd, outfd, flags); return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
exit: exit:
return return_value; return return_value;
@ -8731,4 +8731,4 @@ exit:
#ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
#define OS__REMOVE_DLL_DIRECTORY_METHODDEF #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
#endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */ #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
/*[clinic end generated code: output=799c75140d84ace5 input=a9049054013a1b77]*/ /*[clinic end generated code: output=fe7897441fed5402 input=a9049054013a1b77]*/

View file

@ -8993,10 +8993,10 @@ os_write_impl(PyObject *module, int fd, Py_buffer *data)
#ifdef HAVE_SENDFILE #ifdef HAVE_SENDFILE
PyDoc_STRVAR(posix_sendfile__doc__, PyDoc_STRVAR(posix_sendfile__doc__,
"sendfile(out, in, offset, count) -> byteswritten\n\ "sendfile(out_fd, in_fd, offset, count) -> byteswritten\n\
sendfile(out, in, offset, count[, headers][, trailers], flags=0)\n\ sendfile(out_fd, in_fd, offset, count[, headers][, trailers], flags=0)\n\
-> byteswritten\n\ -> byteswritten\n\
Copy count bytes from file descriptor in to file descriptor out."); Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
/* AC 3.5: don't bother converting, has optional group*/ /* AC 3.5: don't bother converting, has optional group*/
static PyObject * static PyObject *
@ -9016,8 +9016,7 @@ posix_sendfile(PyObject *self, PyObject *args, PyObject *kwdict)
off_t sbytes; off_t sbytes;
struct sf_hdtr sf; struct sf_hdtr sf;
int flags = 0; int flags = 0;
/* Beware that "in" clashes with Python's own "in" operator keyword */ static char *keywords[] = {"out_fd", "in_fd",
static char *keywords[] = {"out", "in",
"offset", "count", "offset", "count",
"headers", "trailers", "flags", NULL}; "headers", "trailers", "flags", NULL};
@ -9133,7 +9132,7 @@ done:
#else #else
Py_ssize_t count; Py_ssize_t count;
PyObject *offobj; PyObject *offobj;
static char *keywords[] = {"out", "in", static char *keywords[] = {"out_fd", "in_fd",
"offset", "count", NULL}; "offset", "count", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiOn:sendfile", if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiOn:sendfile",
keywords, &out, &in, &offobj, &count)) keywords, &out, &in, &offobj, &count))
@ -9170,8 +9169,8 @@ done:
/*[clinic input] /*[clinic input]
os._fcopyfile os._fcopyfile
infd: int in_fd: int
outfd: int out_fd: int
flags: int flags: int
/ /
@ -9179,13 +9178,13 @@ Efficiently copy content or metadata of 2 regular file descriptors (macOS).
[clinic start generated code]*/ [clinic start generated code]*/
static PyObject * static PyObject *
os__fcopyfile_impl(PyObject *module, int infd, int outfd, int flags) os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags)
/*[clinic end generated code: output=8e8885c721ec38e3 input=69e0770e600cb44f]*/ /*[clinic end generated code: output=c9d1a35a992e401b input=1e34638a86948795]*/
{ {
int ret; int ret;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
ret = fcopyfile(infd, outfd, NULL, flags); ret = fcopyfile(in_fd, out_fd, NULL, flags);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
if (ret < 0) if (ret < 0)
return posix_error(); return posix_error();