From 7b12978bbeea3d18b13dd750ca4a77ca4520308f Mon Sep 17 00:00:00 2001 From: Timo Furrer Date: Thu, 31 May 2018 13:32:26 +0200 Subject: [PATCH 1/2] bpo-33687: fix call to os.chmod --- Lib/test/test_uu.py | 19 +++++++++++++++++++ Lib/uu.py | 5 +---- .../2018-06-10-14-08-52.bpo-33687.1zZdnA.rst | 4 ++++ 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst diff --git a/Lib/test/test_uu.py b/Lib/test/test_uu.py index 1147205a3b5330..c9f05e5b760d92 100644 --- a/Lib/test/test_uu.py +++ b/Lib/test/test_uu.py @@ -6,6 +6,8 @@ import unittest from test import support +import os +import stat import sys import uu import io @@ -218,6 +220,23 @@ def test_decodetwice(self): with open(self.tmpin, 'rb') as f: self.assertRaises(uu.Error, uu.decode, f) + def test_decode_mode(self): + # Verify that decode() will set the given mode for the out_file + expected_mode = 0o444 + with open(self.tmpin, 'wb') as f: + f.write(encodedtextwrapped(expected_mode, self.tmpout)) + + # make file writable again, so it can be removed (Windows only) + self.addCleanup(os.chmod, self.tmpout, expected_mode | stat.S_IWRITE) + + with open(self.tmpin, 'rb') as f: + uu.decode(f) + + self.assertEqual( + stat.S_IMODE(os.stat(self.tmpout).st_mode), + expected_mode + ) + if __name__=="__main__": unittest.main() diff --git a/Lib/uu.py b/Lib/uu.py index 8333e864d8f95d..9b1e5e607207f7 100755 --- a/Lib/uu.py +++ b/Lib/uu.py @@ -133,10 +133,7 @@ def decode(in_file, out_file=None, mode=None, quiet=False): out_file = sys.stdout.buffer elif isinstance(out_file, str): fp = open(out_file, 'wb') - try: - os.path.chmod(out_file, mode) - except AttributeError: - pass + os.chmod(out_file, mode) out_file = fp opened_files.append(out_file) # diff --git a/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst b/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst new file mode 100644 index 00000000000000..9f5c40902c3cde --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst @@ -0,0 +1,4 @@ +Fix the call to ``os.chmod()`` for ``uu.decode()`` if a mode is given or +decoded. + +Patch by Timo Furrer. From beea7904212b002b55d475ae5f62a8dc6dbe96d7 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 16 Jul 2018 15:05:55 +0900 Subject: [PATCH 2/2] News entry must be one paragraph --- .../next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst b/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst index 9f5c40902c3cde..63c5bfcac474b5 100644 --- a/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst +++ b/Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst @@ -1,4 +1,2 @@ Fix the call to ``os.chmod()`` for ``uu.decode()`` if a mode is given or -decoded. - -Patch by Timo Furrer. +decoded. Patch by Timo Furrer.