From 98608b9d6b3c58bce19288a3981a514ac49cedd9 Mon Sep 17 00:00:00 2001 From: bezoka Date: Sat, 1 Jun 2019 23:11:28 +0200 Subject: [PATCH 1/6] add RWF_APPEND flag --- Doc/library/os.rst | 10 ++++++++++ Modules/clinic/posixmodule.c.h | 1 + Modules/posixmodule.c | 3 +++ 3 files changed, 14 insertions(+) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 107764ba4d539e..3d7d01add9c0e3 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1196,6 +1196,7 @@ or `the MSDN `_ on Windo - :data:`RWF_DSYNC` - :data:`RWF_SYNC` + - :data:`RWF_APPEND` Return the total number of bytes actually written. @@ -1230,6 +1231,15 @@ or `the MSDN `_ on Windo .. versionadded:: 3.7 +.. data:: RWF_APPEND + + Append data to the end of the file. + + .. availability:: Linux 4.7 and newer. + + .. versionadded:: 3.8 + + .. function:: read(fd, n) Read at most *n* bytes from file descriptor *fd*. diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 22cb94761de5c7..97aa10c74e72cc 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -5334,6 +5334,7 @@ PyDoc_STRVAR(os_pwritev__doc__, "\n" "- RWF_DSYNC\n" "- RWF_SYNC\n" +"- RWF_APPEND\n" "\n" "Using non-zero flags requires Linux 4.7 or newer."); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8f6cffffcdfbe8..a9c82008ff0198 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -14023,6 +14023,9 @@ all_ins(PyObject *m) #ifdef RWF_NOWAIT if (PyModule_AddIntConstant(m, "RWF_NOWAIT", RWF_NOWAIT)) return -1; #endif +#ifdef RWF_APPEND + if (PyModule_AddIntConstant(m, "RWF_APPEND", RWF_APPEND)) return -1; +#endif /* constants for posix_spawn */ #ifdef HAVE_POSIX_SPAWN From f4ab619acd200b28557b9a4e2cdbb68715e2dcba Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Sat, 1 Jun 2019 21:58:51 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-06-01-21-58-50.bpo-37129.Uzw_V-.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-06-01-21-58-50.bpo-37129.Uzw_V-.rst diff --git a/Misc/NEWS.d/next/Library/2019-06-01-21-58-50.bpo-37129.Uzw_V-.rst b/Misc/NEWS.d/next/Library/2019-06-01-21-58-50.bpo-37129.Uzw_V-.rst new file mode 100644 index 00000000000000..3bbc2e04e11032 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-06-01-21-58-50.bpo-37129.Uzw_V-.rst @@ -0,0 +1 @@ +add RWF_APPEND flag \ No newline at end of file From 10c34b4e76b638d5f643f7bf496912fd1463cd7f Mon Sep 17 00:00:00 2001 From: bezoka Date: Sun, 2 Jun 2019 00:08:20 +0200 Subject: [PATCH 3/6] fix typo --- Doc/library/os.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index 3d7d01add9c0e3..c277f411cb4be8 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1235,7 +1235,7 @@ or `the MSDN `_ on Windo Append data to the end of the file. - .. availability:: Linux 4.7 and newer. + .. availability:: Linux 4.16 and newer. .. versionadded:: 3.8 From 2504743ab7e814a652f9a822dd8c9a298572c770 Mon Sep 17 00:00:00 2001 From: bezoka Date: Sun, 2 Jun 2019 01:02:49 +0200 Subject: [PATCH 4/6] Extend documentation --- Doc/library/os.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/os.rst b/Doc/library/os.rst index c277f411cb4be8..39930b5aa1d1f4 100644 --- a/Doc/library/os.rst +++ b/Doc/library/os.rst @@ -1233,7 +1233,8 @@ or `the MSDN `_ on Windo .. data:: RWF_APPEND - Append data to the end of the file. + Append data to the end of the file. See the description of the flag 'O_APPEND' in ''os.open()''. + The *offset* field is ignored. The file *offset* is not changed. .. availability:: Linux 4.16 and newer. From 8ba3028945b6aeedcd8d5c15d98852a889a2673f Mon Sep 17 00:00:00 2001 From: bezoka Date: Sun, 2 Jun 2019 01:04:38 +0200 Subject: [PATCH 5/6] Add test to RWF_NOWAIT flag --- Lib/test/test_posix.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 5c93d0d507d252..d2ee92ab80326a 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -321,6 +321,26 @@ def test_preadv_flags(self): finally: os.close(fd) + @unittest.skipUnless(hasattr(posix, 'preadv'), "test needs posix.preadv()") + @unittest.skipUnless(hasattr(posix, 'RWF_NOWAIT'), "test needs posix.RWF_NOWAIT") + def test_preadv_flags_rwf_nowait(self): + fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) + try: + os.write(fd, b'test1tt2t3t5t6t6t8') + buf = [bytearray(i) for i in [5, 3, 2]] + self.assertEqual(posix.preadv(fd, buf, 3, os.RWF_NOWAIT), 10) + self.assertEqual([b't1tt2', b't3t', b'5t'], list(buf)) + except OSError as inst: + # Is possible that the macro RWF_HIPRI was defined at compilation time + # but the option is not supported by the kernel or the runtime libc shared + # library. + if inst.errno in {errno.EINVAL, errno.ENOTSUP}: + raise unittest.SkipTest("RWF_HIPRI is not supported by the current system") + else: + raise + finally: + os.close(fd) + @unittest.skipUnless(hasattr(posix, 'preadv'), "test needs posix.preadv()") @requires_32b def test_preadv_overflow_32bits(self): From 884466ec26e0030e8d2796e9fd64eb3a3196c1e0 Mon Sep 17 00:00:00 2001 From: bezoka Date: Sun, 2 Jun 2019 02:02:51 +0200 Subject: [PATCH 6/6] remove not needed test --- Lib/test/test_posix.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index d2ee92ab80326a..5c93d0d507d252 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -321,26 +321,6 @@ def test_preadv_flags(self): finally: os.close(fd) - @unittest.skipUnless(hasattr(posix, 'preadv'), "test needs posix.preadv()") - @unittest.skipUnless(hasattr(posix, 'RWF_NOWAIT'), "test needs posix.RWF_NOWAIT") - def test_preadv_flags_rwf_nowait(self): - fd = os.open(support.TESTFN, os.O_RDWR | os.O_CREAT) - try: - os.write(fd, b'test1tt2t3t5t6t6t8') - buf = [bytearray(i) for i in [5, 3, 2]] - self.assertEqual(posix.preadv(fd, buf, 3, os.RWF_NOWAIT), 10) - self.assertEqual([b't1tt2', b't3t', b'5t'], list(buf)) - except OSError as inst: - # Is possible that the macro RWF_HIPRI was defined at compilation time - # but the option is not supported by the kernel or the runtime libc shared - # library. - if inst.errno in {errno.EINVAL, errno.ENOTSUP}: - raise unittest.SkipTest("RWF_HIPRI is not supported by the current system") - else: - raise - finally: - os.close(fd) - @unittest.skipUnless(hasattr(posix, 'preadv'), "test needs posix.preadv()") @requires_32b def test_preadv_overflow_32bits(self):