Merged revisions 62350-62355,62358-62359,62364-62365,62370,62372-62375,62378-62379,62381 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r62350 | nick.coghlan | 2008-04-15 12:25:31 +0200 (Tue, 15 Apr 2008) | 1 line

  Issue 2439: add pkgutils.get_data() as a convenience wrapper for the PEP 302 get_data() API (contributed by Paul Moore)
........
  r62351 | nick.coghlan | 2008-04-15 12:28:14 +0200 (Tue, 15 Apr 2008) | 1 line

  Add test file missing from rev 62350
........
  r62352 | benjamin.peterson | 2008-04-15 13:58:46 +0200 (Tue, 15 Apr 2008) | 2 lines

  Add myself to Doc/ACKS.txt
........
  r62353 | andrew.kuchling | 2008-04-15 15:10:07 +0200 (Tue, 15 Apr 2008) | 6 lines

  Add *,**,@ to index, as suggested by
  http://farmdev.com/thoughts/24/what-does-the-def-star-variable-or-def-asterisk-parameter-syntax-do-in-python-/

  The right entry type to use isn't clear; operator seems wrong, because *,**,@
  aren't being used in expressions here.  I put them as 'statement'; 'syntax'
  might be better.
........
  r62354 | andrew.kuchling | 2008-04-15 15:10:41 +0200 (Tue, 15 Apr 2008) | 1 line

  Typo fix
........
  r62355 | mark.dickinson | 2008-04-15 22:51:18 +0200 (Tue, 15 Apr 2008) | 3 lines

  Fix for possible signed overflow:  the behaviour of -LONG_MIN is
  undefined in ANSI C.
........
  r62358 | jeroen.ruigrok | 2008-04-16 14:47:01 +0200 (Wed, 16 Apr 2008) | 2 lines

  Reformat to 80 columns prior to adding documentation.
........
  r62359 | jeroen.ruigrok | 2008-04-16 14:57:43 +0200 (Wed, 16 Apr 2008) | 2 lines

  Add details about the return value for mmap.flush().
........
  r62364 | raymond.hettinger | 2008-04-17 12:48:31 +0200 (Thu, 17 Apr 2008) | 1 line

  Issue 2648: Add leading zero to money format recipe in the docs.
........
  r62365 | jeroen.ruigrok | 2008-04-17 14:39:45 +0200 (Thu, 17 Apr 2008) | 2 lines

  Be consistent in the use of read-only.
........
  r62370 | andrew.kuchling | 2008-04-17 22:44:06 +0200 (Thu, 17 Apr 2008) | 1 line

  Typo fixes
........
  r62372 | andrew.kuchling | 2008-04-18 04:40:47 +0200 (Fri, 18 Apr 2008) | 1 line

  Use correct parameter name
........
  r62373 | andrew.kuchling | 2008-04-18 18:53:09 +0200 (Fri, 18 Apr 2008) | 1 line

  #2654: fix typo
........
  r62374 | andrew.kuchling | 2008-04-18 20:28:23 +0200 (Fri, 18 Apr 2008) | 4 lines

  Remove personal note from Jim Roskind; it no longer applies, and the
  e-mail address is for a previous employer.

  Can we move the big long copyright statement into a sidebar or something?
........
  r62375 | andrew.kuchling | 2008-04-18 20:39:55 +0200 (Fri, 18 Apr 2008) | 1 line

  Rewrite introductory section, and remove old section.  (It was already commented-out, but why keep it?)
........
  r62378 | skip.montanaro | 2008-04-18 22:35:46 +0200 (Fri, 18 Apr 2008) | 1 line

  resolve issue 2014
........
  r62379 | benjamin.peterson | 2008-04-18 22:45:33 +0200 (Fri, 18 Apr 2008) | 2 lines

  Fix indentation in sysmodule.c
........
  r62381 | amaury.forgeotdarc | 2008-04-19 01:31:33 +0200 (Sat, 19 Apr 2008) | 3 lines

  Some tests did not pass on repeated calls (regrtest -R::)
  Perform additional cleanup, mostly deleting from sys.modules, or clearing the warnings registry.
........
diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py
index 000f241..675cea3 100755
--- a/Lib/test/regrtest.py
+++ b/Lib/test/regrtest.py
@@ -731,6 +731,11 @@
     from distutils.dir_util import _path_created
     from weakref import WeakSet
 
+    # Clear the warnings registry, so they can be displayed again
+    for mod in sys.modules.values():
+        if hasattr(mod, '__warningregistry__'):
+            del mod.__warningregistry__
+
     # Restore some original values.
     warnings.filters[:] = fs
     copy_reg.dispatch_table.clear()
diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py
index 99f499d..c86a24d 100644
--- a/Lib/test/test_frozen.py
+++ b/Lib/test/test_frozen.py
@@ -39,6 +39,18 @@
         else:
             self.fail("import __phello__.foo should have failed")
 
+            if sys.platform != "mac":  # On the Mac this import does succeed.
+                try:
+                    import __phello__.foo
+                except ImportError:
+                    pass
+                else:
+                    self.fail("import __phello__.foo should have failed")
+
+        del sys.modules['__hello__']
+        del sys.modules['__phello__']
+        del sys.modules['__phello__.spam']
+
 def test_main():
     run_unittest(FrozenTests)
 
diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py
index dcc7433..db8e844 100644
--- a/Lib/test/test_pkg.py
+++ b/Lib/test/test_pkg.py
@@ -46,6 +46,7 @@
 
     def setUp(self):
         self.root = None
+        self.pkgname = None
         self.syspath = list(sys.path)
         self.sysmodules = sys.modules.copy()
 
@@ -56,6 +57,13 @@
         del self.sysmodules
         cleanout(self.root)
 
+        # delete all modules concerning the tested hiearchy
+        if self.pkgname:
+            modules = [name for name in sys.modules
+                       if self.pkgname in name.split('.')]
+            for name in modules:
+                del sys.modules[name]
+
     def run_code(self, code):
         exec(textwrap.dedent(code), globals(), {"self": self})
 
@@ -78,6 +86,8 @@
                     f.write('\n')
                 f.close()
         self.root = root
+        # package name is the name of the first item
+        self.pkgname = descr[0][0]
 
     def test_1(self):
         hier = [("t1", None), ("t1 __init__.py", "")]
diff --git a/Lib/test/test_pkgutil.py b/Lib/test/test_pkgutil.py
new file mode 100644
index 0000000..c9ec060
--- /dev/null
+++ b/Lib/test/test_pkgutil.py
@@ -0,0 +1,127 @@
+from test.test_support import run_unittest
+import unittest
+import sys
+import imp
+import pkgutil
+import os
+import os.path
+import tempfile
+import shutil
+import zipfile
+
+
+
+class PkgutilTests(unittest.TestCase):
+
+    def setUp(self):
+        self.dirname = tempfile.mkdtemp()
+        sys.path.insert(0, self.dirname)
+
+    def tearDown(self):
+        del sys.path[0]
+        shutil.rmtree(self.dirname)
+
+    def test_getdata_filesys(self):
+        pkg = 'test_getdata_filesys'
+
+        # Include a LF and a CRLF, to test that binary data is read back
+        RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line'
+
+        # Make a package with some resources
+        package_dir = os.path.join(self.dirname, pkg)
+        os.mkdir(package_dir)
+        # Empty init.py
+        f = open(os.path.join(package_dir, '__init__.py'), "wb")
+        f.close()
+        # Resource files, res.txt, sub/res.txt
+        f = open(os.path.join(package_dir, 'res.txt'), "wb")
+        f.write(RESOURCE_DATA)
+        f.close()
+        os.mkdir(os.path.join(package_dir, 'sub'))
+        f = open(os.path.join(package_dir, 'sub', 'res.txt'), "wb")
+        f.write(RESOURCE_DATA)
+        f.close()
+
+        # Check we can read the resources
+        res1 = pkgutil.get_data(pkg, 'res.txt')
+        self.assertEqual(res1, RESOURCE_DATA)
+        res2 = pkgutil.get_data(pkg, 'sub/res.txt')
+        self.assertEqual(res2, RESOURCE_DATA)
+
+        del sys.modules[pkg]
+
+    def test_getdata_zipfile(self):
+        zip = 'test_getdata_zipfile.zip'
+        pkg = 'test_getdata_zipfile'
+
+        # Include a LF and a CRLF, to test that binary data is read back
+        RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line'
+
+        # Make a package with some resources
+        zip_file = os.path.join(self.dirname, zip)
+        z = zipfile.ZipFile(zip_file, 'w')
+
+        # Empty init.py
+        z.writestr(pkg + '/__init__.py', "")
+        # Resource files, res.txt, sub/res.txt
+        z.writestr(pkg + '/res.txt', RESOURCE_DATA)
+        z.writestr(pkg + '/sub/res.txt', RESOURCE_DATA)
+        z.close()
+
+        # Check we can read the resources
+        sys.path.insert(0, zip_file)
+        res1 = pkgutil.get_data(pkg, 'res.txt')
+        self.assertEqual(res1, RESOURCE_DATA)
+        res2 = pkgutil.get_data(pkg, 'sub/res.txt')
+        self.assertEqual(res2, RESOURCE_DATA)
+        del sys.path[0]
+
+        del sys.modules[pkg]
+
+class PkgutilPEP302Tests(unittest.TestCase):
+
+    class MyTestLoader(object):
+        def load_module(self, fullname):
+            # Create an empty module
+            mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
+            mod.__file__ = "<%s>" % self.__class__.__name__
+            mod.__loader__ = self
+            # Make it a package
+            mod.__path__ = []
+            # Count how many times the module is reloaded
+            mod.__dict__['loads'] = mod.__dict__.get('loads',0) + 1
+            return mod
+
+        def get_data(self, path):
+            return "Hello, world!"
+
+    class MyTestImporter(object):
+        def find_module(self, fullname, path=None):
+            return PkgutilPEP302Tests.MyTestLoader()
+
+    def setUp(self):
+        sys.meta_path.insert(0, self.MyTestImporter())
+
+    def tearDown(self):
+        del sys.meta_path[0]
+
+    def test_getdata_pep302(self):
+        # Use a dummy importer/loader
+        self.assertEqual(pkgutil.get_data('foo', 'dummy'), "Hello, world!")
+        del sys.modules['foo']
+
+    def test_alreadyloaded(self):
+        # Ensure that get_data works without reloading - the "loads" module
+        # variable in the example loader should count how many times a reload
+        # occurs.
+        import foo
+        self.assertEqual(foo.loads, 1)
+        self.assertEqual(pkgutil.get_data('foo', 'dummy'), "Hello, world!")
+        self.assertEqual(foo.loads, 1)
+        del sys.modules['foo']
+
+def test_main():
+    run_unittest(PkgutilTests, PkgutilPEP302Tests)
+
+if __name__ == '__main__':
+    test_main()
diff --git a/Lib/test/test_profile.py b/Lib/test/test_profile.py
index 398ab86..9fea434 100755
--- a/Lib/test/test_profile.py
+++ b/Lib/test/test_profile.py
@@ -22,8 +22,9 @@
     def do_profiling(cls):
         results = []
         prof = cls.profilerclass(timer, 0.001)
