Skip to content

Commit 5563b8d

Browse files
committed
Correct typos, docstring and improve Docs
1 parent cb74d38 commit 5563b8d

5 files changed

Lines changed: 90 additions & 52 deletions

File tree

Doc/library/os.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,34 +1112,30 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
11121112
:func:`~os.pwritev` writes the contents of each object to the file descriptor
11131113
and returns the total number of bytes written.
11141114

1115-
11161115
The *flags* argument contains a bitwise OR of zero or more of the following
11171116
flags:
11181117

11191118
- RWF_DSYNC
11201119
- RWF_SYNC
11211120

1122-
:func:`~os.pwritev` will call *pwritev2* system call if available, which modifies
1123-
the behavior on a per-call basis based on the value of the *flags* argument. The
1124-
:func:`~os.pwritev2` function is required to pass flags.
1125-
1126-
The :func:`~os.pwritev2` function is required to pass flags.
1127-
1128-
*pwritev2* and *flags* different than zero are available since Linux version
1129-
4.7.
1121+
Using non-zero flags requires Linux 4.7 or newer.
11301122

11311123
Availability: Linux (version 2.6.30), FreeBSD 6.0 and newer,
11321124
OpenBSD (version 2.7 and newer).
11331125

11341126
.. versionadded:: 3.7
11351127

1128+
.. data:: RWF_DSYNC (since Linux 4.7)
1129+
Provide a per-write equivalent of the O_DSYNC open(2) flag. This flag
1130+
is meaningful only for pwritev2(), and its effect applies only to the
1131+
data range written by the system call.
11361132

1137-
.. data:: RWF_DSYNC
1138-
RWF_SYNC
1139-
1140-
The above constants are available on Linux Kernel 4.7 (or newer).
1133+
.. versionadded:: 3.7
11411134

1142-
Availability: Linux.
1135+
.. data:: RWF_SYNC (since Linux 4.7)
1136+
Provide a per-write equivalent of the O_SYNC open(2) flag. This flag is
1137+
meaningful only for pwritev2(), and its effect applies only to the data
1138+
range written by the system call.
11431139

11441140
.. versionadded:: 3.7
11451141

@@ -1252,29 +1248,33 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
12521248
The flags argument contains a bitwise OR of zero or more of the following
12531249
flags:
12541250

1255-
- RWF_HIPRI
1256-
- RWF_NOWAIT
1251+
- RWF_HIPRI
1252+
- RWF_NOWAIT
12571253

1258-
:func:`~os.preadv` will call *preadv2* system call if available, which modifies
1259-
the behavior on a per-call basis based on the value of the *flags* argument. The
1260-
:c:func:`preadv2` function is required to pass flags.
1261-
1262-
*preadv2* and flags different than zero are available since Linux version
1263-
4.6 and newer.
1254+
Using non-zero flags requires Linux 4.6 or newer.
12641255

12651256
Availability: Linux (version 2.6.30), FreeBSD 6.0 and newer,
12661257
OpenBSD (version 2.7 and newer).
12671258

12681259
.. versionadded:: 3.7
12691260

12701261

1271-
.. data:: RWF_HIPRI
1272-
RWF_NOWAIT
1262+
.. data:: RWF_HIPRI (since Linux 4.6)
1263+
High priority read/write. Allows block-based filesystems to use polling
1264+
of the device, which provides lower latency, but may use additional
1265+
resources. (Currently, this feature is usable only on a file descriptor
1266+
opened using the O_DIRECT flag.)
1267+
1268+
.. versionadded:: 3.7
12731269

1274-
The above constants are available on Linux Kernel 4.11 and 4.6 (or newer)
1275-
respectively.
12761270

1277-
Availability: Linux.
1271+
.. data:: RWF_NOWAIT (since Linux 4.14)
1272+
Do not wait for data which is not immediately available. If this flag
1273+
is specified, the preadv2() system call will return instantly
1274+
if it would have to read data from the backing storage or wait for a lock.
1275+
If some data was successfully read, it will return the number of bytes
1276+
read. If no bytes were read, it will return -1 and set errno to EAGAIN.
1277+
Currently, this flag is meaningful only for preadv2().
12781278

