]> granicus.if.org Git - python/commitdiff
bpo-33687: Fix call to os.chmod() in uu.decode() (GH-7282)
authorTimo Furrer <tuxtimo@gmail.com>
Thu, 17 Jan 2019 14:15:53 +0000 (15:15 +0100)
committerBerker Peksag <berker.peksag@gmail.com>
Thu, 17 Jan 2019 14:15:53 +0000 (17:15 +0300)
Lib/test/test_uu.py
Lib/uu.py
Misc/NEWS.d/next/Library/2018-06-10-14-08-52.bpo-33687.1zZdnA.rst [new file with mode: 0644]

index 1147205a3b533045107012847da9b834dcf49fea..c9f05e5b760d922cfaddf4a509d2fbc317b8b97f 100644 (file)
@@ -6,6 +6,8 @@ Nick Mathewson
 import unittest
 from test import support
 
+import os
+import stat
 import sys
 import uu
 import io
@@ -218,6 +220,23 @@ class UUFileTest(unittest.TestCase):
         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()
index 8333e864d8f95df6df1a8197b9fac2dd863ef5c0..9b1e5e607207f789deec21efa1a19fb8a5f7a788 100755 (executable)
--- 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 (file)
index 0000000..63c5bfc
--- /dev/null
@@ -0,0 +1,2 @@
+Fix the call to ``os.chmod()`` for ``uu.decode()`` if a mode is given or
+decoded. Patch by Timo Furrer.