+        start_timer = timer()
         prof.runctx("testfunc()", globals(), locals())
-        results.append(timer())
+        results.append(timer() - start_timer)
         for methodname in cls.methodnames:
             s = StringIO()
             stats = pstats.Stats(prof, stream=s)
@@ -40,7 +41,7 @@
 
     def test_cprofile(self):
         results = self.do_profiling()
-        self.assertEqual(results[0], 43000)
+        self.assertEqual(results[0], 1000)
         for i, method in enumerate(self.methodnames):
             if results[i+1] != self.expected_output[method]:
                 print("Stats.%s output for %s doesn't fit expectation!" %
diff --git a/Lib/test/test_structmembers.py b/Lib/test/test_structmembers.py
index 27b4b70..97d7b23 100644
--- a/Lib/test/test_structmembers.py
+++ b/Lib/test/test_structmembers.py
@@ -101,12 +101,6 @@
 
 
 def test_main(verbose=None):
-    # Obscure hack so that this test passes after reloads or repeated calls
-    # to test_main (regrtest -R).
-    if '__warningregistry__' in globals():
-        del globals()['__warningregistry__']
-    if hasattr(sys, '__warningregistry__'):
-        del sys.__warningregistry__
     test_support.run_unittest(__name__)
 
 if __name__ == "__main__":
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index d8aee79..a6cbddf 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -391,6 +391,8 @@
 
 
 def test_main():
+    py_warnings.onceregistry.clear()
+    c_warnings.onceregistry.clear()
     test_support.run_unittest(CFilterTests,
                                 PyFilterTests,
                                 CWarnTests,
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index e708927..a254eee 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -49,6 +49,17 @@
         (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
         self.assertEquals(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
 
+    def test_datetime_before_1900(self):
+        # same as before but with an date before 1900
+        dt = datetime.datetime(1,  2, 10, 11, 41, 23)
+        s = xmlrpclib.dumps((dt,))
+        (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
+        self.assertEquals(newdt, dt)
+        self.assertEquals(m, None)
+
+        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
+        self.assertEquals(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
+
     def test_cmp_datetime_DateTime(self):
         now = datetime.datetime.now()
         dt = xmlrpclib.DateTime(now.timetuple())