[Python-checkins] cpython (merge 3.6 -> default): Issue #26384: Merge from 3.6

berker.peksag python-checkins at python.org
Sat Sep 17 16:22:33 EDT 2016


https://hg.python.org/cpython/rev/0d440fda8604
changeset:   103892:0d440fda8604
parent:      103889:5fab409f97de
parent:      103891:2156aa4050c7
user:        Berker Peksag <berker.peksag at gmail.com>
date:        Sat Sep 17 23:23:35 2016 +0300
summary:
  Issue #26384: Merge from 3.6

files:
  Lib/socket.py           |   2 +-
  Lib/test/test_socket.py |  19 +++++++++++++++++++
  Misc/NEWS               |   2 ++
  3 files changed, 22 insertions(+), 1 deletions(-)


diff --git a/Lib/socket.py b/Lib/socket.py
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -268,7 +268,7 @@
                 raise _GiveupOnSendfile(err)  # not a regular file
             try:
                 fsize = os.fstat(fileno).st_size
-            except OSError:
+            except OSError as err:
                 raise _GiveupOnSendfile(err)  # not a regular file
             if not fsize:
                 return 0  # empty file
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1485,6 +1485,25 @@
             self.assertEqual(s.family, 42424)
             self.assertEqual(s.type, 13331)
 
+    @unittest.skipUnless(hasattr(os, 'sendfile'), 'test needs os.sendfile()')
+    def test__sendfile_use_sendfile(self):
+        class File:
+            def __init__(self, fd):
+                self.fd = fd
+
+            def fileno(self):
+                return self.fd
+        with socket.socket() as sock:
+            fd = os.open(os.curdir, os.O_RDONLY)
+            os.close(fd)
+            with self.assertRaises(socket._GiveupOnSendfile):
+                sock._sendfile_use_sendfile(File(fd))
+            with self.assertRaises(OverflowError):
+                sock._sendfile_use_sendfile(File(2**1000))
+            with self.assertRaises(TypeError):
+                sock._sendfile_use_sendfile(File(None))
+
+
 @unittest.skipUnless(HAVE_SOCKET_CAN, 'SocketCan required for this test.')
 class BasicCANTest(unittest.TestCase):
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -35,6 +35,8 @@
 Library
 -------
 
+- Fix UnboundLocalError in socket._sendfile_use_sendfile.
+
 - Issue #28075: Check for ERROR_ACCESS_DENIED in Windows implementation of
   os.stat().  Patch by Eryk Sun.
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list