12791279
.. versionadded:: 3.7
12801280

Lib/test/test_posix.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,16 @@ def test_pwrite(self):
309309
def test_pwritev(self):
310310
fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
311311
try:
312-
os.write(fd,b"xx")
312+
os.write(fd, b"xx")
313313
os.lseek(fd, 0, os.SEEK_SET)
314314
n = os.pwritev(fd, [b'test1', b'tt2', b't3'], 2)
315315
self.assertEqual(n, 10)
316316

317317
os.lseek(fd, 0, os.SEEK_SET)
318-
self.assertEqual(b'xxtest1tt2', posix.read(fd, 10))
319-
318+
self.assertEqual(b'xxtest1tt2t3', posix.read(fd, 100))
320319
finally:
321320
os.close(fd)
322321

323-
324322
@unittest.skipUnless(hasattr(posix, 'os.RWF_SYNC'), "test needs os.RWF_SYNC")
325323
def test_pwritev_flags(self):
326324
fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT)
@@ -331,11 +329,10 @@ def test_pwritev_flags(self):
331329
self.assertEqual(n, 10)
332330

333331
os.lseek(fd, 0, os.SEEK_SET)
334-
self.assertEqual(b'xxtest1tt2', posix.read(fd, 10))
332+
self.assertEqual(b'xxtest1tt2', posix.read(fd, 100))
335333
finally:
336334
os.close(fd)
337335

338-
339336
@unittest.skipUnless(hasattr(posix, 'posix_fallocate'),
340337
"test needs posix.posix_fallocate()")
341338
def test_posix_fallocate(self):
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Expose preadv (preadv2) and pwritev (pwritev2) system calls in the os module.
2-
Patch by Pablo Galindo
1+
Expose preadv and pwritev system calls in the os module. Patch by Pablo Galindo

Modules/clinic/posixmodule.c.h

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,10 +3711,21 @@ PyDoc_STRVAR(os_preadv__doc__,
37113711
"preadv($module, fd, buffers, offset, flags=0, /)\n"
37123712
"--\n"
37133713
"\n"
3714-
"Read a number of bytes from a file descriptor starting at a particular offset.\n"
3714+
"Reads from a file descriptor into a number of mutable bytes-like objects.\n"
37153715
"\n"
3716-
"Read length bytes from file descriptor fd, starting at offset bytes from\n"
3717-
"the beginning of the file. The file offset remains unchanged.");
3716+
"Combines the functionality of readv() and pread(). As readv(), it will\n"
3717+
"transfer data into each buffer until it is full and then move on to the next\n"
3718+
"buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
3719+
"specifies the file offset at which the input operation is to be performed. It\n"
3720+
"will return the total number of bytes read (which can be less than the total\n"
3721+
"capacity of all the objects).\n"
3722+
"\n"
3723+
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
3724+
"\n"
3725+
"- RWF_HIPRI\n"
3726+
"- RWF_NOWAIT\n"
3727+
"\n"
3728+
"Using non-zero flags requires Linux 4.6 or newer.");
37183729

37193730
#define OS_PREADV_METHODDEF \
37203731
{"preadv", (PyCFunction)os_preadv, METH_FASTCALL, os_preadv__doc__},
@@ -4013,11 +4024,21 @@ PyDoc_STRVAR(os_pwritev__doc__,
40134024
"pwritev($module, fd, buffers, offset, flags=0, /)\n"
40144025
"--\n"
40154026
"\n"
4016-
"Write bytes to a file descriptor starting at a particular offset.\n"
4027+
"Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
40174028
"\n"
4018-
"Write buffer to fd, starting at offset bytes from the beginning of\n"
4019-
"the file. Returns the number of bytes writte. Does not change the\n"
4020-
"current file offset.");
4029+
"Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
4030+
"of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
4031+
"buffer is written before proceeding to second, and so on. The operating system may\n"
4032+
"set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
4033+
"This function writes the contents of each object to the file descriptor and returns\n"
4034+
"the total number of bytes written.\n"
4035+
"\n"
4036+
"The flags argument contains a bitwise OR of zero or more of the following flags:\n"
4037+
"\n"
4038+
"- RWF_DSYNC\n"
4039+
"- RWF_SYNC\n"
4040+
"\n"
4041+
"Using non-zero flags requires Linux 4.7 or newer.");
40214042

