Commit c3eff41a authored by Skip Montanaro's avatar Skip Montanaro

The socket module now always uses the _socketobject wrapper class, even on

platforms which have dup(2).  The makefile() method is built directly on top
of the socket without duplicating the file descriptor, allowing timeouts to
work properly.  Includes a new test case (urllibnet) which requires the
network resource.

Closes bug 707074.
parent 8d20b0ed
...@@ -59,13 +59,10 @@ if _have_ssl: ...@@ -59,13 +59,10 @@ if _have_ssl:
__all__.extend(os._get_exports_list(_ssl)) __all__.extend(os._get_exports_list(_ssl))
_realsocket = socket _realsocket = socket
_needwrapper = False
if (sys.platform.lower().startswith("win") if (sys.platform.lower().startswith("win")
or (hasattr(os, 'uname') and os.uname()[0] == "BeOS") or (hasattr(os, 'uname') and os.uname()[0] == "BeOS")
or sys.platform=="riscos"): or sys.platform=="riscos"):
_needwrapper = True
if _have_ssl: if _have_ssl:
_realssl = ssl _realssl = ssl
def ssl(sock, keyfile=None, certfile=None): def ssl(sock, keyfile=None, certfile=None):
...@@ -180,8 +177,7 @@ class _socketobject(object): ...@@ -180,8 +177,7 @@ class _socketobject(object):
exec _s % (_m, _m, _m, _m) exec _s % (_m, _m, _m, _m)
del _m, _s del _m, _s
if _needwrapper: socket = SocketType = _socketobject
socket = SocketType = _socketobject
class _fileobject(object): class _fileobject(object):
"""Faux file object attached to a socket object.""" """Faux file object attached to a socket object."""
......
#!/usr/bin/env python
import unittest
from test import test_support
import socket
import urllib2
import sys
class URLTimeoutTest(unittest.TestCase):
TIMEOUT = 10.0
def setUp(self):
socket.setdefaulttimeout(self.TIMEOUT)
def tearDown(self):
socket.setdefaulttimeout(None)
def testURLread(self):
f = urllib2.urlopen("http://www.python.org/")
x = f.read()
def test_main():
test_support.requires('network')
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(URLTimeoutTest))
test_support.run_suite(suite)
if __name__ == "__main__":
test_main()
...@@ -59,6 +59,11 @@ Extension modules ...@@ -59,6 +59,11 @@ Extension modules
Subsumed the times() function into repeat(). Subsumed the times() function into repeat().
Added chain() and cycle(). Added chain() and cycle().
- The socket module now always uses the _socketobject wrapper class, even on
platforms which have dup(2). The makefile() method is built directly
on top of the socket without duplicating the file descriptor, allowing
timeouts to work properly.
Library Library
------- -------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment