summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-09-17 20:23:13 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-09-17 20:23:13 (GMT)
commit5d625cff07bf9a9dbe9be3b598fbaf673a3be819 (patch)
treee134a898a89944401a695310dc71d47780666a41
parented51b268580c1100b46bf5dbc4b4201146019644 (diff)
parentbcfb35f80d9d1f87d9fa6993c1d3bc35dd5db865 (diff)
downloadcpython-5d625cff07bf9a9dbe9be3b598fbaf673a3be819.zip
cpython-5d625cff07bf9a9dbe9be3b598fbaf673a3be819.tar.gz
cpython-5d625cff07bf9a9dbe9be3b598fbaf673a3be819.tar.bz2
Issue #26384: Merge from 3.5
-rw-r--r--Lib/socket.py2
-rw-r--r--Lib/test/test_socket.py19
-rw-r--r--Misc/NEWS2
3 files changed, 22 insertions, 1 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index bc8f467..740e717 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -268,7 +268,7 @@ class socket(_socket.socket):
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
index 441926f..41c206b 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -1485,6 +1485,25 @@ class GeneralModuleTests(unittest.TestCase):
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
index f9e2474..c0c6305 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,8 @@ Core and Builtins
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.