40224043
#define OS_PWRITEV_METHODDEF \
40234044
{"pwritev", (PyCFunction)os_pwritev, METH_FASTCALL, os_pwritev__doc__},
@@ -6507,4 +6528,4 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject
65076528
#ifndef OS_GETRANDOM_METHODDEF
65086529
#define OS_GETRANDOM_METHODDEF
65096530
#endif /* !defined(OS_GETRANDOM_METHODDEF) */
6510-
/*[clinic end generated code: output=d50830cf566cb297 input=a9049054013a1b77]*/
6531+
/*[clinic end generated code: output=06ace805893aa10c input=a9049054013a1b77]*/

Modules/posixmodule.c

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8173,16 +8173,27 @@ os.preadv -> Py_ssize_t
81738173
flags: int = 0
81748174
/
81758175
8176-
Read a number of bytes from a file descriptor starting at a particular offset.
8176+
Reads from a file descriptor into a number of mutable bytes-like objects.
81778177
8178-
Read length bytes from file descriptor fd, starting at offset bytes from
8179-
the beginning of the file. The file offset remains unchanged.
8178+
Combines the functionality of readv() and pread(). As readv(), it will
8179+
transfer data into each buffer until it is full and then move on to the next
8180+
buffer in the sequence to hold the rest of the data. Its fourth argument,
8181+
specifies the file offset at which the input operation is to be performed. It
8182+
will return the total number of bytes read (which can be less than the total
8183+
capacity of all the objects).
8184+
8185+
The flags argument contains a bitwise OR of zero or more of the following flags:
8186+
8187+
- RWF_HIPRI
8188+
- RWF_NOWAIT
8189+
8190+
Using non-zero flags requires Linux 4.6 or newer.
81808191
[clinic start generated code]*/
81818192

81828193
static Py_ssize_t
81838194
os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
81848195
int flags)
8185-
/*[clinic end generated code: output=26fc9c6e58e7ada5 input=5b07b7e2d1825627]*/
8196+
/*[clinic end generated code: output=26fc9c6e58e7ada5 input=4173919dc1f7ed99]*/
81868197
{
81878198
Py_ssize_t cnt, n;
81888199
int async_err = 0;
@@ -8700,17 +8711,27 @@ os.pwritev -> Py_ssize_t
87008711
flags: int = 0
87018712
/
87028713
8703-
Write bytes to a file descriptor starting at a particular offset.
8714+
Writes the contents of bytes-like objects to a file descriptor at a given offset.
87048715
8705-
Write buffer to fd, starting at offset bytes from the beginning of
8706-
the file. Returns the number of bytes writte. Does not change the
8707-
current file offset.
8716+
Combines the functionality of writev() and pwrite(). All buffers must be a sequence
8717+
of bytes-like objects. Buffers are processed in array order. Entire contents of first
8718+
buffer is written before proceeding to second, and so on. The operating system may
8719+
set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.
8720+
This function writes the contents of each object to the file descriptor and returns
8721+
the total number of bytes written.
8722+
8723+
The flags argument contains a bitwise OR of zero or more of the following flags:
8724+
8725+
- RWF_DSYNC
8726+
- RWF_SYNC
8727+
8728+
Using non-zero flags requires Linux 4.7 or newer.
87088729
[clinic start generated code]*/
87098730

87108731
static Py_ssize_t
87118732
os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
87128733
int flags)
8713-
/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=76ec1699089ae61c]*/
8734+
/*[clinic end generated code: output=e3dd3e9d11a6a5c7 input=803dc5ddbf0cfd3b]*/
87148735
{
87158736
Py_ssize_t cnt;
87168737
Py_ssize_t result;

0 commit comments

Comments
 (0)