merge from trunk
diff --git a/Lib/optparse.py b/Lib/optparse.py
index ab2ce40..3792e76 100644
--- a/Lib/optparse.py
+++ b/Lib/optparse.py
@@ -1,21 +1,13 @@
-"""optparse - a powerful, extensible, and easy-to-use option parser.
+"""A powerful, extensible, and easy-to-use option parser.
 
 By Greg Ward <gward@python.net>
 
-Originally distributed as Optik; see http://optik.sourceforge.net/ .
-
-If you have problems with this module, please do not file bugs,
-patches, or feature requests with Python; instead, use Optik's
-SourceForge project page:
-  http://sourceforge.net/projects/optik
+Originally distributed as Optik.
 
 For support, use the optik-users@lists.sourceforge.net mailing list
 (http://lists.sourceforge.net/lists/listinfo/optik-users).
 """
 
-# Python developers: please do not make changes to this file, since
-# it is automatically generated from the Optik source code.
-
 __version__ = "1.5.3"
 
 __all__ = ['Option',
@@ -1263,9 +1255,19 @@
             self.usage = usage
 
     def enable_interspersed_args(self):
+        """Set parsing to not stop on the first non-option, allowing
+        interspersing switches with command arguments. This is the
+        default behavior. See also disable_interspersed_args() and the
+        class documentation description of the attribute
+        allow_interspersed_args."""
         self.allow_interspersed_args = True
 
     def disable_interspersed_args(self):
+        """Set parsing to stop on the first non-option. Use this if
+        you have a command processor which runs another command that
+        has options of its own and you want to make sure these options
+        don't get confused.
+        """
         self.allow_interspersed_args = False
 
     def set_process_default_values(self, process):
diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py
index 04af9fb..8a71036 100644
--- a/Lib/test/test_atexit.py
+++ b/Lib/test/test_atexit.py
@@ -26,12 +26,13 @@
 class TestCase(unittest.TestCase):
     def setUp(self):
         self.stream = io.StringIO()
+        self.save_stdout, self.save_stderr = sys.stderr, sys.stdout
         sys.stdout = sys.stderr = self.stream
         atexit._clear()
 
     def tearDown(self):
-        sys.stdout = sys.__stdout__
-        sys.stderr = sys.__stderr__
+        sys.stdout = self.save_stdout
+        sys.stderr = self.save_stderr
         atexit._clear()
 
     def test_args(self):
diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py
index 987f33c..df2f8b1 100644
--- a/Lib/test/test_bisect.py
+++ b/Lib/test/test_bisect.py
@@ -196,6 +196,17 @@
     def test_backcompatibility(self):
         self.assertEqual(self.module.insort, self.module.insort_right)
 
+    def test_listDerived(self):
+        class List(list):
+            data = []
+            def insert(self, index, item):
+                self.data.insert(index, item)
+
+        lst = List()
+        self.module.insort_left(lst, 10)
+        self.module.insort_right(lst, 5)
+        self.assertEqual([5, 10], lst.data)
+
 class TestInsortPython(TestInsort):
     module = py_bisect
 
diff --git a/Lib/test/test_datetime.py b/Lib/test/test_datetime.py
index 4b8ae82..ead4b1c 100644
--- a/Lib/test/test_datetime.py
+++ b/Lib/test/test_datetime.py
@@ -249,7 +249,7 @@
         self.assertRaises(TypeError, lambda: a // x)
         self.assertRaises(TypeError, lambda: x // a)
 
-        # Divison of int by timedelta doesn't make sense.
+        # Division of int by timedelta doesn't make sense.
         # Division by zero doesn't make sense.
         for zero in 0, 0:
             self.assertRaises(TypeError, lambda: zero // a)
diff --git a/Lib/test/test_dbm.py b/Lib/test/test_dbm.py
index ee82dd2..9f929f4 100644
--- a/Lib/test/test_dbm.py
+++ b/Lib/test/test_dbm.py
@@ -140,6 +140,23 @@
 
     def setUp(self):
         delete_files()
+        self.filename = test.support.TESTFN
+        self.d = dbm.open(self.filename, 'c')
+        self.d.close()
+
+    def test_keys(self):
+        self.d = dbm.open(self.filename, 'c')
+        self.assertEqual(self.d.keys(), [])
+        a = [(b'a', b'b'), (b'12345678910', b'019237410982340912840198242')]
+        for k, v in a:
+            self.d[k] = v
+        self.assertEqual(sorted(self.d.keys()), sorted(k for (k, v) in a))
+        for k, v in a:
+            self.assert_(k in self.d)
+            self.assertEqual(self.d[k], v)
+        self.assert_('xxx' not in self.d)
+        self.assertRaises(KeyError, lambda: self.d['xxx'])
+        self.d.close()
 
 
 def test_main():
diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py
index d1799a2..bd96e23 100644
--- a/Lib/test/test_docxmlrpc.py
+++ b/Lib/test/test_docxmlrpc.py
@@ -8,9 +8,9 @@
 PORT = None
 
 def server(evt, numrequests):
-    try:
-        serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
+    serv = DocXMLRPCServer(("localhost", 0), logRequests=False)
 
+    try:
         global PORT
         PORT = serv.socket.getsockname()[1]
 
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 0e92551..0effd65 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -391,6 +391,17 @@
             else:
                 self.fail()
 
+    def test_remove_keyerror_set(self):
+        key = self.thetype([3, 4])
+        try:
+            self.s.remove(key)
+        except KeyError as e:
+            self.assert_(e.args[0] is key,
+                         "KeyError should be {0}, not {1}".format(key,
+                                                                  e.args[0]))
+        else:
+            self.fail()
+
     def test_discard(self):
         self.s.discard('a')
         self.assert_('a' not in self.s)