Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/tutorial/datastructures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ objects:
.. method:: list.index(x[, start[, end]])
:noindex:

Return zero-based index in the list of the first item whose value is equal to *x*.
Return zero-based index of the first occurrence of *x* in the list.
Raises a :exc:`ValueError` if there is no such item.

The optional arguments *start* and *end* are interpreted as in the slice
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -3957,6 +3957,11 @@ async def test_invalid_offset(self):
await self.async_sendfile(self.sockno, self.fileno, -1, 4096)
self.assertEqual(cm.exception.errno, errno.EINVAL)

async def test_invalid_count(self):
with self.assertRaises(ValueError, msg="count cannot be negative"):
await self.sendfile_wrapper(self.sockno, self.fileno, offset=0,
count=-1)

async def test_keywords(self):
# Keyword arguments should be supported
await self.async_sendfile(out_fd=self.sockno, in_fd=self.fileno,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add missing validation of argument ``count`` in :func:`os.sendfile` to be
non-negative.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:mod:`email` is added to Emscripten build.
12 changes: 11 additions & 1 deletion Modules/clinic/posixmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11874,7 +11874,7 @@ os.sendfile
out_fd: int
in_fd: int
offset: Py_off_t
count: Py_ssize_t
count: Py_ssize_t(allow_negative=False)
headers: object(c_default="NULL") = ()
trailers: object(c_default="NULL") = ()
flags: int = 0
Expand All @@ -11886,28 +11886,38 @@ static PyObject *
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
Py_ssize_t count, PyObject *headers, PyObject *trailers,
int flags)
/*[clinic end generated code: output=329ea009bdd55afc input=338adb8ff84ae8cd]*/
/*[clinic end generated code: output=329ea009bdd55afc input=dcb026b94effa922]*/
#else
/*[clinic input]
os.sendfile

out_fd: int
in_fd: int
offset as offobj: object
count: Py_ssize_t
count: Py_ssize_t(allow_negative=False)

Copy count bytes from file descriptor in_fd to file descriptor out_fd.
[clinic start generated code]*/

static PyObject *
os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
Py_ssize_t count)
/*[clinic end generated code: output=ae81216e40f167d8 input=76d64058c74477ba]*/
/*[clinic end generated code: output=ae81216e40f167d8 input=424df0949059ea5b]*/
#endif
{
Py_ssize_t ret;
int async_err = 0;

#ifdef __APPLE__
if(sbytes < 0) {
PyErr_SetString(PyExc_ValueError,
"count cannot be negative");
return NULL;
}
#else
assert(count >= 0);
#endif

#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
#ifndef __APPLE__
off_t sbytes;
Expand Down
2 changes: 1 addition & 1 deletion Objects/odictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds)
if (len == -1)
return -1;
if (len > 1) {
const char *msg = "expected at most 1 arguments, got %zd";
const char *msg = "expected at most 1 argument, got %zd";
PyErr_Format(PyExc_TypeError, msg, len);
return -1;
}
Expand Down
1 change: 0 additions & 1 deletion Tools/wasm/emscripten/wasm_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
# socket.create_connection() raises an exception:
# "BlockingIOError: [Errno 26] Operation in progress".
OMIT_NETWORKING_FILES = (
"email/",
"ftplib.py",
"http/",
"imaplib.py",
Expand Down
Loading