Add default timeout functionality.  This adds setdefaulttimeout() and
getdefaulttimeout() functions to the socket and _socket modules, and
appropriate tests.
diff --git a/Lib/socket.py b/Lib/socket.py
index bd0bfd7..c351a91 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -21,6 +21,8 @@
 inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
 inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
 ssl() -- secure socket layer support (only available if configured)
+socket.getdefaulttimeout() -- get the default timeout value
+socket.setdefaulttimeout() -- set the default timeout value
 
  [*] not available on all platforms!
 
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index c9ef5d6..b9b9db6 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -297,6 +297,36 @@
             except socket.error:
                 pass
 
+    def testDefaultTimeout(self):
+        """Testing default timeout."""
+        # The default timeout should initially be None
+        self.assertEqual(socket.getdefaulttimeout(), None)
+        s = socket.socket()
+        self.assertEqual(s.gettimeout(), None)
+        s.close()
+
+        # Set the default timeout to 10, and see if it propagates
+        socket.setdefaulttimeout(10)
+        self.assertEqual(socket.getdefaulttimeout(), 10)
+        s = socket.socket()
+        self.assertEqual(s.gettimeout(), 10)
+        s.close()
+
+        # Reset the default timeout to None, and see if it propagates
+        socket.setdefaulttimeout(None)
+        self.assertEqual(socket.getdefaulttimeout(), None)
+        s = socket.socket()
+        self.assertEqual(s.gettimeout(), None)
+        s.close()
+
+        # Check that setting it to an invalid value raises ValueError
+        self.assertRaises(ValueError, socket.setdefaulttimeout, -1)
+
+        # Check that setting it to an invalid type raises TypeError
+        self.assertRaises(TypeError, socket.setdefaulttimeout, "spam")
+
+    # XXX The following three don't test module-level functionality...
+
     def testSockName(self):
         """Testing getsockname()."""
         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)