[Python-checkins] r83247 - in python/branches/import_unicode: Doc/Makefile Doc/c-api/unicode.rst Doc/conf.py Doc/distutils/apiref.rst Doc/distutils/extending.rst Doc/documenting/markup.rst Doc/faq/extending.rst Doc/glossary.rst Doc/install/index.rst Doc/library/abc.rst Doc/library/argparse.rst Doc/library/ast.rst Doc/library/binascii.rst Doc/library/cmath.rst Doc/library/collections.rst Doc/library/configparser.rst Doc/library/contextlib.rst Doc/library/dbm.rst Doc/library/doctest.rst Doc/library/fnmatch.rst Doc/library/functions.rst Doc/library/functools.rst Doc/library/html.parser.rst Doc/library/http.cookiejar.rst Doc/library/importlib.rst Doc/library/io.rst Doc/library/itertools.rst Doc/library/locale.rst Doc/library/math.rst Doc/library/multiprocessing.rst Doc/library/os.path.rst Doc/library/os.rst Doc/library/pdb.rst Doc/library/pickletools.rst Doc/library/re.rst Doc/library/select.rst Doc/library/smtpd.rst Doc/library/socket.rst Doc/library/sqlite3.rst Doc/library/stdtypes.rst Doc/library/string.rst Doc/library/struct.rst Doc/library/subprocess.rst Doc/library/test.rst Doc/library/threading.rst Doc/library/tkinter.rst Doc/library/unittest.rst Doc/library/urllib.request.rst Doc/library/xml.dom.minidom.rst Doc/library/xml.dom.rst Doc/reference/expressions.rst Doc/tools/sphinxext/indexsidebar.html Doc/tools/sphinxext/pyspecific.py Doc/tutorial/classes.rst Doc/tutorial/floatingpoint.rst Doc/whatsnew/2.0.rst Doc/whatsnew/2.5.rst Doc/whatsnew/2.7.rst Grammar/Grammar Include/Python.h Lib/_abcoll.py Lib/_strptime.py Lib/ast.py Lib/asyncore.py Lib/base64.py Lib/configparser.py Lib/ctypes/__init__.py Lib/ctypes/test/test_arrays.py Lib/ctypes/test/test_bitfields.py Lib/ctypes/test/test_buffers.py Lib/ctypes/test/test_bytes.py Lib/ctypes/test/test_callbacks.py Lib/ctypes/test/test_cast.py Lib/ctypes/test/test_cfuncs.py Lib/ctypes/test/test_errno.py Lib/ctypes/test/test_internals.py Lib/ctypes/test/test_keeprefs.py Lib/ctypes/test/test_libc.py Lib/ctypes/test/test_objects.py Lib/ctypes/test/test_parameters.py Lib/ctypes/test/test_prototypes.py Lib/ctypes/test/test_python_api.py Lib/ctypes/test/test_random_things.py Lib/ctypes/test/test_repr.py Lib/ctypes/test/test_returnfuncptrs.py Lib/ctypes/test/test_stringptr.py Lib/ctypes/test/test_strings.py Lib/ctypes/test/test_structures.py Lib/ctypes/test/test_unicode.py Lib/datetime.py Lib/dbm/__init__.py Lib/distutils/archive_util.py Lib/distutils/bcppcompiler.py Lib/distutils/ccompiler.py Lib/distutils/cmd.py Lib/distutils/command/bdist.py Lib/distutils/command/bdist_dumb.py Lib/distutils/command/bdist_msi.py Lib/distutils/command/bdist_rpm.py Lib/distutils/command/bdist_wininst.py Lib/distutils/command/build.py Lib/distutils/command/build_clib.py Lib/distutils/command/build_ext.py Lib/distutils/command/build_py.py Lib/distutils/command/build_scripts.py Lib/distutils/command/config.py Lib/distutils/command/install.py Lib/distutils/command/register.py Lib/distutils/command/sdist.py Lib/distutils/command/upload.py Lib/distutils/config.py Lib/distutils/core.py Lib/distutils/cygwinccompiler.py Lib/distutils/dep_util.py Lib/distutils/dir_util.py Lib/distutils/dist.py Lib/distutils/emxccompiler.py Lib/distutils/errors.py Lib/distutils/extension.py Lib/distutils/fancy_getopt.py Lib/distutils/file_util.py Lib/distutils/filelist.py Lib/distutils/msvc9compiler.py Lib/distutils/msvccompiler.py Lib/distutils/sysconfig.py Lib/distutils/tests/support.py Lib/distutils/tests/test_archive_util.py Lib/distutils/tests/test_bdist.py Lib/distutils/tests/test_bdist_dumb.py Lib/distutils/tests/test_bdist_rpm.py Lib/distutils/tests/test_bdist_wininst.py Lib/distutils/tests/test_build_clib.py Lib/distutils/tests/test_build_ext.py Lib/distutils/tests/test_build_py.py Lib/distutils/tests/test_build_scripts.py Lib/distutils/tests/test_ccompiler.py Lib/distutils/tests/test_cmd.py Lib/distutils/tests/test_cygwinccompiler.py Lib/distutils/tests/test_dist.py Lib/distutils/tests/test_emxccompiler.py Lib/distutils/tests/test_extension.py Lib/distutils/tests/test_file_util.py Lib/distutils/tests/test_filelist.py Lib/distutils/tests/test_install.py Lib/distutils/tests/test_install_lib.py Lib/distutils/tests/test_register.py Lib/distutils/tests/test_sdist.py Lib/distutils/tests/test_sysconfig.py Lib/distutils/tests/test_unixccompiler.py Lib/distutils/tests/test_upload.py Lib/distutils/tests/test_util.py Lib/distutils/text_file.py Lib/distutils/unixccompiler.py Lib/distutils/util.py Lib/email/base64mime.py Lib/email/feedparser.py Lib/email/message.py Lib/email/test/test_email.py Lib/fnmatch.py Lib/getopt.py Lib/http/client.py Lib/http/cookiejar.py Lib/idlelib/PyShell.py Lib/importlib/test/benchmark.py Lib/json/encoder.py Lib/json/tests/test_fail.py Lib/ntpath.py Lib/os.py Lib/pdb.doc Lib/pdb.py Lib/pickle.py Lib/pickletools.py Lib/platform.py Lib/re.py Lib/smtpd.py Lib/sndhdr.py Lib/socket.py Lib/string.py Lib/subprocess.py Lib/sysconfig.py Lib/tarfile.py Lib/test/cfgparser.2 Lib/test/cfgparser.3 Lib/test/datetimetester.py Lib/test/pickletester.py Lib/test/script_helper.py Lib/test/sndhdrdata Lib/test/support.py Lib/test/symlink_support.py Lib/test/test_array.py Lib/test/test_ast.py Lib/test/test_asyncore.py Lib/test/test_binascii.py Lib/test/test_binop.py Lib/test/test_calendar.py Lib/test/test_cfgparser.py Lib/test/test_cmath.py Lib/test/test_collections.py Lib/test/test_datetime.py Lib/test/test_fnmatch.py Lib/test/test_getopt.py Lib/test/test_http_cookiejar.py Lib/test/test_import.py Lib/test/test_math.py Lib/test/test_minidom.py Lib/test/test_os.py Lib/test/test_osx_env.py Lib/test/test_platform.py Lib/test/test_posix.py Lib/test/test_posixpath.py Lib/test/test_pow.py Lib/test/test_profilehooks.py Lib/test/test_queue.py Lib/test/test_re.py Lib/test/test_robotparser.py Lib/test/test_smtpd.py Lib/test/test_sndhdr.py Lib/test/test_struct.py Lib/test/test_structseq.py Lib/test/test_subprocess.py Lib/test/test_sys.py Lib/test/test_sys_setprofile.py Lib/test/test_sys_settrace.py Lib/test/test_sysconfig.py Lib/test/test_tarfile.py Lib/test/test_threaded_import.py Lib/test/test_threading.py Lib/test/test_trace.py Lib/test/test_unicode.py Lib/test/test_unpack.py Lib/test/test_urllib.py Lib/test/test_urllib2.py Lib/test/test_urlparse.py Lib/threading.py Lib/tkinter/__main__.py Lib/trace.py Lib/unittest/case.py Lib/unittest/test/test_case.py Lib/urllib/parse.py Lib/urllib/request.py Lib/urllib/robotparser.py Lib/xml/dom/expatbuilder.py Lib/xml/dom/minidom.py Lib/xmlrpc/client.py Makefile.pre.in Misc/ACKS Misc/NEWS Misc/developers.txt Misc/maintainers.rst Misc/python-wing.wpr Modules/Setup.dist Modules/_ctypes/_ctypes.c Modules/_ctypes/callproc.c Modules/_ctypes/cfield.c Modules/_datetimemodule.c Modules/_io/_iomodule.c Modules/_json.c Modules/_pickle.c Modules/_struct.c Modules/binascii.c Modules/cmathmodule.c Modules/datetimemodule.c Modules/getpath.c Modules/makesetup Modules/mathmodule.c Modules/posixmodule.c Modules/sha1module.c Modules/zipimport.c Objects/bytearrayobject.c Objects/memoryobject.c Objects/object.c Objects/stringlib/formatter.h Objects/unicodeobject.c PC/config.c PCbuild/pythoncore.vcproj Python/ceval.c Python/getargs.c Python/graminit.c Tools/gdb/libpython.py Tools/i18n/msgfmt.py configure configure.in setup.py

victor.stinner python-checkins at python.org
Fri Jul 30 01:19:40 CEST 2010


Author: victor.stinner
Date: Fri Jul 30 01:19:37 2010
New Revision: 83247

Log:
Merge import_unicode with py3k (r83246)


Added:
   python/branches/import_unicode/Lib/datetime.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/datetime.py
   python/branches/import_unicode/Lib/test/cfgparser.2
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/cfgparser.2
   python/branches/import_unicode/Lib/test/cfgparser.3
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/cfgparser.3
   python/branches/import_unicode/Lib/test/datetimetester.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/datetimetester.py
   python/branches/import_unicode/Lib/test/sndhdrdata/
      - copied from r83246, /python/branches/py3k/Lib/test/sndhdrdata/
   python/branches/import_unicode/Lib/test/test_smtpd.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/test_smtpd.py
   python/branches/import_unicode/Lib/test/test_sndhdr.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/test_sndhdr.py
   python/branches/import_unicode/Lib/test/test_sys_setprofile.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/test_sys_setprofile.py
   python/branches/import_unicode/Lib/test/test_sys_settrace.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/test/test_sys_settrace.py
   python/branches/import_unicode/Lib/tkinter/__main__.py
      - copied unchanged from r83246, /python/branches/py3k/Lib/tkinter/__main__.py
   python/branches/import_unicode/Modules/_datetimemodule.c
      - copied unchanged from r83246, /python/branches/py3k/Modules/_datetimemodule.c
Removed:
   python/branches/import_unicode/Lib/distutils/tests/test_ccompiler.py
   python/branches/import_unicode/Lib/distutils/tests/test_emxccompiler.py
   python/branches/import_unicode/Lib/pdb.doc
   python/branches/import_unicode/Lib/test/test_profilehooks.py
   python/branches/import_unicode/Lib/test/test_trace.py
   python/branches/import_unicode/Modules/datetimemodule.c
Modified:
   python/branches/import_unicode/Doc/Makefile
   python/branches/import_unicode/Doc/c-api/unicode.rst
   python/branches/import_unicode/Doc/conf.py
   python/branches/import_unicode/Doc/distutils/apiref.rst
   python/branches/import_unicode/Doc/distutils/extending.rst
   python/branches/import_unicode/Doc/documenting/markup.rst
   python/branches/import_unicode/Doc/faq/extending.rst
   python/branches/import_unicode/Doc/glossary.rst
   python/branches/import_unicode/Doc/install/index.rst
   python/branches/import_unicode/Doc/library/abc.rst
   python/branches/import_unicode/Doc/library/argparse.rst
   python/branches/import_unicode/Doc/library/ast.rst
   python/branches/import_unicode/Doc/library/binascii.rst
   python/branches/import_unicode/Doc/library/cmath.rst
   python/branches/import_unicode/Doc/library/collections.rst
   python/branches/import_unicode/Doc/library/configparser.rst
   python/branches/import_unicode/Doc/library/contextlib.rst
   python/branches/import_unicode/Doc/library/dbm.rst
   python/branches/import_unicode/Doc/library/doctest.rst
   python/branches/import_unicode/Doc/library/fnmatch.rst
   python/branches/import_unicode/Doc/library/functions.rst
   python/branches/import_unicode/Doc/library/functools.rst
   python/branches/import_unicode/Doc/library/html.parser.rst
   python/branches/import_unicode/Doc/library/http.cookiejar.rst
   python/branches/import_unicode/Doc/library/importlib.rst
   python/branches/import_unicode/Doc/library/io.rst
   python/branches/import_unicode/Doc/library/itertools.rst
   python/branches/import_unicode/Doc/library/locale.rst
   python/branches/import_unicode/Doc/library/math.rst
   python/branches/import_unicode/Doc/library/multiprocessing.rst
   python/branches/import_unicode/Doc/library/os.path.rst
   python/branches/import_unicode/Doc/library/os.rst
   python/branches/import_unicode/Doc/library/pdb.rst
   python/branches/import_unicode/Doc/library/pickletools.rst
   python/branches/import_unicode/Doc/library/re.rst
   python/branches/import_unicode/Doc/library/select.rst
   python/branches/import_unicode/Doc/library/smtpd.rst
   python/branches/import_unicode/Doc/library/socket.rst
   python/branches/import_unicode/Doc/library/sqlite3.rst
   python/branches/import_unicode/Doc/library/stdtypes.rst
   python/branches/import_unicode/Doc/library/string.rst
   python/branches/import_unicode/Doc/library/struct.rst
   python/branches/import_unicode/Doc/library/subprocess.rst
   python/branches/import_unicode/Doc/library/test.rst
   python/branches/import_unicode/Doc/library/threading.rst
   python/branches/import_unicode/Doc/library/tkinter.rst
   python/branches/import_unicode/Doc/library/unittest.rst
   python/branches/import_unicode/Doc/library/urllib.request.rst
   python/branches/import_unicode/Doc/library/xml.dom.minidom.rst
   python/branches/import_unicode/Doc/library/xml.dom.rst
   python/branches/import_unicode/Doc/reference/expressions.rst
   python/branches/import_unicode/Doc/tools/sphinxext/indexsidebar.html
   python/branches/import_unicode/Doc/tools/sphinxext/pyspecific.py
   python/branches/import_unicode/Doc/tutorial/classes.rst
   python/branches/import_unicode/Doc/tutorial/floatingpoint.rst
   python/branches/import_unicode/Doc/whatsnew/2.0.rst
   python/branches/import_unicode/Doc/whatsnew/2.5.rst
   python/branches/import_unicode/Doc/whatsnew/2.7.rst
   python/branches/import_unicode/Grammar/Grammar
   python/branches/import_unicode/Include/Python.h
   python/branches/import_unicode/Lib/_abcoll.py
   python/branches/import_unicode/Lib/_strptime.py
   python/branches/import_unicode/Lib/ast.py
   python/branches/import_unicode/Lib/asyncore.py
   python/branches/import_unicode/Lib/base64.py
   python/branches/import_unicode/Lib/configparser.py
   python/branches/import_unicode/Lib/ctypes/__init__.py
   python/branches/import_unicode/Lib/ctypes/test/test_arrays.py
   python/branches/import_unicode/Lib/ctypes/test/test_bitfields.py
   python/branches/import_unicode/Lib/ctypes/test/test_buffers.py
   python/branches/import_unicode/Lib/ctypes/test/test_bytes.py
   python/branches/import_unicode/Lib/ctypes/test/test_callbacks.py
   python/branches/import_unicode/Lib/ctypes/test/test_cast.py
   python/branches/import_unicode/Lib/ctypes/test/test_cfuncs.py
   python/branches/import_unicode/Lib/ctypes/test/test_errno.py
   python/branches/import_unicode/Lib/ctypes/test/test_internals.py
   python/branches/import_unicode/Lib/ctypes/test/test_keeprefs.py
   python/branches/import_unicode/Lib/ctypes/test/test_libc.py
   python/branches/import_unicode/Lib/ctypes/test/test_objects.py
   python/branches/import_unicode/Lib/ctypes/test/test_parameters.py
   python/branches/import_unicode/Lib/ctypes/test/test_prototypes.py
   python/branches/import_unicode/Lib/ctypes/test/test_python_api.py
   python/branches/import_unicode/Lib/ctypes/test/test_random_things.py
   python/branches/import_unicode/Lib/ctypes/test/test_repr.py
   python/branches/import_unicode/Lib/ctypes/test/test_returnfuncptrs.py
   python/branches/import_unicode/Lib/ctypes/test/test_stringptr.py
   python/branches/import_unicode/Lib/ctypes/test/test_strings.py
   python/branches/import_unicode/Lib/ctypes/test/test_structures.py
   python/branches/import_unicode/Lib/ctypes/test/test_unicode.py
   python/branches/import_unicode/Lib/dbm/__init__.py
   python/branches/import_unicode/Lib/distutils/archive_util.py
   python/branches/import_unicode/Lib/distutils/bcppcompiler.py
   python/branches/import_unicode/Lib/distutils/ccompiler.py
   python/branches/import_unicode/Lib/distutils/cmd.py
   python/branches/import_unicode/Lib/distutils/command/bdist.py
   python/branches/import_unicode/Lib/distutils/command/bdist_dumb.py
   python/branches/import_unicode/Lib/distutils/command/bdist_msi.py
   python/branches/import_unicode/Lib/distutils/command/bdist_rpm.py
   python/branches/import_unicode/Lib/distutils/command/bdist_wininst.py
   python/branches/import_unicode/Lib/distutils/command/build.py
   python/branches/import_unicode/Lib/distutils/command/build_clib.py
   python/branches/import_unicode/Lib/distutils/command/build_ext.py
   python/branches/import_unicode/Lib/distutils/command/build_py.py
   python/branches/import_unicode/Lib/distutils/command/build_scripts.py
   python/branches/import_unicode/Lib/distutils/command/config.py
   python/branches/import_unicode/Lib/distutils/command/install.py
   python/branches/import_unicode/Lib/distutils/command/register.py
   python/branches/import_unicode/Lib/distutils/command/sdist.py
   python/branches/import_unicode/Lib/distutils/command/upload.py
   python/branches/import_unicode/Lib/distutils/config.py
   python/branches/import_unicode/Lib/distutils/core.py
   python/branches/import_unicode/Lib/distutils/cygwinccompiler.py
   python/branches/import_unicode/Lib/distutils/dep_util.py
   python/branches/import_unicode/Lib/distutils/dir_util.py
   python/branches/import_unicode/Lib/distutils/dist.py
   python/branches/import_unicode/Lib/distutils/emxccompiler.py
   python/branches/import_unicode/Lib/distutils/errors.py
   python/branches/import_unicode/Lib/distutils/extension.py
   python/branches/import_unicode/Lib/distutils/fancy_getopt.py
   python/branches/import_unicode/Lib/distutils/file_util.py
   python/branches/import_unicode/Lib/distutils/filelist.py
   python/branches/import_unicode/Lib/distutils/msvc9compiler.py
   python/branches/import_unicode/Lib/distutils/msvccompiler.py
   python/branches/import_unicode/Lib/distutils/sysconfig.py
   python/branches/import_unicode/Lib/distutils/tests/support.py
   python/branches/import_unicode/Lib/distutils/tests/test_archive_util.py
   python/branches/import_unicode/Lib/distutils/tests/test_bdist.py
   python/branches/import_unicode/Lib/distutils/tests/test_bdist_dumb.py
   python/branches/import_unicode/Lib/distutils/tests/test_bdist_rpm.py
   python/branches/import_unicode/Lib/distutils/tests/test_bdist_wininst.py
   python/branches/import_unicode/Lib/distutils/tests/test_build_clib.py
   python/branches/import_unicode/Lib/distutils/tests/test_build_ext.py
   python/branches/import_unicode/Lib/distutils/tests/test_build_py.py
   python/branches/import_unicode/Lib/distutils/tests/test_build_scripts.py
   python/branches/import_unicode/Lib/distutils/tests/test_cmd.py
   python/branches/import_unicode/Lib/distutils/tests/test_cygwinccompiler.py
   python/branches/import_unicode/Lib/distutils/tests/test_dist.py
   python/branches/import_unicode/Lib/distutils/tests/test_extension.py
   python/branches/import_unicode/Lib/distutils/tests/test_file_util.py
   python/branches/import_unicode/Lib/distutils/tests/test_filelist.py
   python/branches/import_unicode/Lib/distutils/tests/test_install.py
   python/branches/import_unicode/Lib/distutils/tests/test_install_lib.py
   python/branches/import_unicode/Lib/distutils/tests/test_register.py
   python/branches/import_unicode/Lib/distutils/tests/test_sdist.py
   python/branches/import_unicode/Lib/distutils/tests/test_sysconfig.py
   python/branches/import_unicode/Lib/distutils/tests/test_unixccompiler.py
   python/branches/import_unicode/Lib/distutils/tests/test_upload.py
   python/branches/import_unicode/Lib/distutils/tests/test_util.py
   python/branches/import_unicode/Lib/distutils/text_file.py
   python/branches/import_unicode/Lib/distutils/unixccompiler.py
   python/branches/import_unicode/Lib/distutils/util.py
   python/branches/import_unicode/Lib/email/base64mime.py
   python/branches/import_unicode/Lib/email/feedparser.py
   python/branches/import_unicode/Lib/email/message.py
   python/branches/import_unicode/Lib/email/test/test_email.py
   python/branches/import_unicode/Lib/fnmatch.py
   python/branches/import_unicode/Lib/getopt.py
   python/branches/import_unicode/Lib/http/client.py
   python/branches/import_unicode/Lib/http/cookiejar.py
   python/branches/import_unicode/Lib/idlelib/PyShell.py
   python/branches/import_unicode/Lib/importlib/test/benchmark.py
   python/branches/import_unicode/Lib/json/encoder.py
   python/branches/import_unicode/Lib/json/tests/test_fail.py
   python/branches/import_unicode/Lib/ntpath.py
   python/branches/import_unicode/Lib/os.py
   python/branches/import_unicode/Lib/pdb.py
   python/branches/import_unicode/Lib/pickle.py
   python/branches/import_unicode/Lib/pickletools.py
   python/branches/import_unicode/Lib/platform.py
   python/branches/import_unicode/Lib/re.py
   python/branches/import_unicode/Lib/smtpd.py
   python/branches/import_unicode/Lib/sndhdr.py
   python/branches/import_unicode/Lib/socket.py
   python/branches/import_unicode/Lib/string.py
   python/branches/import_unicode/Lib/subprocess.py
   python/branches/import_unicode/Lib/sysconfig.py
   python/branches/import_unicode/Lib/tarfile.py
   python/branches/import_unicode/Lib/test/pickletester.py
   python/branches/import_unicode/Lib/test/script_helper.py
   python/branches/import_unicode/Lib/test/support.py
   python/branches/import_unicode/Lib/test/symlink_support.py
   python/branches/import_unicode/Lib/test/test_array.py
   python/branches/import_unicode/Lib/test/test_ast.py
   python/branches/import_unicode/Lib/test/test_asyncore.py
   python/branches/import_unicode/Lib/test/test_binascii.py
   python/branches/import_unicode/Lib/test/test_binop.py
   python/branches/import_unicode/Lib/test/test_calendar.py
   python/branches/import_unicode/Lib/test/test_cfgparser.py
   python/branches/import_unicode/Lib/test/test_cmath.py
   python/branches/import_unicode/Lib/test/test_collections.py
   python/branches/import_unicode/Lib/test/test_datetime.py
   python/branches/import_unicode/Lib/test/test_fnmatch.py
   python/branches/import_unicode/Lib/test/test_getopt.py
   python/branches/import_unicode/Lib/test/test_http_cookiejar.py
   python/branches/import_unicode/Lib/test/test_import.py
   python/branches/import_unicode/Lib/test/test_math.py
   python/branches/import_unicode/Lib/test/test_minidom.py
   python/branches/import_unicode/Lib/test/test_os.py
   python/branches/import_unicode/Lib/test/test_osx_env.py
   python/branches/import_unicode/Lib/test/test_platform.py
   python/branches/import_unicode/Lib/test/test_posix.py
   python/branches/import_unicode/Lib/test/test_posixpath.py
   python/branches/import_unicode/Lib/test/test_pow.py
   python/branches/import_unicode/Lib/test/test_queue.py
   python/branches/import_unicode/Lib/test/test_re.py
   python/branches/import_unicode/Lib/test/test_robotparser.py
   python/branches/import_unicode/Lib/test/test_struct.py
   python/branches/import_unicode/Lib/test/test_structseq.py
   python/branches/import_unicode/Lib/test/test_subprocess.py
   python/branches/import_unicode/Lib/test/test_sys.py
   python/branches/import_unicode/Lib/test/test_sysconfig.py
   python/branches/import_unicode/Lib/test/test_tarfile.py
   python/branches/import_unicode/Lib/test/test_threaded_import.py
   python/branches/import_unicode/Lib/test/test_threading.py
   python/branches/import_unicode/Lib/test/test_unicode.py
   python/branches/import_unicode/Lib/test/test_unpack.py
   python/branches/import_unicode/Lib/test/test_urllib.py
   python/branches/import_unicode/Lib/test/test_urllib2.py
   python/branches/import_unicode/Lib/test/test_urlparse.py
   python/branches/import_unicode/Lib/threading.py
   python/branches/import_unicode/Lib/trace.py
   python/branches/import_unicode/Lib/unittest/case.py
   python/branches/import_unicode/Lib/unittest/test/test_case.py
   python/branches/import_unicode/Lib/urllib/parse.py
   python/branches/import_unicode/Lib/urllib/request.py
   python/branches/import_unicode/Lib/urllib/robotparser.py
   python/branches/import_unicode/Lib/xml/dom/expatbuilder.py
   python/branches/import_unicode/Lib/xml/dom/minidom.py
   python/branches/import_unicode/Lib/xmlrpc/client.py
   python/branches/import_unicode/Makefile.pre.in
   python/branches/import_unicode/Misc/ACKS
   python/branches/import_unicode/Misc/NEWS
   python/branches/import_unicode/Misc/developers.txt
   python/branches/import_unicode/Misc/maintainers.rst
   python/branches/import_unicode/Misc/python-wing.wpr
   python/branches/import_unicode/Modules/Setup.dist
   python/branches/import_unicode/Modules/_ctypes/_ctypes.c
   python/branches/import_unicode/Modules/_ctypes/callproc.c
   python/branches/import_unicode/Modules/_ctypes/cfield.c
   python/branches/import_unicode/Modules/_io/_iomodule.c
   python/branches/import_unicode/Modules/_json.c
   python/branches/import_unicode/Modules/_pickle.c
   python/branches/import_unicode/Modules/_struct.c
   python/branches/import_unicode/Modules/binascii.c
   python/branches/import_unicode/Modules/cmathmodule.c
   python/branches/import_unicode/Modules/getpath.c
   python/branches/import_unicode/Modules/makesetup
   python/branches/import_unicode/Modules/mathmodule.c
   python/branches/import_unicode/Modules/posixmodule.c
   python/branches/import_unicode/Modules/sha1module.c
   python/branches/import_unicode/Modules/zipimport.c
   python/branches/import_unicode/Objects/bytearrayobject.c
   python/branches/import_unicode/Objects/memoryobject.c
   python/branches/import_unicode/Objects/object.c
   python/branches/import_unicode/Objects/stringlib/formatter.h
   python/branches/import_unicode/Objects/unicodeobject.c
   python/branches/import_unicode/PC/config.c
   python/branches/import_unicode/PCbuild/pythoncore.vcproj
   python/branches/import_unicode/Python/ceval.c
   python/branches/import_unicode/Python/getargs.c
   python/branches/import_unicode/Python/graminit.c
   python/branches/import_unicode/Tools/gdb/libpython.py
   python/branches/import_unicode/Tools/i18n/msgfmt.py
   python/branches/import_unicode/configure
   python/branches/import_unicode/configure.in
   python/branches/import_unicode/setup.py

Modified: python/branches/import_unicode/Doc/Makefile
==============================================================================
--- python/branches/import_unicode/Doc/Makefile	(original)
+++ python/branches/import_unicode/Doc/Makefile	Fri Jul 30 01:19:37 2010
@@ -40,7 +40,7 @@
 checkout:
 	@if [ ! -d tools/sphinx ]; then \
 	  echo "Checking out Sphinx..."; \
-	  svn checkout $(SVNROOT)/external/Sphinx-0.6.5/sphinx tools/sphinx; \
+	  svn checkout $(SVNROOT)/external/Sphinx-1.0.1/sphinx tools/sphinx; \
 	fi
 	@if [ ! -d tools/docutils ]; then \
 	  echo "Checking out Docutils..."; \
@@ -144,6 +144,7 @@
 	# archive the A4 latex
 	-rm -r build/latex
 	make latex PAPER=a4
+	-sed -i 's/makeindex/makeindex -q/' build/latex/Makefile
 	(cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2)
 	cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-a4.zip
 	cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
@@ -151,6 +152,7 @@
 	# archive the letter latex
 	rm -r build/latex
 	make latex PAPER=letter
+	-sed -i 's/makeindex/makeindex -q/' build/latex/Makefile
 	(cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2)
 	cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip
 	cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2

Modified: python/branches/import_unicode/Doc/c-api/unicode.rst
==============================================================================
--- python/branches/import_unicode/Doc/c-api/unicode.rst	(original)
+++ python/branches/import_unicode/Doc/c-api/unicode.rst	Fri Jul 30 01:19:37 2010
@@ -376,7 +376,7 @@
 :cdata:`Py_FileSystemEncoding` should be used as the encoding, and
 ``"surrogateescape"`` should be used as the error handler (:pep:`383`). To
 encode file names during argument parsing, the ``"O&"`` converter should be
-used, passsing :func:PyUnicode_FSConverter as the conversion function:
+used, passsing :func:`PyUnicode_FSConverter` as the conversion function:
 
 .. cfunction:: int PyUnicode_FSConverter(PyObject* obj, void* result)
 

Modified: python/branches/import_unicode/Doc/conf.py
==============================================================================
--- python/branches/import_unicode/Doc/conf.py	(original)
+++ python/branches/import_unicode/Doc/conf.py	Fri Jul 30 01:19:37 2010
@@ -152,7 +152,7 @@
 latex_appendices = ['glossary', 'about', 'license', 'copyright']
 
 # Get LaTeX to handle Unicode correctly
-latex_elements = {'inputenc': r'\usepackage[utf8x]{inputenc}'}
+latex_elements = {'inputenc': r'\usepackage[utf8x]{inputenc}', 'utf8extra': ''}
 
 # Options for the coverage checker
 # --------------------------------

Modified: python/branches/import_unicode/Doc/distutils/apiref.rst
==============================================================================
--- python/branches/import_unicode/Doc/distutils/apiref.rst	(original)
+++ python/branches/import_unicode/Doc/distutils/apiref.rst	Fri Jul 30 01:19:37 2010
@@ -21,7 +21,9 @@
 .. function:: setup(arguments)
 
    The basic do-everything function that does most everything you could ever ask
-   for from a Distutils method. See XXXXX
+   for from a Distutils method.
+
+   .. See XXXXX
 
    The setup function takes a large number of arguments. These are laid out in the
    following table.
@@ -147,11 +149,11 @@
 In addition, the :mod:`distutils.core` module exposed a number of  classes that
 live elsewhere.
 
-* :class:`Extension` from :mod:`distutils.extension`
+* :class:`~distutils.extension.Extension` from :mod:`distutils.extension`
 
-* :class:`Command` from :mod:`distutils.cmd`
+* :class:`~distutils.cmd.Command` from :mod:`distutils.cmd`
 
-* :class:`Distribution` from :mod:`distutils.dist`
+* :class:`~distutils.dist.Distribution` from :mod:`distutils.dist`
 
 A short description of each of these follows, but see the relevant module for
 the full reference.
@@ -1679,8 +1681,8 @@
 ===================================================================
 
 .. module:: distutils.cmd
-   :synopsis: This module provides the abstract base class Command. This class is subclassed
-              by the modules in the distutils.command  subpackage.
+   :synopsis: This module provides the abstract base class Command. This class
+              is subclassed by the modules in the distutils.command subpackage.
 
 
 This module supplies the abstract base class :class:`Command`.
@@ -1690,20 +1692,84 @@
 
    Abstract base class for defining command classes, the "worker bees" of the
    Distutils.  A useful analogy for command classes is to think of them as
-   subroutines with local variables called *options*.  The options are declared in
-   :meth:`initialize_options` and defined (given their final values) in
-   :meth:`finalize_options`, both of which must be defined by every command class.
-   The distinction between the two is necessary because option values might come
-   from the outside world (command line, config file, ...), and any options
-   dependent on other options must be computed after these outside influences have
-   been processed --- hence :meth:`finalize_options`.  The body of the subroutine,
-   where it does all its work based on the values of its options, is the
-   :meth:`run` method, which must also be implemented by every command class.
+   subroutines with local variables called *options*.  The options are declared
+   in :meth:`initialize_options` and defined (given their final values) in
+   :meth:`finalize_options`, both of which must be defined by every command
+   class.  The distinction between the two is necessary because option values
+   might come from the outside world (command line, config file, ...), and any
+   options dependent on other options must be computed after these outside
+   influences have been processed --- hence :meth:`finalize_options`.  The body
+   of the subroutine, where it does all its work based on the values of its
+   options, is the :meth:`run` method, which must also be implemented by every
+   command class.
 
-   The class constructor takes a single argument *dist*, a  :class:`Distribution`
+   The class constructor takes a single argument *dist*, a :class:`Distribution`
    instance.
 
 
+Creating a new Distutils command
+================================
+
+This section outlines the steps to create a new Distutils command.
+
+A new command lives in a module in the :mod:`distutils.command` package. There
+is a sample template in that directory called :file:`command_template`.  Copy
+this file to a new module with the same name as the new command you're
+implementing.  This module should implement a class with the same name as the
+module (and the command).  So, for instance, to create the command
+``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
+:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
+it so that it's implementing the class :class:`peel_banana`, a subclass of
+:class:`distutils.cmd.Command`.
+
+Subclasses of :class:`Command` must define the following methods.
+
+.. method:: Command.initialize_options()
+
+   Set default values for all the options that this command supports.  Note that
+   these defaults may be overridden by other commands, by the setup script, by
+   config files, or by the command-line.  Thus, this is not the place to code
+   dependencies between options; generally, :meth:`initialize_options`
+   implementations are just a bunch of ``self.foo = None`` assignments.
+
+
+.. method:: Command.finalize_options()
+
+   Set final values for all the options that this command supports. This is
+   always called as late as possible, ie.  after any option assignments from the
+   command-line or from other commands have been done.  Thus, this is the place
+   to to code option dependencies: if *foo* depends on *bar*, then it is safe to
+   set *foo* from *bar* as long as *foo* still has the same value it was
+   assigned in :meth:`initialize_options`.
+
+
+.. method:: Command.run()
+
+   A command's raison d'etre: carry out the action it exists to perform,
+   controlled by the options initialized in :meth:`initialize_options`,
+   customized by other commands, the setup script, the command-line, and config
+   files, and finalized in :meth:`finalize_options`.  All terminal output and
+   filesystem interaction should be done by :meth:`run`.
+
+
+.. attribute:: Command.sub_commands
+
+   *sub_commands* formalizes the notion of a "family" of commands,
+   e.g. ``install`` as the parent with sub-commands ``install_lib``,
+   ``install_headers``, etc.  The parent of a family of commands defines
+   *sub_commands* as a class attribute; it's a list of 2-tuples ``(command_name,
+   predicate)``, with *command_name* a string and *predicate* a function, a
+   string or ``None``.  *predicate* is a method of the parent command that
+   determines whether the corresponding command is applicable in the current
+   situation.  (E.g. we ``install_headers`` is only applicable if we have any C
+   header files to install.)  If *predicate* is ``None``, that command is always
+   applicable.
+
+   *sub_commands* is usually defined at the *end* of a class, because
+   predicates can be methods of the class, so they must already have been
+   defined.  The canonical example is the :command:`install` command.
+
+
 :mod:`distutils.command` --- Individual Distutils commands
 ==========================================================
 
@@ -1942,63 +2008,3 @@
 This is described in more detail in :pep:`301`.
 
 .. % todo
-
-
-Creating a new Distutils command
-================================
-
-This section outlines the steps to create a new Distutils command.
-
-A new command lives in a module in the :mod:`distutils.command` package. There
-is a sample template in that directory called  :file:`command_template`. Copy
-this file to a new module with the same name as the new command you're
-implementing. This module should implement a class with the same name as the
-module (and the command). So, for instance, to create the command
-``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
-:file:`command_template`  to :file:`distutils/command/peel_banana.py`, then edit
-it so that it's implementing the class :class:`peel_banana`, a subclass of
-:class:`distutils.cmd.Command`.
-
-Subclasses of :class:`Command` must define the following methods.
-
-
-.. method:: Command.initialize_options()
-
-   Set default values for all the options that this command supports.  Note that
-   these defaults may be overridden by other commands, by the setup script, by
-   config files, or by the command-line.  Thus, this is not the place to code
-   dependencies between options; generally, :meth:`initialize_options`
-   implementations are just a bunch of ``self.foo = None`` assignments.
-
-
-.. method:: Command.finalize_options()
-
-   Set final values for all the options that this command supports. This is
-   always called as late as possible, ie.  after any option assignments from the
-   command-line or from other commands have been done.  Thus, this is the place
-   to to code option dependencies: if *foo* depends on *bar*, then it is safe to
-   set *foo* from *bar* as long as *foo* still has the same value it was
-   assigned in :meth:`initialize_options`.
-
-
-.. method:: Command.run()
-
-   A command's raison d'etre: carry out the action it exists to perform, controlled
-   by the options initialized in :meth:`initialize_options`, customized by other
-   commands, the setup script, the command-line, and config files, and finalized in
-   :meth:`finalize_options`.  All terminal output and filesystem interaction should
-   be done by :meth:`run`.
-
-*sub_commands* formalizes the notion of a "family" of commands, eg. ``install``
-as the parent with sub-commands ``install_lib``, ``install_headers``, etc.  The
-parent of a family of commands defines *sub_commands* as a class attribute; it's
-a list of 2-tuples ``(command_name, predicate)``, with *command_name* a string
-and *predicate* a function, a string or None. *predicate* is a method of
-the parent command that determines whether the corresponding command is
-applicable in the current situation.  (Eg. we ``install_headers`` is only
-applicable if we have any C header files to install.)  If *predicate* is None,
-that command is always applicable.
-
-*sub_commands* is usually defined at the \*end\* of a class, because predicates
-can be methods of the class, so they must already have been defined.  The
-canonical example is the :command:`install` command.

Modified: python/branches/import_unicode/Doc/distutils/extending.rst
==============================================================================
--- python/branches/import_unicode/Doc/distutils/extending.rst	(original)
+++ python/branches/import_unicode/Doc/distutils/extending.rst	Fri Jul 30 01:19:37 2010
@@ -15,8 +15,8 @@
 should be copied into packages in addition to :file:`.py` files as a
 convenience.
 
-Most distutils command implementations are subclasses of the :class:`Command`
-class from :mod:`distutils.cmd`.  New commands may directly inherit from
+Most distutils command implementations are subclasses of the
+:class:`distutils.cmd.Command` class.  New commands may directly inherit from
 :class:`Command`, while replacements often derive from :class:`Command`
 indirectly, directly subclassing the command they are replacing.  Commands are
 required to derive from :class:`Command`.

Modified: python/branches/import_unicode/Doc/documenting/markup.rst
==============================================================================
--- python/branches/import_unicode/Doc/documenting/markup.rst	(original)
+++ python/branches/import_unicode/Doc/documenting/markup.rst	Fri Jul 30 01:19:37 2010
@@ -177,6 +177,34 @@
    are modified), side effects, and possible exceptions.  A small example may be
    provided.
 
+.. describe:: decorator
+
+   Describes a decorator function.  The signature should *not* represent the
+   signature of the actual function, but the usage as a decorator.  For example,
+   given the functions
+
+   .. code-block:: python
+
+      def removename(func):
+          func.__name__ = ''
+          return func
+
+      def setnewname(name):
+          def decorator(func):
+              func.__name__ = name
+              return func
+          return decorator
+
+   the descriptions should look like this::
+
+      .. decorator:: removename
+
+         Remove name of the decorated function.
+
+      .. decorator:: setnewname(name)
+
+         Set name of the decorated function to *name*.
+
 .. describe:: class
 
    Describes a class.  The signature can include parentheses with parameters
@@ -194,14 +222,18 @@
    parameter.  The description should include similar information to that
    described for ``function``.
 
+.. describe:: decoratormethod
+
+   Same as ``decorator``, but for decorators that are methods.
+
 .. describe:: opcode
 
    Describes a Python :term:`bytecode` instruction.
 
 .. describe:: cmdoption
 
-   Describes a command line option or switch.  Option argument names should be
-   enclosed in angle brackets.  Example::
+   Describes a Python command line option or switch.  Option argument names
+   should be enclosed in angle brackets.  Example::
 
       .. cmdoption:: -m <module>
 
@@ -502,8 +534,9 @@
 
 .. describe:: option
 
-   A command-line option to an executable program.  The leading hyphen(s) must
-   be included.
+   A command-line option of Python.  The leading hyphen(s) must be included.
+   If a matching ``cmdoption`` directive exists, it is linked to.  For options
+   of other programs or scripts, use simple ````code```` markup.
 
 .. describe:: program
 

Modified: python/branches/import_unicode/Doc/faq/extending.rst
==============================================================================
--- python/branches/import_unicode/Doc/faq/extending.rst	(original)
+++ python/branches/import_unicode/Doc/faq/extending.rst	Fri Jul 30 01:19:37 2010
@@ -29,6 +29,8 @@
 C++ objects with constructors are probably not a good idea.
 
 
+.. _c-wrapper-software:
+
 Writing C is hard; are there any alternatives?
 ----------------------------------------------
 
@@ -200,11 +202,7 @@
 whole lot of difference between C and C++ -- so the strategy of building a new
 Python type around a C structure (pointer) type will also work for C++ objects.
 
-For C++ libraries, you can look at `SIP
-<http://www.riverbankcomputing.co.uk/software/sip/>`_, `CXX
-<http://cxx.sourceforge.net/>`_, `Boost
-<http://www.boost.org/libs/python/doc/index.html>`_, `Weave
-<http://www.scipy.org/Weave>`_ or `SWIG <http://www.swig.org>`_
+For C++ libraries, see :ref:`c-wrapper-software`.
 
 
 I added a module using the Setup file and the make fails; why?

Modified: python/branches/import_unicode/Doc/glossary.rst
==============================================================================
--- python/branches/import_unicode/Doc/glossary.rst	(original)
+++ python/branches/import_unicode/Doc/glossary.rst	Fri Jul 30 01:19:37 2010
@@ -154,15 +154,15 @@
       object.
 
    duck-typing
-      A pythonic programming style which determines an object's type by inspection
-      of its method or attribute signature rather than by explicit relationship
-      to some type object ("If it looks like a duck and quacks like a duck, it
+      A programming style which does not look at an object's type to determine
+      if it has the right interface; instead, the method or attribute is simply
+      called or used ("If it looks like a duck and quacks like a duck, it
       must be a duck.")  By emphasizing interfaces rather than specific types,
       well-designed code improves its flexibility by allowing polymorphic
       substitution.  Duck-typing avoids tests using :func:`type` or
-      :func:`isinstance`. (Note, however, that duck-typing can be complemented
-      with abstract base classes.) Instead, it typically employs :func:`hasattr`
-      tests or :term:`EAFP` programming.
+      :func:`isinstance`.  (Note, however, that duck-typing can be complemented
+      with :term:`abstract base class`\ es.)  Instead, it typically employs
+      :func:`hasattr` tests or :term:`EAFP` programming.
 
    EAFP
       Easier to ask for forgiveness than permission.  This common Python coding

Modified: python/branches/import_unicode/Doc/install/index.rst
==============================================================================
--- python/branches/import_unicode/Doc/install/index.rst	(original)
+++ python/branches/import_unicode/Doc/install/index.rst	Fri Jul 30 01:19:37 2010
@@ -314,8 +314,8 @@
 stash of Python modules.  This scheme's name is derived from the idea of a
 "home" directory on Unix, since it's not unusual for a Unix user to make their
 home directory have a layout similar to :file:`/usr/` or :file:`/usr/local/`.
-This scheme can be used by anyone, regardless of the operating system their
-installing for.
+This scheme can be used by anyone, regardless of the operating system they
+are installing for.
 
 Installing a new module distribution is as simple as ::
 

Modified: python/branches/import_unicode/Doc/library/abc.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/abc.rst	(original)
+++ python/branches/import_unicode/Doc/library/abc.rst	Fri Jul 30 01:19:37 2010
@@ -122,7 +122,7 @@
 
 It also provides the following decorators:
 
-.. function:: abstractmethod(function)
+.. decorator:: abstractmethod(function)
 
    A decorator indicating abstract methods.
 

Modified: python/branches/import_unicode/Doc/library/argparse.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/argparse.rst	(original)
+++ python/branches/import_unicode/Doc/library/argparse.rst	Fri Jul 30 01:19:37 2010
@@ -698,8 +698,8 @@
 
    >>> class FooAction(argparse.Action):
    ...     def __call__(self, parser, namespace, values, option_string=None):
-   ...     print('%r %r %r' % (namespace, values, option_string))
-   ...     setattr(namespace, self.dest, values)
+   ...         print('%r %r %r' % (namespace, values, option_string))
+   ...         setattr(namespace, self.dest, values)
    ...
    >>> parser = argparse.ArgumentParser()
    >>> parser.add_argument('--foo', action=FooAction)

Modified: python/branches/import_unicode/Doc/library/ast.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/ast.rst	(original)
+++ python/branches/import_unicode/Doc/library/ast.rst	Fri Jul 30 01:19:37 2010
@@ -119,12 +119,15 @@
 
    Safely evaluate an expression node or a string containing a Python
    expression.  The string or node provided may only consist of the following
-   Python literal structures: strings, numbers, tuples, lists, dicts, booleans,
-   and ``None``.
+   Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
+   sets, booleans, and ``None``.
 
    This can be used for safely evaluating strings containing Python expressions
    from untrusted sources without the need to parse the values oneself.
 
+   .. versionchanged:: 3.2
+      Now allows bytes and set literals.
+
 
 .. function:: get_docstring(node, clean=True)
 

Modified: python/branches/import_unicode/Doc/library/binascii.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/binascii.rst	(original)
+++ python/branches/import_unicode/Doc/library/binascii.rst	Fri Jul 30 01:19:37 2010
@@ -18,6 +18,11 @@
 low-level functions written in C for greater speed that are used by the
 higher-level modules.
 
+.. note::
+
+   Encoding and decoding functions do not accept Unicode strings.  Only bytestring
+   and bytearray objects can be processed.
+
 The :mod:`binascii` module defines the following functions:
 
 
@@ -54,6 +59,9 @@
    data. More than one line may be passed at a time. If the optional argument
    *header* is present and true, underscores will be decoded as spaces.
 
+   .. versionchanged:: 3.2
+      accept only bytestring or bytearray object as input.
+
 
 .. function:: b2a_qp(data, quotetabs=False, istext=True, header=False)
 
@@ -83,6 +91,9 @@
    decompressed data, unless data input data ends in an orphaned repeat indicator,
    in which case the :exc:`Incomplete` exception is raised.
 
+   .. versionchanged:: 3.2
+      accept only bytestring or bytearray object as input.
+
 
 .. function:: rlecode_hqx(data)
 
@@ -139,6 +150,9 @@
    of hexadecimal digits (which can be upper or lower case), otherwise a
    :exc:`TypeError` is raised.
 
+   .. versionchanged:: 3.2
+      accept only bytestring or bytearray object as input.
+
 
 .. exception:: Error
 
@@ -164,4 +178,3 @@
 
    Module :mod:`quopri`
       Support for quoted-printable encoding used in MIME email messages.
-

Modified: python/branches/import_unicode/Doc/library/cmath.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/cmath.rst	(original)
+++ python/branches/import_unicode/Doc/library/cmath.rst	Fri Jul 30 01:19:37 2010
@@ -187,15 +187,24 @@
 Classification functions
 ------------------------
 
+.. function:: isfinite(x)
+
+   Return ``True`` if both the real and imaginary parts of *x* are finite, and
+   ``False`` otherwise.
+
+   .. versionadded:: 3.2
+
+
 .. function:: isinf(x)
 
-   Return *True* if the real or the imaginary part of x is positive
-   or negative infinity.
+   Return ``True`` if either the real or the imaginary part of *x* is an
+   infinity, and ``False`` otherwise.
 
 
 .. function:: isnan(x)
 
-   Return *True* if the real or imaginary part of x is not a number (NaN).
+   Return ``True`` if either the real or the imaginary part of *x* is a NaN,
+   and ``False`` otherwise.
 
 
 Constants

Modified: python/branches/import_unicode/Doc/library/collections.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/collections.rst	(original)
+++ python/branches/import_unicode/Doc/library/collections.rst	Fri Jul 30 01:19:37 2010
@@ -551,7 +551,7 @@
    :class:`defaultdict` objects support the following method in addition to the
    standard :class:`dict` operations:
 
-   .. method:: defaultdict.__missing__(key)
+   .. method:: __missing__(key)
 
       If the :attr:`default_factory` attribute is ``None``, this raises a
       :exc:`KeyError` exception with the *key* as argument.
@@ -571,7 +571,7 @@
    :class:`defaultdict` objects support the following instance variable:
 
 
-   .. attribute:: defaultdict.default_factory
+   .. attribute:: default_factory
 
       This attribute is used by the :meth:`__missing__` method; it is
       initialized from the first argument to the constructor, if present, or to
@@ -763,7 +763,7 @@
 three additional methods and one attribute.  To prevent conflicts with
 field names, the method and attribute names start with an underscore.
 
-.. method:: somenamedtuple._make(iterable)
+.. classmethod:: somenamedtuple._make(iterable)
 
    Class method that makes a new instance from an existing sequence or iterable.
 
@@ -891,11 +891,11 @@
 
    .. versionadded:: 3.1
 
-.. method:: OrderedDict.popitem(last=True)
+   .. method:: popitem(last=True)
 
-   The :meth:`popitem` method for ordered dictionaries returns and removes
-   a (key, value) pair.  The pairs are returned in LIFO order if *last* is
-   true or FIFO order if false.
+      The :meth:`popitem` method for ordered dictionaries returns and removes a
+      (key, value) pair.  The pairs are returned in LIFO order if *last* is true
+      or FIFO order if false.
 
 In addition to the usual mapping methods, ordered dictionaries also support
 reverse iteration using :func:`reversed`.
@@ -956,12 +956,13 @@
    initialized with its contents; note that a reference to *initialdata* will not
    be kept, allowing it be used for other purposes.
 
-In addition to supporting the methods and operations of mappings,
-:class:`UserDict` instances provide the following attribute:
+   In addition to supporting the methods and operations of mappings,
+   :class:`UserDict` instances provide the following attribute:
 
-.. attribute:: UserDict.data
+   .. attribute:: data
 
-   A real dictionary used to store the contents of the :class:`UserDict` class.
+      A real dictionary used to store the contents of the :class:`UserDict`
+      class.
 
 
 
@@ -985,13 +986,13 @@
    defaulting to the empty list ``[]``.  *list* can be any iterable, for
    example a real Python list or a :class:`UserList` object.
 
-In addition to supporting the methods and operations of mutable sequences,
-:class:`UserList` instances provide the following attribute:
+   In addition to supporting the methods and operations of mutable sequences,
+   :class:`UserList` instances provide the following attribute:
 
-.. attribute:: UserList.data
+   .. attribute:: data
 
-   A real :class:`list` object used to store the contents of the
-   :class:`UserList` class.
+      A real :class:`list` object used to store the contents of the
+      :class:`UserList` class.
 
 **Subclassing requirements:** Subclasses of :class:`UserList` are expect to
 offer a constructor which can be called with either no arguments or one

Modified: python/branches/import_unicode/Doc/library/configparser.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/configparser.rst	(original)
+++ python/branches/import_unicode/Doc/library/configparser.rst	Fri Jul 30 01:19:37 2010
@@ -15,105 +15,172 @@
    single: ini file
    single: Windows ini file
 
-This module defines the class :class:`ConfigParser`.   The :class:`ConfigParser`
-class implements a basic configuration file parser language which provides a
-structure similar to what you would find on Microsoft Windows INI files.  You
-can use this to write Python programs which can be customized by end users
-easily.
+This module provides the classes :class:`RawConfigParser` and
+:class:`SafeConfigParser`.  They implement a basic configuration file parser
+language which provides a structure similar to what you would find in Microsoft
+Windows INI files.  You can use this to write Python programs which can be
+customized by end users easily.
 
 .. note::
 
    This library does *not* interpret or write the value-type prefixes used in
    the Windows Registry extended version of INI syntax.
 
-The configuration file consists of sections, led by a ``[section]`` header and
-followed by ``name: value`` entries, with continuations in the style of
-:rfc:`822` (see section 3.1.1, "LONG HEADER FIELDS"); ``name=value`` is also
-accepted.  Note that leading whitespace is removed from values. The optional
-values can contain format strings which refer to other values in the same
-section, or values in a special ``DEFAULT`` section.  Additional defaults can be
-provided on initialization and retrieval.  Lines beginning with ``'#'`` or
-``';'`` are ignored and may be used to provide comments.
+A configuration file consists of sections, each led by a ``[section]`` header,
+followed by name/value entries separated by a specific string (``=`` or ``:`` by
+default).  Note that leading whitespace is removed from values.  Values can be
+ommitted, in which case the key/value delimiter may also be left out.  Values
+can also span multiple lines, as long as they are indented deeper than the first
+line of the value.  Depending on the parser's mode, blank lines may be treated
+as parts of multiline values or ignored.
+
+Configuration files may include comments, prefixed by specific characters (``#``
+and ``;`` by default).  Comments may appear on their own in an otherwise empty
+line, or may be entered in lines holding values or spection names.  In the
+latter case, they need to be preceded by a whitespace character to be recognized
+as a comment.  (For backwards compatibility, by default only ``;`` starts an
+inline comment, while ``#`` does not.)
+
+On top of the core functionality, :class:`SafeConfigParser` supports
+interpolation.  This means values can contain format strings which refer to
+other values in the same section, or values in a special ``DEFAULT`` section.
+Additional defaults can be provided on initialization.
 
 For example::
 
-   [My Section]
-   foodir: %(dir)s/whatever
-   dir=frob
-   long: this value continues
-      in the next line
-
-would resolve the ``%(dir)s`` to the value of ``dir`` (``frob`` in this case).
-All reference expansions are done on demand.
-
-Default values can be specified by passing them into the :class:`ConfigParser`
-constructor as a dictionary.  Additional defaults  may be passed into the
-:meth:`get` method which will override all others.
-
-Sections are normally stored in a built-in dictionary. An alternative dictionary
-type can be passed to the :class:`ConfigParser` constructor. For example, if a
-dictionary type is passed that sorts its keys, the sections will be sorted on
-write-back, as will be the keys within each section.
+   [Paths]
+   home_dir: /Users
+   my_dir: %(home_dir)s/lumberjack
+   my_pictures: %(my_dir)s/Pictures
+
+   [Multiline Values]
+   chorus: I'm a lumberjack, and I'm okay
+      I sleep all night and I work all day
+
+   [No Values]
+   key_without_value
+   empty string value here =
+
+   [You can use comments] ; after a useful line
+   ; in an empty line
+   after: a_value ; here's another comment
+   inside: a         ;comment
+           multiline ;comment
+           value!    ;comment
+
+      [Sections Can Be Indented]
+         can_values_be_as_well = True
+         does_that_mean_anything_special = False
+         purpose = formatting for readability
+         multiline_values = are
+            handled just fine as
+            long as they are indented
+            deeper than the first line
+            of a value
+         # Did I mention we can indent comments, too?
+
+
+In the example above, :class:`SafeConfigParser` would resolve ``%(home_dir)s``
+to the value of ``home_dir`` (``/Users`` in this case).  ``%(my_dir)s`` in
+effect would resolve to ``/Users/lumberjack``.  All interpolations are done on
+demand so keys used in the chain of references do not have to be specified in
+any specific order in the configuration file.
+
+:class:`RawConfigParser` would simply return ``%(my_dir)s/Pictures`` as the
+value of ``my_pictures`` and ``%(home_dir)s/lumberjack`` as the value of
+``my_dir``.  Other features presented in the example are handled in the same
+manner by both parsers.
+
+Default values can be specified by passing them as a dictionary when
+constructing the :class:`SafeConfigParser`.
+
+Sections are normally stored in an :class:`collections.OrderedDict` which
+maintains the order of all keys.  An alternative dictionary type can be passed
+to the :meth:`__init__` method.  For example, if a dictionary type is passed
+that sorts its keys, the sections will be sorted on write-back, as will be the
+keys within each section.
 
 
-.. class:: RawConfigParser(defaults=None, dict_type=collections.OrderedDict,
-                           allow_no_value=False)
+.. class:: RawConfigParser(defaults=None, dict_type=collections.OrderedDict, delimiters=('=', ':'), comment_prefixes=_COMPATIBLE, empty_lines_in_values=True, allow_no_value=False)
 
    The basic configuration object.  When *defaults* is given, it is initialized
-   into the dictionary of intrinsic defaults.  When *dict_type* is given, it will
-   be used to create the dictionary objects for the list of sections, for the
-   options within a section, and for the default values.  When *allow_no_value*
-   is true (default: ``False``), options without values are accepted; the value
+   into the dictionary of intrinsic defaults.  When *dict_type* is given, it
+   will be used to create the dictionary objects for the list of sections, for
+   the options within a section, and for the default values.
+
+   When *delimiters* is given, it will be used as the set of substrings that
+   divide keys from values.  When *comment_prefixes* is given, it will be used
+   as the set of substrings that prefix comments in a line, both for the whole
+   line and inline comments.  For backwards compatibility, the default value for
+   *comment_prefixes* is a special value that indicates that ``;`` and ``#`` can
+   start whole line comments while only ``;`` can start inline comments.
+
+   When *empty_lines_in_values* is ``False`` (default: ``True``), each empty
+   line marks the end of an option.  Otherwise, internal empty lines of a
+   multiline option are kept as part of the value.  When *allow_no_value* is
+   true (default: ``False``), options without values are accepted; the value
    presented for these is ``None``.
 
-   This class does not
-   support the magical interpolation behavior.
+   This class does not support the magical interpolation behavior.
 
    .. versionchanged:: 3.1
       The default *dict_type* is :class:`collections.OrderedDict`.
 
    .. versionchanged:: 3.2
-      *allow_no_value* was added.
+      *delimiters*, *comment_prefixes*, *empty_lines_in_values* and
+      *allow_no_value* were added.
 
 
-.. class:: ConfigParser(defaults=None, dict_type=collections.OrderedDict,
-                        allow_no_value=False)
+.. class:: SafeConfigParser(defaults=None, dict_type=collections.OrderedDict, delimiters=('=', ':'), comment_prefixes=('#', ';'), empty_lines_in_values=True, allow_no_value=False)
 
-   Derived class of :class:`RawConfigParser` that implements the magical
-   interpolation feature and adds optional arguments to the :meth:`get` and
-   :meth:`items` methods.  The values in *defaults* must be appropriate for the
-   ``%()s`` string interpolation.  Note that *__name__* is an intrinsic default;
-   its value is the section name, and will override any value provided in
-   *defaults*.
+   Derived class of :class:`ConfigParser` that implements a sane variant of the
+   magical interpolation feature.  This implementation is more predictable as it
+   validates the interpolation syntax used within a configuration file.  This
+   class also enables escaping the interpolation character (e.g. a key can have
+   ``%`` as part of the value by specifying ``%%`` in the file).
 
-   All option names used in interpolation will be passed through the
-   :meth:`optionxform` method just like any other option name reference.  For
-   example, using the default implementation of :meth:`optionxform` (which converts
-   option names to lower case), the values ``foo %(bar)s`` and ``foo %(BAR)s`` are
-   equivalent.
+   Applications that don't require interpolation should use
+   :class:`RawConfigParser`, otherwise :class:`SafeConfigParser` is the best
+   option.
 
    .. versionchanged:: 3.1
       The default *dict_type* is :class:`collections.OrderedDict`.
 
    .. versionchanged:: 3.2
-      *allow_no_value* was added.
+      *delimiters*, *comment_prefixes*, *empty_lines_in_values* and
+      *allow_no_value* were added.
 
 
-.. class:: SafeConfigParser(defaults=None, dict_type=collections.OrderedDict,
-                            allow_no_value=False)
+.. class:: ConfigParser(defaults=None, dict_type=collections.OrderedDict, delimiters=('=', ':'), comment_prefixes=('#', ';'), empty_lines_in_values=True, allow_no_value=False)
 
-   Derived class of :class:`ConfigParser` that implements a more-sane variant of
-   the magical interpolation feature.  This implementation is more predictable as
-   well. New applications should prefer this version if they don't need to be
-   compatible with older versions of Python.
+   Derived class of :class:`RawConfigParser` that implements the magical
+   interpolation feature and adds optional arguments to the :meth:`get` and
+   :meth:`items` methods.
 
-   .. XXX Need to explain what's safer/more predictable about it.
+   :class:`SafeConfigParser` is generally recommended over this class if you
+   need interpolation.
+
+   The values in *defaults* must be appropriate for the ``%()s`` string
+   interpolation.  Note that *__name__* is an intrinsic default; its value is
+   the section name, and will override any value provided in *defaults*.
+
+   All option names used in interpolation will be passed through the
+   :meth:`optionxform` method just like any other option name reference.  For
+   example, using the default implementation of :meth:`optionxform` (which
+   converts option names to lower case), the values ``foo %(bar)s`` and ``foo
+   %(BAR)s`` are equivalent.
 
    .. versionchanged:: 3.1
       The default *dict_type* is :class:`collections.OrderedDict`.
 
    .. versionchanged:: 3.2
-      *allow_no_value* was added.
+      *delimiters*, *comment_prefixes*, *empty_lines_in_values* and
+      *allow_no_value* were added.
+
+
+.. exception:: Error
+
+   Base class for all other configparser exceptions.
 
 
 .. exception:: NoSectionError
@@ -223,25 +290,29 @@
    :const:`True`; otherwise return :const:`False`.
 
 
-.. method:: RawConfigParser.read(filenames)
+.. method:: RawConfigParser.read(filenames, encoding=None)
 
    Attempt to read and parse a list of filenames, returning a list of filenames
-   which were successfully parsed.  If *filenames* is a string,
-   it is treated as a single filename. If a file named in *filenames* cannot be
-   opened, that file will be ignored.  This is designed so that you can specify a
-   list of potential configuration file locations (for example, the current
-   directory, the user's home directory, and some system-wide directory), and all
-   existing configuration files in the list will be read.  If none of the named
-   files exist, the :class:`ConfigParser` instance will contain an empty dataset.
-   An application which requires initial values to be loaded from a file should
-   load the required file or files using :meth:`readfp` before calling :meth:`read`
-   for any optional files::
+   which were successfully parsed.  If *filenames* is a string, it is treated as
+   a single filename.  If a file named in *filenames* cannot be opened, that
+   file will be ignored.  This is designed so that you can specify a list of
+   potential configuration file locations (for example, the current directory,
+   the user's home directory, and some system-wide directory), and all existing
+   configuration files in the list will be read.  If none of the named files
+   exist, the :class:`ConfigParser` instance will contain an empty dataset.  An
+   application which requires initial values to be loaded from a file should
+   load the required file or files using :meth:`readfp` before calling
+   :meth:`read` for any optional files::
 
       import configparser, os
 
       config = configparser.ConfigParser()
       config.readfp(open('defaults.cfg'))
-      config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')])
+      config.read(['site.cfg', os.path.expanduser('~/.myapp.cfg')], encoding='cp1250')
+
+   .. versionadded:: 3.2
+      The *encoding* parameter.  Previously, all files were read using the
+      default encoding for :func:`open`.
 
 
 .. method:: RawConfigParser.readfp(fp, filename=None)
@@ -295,11 +366,13 @@
    interpolation and output to files) can only be achieved using string values.
 
 
-.. method:: RawConfigParser.write(fileobject)
+.. method:: RawConfigParser.write(fileobject, space_around_delimiters=True)
 
    Write a representation of the configuration to the specified file object,
    which must be opened in text mode (accepting strings).  This representation
-   can be parsed by a future :meth:`read` call.
+   can be parsed by a future :meth:`read` call. If ``space_around_delimiters``
+   is ``True`` (the default), delimiters between keys and values are surrounded
+   by spaces.
 
 
 .. method:: RawConfigParser.remove_option(section, option)
@@ -342,21 +415,27 @@
 --------------------
 
 The :class:`ConfigParser` class extends some methods of the
-:class:`RawConfigParser` interface, adding some optional arguments.
+:class:`RawConfigParser` interface, adding some optional arguments. Whenever you
+can, consider using :class:`SafeConfigParser` which adds validation and escaping
+for the interpolation.
 
 
 .. method:: ConfigParser.get(section, option, raw=False, vars=None)
 
-   Get an *option* value for the named *section*.  All the ``'%'`` interpolations
-   are expanded in the return values, based on the defaults passed into the
-   constructor, as well as the options *vars* provided, unless the *raw* argument
-   is true.
+   Get an *option* value for the named *section*.  If *vars* is provided, it
+   must be a dictionary.  The *option* is looked up in *vars* (if provided),
+   *section*, and in *defaults* in that order.
+
+   All the ``'%'`` interpolations are expanded in the return values, unless the
+   *raw* argument is true.  Values for interpolation keys are looked up in the
+   same manner as the option.
 
 
 .. method:: ConfigParser.items(section, raw=False, vars=None)
 
-   Return a list of ``(name, value)`` pairs for each option in the given *section*.
-   Optional arguments have the same meaning as for the :meth:`get` method.
+   Return a list of ``(name, value)`` pairs for each option in the given
+   *section*.  Optional arguments have the same meaning as for the :meth:`get`
+   method.
 
 
 .. _safeconfigparser-objects:
@@ -466,8 +545,8 @@
 
 Some configuration files are known to include settings without values, but which
 otherwise conform to the syntax supported by :mod:`configparser`.  The
-*allow_no_value* parameter to the constructor can be used to indicate that such
-values should be accepted:
+*allow_no_value* parameter to the :meth:`__init__` method can be used to
+indicate that such values should be accepted:
 
 .. doctest::
 
@@ -476,12 +555,12 @@
 
    >>> sample_config = """
    ... [mysqld]
-   ... user = mysql
-   ... pid-file = /var/run/mysqld/mysqld.pid
-   ... skip-external-locking
-   ... old_passwords = 1
-   ... skip-bdb
-   ... skip-innodb
+   ...   user = mysql
+   ...   pid-file = /var/run/mysqld/mysqld.pid
+   ...   skip-external-locking
+   ...   old_passwords = 1
+   ...   skip-bdb
+   ...   skip-innodb # we don't need ACID today
    ... """
    >>> config = configparser.RawConfigParser(allow_no_value=True)
    >>> config.readfp(io.BytesIO(sample_config))

Modified: python/branches/import_unicode/Doc/library/contextlib.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/contextlib.rst	(original)
+++ python/branches/import_unicode/Doc/library/contextlib.rst	Fri Jul 30 01:19:37 2010
@@ -12,7 +12,7 @@
 Functions provided:
 
 
-.. function:: contextmanager(func)
+.. decorator:: contextmanager
 
    This function is a :term:`decorator` that can be used to define a factory
    function for :keyword:`with` statement context managers, without needing to
@@ -57,6 +57,7 @@
    .. versionchanged:: 3.2
       Use of :class:`ContextDecorator`.
 
+
 .. function:: closing(thing)
 
    Return a context manager that closes *thing* upon completion of the block.  This
@@ -92,22 +93,25 @@
    ``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its optional
    exception handling even when used as a decorator.
 
-   Example::
+   ``ContextDecorator`` is used by :func:`contextmanager`, so you get this
+   functionality automatically.
+
+   Example of ``ContextDecorator``::
 
       from contextlib import ContextDecorator
 
       class mycontext(ContextDecorator):
-         def __enter__(self):
-            print('Starting')
-            return self
-
-         def __exit__(self, *exc):
-            print('Finishing')
-            return False
+          def __enter__(self):
+              print('Starting')
+              return self
+
+          def __exit__(self, *exc):
+              print('Finishing')
+              return False
 
       >>> @mycontext()
       ... def function():
-      ...    print('The bit in the middle')
+      ...     print('The bit in the middle')
       ...
       >>> function()
       Starting
@@ -115,23 +119,38 @@
       Finishing
 
       >>> with mycontext():
-      ...    print('The bit in the middle')
+      ...     print('The bit in the middle')
       ...
       Starting
       The bit in the middle
       Finishing
 
+   This change is just syntactic sugar for any construct of the following form::
+
+      def f():
+          with cm():
+              # Do stuff
+
+   ``ContextDecorator`` lets you instead write::
+
+      @cm()
+      def f():
+          # Do stuff
+
+   It makes it clear that the ``cm`` applies to the whole function, rather than
+   just a piece of it (and saving an indentation level is nice, too).
+
    Existing context managers that already have a base class can be extended by
    using ``ContextDecorator`` as a mixin class::
 
       from contextlib import ContextDecorator
 
       class mycontext(ContextBaseClass, ContextDecorator):
-         def __enter__(self):
-            return self
+          def __enter__(self):
+              return self
 
-         def __exit__(self, *exc):
-            return False
+          def __exit__(self, *exc):
+              return False
 
    .. versionadded:: 3.2
 

Modified: python/branches/import_unicode/Doc/library/dbm.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/dbm.rst	(original)
+++ python/branches/import_unicode/Doc/library/dbm.rst	Fri Jul 30 01:19:37 2010
@@ -5,10 +5,10 @@
    :synopsis: Interfaces to various Unix "database" formats.
 
 :mod:`dbm` is a generic interface to variants of the DBM database ---
- :mod:`dbm.gnu` or :mod:`dbm.ndbm`.  If none of these modules is installed, the
- slow-but-simple implementation in module :mod:`dbm.dumb` will be used.  There
- is a `third party interface <http://www.jcea.es/programacion/pybsddb.htm>`_ to
- the Oracle Berkely DB.
+:mod:`dbm.gnu` or :mod:`dbm.ndbm`.  If none of these modules is installed, the
+slow-but-simple implementation in module :mod:`dbm.dumb` will be used.  There
+is a `third party interface <http://www.jcea.es/programacion/pybsddb.htm>`_ to
+the Oracle Berkely DB.
 
 
 .. exception:: error
@@ -21,8 +21,8 @@
 .. function:: whichdb(filename)
 
    This functionattempts to guess which of the several simple database modules
-   available --- :mod:`dbm.bsd`, :mod:`dbm.gnu`, :mod:`dbm.ndbm` or
-   :mod:`dbm.dumb` --- should be used to open a given file.
+   available --- :mod:`dbm.gnu`, :mod:`dbm.ndbm` or :mod:`dbm.dumb` --- should
+   be used to open a given file.
 
    Returns one of the following values: ``None`` if the file can't be opened
    because it's unreadable or doesn't exist; the empty string (``''``) if the
@@ -227,10 +227,9 @@
 always stored as bytes. Printing a ``dbm`` object doesn't print the keys and
 values, and the :meth:`items` and :meth:`values` methods are not supported.
 
-This module can be used with the "classic" ndbm interface, the BSD DB
-compatibility interface, or the GNU GDBM compatibility interface. On Unix, the
-:program:`configure` script will attempt to locate the appropriate header file
-to simplify building this module.
+This module can be used with the "classic" ndbm interface or the GNU GDBM
+compatibility interface. On Unix, the :program:`configure` script will attempt
+to locate the appropriate header file to simplify building this module.
 
 .. exception:: error
 
@@ -246,9 +245,7 @@
 .. function:: open(filename[, flag[, mode]])
 
    Open a dbm database and return a ``dbm`` object.  The *filename* argument is the
-   name of the database file (without the :file:`.dir` or :file:`.pag` extensions;
-   note that the BSD DB implementation of the interface will append the extension
-   :file:`.db` and only create one file).
+   name of the database file (without the :file:`.dir` or :file:`.pag` extensions).
 
    The optional *flag* argument must be one of these values:
 

Modified: python/branches/import_unicode/Doc/library/doctest.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/doctest.rst	(original)
+++ python/branches/import_unicode/Doc/library/doctest.rst	Fri Jul 30 01:19:37 2010
@@ -913,18 +913,16 @@
 As your collection of doctest'ed modules grows, you'll want a way to run all
 their doctests systematically.  :mod:`doctest` provides two functions that can
 be used to create :mod:`unittest` test suites from modules and text files
-containing doctests.  These test suites can then be run using :mod:`unittest`
-test runners::
+containing doctests.  To integrate with :mod:`unittest` test discovery, include
+a :func:`load_tests` function in your test module::
 
    import unittest
    import doctest
-   import my_module_with_doctests, and_another
+   import my_module_with_doctests
 
-   suite = unittest.TestSuite()
-   for mod in my_module_with_doctests, and_another:
-       suite.addTest(doctest.DocTestSuite(mod))
-   runner = unittest.TextTestRunner()
-   runner.run(suite)
+   def load_tests(loader, tests, ignore):
+       tests.addTests(doctest.DocTestSuite(my_module_with_doctests))
+       return test
 
 There are two main functions for creating :class:`unittest.TestSuite` instances
 from text files and modules with doctests:

Modified: python/branches/import_unicode/Doc/library/fnmatch.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/fnmatch.rst	(original)
+++ python/branches/import_unicode/Doc/library/fnmatch.rst	Fri Jul 30 01:19:37 2010
@@ -70,6 +70,8 @@
 
    Return the shell-style *pattern* converted to a regular expression.
 
+   Be aware there is no way to quote meta-characters.
+
    Example:
 
       >>> import fnmatch, re
@@ -82,6 +84,13 @@
       <_sre.SRE_Match object at 0x...>
 
 
+.. function:: purge()
+
+   Clear the internal pattern cache.
+
+   .. versionadded:: 3.2
+
+
 .. seealso::
 
    Module :mod:`glob`

Modified: python/branches/import_unicode/Doc/library/functions.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/functions.rst	(original)
+++ python/branches/import_unicode/Doc/library/functions.rst	Fri Jul 30 01:19:37 2010
@@ -335,6 +335,9 @@
    returns the current global and local dictionary, respectively, which may be
    useful to pass around for use by :func:`eval` or :func:`exec`.
 
+   See :func:`ast.literal_eval` for a function that can safely evaluate strings
+   with expressions containing only literals.
+
 
 .. function:: exec(object[, globals[, locals]])
 
@@ -676,7 +679,7 @@
    :meth:`__index__` method that returns an integer.
 
 
-.. function:: open(file, mode='r', buffering=None, encoding=None, errors=None, newline=None, closefd=True)
+.. function:: open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True)
 
    Open *file* and return a corresponding stream.  If the file cannot be opened,
    an :exc:`IOError` is raised.

Modified: python/branches/import_unicode/Doc/library/functools.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/functools.rst	(original)
+++ python/branches/import_unicode/Doc/library/functools.rst	Fri Jul 30 01:19:37 2010
@@ -37,7 +37,7 @@
 
    .. versionadded:: 3.2
 
-.. function:: total_ordering(cls)
+.. decorator:: total_ordering
 
    Given a class defining one or more rich comparison ordering methods, this
    class decorator supplies the rest.  This simplifies the effort involved
@@ -122,7 +122,7 @@
    than helpful.
 
 
-.. function:: wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)
+.. decorator:: wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS, updated=WRAPPER_UPDATES)
 
    This is a convenience function for invoking ``partial(update_wrapper,
    wrapped=wrapped, assigned=assigned, updated=updated)`` as a function decorator

Modified: python/branches/import_unicode/Doc/library/html.parser.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/html.parser.rst	(original)
+++ python/branches/import_unicode/Doc/library/html.parser.rst	Fri Jul 30 01:19:37 2010
@@ -134,10 +134,18 @@
 
 .. method:: HTMLParser.handle_decl(decl)
 
-   Method called when an SGML declaration is read by the parser.  The *decl*
-   parameter will be the entire contents of the declaration inside the ``<!``...\
-   ``>`` markup.  It is intended to be overridden by a derived class; the base
-   class implementation does nothing.
+   Method called when an SGML ``doctype`` declaration is read by the parser.
+   The *decl* parameter will be the entire contents of the declaration inside
+   the ``<!...>`` markup.  It is intended to be overridden by a derived class;
+   the base class implementation does nothing.
+
+
+.. method:: HTMLParser.unknown_decl(data)
+
+   Method called when an unrecognized SGML declaration is read by the parser.
+   The *data* parameter will be the entire contents of the declaration inside
+   the ``<!...>`` markup.  It is sometimes useful to be be overridden by a
+   derived class; the base class implementation throws an :exc:`HTMLParseError`.
 
 
 .. method:: HTMLParser.handle_pi(data)

Modified: python/branches/import_unicode/Doc/library/http.cookiejar.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/http.cookiejar.rst	(original)
+++ python/branches/import_unicode/Doc/library/http.cookiejar.rst	Fri Jul 30 01:19:37 2010
@@ -108,10 +108,6 @@
       :mod:`http.cookiejar` and :mod:`http.cookies` modules do not depend on each
       other.
 
-   http://wwwsearch.sourceforge.net/mechanize/
-      Extensions to this module, including a class for reading Microsoft Internet
-      Explorer cookies on Windows.
-
    http://wp.netscape.com/newsref/std/cookie_spec.html
       The specification of the original Netscape cookie protocol.  Though this is
       still the dominant protocol, the 'Netscape cookie protocol' implemented by all
@@ -292,11 +288,8 @@
 FileCookieJar subclasses and co-operation with web browsers
 -----------------------------------------------------------
 
-The following :class:`CookieJar` subclasses are provided for reading and writing
-.  Further :class:`CookieJar` subclasses, including one that reads Microsoft
-Internet Explorer cookies, are available at
-http://wwwsearch.sourceforge.net/mechanize/.
-
+The following :class:`CookieJar` subclasses are provided for reading and
+writing .
 
 .. class:: MozillaCookieJar(filename, delayload=None, policy=None)
 

Modified: python/branches/import_unicode/Doc/library/importlib.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/importlib.rst	(original)
+++ python/branches/import_unicode/Doc/library/importlib.rst	Fri Jul 30 01:19:37 2010
@@ -228,7 +228,7 @@
 
     * :meth:`ResourceLoader.get_data`
     * :meth:`ExecutionLoader.get_filename`
-          Implement to only return the path to the source file; sourceless
+          Should only return the path to the source file; sourceless
           loading is not supported.
 
     The abstract methods defined by this class are to add optional bytecode
@@ -469,7 +469,7 @@
 This module contains the various objects that help in the construction of
 an :term:`importer`.
 
-.. function:: module_for_loader(method)
+.. decorator:: module_for_loader
 
     A :term:`decorator` for a :term:`loader` method,
     to handle selecting the proper
@@ -494,7 +494,7 @@
     Use of this decorator handles all the details of which module object a
     loader should initialize as specified by :pep:`302`.
 
-.. function:: set_loader(fxn)
+.. decorator:: set_loader
 
     A :term:`decorator` for a :term:`loader` method,
     to set the :attr:`__loader__`
@@ -502,7 +502,7 @@
     does nothing. It is assumed that the first positional argument to the
     wrapped method is what :attr:`__loader__` should be set to.
 
-.. function:: set_package(fxn)
+.. decorator:: set_package
 
     A :term:`decorator` for a :term:`loader` to set the :attr:`__package__`
     attribute on the module returned by the loader. If :attr:`__package__` is

Modified: python/branches/import_unicode/Doc/library/io.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/io.rst	(original)
+++ python/branches/import_unicode/Doc/library/io.rst	Fri Jul 30 01:19:37 2010
@@ -61,8 +61,8 @@
    Open *file* and return a corresponding stream.  If the file cannot be opened,
    an :exc:`IOError` is raised.
 
-   *file* is either a string or bytes object giving the name (and the path if
-   the file isn't in the current working directory) of the file to be opened or
+   *file* is either a string or bytes object giving the pathname (absolute or
+   relative to the current working directory) of the file to be opened or
    an integer file descriptor of the file to be wrapped.  (If a file descriptor
    is given, it is closed when the returned I/O object is closed, unless
    *closefd* is set to ``False``.)

Modified: python/branches/import_unicode/Doc/library/itertools.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/itertools.rst	(original)
+++ python/branches/import_unicode/Doc/library/itertools.rst	Fri Jul 30 01:19:37 2010
@@ -99,7 +99,7 @@
                   yield element
 
 
-.. function:: itertools.chain.from_iterable(iterable)
+.. classmethod:: chain.from_iterable(iterable)
 
    Alternate constructor for :func:`chain`.  Gets chained inputs from a
    single iterable argument that is evaluated lazily.  Equivalent to::

Modified: python/branches/import_unicode/Doc/library/locale.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/locale.rst	(original)
+++ python/branches/import_unicode/Doc/library/locale.rst	Fri Jul 30 01:19:37 2010
@@ -244,10 +244,6 @@
       specified, and therefore you should not assume knowledge of it on different
       systems.
 
-   .. data:: ERA_YEAR
-
-      Get the year in the relevant era of the locale.
-
    .. data:: ERA_D_T_FMT
 
       Get a format string for :func:`strftime` to represent dates and times in a

Modified: python/branches/import_unicode/Doc/library/math.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/math.rst	(original)
+++ python/branches/import_unicode/Doc/library/math.rst	Fri Jul 30 01:19:37 2010
@@ -97,15 +97,23 @@
    <http://code.activestate.com/recipes/393090/>`_\.
 
 
+.. function:: isfinite(x)
+
+   Return ``True`` if *x* is neither an infinity nor a NaN, and
+   ``False`` otherwise.  (Note that ``0.0`` *is* considered finite.)
+
+   .. versionadded:: 3.2
+
+
 .. function:: isinf(x)
 
-   Check if the float *x* is positive or negative infinity.
+   Return ``True`` if *x* is a positive or negative infinity, and
+   ``False`` otherwise.
 
 
 .. function:: isnan(x)
 
-   Check if the float *x* is a NaN (not a number).  For more information
-   on NaNs, see the IEEE 754 standards.
+   Return ``True`` if *x* is a NaN (not a number), and ``False`` otherwise.
 
 
 .. function:: ldexp(x, i)

Modified: python/branches/import_unicode/Doc/library/multiprocessing.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/multiprocessing.rst	(original)
+++ python/branches/import_unicode/Doc/library/multiprocessing.rst	Fri Jul 30 01:19:37 2010
@@ -2228,8 +2228,8 @@
 
 
 An example of how a pool of worker processes can each run a
-:class:`SimpleHTTPServer.HttpServer` instance while sharing a single listening
-socket.
+:class:`~http.server.SimpleHTTPRequestHandler` instance while sharing a single
+listening socket.
 
 .. literalinclude:: ../includes/mp_webserver.py
 

Modified: python/branches/import_unicode/Doc/library/os.path.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/os.path.rst	(original)
+++ python/branches/import_unicode/Doc/library/os.path.rst	Fri Jul 30 01:19:37 2010
@@ -236,11 +236,14 @@
    exception if a :func:`os.stat` call on either pathname fails.
 
    On Windows, two files are the same if they resolve to the same final path
-   name using the Windows API call GetFinalPathNameByHandle and this function
+   name using the Windows API call GetFinalPathNameByHandle. This function
    raises an exception if handles cannot be obtained to either file.
 
    Availability: Windows, Unix.
 
+   .. versionchanged:: 3.2
+      Added Windows support.
+
 
 .. function:: sameopenfile(fp1, fp2)
 

Modified: python/branches/import_unicode/Doc/library/os.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/os.rst	(original)
+++ python/branches/import_unicode/Doc/library/os.rst	Fri Jul 30 01:19:37 2010
@@ -723,7 +723,7 @@
 
       This function is intended for low-level I/O.  For normal usage, use the
       built-in function :func:`open`, which returns a "file object" with
-      :meth:`~file.read` and :meth:`~file.wprite` methods (and many more).  To
+      :meth:`~file.read` and :meth:`~file.write` methods (and many more).  To
       wrap a file descriptor in a "file object", use :func:`fdopen`.
 
 
@@ -1049,10 +1049,10 @@
    Availability: Unix.
 
 
-.. function:: listdir(path)
+.. function:: listdir(path='.')
 
    Return a list containing the names of the entries in the directory given by
-   *path*.  The list is in arbitrary order.  It does not include the special
+   *path* (default: ``'.'``).  The list is in arbitrary order.  It does not include the special
    entries ``'.'`` and ``'..'`` even if they are present in the directory.
 
    This function can be called with a bytes or string argument, and returns
@@ -1060,12 +1060,16 @@
 
    Availability: Unix, Windows.
 
+   .. versionchanged:: 3.2
+      The *path* parameter became optional.
 
 .. function:: lstat(path)
 
    Like :func:`stat`, but do not follow symbolic links.  This is an alias for
-   :func:`stat` on platforms that do not support symbolic links, such as
-   Windows prior to 6.0 (Vista).
+   :func:`stat` on platforms that do not support symbolic links.
+
+   .. versionchanged:: 3.2
+      Added support for Windows 6.0 (Vista) symbolic links.
 
 
 .. function:: mkfifo(path[, mode])
@@ -1181,7 +1185,10 @@
    and the call may raise an UnicodeDecodeError. If the *path* is a bytes
    object, the result will be a bytes object.
 
-   Availability: Unix, Windows.
+   Availability: Unix, Windows
+
+   .. versionchanged:: 3.2
+      Added support for Windows 6.0 (Vista) symbolic links.
 
 
 .. function:: remove(path)
@@ -1341,8 +1348,9 @@
 
 .. function:: symlink(source, link_name)
 
-   Create a symbolic link pointing to *source* named *link_name*.  On Windows,
-   symlink version takes an additional, optional parameter,
+   Create a symbolic link pointing to *source* named *link_name*.
+
+   On Windows, symlink version takes an additional, optional parameter,
    *target_is_directory*, which defaults to False.
 
    symlink(source, link_name, target_is_directory=False)
@@ -1359,7 +1367,10 @@
    will raise a NotImplementedError on Windows versions earlier than 6.0. The
    SeCreateSymbolicLinkPrivilege is required in order to create symlinks.
 
-   Availability:  Unix, Windows 6.0.
+   Availability:  Unix, Windows
+
+   .. versionchanged:: 3.2
+      Added support for Windows 6.0 (Vista) symbolic links.
 
 
 .. function:: unlink(path)
@@ -1912,8 +1923,9 @@
 
    The :mod:`subprocess` module provides more powerful facilities for spawning new
    processes and retrieving their results; using that module is preferable to using
-   this function.  Use the :mod:`subprocess` module.  Check especially the
-   :ref:`subprocess-replacements` section.
+   this function.  See the
+   :ref:`subprocess-replacements` section in the :mod:`subprocess` documentation
+   for some helpful recipes.
 
    Availability: Unix, Windows.
 

Modified: python/branches/import_unicode/Doc/library/pdb.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/pdb.rst	(original)
+++ python/branches/import_unicode/Doc/library/pdb.rst	Fri Jul 30 01:19:37 2010
@@ -20,7 +20,7 @@
    module: bdb
    module: cmd
 
-The debugger is extensible --- it is actually defined as the class :class:`Pdb`.
+The debugger is extensible -- it is actually defined as the class :class:`Pdb`.
 This is currently undocumented but easily understood by reading the source.  The
 extension interface uses the modules :mod:`bdb` and :mod:`cmd`.
 
@@ -55,8 +55,8 @@
    import pdb; pdb.set_trace()
 
 at the location you want to break into the debugger.  You can then step through
-the code following this statement, and continue running without the debugger using
-the ``c`` command.
+the code following this statement, and continue running without the debugger
+using the :pdbcmd:`continue` command.
 
 The typical usage to inspect a crashed program is::
 
@@ -82,26 +82,28 @@
 .. function:: run(statement, globals=None, locals=None)
 
    Execute the *statement* (given as a string) under debugger control.  The
-   debugger prompt appears before any code is executed; you can set breakpoints and
-   type ``continue``, or you can step through the statement using ``step`` or
-   ``next`` (all these commands are explained below).  The optional *globals* and
-   *locals* arguments specify the environment in which the code is executed; by
-   default the dictionary of the module :mod:`__main__` is used.  (See the
-   explanation of the built-in :func:`exec` or :func:`eval` functions.)
+   debugger prompt appears before any code is executed; you can set breakpoints
+   and type :pdbcmd:`continue`, or you can step through the statement using
+   :pdbcmd:`step` or :pdbcmd:`next` (all these commands are explained below).
+   The optional *globals* and *locals* arguments specify the environment in
+   which the code is executed; by default the dictionary of the module
+   :mod:`__main__` is used.  (See the explanation of the built-in :func:`exec`
+   or :func:`eval` functions.)
 
 
 .. function:: runeval(expression, globals=None, locals=None)
 
    Evaluate the *expression* (given as a string) under debugger control.  When
-   :func:`runeval` returns, it returns the value of the expression.  Otherwise this
-   function is similar to :func:`run`.
+   :func:`runeval` returns, it returns the value of the expression.  Otherwise
+   this function is similar to :func:`run`.
 
 
 .. function:: runcall(function, *args, **kwds)
 
-   Call the *function* (a function or method object, not a string) with the given
-   arguments.  When :func:`runcall` returns, it returns whatever the function call
-   returned.  The debugger prompt appears as soon as the function is entered.
+   Call the *function* (a function or method object, not a string) with the
+   given arguments.  When :func:`runcall` returns, it returns whatever the
+   function call returned.  The debugger prompt appears as soon as the function
+   is entered.
 
 
 .. function:: set_trace()
@@ -160,16 +162,17 @@
 Debugger Commands
 =================
 
-The debugger recognizes the following commands.  Most commands can be
-abbreviated to one or two letters; e.g. ``h(elp)`` means that either ``h`` or
-``help`` can be used to enter the help command (but not ``he`` or ``hel``, nor
-``H`` or ``Help`` or ``HELP``).  Arguments to commands must be separated by
-whitespace (spaces or tabs).  Optional arguments are enclosed in square brackets
-(``[]``) in the command syntax; the square brackets must not be typed.
-Alternatives in the command syntax are separated by a vertical bar (``|``).
+The commands recognized by the debugger are listed below.  Most commands can be
+abbreviated to one or two letters as indicated; e.g. ``h(elp)`` means that
+either ``h`` or ``help`` can be used to enter the help command (but not ``he``
+or ``hel``, nor ``H`` or ``Help`` or ``HELP``).  Arguments to commands must be
+separated by whitespace (spaces or tabs).  Optional arguments are enclosed in
+square brackets (``[]``) in the command syntax; the square brackets must not be
+typed.  Alternatives in the command syntax are separated by a vertical bar
+(``|``).
 
 Entering a blank line repeats the last command entered.  Exception: if the last
-command was a ``list`` command, the next 11 lines are listed.
+command was a :pdbcmd:`list` command, the next 11 lines are listed.
 
 Commands that the debugger doesn't recognize are assumed to be Python statements
 and are executed in the context of the program being debugged.  Python
@@ -179,93 +182,106 @@
 statement, the exception name is printed but the debugger's state is not
 changed.
 
+The debugger supports :ref:`aliases <debugger-aliases>`.  Aliases can have
+parameters which allows one a certain level of adaptability to the context under
+examination.
+
 Multiple commands may be entered on a single line, separated by ``;;``.  (A
 single ``;`` is not used as it is the separator for multiple commands in a line
-that is passed to the Python parser.) No intelligence is applied to separating
+that is passed to the Python parser.)  No intelligence is applied to separating
 the commands; the input is split at the first ``;;`` pair, even if it is in the
 middle of a quoted string.
 
-The debugger supports aliases.  Aliases can have parameters which allows one a
-certain level of adaptability to the context under examination.
-
 .. index::
    pair: .pdbrc; file
    triple: debugger; configuration; file
 
-If a file :file:`.pdbrc`  exists in the user's home directory or in the current
+If a file :file:`.pdbrc` exists in the user's home directory or in the current
 directory, it is read in and executed as if it had been typed at the debugger
-prompt. This is particularly useful for aliases.  If both files exist, the one
+prompt.  This is particularly useful for aliases.  If both files exist, the one
 in the home directory is read first and aliases defined there can be overridden
 by the local file.
 
-h(elp) [*command*]
+
+.. pdbcommand:: h(elp) [command]
+
    Without argument, print the list of available commands.  With a *command* as
    argument, print help about that command.  ``help pdb`` displays the full
-   documentation file; if the environment variable :envvar:`PAGER` is defined, the
-   file is piped through that command instead.  Since the *command* argument must
-   be an identifier, ``help exec`` must be entered to get help on the ``!``
-   command.
+   documentation (the docstring of the :mod:`pdb` module).  Since the *command*
+   argument must be an identifier, ``help exec`` must be entered to get help on
+   the ``!`` command.
+
+.. pdbcommand:: w(here)
 
-w(here)
    Print a stack trace, with the most recent frame at the bottom.  An arrow
    indicates the current frame, which determines the context of most commands.
 
-d(own) [*count*]
+.. pdbcommand:: d(own) [count]
+
    Move the current frame *count* (default one) levels down in the stack trace
    (to a newer frame).
 
-u(p) [*count*]
-   Move the current frame *count* (default one) levels up in the stack trace
-   (to an older frame).
+.. pdbcommand:: u(p) [count]
+
+   Move the current frame *count* (default one) levels up in the stack trace (to
+   an older frame).
+
+.. pdbcommand:: b(reak) [([filename:]lineno | function) [, condition]]
 
-b(reak) [[*filename*:]\ *lineno* | *function*\ [, *condition*]]
    With a *lineno* argument, set a break there in the current file.  With a
-   *function* argument, set a break at the first executable statement within that
-   function. The line number may be prefixed with a filename and a colon, to
-   specify a breakpoint in another file (probably one that hasn't been loaded yet).
-   The file is searched on ``sys.path``. Note that each breakpoint is assigned a
-   number to which all the other breakpoint commands refer.
-
-   If a second argument is present, it is an expression which must evaluate to true
-   before the breakpoint is honored.
-
-   Without argument, list all breaks, including for each breakpoint, the number of
-   times that breakpoint has been hit, the current ignore count, and the associated
-   condition if any.
-
-tbreak [[*filename*:]\ *lineno* | *function*\ [, *condition*]]
-   Temporary breakpoint, which is removed automatically when it is first hit.  The
-   arguments are the same as break.
+   *function* argument, set a break at the first executable statement within
+   that function.  The line number may be prefixed with a filename and a colon,
+   to specify a breakpoint in another file (probably one that hasn't been loaded
+   yet).  The file is searched on :data:`sys.path`.  Note that each breakpoint
+   is assigned a number to which all the other breakpoint commands refer.
+
+   If a second argument is present, it is an expression which must evaluate to
+   true before the breakpoint is honored.
+
+   Without argument, list all breaks, including for each breakpoint, the number
+   of times that breakpoint has been hit, the current ignore count, and the
+   associated condition if any.
+
+.. pdbcommand:: tbreak [([filename:]lineno | function) [, condition]]
+
+   Temporary breakpoint, which is removed automatically when it is first hit.
+   The arguments are the same as for :pdbcmd:`break`.
+
+.. pdbcommand:: cl(ear) [bpnumber [bpnumber ...]]
 
-cl(ear) [*bpnumber* [*bpnumber ...*]]
    With a space separated list of breakpoint numbers, clear those breakpoints.
    Without argument, clear all breaks (but first ask confirmation).
 
-disable [*bpnumber* [*bpnumber ...*]]
-   Disables the breakpoints given as a space separated list of breakpoint numbers.
-   Disabling a breakpoint means it cannot cause the program to stop execution, but
-   unlike clearing a breakpoint, it remains in the list of breakpoints and can be
-   (re-)enabled.
-
-enable [*bpnumber* [*bpnumber ...*]]
-   Enables the breakpoints specified.
-
-ignore *bpnumber* [*count*]
-   Sets the ignore count for the given breakpoint number.  If count is omitted, the
-   ignore count is set to 0.  A breakpoint becomes active when the ignore count is
-   zero.  When non-zero, the count is decremented each time the breakpoint is
-   reached and the breakpoint is not disabled and any associated condition
-   evaluates to true.
-
-condition *bpnumber* [*condition*]
-   Condition is an expression which must evaluate to true before the breakpoint is
-   honored.  If condition is absent, any existing condition is removed; i.e., the
-   breakpoint is made unconditional.
+.. pdbcommand:: disable [bpnumber [bpnumber ...]]
+
+   Disable the breakpoints given as a space separated list of breakpoint
+   numbers.  Disabling a breakpoint means it cannot cause the program to stop
+   execution, but unlike clearing a breakpoint, it remains in the list of
+   breakpoints and can be (re-)enabled.
+
+.. pdbcommand:: enable [bpnumber [bpnumber ...]]
+
+   Enable the breakpoints specified.
+
+.. pdbcommand:: ignore bpnumber [count]
+
+   Set the ignore count for the given breakpoint number.  If count is omitted,
+   the ignore count is set to 0.  A breakpoint becomes active when the ignore
+   count is zero.  When non-zero, the count is decremented each time the
+   breakpoint is reached and the breakpoint is not disabled and any associated
+   condition evaluates to true.
+
+.. pdbcommand:: condition bpnumber [condition]
+
+   Set a new *condition* for the breakpoint, an expression which must evaluate
+   to true before the breakpoint is honored.  If *condition* is absent, any
+   existing condition is removed; i.e., the breakpoint is made unconditional.
+
+.. pdbcommand:: commands [bpnumber]
 
-commands [*bpnumber*]
    Specify a list of commands for breakpoint number *bpnumber*.  The commands
-   themselves appear on the following lines.  Type a line containing just 'end' to
-   terminate the commands. An example::
+   themselves appear on the following lines.  Type a line containing just
+   ``end`` to terminate the commands. An example::
 
       (Pdb) commands 1
       (com) print some_variable
@@ -273,12 +289,12 @@
       (Pdb)
 
    To remove all commands from a breakpoint, type commands and follow it
-   immediately with  end; that is, give no commands.
+   immediately with ``end``; that is, give no commands.
 
    With no *bpnumber* argument, commands refers to the last breakpoint set.
 
-   You can use breakpoint commands to start your program up again. Simply use the
-   continue command, or step, or any other command that resumes execution.
+   You can use breakpoint commands to start your program up again.  Simply use
+   the continue command, or step, or any other command that resumes execution.
 
    Specifying any command resuming execution (currently continue, step, next,
    return, jump, quit and their abbreviations) terminates the command list (as if
@@ -292,63 +308,82 @@
    that are to print a specific message and then continue.  If none of the other
    commands print anything, you see no sign that the breakpoint was reached.
 
-s(tep)
+.. pdbcommand:: s(tep)
+
    Execute the current line, stop at the first possible occasion (either in a
    function that is called or on the next line in the current function).
 
-n(ext)
-   Continue execution until the next line in the current function is reached or it
-   returns.  (The difference between ``next`` and ``step`` is that ``step`` stops
-   inside a called function, while ``next`` executes called functions at (nearly)
-   full speed, only stopping at the next line in the current function.)
+.. pdbcommand:: n(ext)
+
+   Continue execution until the next line in the current function is reached or
+   it returns.  (The difference between :pdbcmd:`next` and :pdbcmd:`step` is
+   that :pdbcmd:`step` stops inside a called function, while :pdbcmd:`next`
+   executes called functions at (nearly) full speed, only stopping at the next
+   line in the current function.)
+
+.. pdbcommand:: unt(il)
 
-unt(il)
    Continue execution until the line with the line number greater than the
    current one is reached or when returning from current frame.
 
-r(eturn)
+.. pdbcommand:: r(eturn)
+
    Continue execution until the current function returns.
 
-c(ont(inue))
+.. pdbcommand:: c(ont(inue))
+
    Continue execution, only stop when a breakpoint is encountered.
 
-j(ump) *lineno*
+.. pdbcommand:: j(ump) lineno
+
    Set the next line that will be executed.  Only available in the bottom-most
-   frame.  This lets you jump back and execute code again, or jump forward to skip
-   code that you don't want to run.
+   frame.  This lets you jump back and execute code again, or jump forward to
+   skip code that you don't want to run.
 
-   It should be noted that not all jumps are allowed --- for instance it is not
+   It should be noted that not all jumps are allowed -- for instance it is not
    possible to jump into the middle of a :keyword:`for` loop or out of a
    :keyword:`finally` clause.
 
-l(ist) [*first*\ [, *last*]]
-   List source code for the current file.  Without arguments, list 11 lines around
-   the current line or continue the previous listing.  With one argument, list 11
-   lines around at that line.  With two arguments, list the given range; if the
-   second argument is less than the first, it is interpreted as a count.
+.. pdbcommand:: l(ist) [first[, last]]
+
+   List source code for the current file.  Without arguments, list 11 lines
+   around the current line or continue the previous listing.  With ``.`` as
+   argument, list 11 lines around the current line.  With one argument,
+   list 11 lines around at that line.  With two arguments, list the given range;
+   if the second argument is less than the first, it is interpreted as a count.
+
+.. pdbcommand:: a(rgs)
 
-a(rgs)
    Print the argument list of the current function.
 
-p(rint) *expression*
+.. pdbcommand:: p(rint) expression
+
    Evaluate the *expression* in the current context and print its value.
 
-pp *expression*
-   Like the ``p`` command, except the value of the expression is pretty-printed
-   using the :mod:`pprint` module.
-
-alias [*name* [command]]
-   Creates an alias called *name* that executes *command*.  The command must *not*
-   be enclosed in quotes.  Replaceable parameters can be indicated by ``%1``,
-   ``%2``, and so on, while ``%*`` is replaced by all the parameters.  If no
-   command is given, the current alias for *name* is shown. If no arguments are
-   given, all aliases are listed.
-
-   Aliases may be nested and can contain anything that can be legally typed at the
-   pdb prompt.  Note that internal pdb commands *can* be overridden by aliases.
-   Such a command is then hidden until the alias is removed.  Aliasing is
-   recursively applied to the first word of the command line; all other words in
-   the line are left alone.
+.. pdbcommand:: pp expression
+
+   Like the :pdbcmd:`print` command, except the value of the expression is
+   pretty-printed using the :mod:`pprint` module.
+
+.. pdbcommand:: whatis expression
+
+   Print the type of the *expression*.
+
+.. _debugger-aliases:
+
+.. pdbcommand:: alias [name [command]]
+
+   Create an alias called *name* that executes *command*.  The command must
+   *not* be enclosed in quotes.  Replaceable parameters can be indicated by
+   ``%1``, ``%2``, and so on, while ``%*`` is replaced by all the parameters.
+   If no command is given, the current alias for *name* is shown. If no
+   arguments are given, all aliases are listed.
+
+   Aliases may be nested and can contain anything that can be legally typed at
+   the pdb prompt.  Note that internal pdb commands *can* be overridden by
+   aliases.  Such a command is then hidden until the alias is removed.  Aliasing
+   is recursively applied to the first word of the command line; all other words
+   in the line are left alone.
 
    As an example, here are two useful aliases (especially when placed in the
    :file:`.pdbrc` file)::
@@ -358,25 +393,32 @@
       #Print instance variables in self
       alias ps pi self
 
-unalias *name*
-   Deletes the specified alias.
+.. pdbcommand:: unalias name
+
+   Delete the specified alias.
+
+.. pdbcommand:: ! statement
 
-[!]\ *statement*
    Execute the (one-line) *statement* in the context of the current stack frame.
    The exclamation point can be omitted unless the first word of the statement
-   resembles a debugger command. To set a global variable, you can prefix the
-   assignment command with a ``global`` command on the same line, e.g.::
+   resembles a debugger command.  To set a global variable, you can prefix the
+   assignment command with a :keyword:`global` statement on the same line,
+   e.g.::
 
       (Pdb) global list_options; list_options = ['-l']
       (Pdb)
 
-run [*args* ...]
-   Restart the debugged Python program. If an argument is supplied, it is split
-   with "shlex" and the result is used as the new sys.argv. History, breakpoints,
-   actions and debugger options are preserved. "restart" is an alias for "run".
+.. pdbcommand:: run [args ...]
+                restart [args ...]
+
+   Restart the debugged Python program.  If an argument is supplied, it is split
+   with :mod:`shlex` and the result is used as the new :data:`sys.argv`.
+   History, breakpoints, actions and debugger options are preserved.
+   :pdbcmd:`restart` is an alias for :pdbcmd:`run`.
+
+.. pdbcommand:: q(uit)
 
-q(uit)
-   Quit from the debugger. The program being executed is aborted.
+   Quit from the debugger.  The program being executed is aborted.
 
 
 .. rubric:: Footnotes

Modified: python/branches/import_unicode/Doc/library/pickletools.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/pickletools.rst	(original)
+++ python/branches/import_unicode/Doc/library/pickletools.rst	Fri Jul 30 01:19:37 2010
@@ -13,14 +13,20 @@
 :mod:`pickletools` module relevant.
 
 
-.. function:: dis(pickle, out=None, memo=None, indentlevel=4)
+.. function:: dis(pickle, out=None, memo=None, indentlevel=4, annotate=0)
 
-   Outputs a symbolic disassembly of the pickle to the file-like object *out*,
-   defaulting to ``sys.stdout``.  *pickle* can be a string or a file-like object.
-   *memo* can be a Python dictionary that will be used as the pickle's memo; it can
-   be used to perform disassemblies across multiple pickles created by the same
-   pickler. Successive levels, indicated by ``MARK`` opcodes in the stream, are
-   indented by *indentlevel* spaces.
+   Outputs a symbolic disassembly of the pickle to the file-like
+   object *out*, defaulting to ``sys.stdout``.  *pickle* can be a
+   string or a file-like object.  *memo* can be a Python dictionary
+   that will be used as the pickle's memo; it can be used to perform
+   disassemblies across multiple pickles created by the same
+   pickler. Successive levels, indicated by ``MARK`` opcodes in the
+   stream, are indented by *indentlevel* spaces.  If a nonzero value
+   is given to *annotate*, each opcode in the output is annotated with
+   a short description.  The value of *annotate* is used as a hint for
+   the column where annotation should start.
+
+  .. versionadded:: 3.2 the *annotate* argument.
 
 .. function:: genops(pickle)
 

Modified: python/branches/import_unicode/Doc/library/re.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/re.rst	(original)
+++ python/branches/import_unicode/Doc/library/re.rst	Fri Jul 30 01:19:37 2010
@@ -33,8 +33,9 @@
 string notation.
 
 It is important to note that most regular expression operations are available as
-module-level functions and :class:`RegexObject` methods.  The functions are
-shortcuts that don't require you to compile a regex object first, but miss some
+module-level functions and methods on
+:ref:`compiled regular expressions <re-objects>`.  The functions are shortcuts
+that don't require you to compile a regex object first, but miss some
 fine-tuning parameters.
 
 .. seealso::
@@ -485,7 +486,7 @@
 
    Note that for backward compatibility, the :const:`re.U` flag still
    exists (as well as its synonym :const:`re.UNICODE` and its embedded
-   counterpart ``(?u)``), but these are redundant in Python 3.0 since
+   counterpart ``(?u)``), but these are redundant in Python 3 since
    matches are Unicode by default for strings (and Unicode matching
    isn't allowed for bytes).
 
@@ -504,7 +505,7 @@
    Make ``\w``, ``\W``, ``\b``, ``\B``, ``\s`` and ``\S`` dependent on the
    current locale. The use of this flag is discouraged as the locale mechanism
    is very unreliable, and it only handles one "culture" at a time anyway;
-   you should use Unicode matching instead, which is the default in Python 3.0
+   you should use Unicode matching instead, which is the default in Python 3
    for Unicode (str) patterns.
 
 
@@ -546,21 +547,21 @@
 
 
 
-.. function:: search(pattern, string[, flags])
+.. function:: search(pattern, string, flags=0)
 
    Scan through *string* looking for a location where the regular expression
-   *pattern* produces a match, and return a corresponding :class:`MatchObject`
-   instance. Return ``None`` if no position in the string matches the pattern; note
-   that this is different from finding a zero-length match at some point in the
-   string.
+   *pattern* produces a match, and return a corresponding :ref:`match object
+   <match-objects>`.  Return ``None`` if no position in the string matches the
+   pattern; note that this is different from finding a zero-length match at some
+   point in the string.
 
 
 .. function:: match(pattern, string, flags=0)
 
    If zero or more characters at the beginning of *string* match the regular
-   expression *pattern*, return a corresponding :class:`MatchObject` instance.
-   Return ``None`` if the string does not match the pattern; note that this is
-   different from a zero-length match.
+   expression *pattern*, return a corresponding :ref:`match object
+   <match-objects>`.  Return ``None`` if the string does not match the pattern;
+   note that this is different from a zero-length match.
 
    .. note::
 
@@ -620,9 +621,9 @@
 
 .. function:: finditer(pattern, string, flags=0)
 
-   Return an :term:`iterator` yielding :class:`MatchObject` instances over all
-   non-overlapping matches for the RE *pattern* in *string*.  The *string* is
-   scanned left-to-right, and matches are returned in the order found.  Empty
+   Return an :term:`iterator` yielding :ref:`match objects <match-objects>` over
+   all non-overlapping matches for the RE *pattern* in *string*.  The *string*
+   is scanned left-to-right, and matches are returned in the order found.  Empty
    matches are included in the result unless they touch the beginning of another
    match.
 
@@ -692,6 +693,11 @@
    metacharacters in it.
 
 
+.. function:: purge()
+
+   Clear the regular expression cache.
+
+
 .. exception:: error
 
    Exception raised when a string passed to one of the functions here is not a
@@ -705,107 +711,107 @@
 Regular Expression Objects
 --------------------------
 
-.. class:: RegexObject
-
-   The :class:`RegexObject` class supports the following methods and attributes:
-
-   .. method:: RegexObject.search(string[, pos[, endpos]])
+Compiled regular expression objects support the following methods and
+attributes.
 
-      Scan through *string* looking for a location where this regular expression
-      produces a match, and return a corresponding :class:`MatchObject` instance.
-      Return ``None`` if no position in the string matches the pattern; note that this
-      is different from finding a zero-length match at some point in the string.
+.. method:: regex.search(string[, pos[, endpos]])
 
-      The optional second parameter *pos* gives an index in the string where the
-      search is to start; it defaults to ``0``.  This is not completely equivalent to
-      slicing the string; the ``'^'`` pattern character matches at the real beginning
-      of the string and at positions just after a newline, but not necessarily at the
-      index where the search is to start.
+   Scan through *string* looking for a location where this regular expression
+   produces a match, and return a corresponding :ref:`match object
+   <match-objects>`.  Return ``None`` if no position in the string matches the
+   pattern; note that this is different from finding a zero-length match at some
+   point in the string.
+
+   The optional second parameter *pos* gives an index in the string where the
+   search is to start; it defaults to ``0``.  This is not completely equivalent to
+   slicing the string; the ``'^'`` pattern character matches at the real beginning
+   of the string and at positions just after a newline, but not necessarily at the
+   index where the search is to start.
+
+   The optional parameter *endpos* limits how far the string will be searched; it
+   will be as if the string is *endpos* characters long, so only the characters
+   from *pos* to ``endpos - 1`` will be searched for a match.  If *endpos* is less
+   than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
+   expression object, ``rx.search(string, 0, 50)`` is equivalent to
+   ``rx.search(string[:50], 0)``.
 
-      The optional parameter *endpos* limits how far the string will be searched; it
-      will be as if the string is *endpos* characters long, so only the characters
-      from *pos* to ``endpos - 1`` will be searched for a match.  If *endpos* is less
-      than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
-      expression object, ``rx.search(string, 0, 50)`` is equivalent to
-      ``rx.search(string[:50], 0)``.
-
-      >>> pattern = re.compile("d")
-      >>> pattern.search("dog")     # Match at index 0
-      <_sre.SRE_Match object at ...>
-      >>> pattern.search("dog", 1)  # No match; search doesn't include the "d"
+   >>> pattern = re.compile("d")
+   >>> pattern.search("dog")     # Match at index 0
+   <_sre.SRE_Match object at ...>
+   >>> pattern.search("dog", 1)  # No match; search doesn't include the "d"
 
 
-   .. method:: RegexObject.match(string[, pos[, endpos]])
+.. method:: regex.match(string[, pos[, endpos]])
 
-      If zero or more characters at the *beginning* of *string* match this regular
-      expression, return a corresponding :class:`MatchObject` instance.  Return
-      ``None`` if the string does not match the pattern; note that this is different
-      from a zero-length match.
+   If zero or more characters at the *beginning* of *string* match this regular
+   expression, return a corresponding :ref:`match object <match-objects>`.
+   Return ``None`` if the string does not match the pattern; note that this is
+   different from a zero-length match.
 
-      The optional *pos* and *endpos* parameters have the same meaning as for the
-      :meth:`~RegexObject.search` method.
+   The optional *pos* and *endpos* parameters have the same meaning as for the
+   :meth:`~regex.search` method.
 
-      .. note::
+   .. note::
 
-         If you want to locate a match anywhere in *string*, use
-         :meth:`~RegexObject.search` instead.
+      If you want to locate a match anywhere in *string*, use
+      :meth:`~regex.search` instead.
 
-      >>> pattern = re.compile("o")
-      >>> pattern.match("dog")      # No match as "o" is not at the start of "dog".
-      >>> pattern.match("dog", 1)   # Match as "o" is the 2nd character of "dog".
-      <_sre.SRE_Match object at ...>
+   >>> pattern = re.compile("o")
+   >>> pattern.match("dog")      # No match as "o" is not at the start of "dog".
+   >>> pattern.match("dog", 1)   # Match as "o" is the 2nd character of "dog".
+   <_sre.SRE_Match object at ...>
 
 
-   .. method:: RegexObject.split(string[, maxsplit=0])
+.. method:: regex.split(string, maxsplit=0)
 
-      Identical to the :func:`split` function, using the compiled pattern.
+   Identical to the :func:`split` function, using the compiled pattern.
 
 
-   .. method:: RegexObject.findall(string[, pos[, endpos]])
+.. method:: regex.findall(string[, pos[, endpos]])
 
-      Similar to the :func:`findall` function, using the compiled pattern, but
-      also accepts optional *pos* and *endpos* parameters that limit the search
-      region like for :meth:`match`.
+   Similar to the :func:`findall` function, using the compiled pattern, but
+   also accepts optional *pos* and *endpos* parameters that limit the search
+   region like for :meth:`match`.
 
 
-   .. method:: RegexObject.finditer(string[, pos[, endpos]])
+.. method:: regex.finditer(string[, pos[, endpos]])
 
-      Similar to the :func:`finditer` function, using the compiled pattern, but
-      also accepts optional *pos* and *endpos* parameters that limit the search
-      region like for :meth:`match`.
+   Similar to the :func:`finditer` function, using the compiled pattern, but
+   also accepts optional *pos* and *endpos* parameters that limit the search
+   region like for :meth:`match`.
 
 
-   .. method:: RegexObject.sub(repl, string[, count=0])
+.. method:: regex.sub(repl, string, count=0)
 
-      Identical to the :func:`sub` function, using the compiled pattern.
+   Identical to the :func:`sub` function, using the compiled pattern.
 
 
-   .. method:: RegexObject.subn(repl, string[, count=0])
+.. method:: regex.subn(repl, string, count=0)
 
-      Identical to the :func:`subn` function, using the compiled pattern.
+   Identical to the :func:`subn` function, using the compiled pattern.
 
 
-   .. attribute:: RegexObject.flags
+.. attribute:: regex.flags
 
-      The flags argument used when the RE object was compiled, or ``0`` if no flags
-      were provided.
+   The flags argument used when the RE object was compiled, or ``0`` if no flags
+   were provided.
 
 
-   .. attribute:: RegexObject.groups
+.. attribute:: regex.groups
 
-      The number of capturing groups in the pattern.
+   The number of capturing groups in the pattern.
 
 
-   .. attribute:: RegexObject.groupindex
+.. attribute:: regex.groupindex
 
-      A dictionary mapping any symbolic group names defined by ``(?P<id>)`` to group
-      numbers.  The dictionary is empty if no symbolic groups were used in the
-      pattern.
+   A dictionary mapping any symbolic group names defined by ``(?P<id>)`` to group
+   numbers.  The dictionary is empty if no symbolic groups were used in the
+   pattern.
 
 
-   .. attribute:: RegexObject.pattern
+.. attribute:: regex.pattern
 
-      The pattern string from which the RE object was compiled.
+   The pattern string from which the RE object was compiled.
 
 
 .. _match-objects:
@@ -813,181 +819,176 @@
 Match Objects
 -------------
 
-.. class:: MatchObject
-
-   Match Objects always have a boolean value of :const:`True`, so that you can test
-   whether e.g. :func:`match` resulted in a match with a simple if statement.  They
-   support the following methods and attributes:
-
-
-   .. method:: MatchObject.expand(template)
+Match objects always have a boolean value of :const:`True`, so that you can test
+whether e.g. :func:`match` resulted in a match with a simple if statement.  They
+support the following methods and attributes:
+
+
+.. method:: match.expand(template)
+
+   Return the string obtained by doing backslash substitution on the template
+   string *template*, as done by the :meth:`~regex.sub` method.
+   Escapes such as ``\n`` are converted to the appropriate characters,
+   and numeric backreferences (``\1``, ``\2``) and named backreferences
+   (``\g<1>``, ``\g<name>``) are replaced by the contents of the
+   corresponding group.
+
+
+.. method:: match.group([group1, ...])
+
+   Returns one or more subgroups of the match.  If there is a single argument, the
+   result is a single string; if there are multiple arguments, the result is a
+   tuple with one item per argument. Without arguments, *group1* defaults to zero
+   (the whole match is returned). If a *groupN* argument is zero, the corresponding
+   return value is the entire matching string; if it is in the inclusive range
+   [1..99], it is the string matching the corresponding parenthesized group.  If a
+   group number is negative or larger than the number of groups defined in the
+   pattern, an :exc:`IndexError` exception is raised. If a group is contained in a
+   part of the pattern that did not match, the corresponding result is ``None``.
+   If a group is contained in a part of the pattern that matched multiple times,
+   the last match is returned.
+
+      >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
+      >>> m.group(0)       # The entire match
+      'Isaac Newton'
+      >>> m.group(1)       # The first parenthesized subgroup.
+      'Isaac'
+      >>> m.group(2)       # The second parenthesized subgroup.
+      'Newton'
+      >>> m.group(1, 2)    # Multiple arguments give us a tuple.
+      ('Isaac', 'Newton')
+
+   If the regular expression uses the ``(?P<name>...)`` syntax, the *groupN*
+   arguments may also be strings identifying groups by their group name.  If a
+   string argument is not used as a group name in the pattern, an :exc:`IndexError`
+   exception is raised.
+
+   A moderately complicated example:
+
+      >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
+      >>> m.group('first_name')
+      'Malcolm'
+      >>> m.group('last_name')
+      'Reynolds'
+
+   Named groups can also be referred to by their index:
+
+      >>> m.group(1)
+      'Malcolm'
+      >>> m.group(2)
+      'Reynolds'
+
+   If a group matches multiple times, only the last match is accessible:
+
+      >>> m = re.match(r"(..)+", "a1b2c3")  # Matches 3 times.
+      >>> m.group(1)                        # Returns only the last match.
+      'c3'
+
+
+.. method:: match.groups(default=None)
+
+   Return a tuple containing all the subgroups of the match, from 1 up to however
+   many groups are in the pattern.  The *default* argument is used for groups that
+   did not participate in the match; it defaults to ``None``.
 
-      Return the string obtained by doing backslash substitution on the template
-      string *template*, as done by the :meth:`~RegexObject.sub` method.  Escapes
-      such as ``\n`` are converted to the appropriate characters, and numeric
-      backreferences (``\1``, ``\2``) and named backreferences (``\g<1>``,
-      ``\g<name>``) are replaced by the contents of the corresponding group.
-
-
-   .. method:: MatchObject.group([group1, ...])
-
-      Returns one or more subgroups of the match.  If there is a single argument, the
-      result is a single string; if there are multiple arguments, the result is a
-      tuple with one item per argument. Without arguments, *group1* defaults to zero
-      (the whole match is returned). If a *groupN* argument is zero, the corresponding
-      return value is the entire matching string; if it is in the inclusive range
-      [1..99], it is the string matching the corresponding parenthesized group.  If a
-      group number is negative or larger than the number of groups defined in the
-      pattern, an :exc:`IndexError` exception is raised. If a group is contained in a
-      part of the pattern that did not match, the corresponding result is ``None``.
-      If a group is contained in a part of the pattern that matched multiple times,
-      the last match is returned.
-
-         >>> m = re.match(r"(\w+) (\w+)", "Isaac Newton, physicist")
-         >>> m.group(0)       # The entire match
-         'Isaac Newton'
-         >>> m.group(1)       # The first parenthesized subgroup.
-         'Isaac'
-         >>> m.group(2)       # The second parenthesized subgroup.
-         'Newton'
-         >>> m.group(1, 2)    # Multiple arguments give us a tuple.
-         ('Isaac', 'Newton')
-
-      If the regular expression uses the ``(?P<name>...)`` syntax, the *groupN*
-      arguments may also be strings identifying groups by their group name.  If a
-      string argument is not used as a group name in the pattern, an :exc:`IndexError`
-      exception is raised.
-
-      A moderately complicated example:
-
-         >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
-         >>> m.group('first_name')
-         'Malcolm'
-         >>> m.group('last_name')
-         'Reynolds'
-
-      Named groups can also be referred to by their index:
-
-         >>> m.group(1)
-         'Malcolm'
-         >>> m.group(2)
-         'Reynolds'
-
-      If a group matches multiple times, only the last match is accessible:
-
-         >>> m = re.match(r"(..)+", "a1b2c3")  # Matches 3 times.
-         >>> m.group(1)                        # Returns only the last match.
-         'c3'
-
-
-   .. method:: MatchObject.groups(default=None)
-
-      Return a tuple containing all the subgroups of the match, from 1 up to however
-      many groups are in the pattern.  The *default* argument is used for groups that
-      did not participate in the match; it defaults to ``None``.  (Incompatibility
-      note: in the original Python 1.5 release, if the tuple was one element long, a
-      string would be returned instead.  In later versions (from 1.5.1 on), a
-      singleton tuple is returned in such cases.)
-
-      For example:
+   For example:
 
-         >>> m = re.match(r"(\d+)\.(\d+)", "24.1632")
-         >>> m.groups()
-         ('24', '1632')
+      >>> m = re.match(r"(\d+)\.(\d+)", "24.1632")
+      >>> m.groups()
+      ('24', '1632')
 
-      If we make the decimal place and everything after it optional, not all groups
-      might participate in the match.  These groups will default to ``None`` unless
-      the *default* argument is given:
+   If we make the decimal place and everything after it optional, not all groups
+   might participate in the match.  These groups will default to ``None`` unless
+   the *default* argument is given:
 
-         >>> m = re.match(r"(\d+)\.?(\d+)?", "24")
-         >>> m.groups()      # Second group defaults to None.
-         ('24', None)
-         >>> m.groups('0')   # Now, the second group defaults to '0'.
-         ('24', '0')
+      >>> m = re.match(r"(\d+)\.?(\d+)?", "24")
+      >>> m.groups()      # Second group defaults to None.
+      ('24', None)
+      >>> m.groups('0')   # Now, the second group defaults to '0'.
+      ('24', '0')
 
 
-   .. method:: MatchObject.groupdict([default])
+.. method:: match.groupdict(default=None)
 
-      Return a dictionary containing all the *named* subgroups of the match, keyed by
-      the subgroup name.  The *default* argument is used for groups that did not
-      participate in the match; it defaults to ``None``.  For example:
+   Return a dictionary containing all the *named* subgroups of the match, keyed by
+   the subgroup name.  The *default* argument is used for groups that did not
+   participate in the match; it defaults to ``None``.  For example:
 
-         >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
-         >>> m.groupdict()
-         {'first_name': 'Malcolm', 'last_name': 'Reynolds'}
+      >>> m = re.match(r"(?P<first_name>\w+) (?P<last_name>\w+)", "Malcolm Reynolds")
+      >>> m.groupdict()
+      {'first_name': 'Malcolm', 'last_name': 'Reynolds'}
 
 
-   .. method:: MatchObject.start([group])
-               MatchObject.end([group])
+.. method:: match.start([group])
+            match.end([group])
 
-      Return the indices of the start and end of the substring matched by *group*;
-      *group* defaults to zero (meaning the whole matched substring). Return ``-1`` if
-      *group* exists but did not contribute to the match.  For a match object *m*, and
-      a group *g* that did contribute to the match, the substring matched by group *g*
-      (equivalent to ``m.group(g)``) is ::
+   Return the indices of the start and end of the substring matched by *group*;
+   *group* defaults to zero (meaning the whole matched substring). Return ``-1`` if
+   *group* exists but did not contribute to the match.  For a match object *m*, and
+   a group *g* that did contribute to the match, the substring matched by group *g*
+   (equivalent to ``m.group(g)``) is ::
 
-         m.string[m.start(g):m.end(g)]
+      m.string[m.start(g):m.end(g)]
 
-      Note that ``m.start(group)`` will equal ``m.end(group)`` if *group* matched a
-      null string.  For example, after ``m = re.search('b(c?)', 'cba')``,
-      ``m.start(0)`` is 1, ``m.end(0)`` is 2, ``m.start(1)`` and ``m.end(1)`` are both
-      2, and ``m.start(2)`` raises an :exc:`IndexError` exception.
+   Note that ``m.start(group)`` will equal ``m.end(group)`` if *group* matched a
+   null string.  For example, after ``m = re.search('b(c?)', 'cba')``,
+   ``m.start(0)`` is 1, ``m.end(0)`` is 2, ``m.start(1)`` and ``m.end(1)`` are both
+   2, and ``m.start(2)`` raises an :exc:`IndexError` exception.
 
-      An example that will remove *remove_this* from email addresses:
+   An example that will remove *remove_this* from email addresses:
 
-         >>> email = "tony at tiremove_thisger.net"
-         >>> m = re.search("remove_this", email)
-         >>> email[:m.start()] + email[m.end():]
-         'tony at tiger.net'
+      >>> email = "tony at tiremove_thisger.net"
+      >>> m = re.search("remove_this", email)
+      >>> email[:m.start()] + email[m.end():]
+      'tony at tiger.net'
 
 
-   .. method:: MatchObject.span([group])
+.. method:: match.span([group])
 
-      For :class:`MatchObject` *m*, return the 2-tuple ``(m.start(group),
-      m.end(group))``. Note that if *group* did not contribute to the match, this is
-      ``(-1, -1)``.  *group* defaults to zero, the entire match.
+   For a match *m*, return the 2-tuple ``(m.start(group), m.end(group))``. Note
+   that if *group* did not contribute to the match, this is ``(-1, -1)``.
+   *group* defaults to zero, the entire match.
 
 
-   .. attribute:: MatchObject.pos
+.. attribute:: match.pos
 
-      The value of *pos* which was passed to the :meth:`~RegexObject.search` or
-      :meth:`~RegexObject.match` method of the :class:`RegexObject`.  This is the
-      index into the string at which the RE engine started looking for a match.
+   The value of *pos* which was passed to the :meth:`~regex.search` or
+   :meth:`~regex.match` method of a :ref:`match object <match-objects>`.  This
+   is the index into the string at which the RE engine started looking for a
+   match.
 
 
-   .. attribute:: MatchObject.endpos
+.. attribute:: match.endpos
 
-      The value of *endpos* which was passed to the :meth:`~RegexObject.search` or
-      :meth:`~RegexObject.match` method of the :class:`RegexObject`.  This is the
-      index into the string beyond which the RE engine will not go.
+   The value of *endpos* which was passed to the :meth:`~regex.search` or
+   :meth:`~regex.match` method of a :ref:`match object <match-objects>`.  This
+   is the index into the string beyond which the RE engine will not go.
 
 
-   .. attribute:: MatchObject.lastindex
+.. attribute:: match.lastindex
 
-      The integer index of the last matched capturing group, or ``None`` if no group
-      was matched at all. For example, the expressions ``(a)b``, ``((a)(b))``, and
-      ``((ab))`` will have ``lastindex == 1`` if applied to the string ``'ab'``, while
-      the expression ``(a)(b)`` will have ``lastindex == 2``, if applied to the same
-      string.
+   The integer index of the last matched capturing group, or ``None`` if no group
+   was matched at all. For example, the expressions ``(a)b``, ``((a)(b))``, and
+   ``((ab))`` will have ``lastindex == 1`` if applied to the string ``'ab'``, while
+   the expression ``(a)(b)`` will have ``lastindex == 2``, if applied to the same
+   string.
 
 
-   .. attribute:: MatchObject.lastgroup
+.. attribute:: match.lastgroup
 
-      The name of the last matched capturing group, or ``None`` if the group didn't
-      have a name, or if no group was matched at all.
+   The name of the last matched capturing group, or ``None`` if the group didn't
+   have a name, or if no group was matched at all.
 
 
-   .. attribute:: MatchObject.re
+.. attribute:: match.re
 
-      The regular expression object whose :meth:`~RegexObject.match` or
-      :meth:`~RegexObject.search` method produced this :class:`MatchObject`
-      instance.
+   The regular expression object whose :meth:`~regex.match` or
+   :meth:`~regex.search` method produced this match instance.
 
 
-   .. attribute:: MatchObject.string
+.. attribute:: match.string
 
-      The string passed to :meth:`~RegexObject.match` or
-      :meth:`~RegexObject.search`.
+   The string passed to :meth:`~regex.match` or :meth:`~regex.search`.
 
 
 Examples
@@ -1033,8 +1034,7 @@
    "<Match: '354aa', groups=('a',)>"
 
 To find out what card the pair consists of, one could use the
-:meth:`~MatchObject.group` method of :class:`MatchObject` in the following
-manner:
+:meth:`~match.group` method of the match object in the following manner:
 
 .. doctest::
 
@@ -1109,7 +1109,7 @@
    >>> re.match('Begin (\w| )*? end', s).end()
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
-     File "/usr/local/lib/python2.5/re.py", line 132, in match
+     File "/usr/local/lib/python3.2/re.py", line 132, in match
        return _compile(pattern, flags).match(string)
    RuntimeError: maximum recursion limit exceeded
 
@@ -1225,9 +1225,9 @@
    ...   random.shuffle(inner_word)
    ...   return m.group(1) + "".join(inner_word) + m.group(3)
    >>> text = "Professor Abdolmalek, please report your absences promptly."
-   >>> re.sub("(\w)(\w+)(\w)", repl, text)
+   >>> re.sub(r"(\w)(\w+)(\w)", repl, text)
    'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.'
-   >>> re.sub("(\w)(\w+)(\w)", repl, text)
+   >>> re.sub(r"(\w)(\w+)(\w)", repl, text)
    'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.'
 
 
@@ -1248,10 +1248,10 @@
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 If one wants more information about all matches of a pattern than the matched
-text, :func:`finditer` is useful as it provides instances of
-:class:`MatchObject` instead of strings.  Continuing with the previous example,
-if one was a writer who wanted to find all of the adverbs *and their positions*
-in some text, he or she would use :func:`finditer` in the following manner:
+text, :func:`finditer` is useful as it provides :ref:`match objects
+<match-objects>` instead of strings.  Continuing with the previous example, if
+one was a writer who wanted to find all of the adverbs *and their positions* in
+some text, he or she would use :func:`finditer` in the following manner:
 
    >>> text = "He was carefully disguised but captured quickly by police."
    >>> for m in re.finditer(r"\w+ly", text):

Modified: python/branches/import_unicode/Doc/library/select.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/select.rst	(original)
+++ python/branches/import_unicode/Doc/library/select.rst	Fri Jul 30 01:19:37 2010
@@ -41,14 +41,14 @@
 
 .. function:: kqueue()
 
-   (Only supported on BSD.)  Returns a kernel queue object object; see section
+   (Only supported on BSD.)  Returns a kernel queue object; see section
    :ref:`kqueue-objects` below for the methods supported by kqueue objects.
 
 
 .. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0)
 
-   (Only supported on BSD.)  Returns a kernel event object object; see section
-   :ref:`kevent-objects` below for the methods supported by kqueue objects.
+   (Only supported on BSD.)  Returns a kernel event object; see section
+   :ref:`kevent-objects` below for the methods supported by kevent objects.
 
 
 .. function:: select(rlist, wlist, xlist[, timeout])
@@ -131,15 +131,15 @@
    | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is     |
    |                       | pulled out, the fd is internally disabled     |
    +-----------------------+-----------------------------------------------+
-   | :const:`EPOLLRDNORM`  | ???                                           |
+   | :const:`EPOLLRDNORM`  | Equivalent to :const:`EPOLLIN`                |
    +-----------------------+-----------------------------------------------+
-   | :const:`EPOLLRDBAND`  | ???                                           |
+   | :const:`EPOLLRDBAND`  | Priority data band can be read.               |
    +-----------------------+-----------------------------------------------+
-   | :const:`EPOLLWRNORM`  | ???                                           |
+   | :const:`EPOLLWRNORM`  | Equivalent to :const:`EPOLLOUT`               |
    +-----------------------+-----------------------------------------------+
-   | :const:`EPOLLWRBAND`  | ???                                           |
+   | :const:`EPOLLWRBAND`  | Priority data may be written.                 |
    +-----------------------+-----------------------------------------------+
-   | :const:`EPOLLMSG`     | ???                                           |
+   | :const:`EPOLLMSG`     | Ignored.                                      |
    +-----------------------+-----------------------------------------------+
 
 
@@ -233,7 +233,7 @@
 .. method:: poll.modify(fd, eventmask)
 
    Modifies an already registered fd. This has the same effect as
-   :meth:`register(fd, eventmask)`.  Attempting to modify a file descriptor
+   ``register(fd, eventmask)``.  Attempting to modify a file descriptor
    that was never registered causes an :exc:`IOError` exception with errno
    :const:`ENOENT` to be raised.
 

Modified: python/branches/import_unicode/Doc/library/smtpd.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/smtpd.rst	(original)
+++ python/branches/import_unicode/Doc/library/smtpd.rst	Fri Jul 30 01:19:37 2010
@@ -10,10 +10,14 @@
 
 
 
-This module offers several classes to implement SMTP servers.  One is a generic
+This module offers several classes to implement SMTP (email) servers.
+
+Several server implementations are present; one is a generic
 do-nothing implementation, which can be overridden, while the other two offer
 specific mail-sending strategies.
 
+Additionally the SMTPChannel may be extended to implement very specific
+interaction behaviour with SMTP clients.
 
 SMTPServer Objects
 ------------------
@@ -26,7 +30,6 @@
    inherits from :class:`asyncore.dispatcher`, and so will insert itself into
    :mod:`asyncore`'s event loop on instantiation.
 
-
    .. method:: process_message(peer, mailfrom, rcpttos, data)
 
       Raise :exc:`NotImplementedError` exception. Override this in subclasses to
@@ -37,6 +40,11 @@
       containing the contents of the e-mail (which should be in :rfc:`2822`
       format).
 
+   .. attribute:: channel_class
+
+      Override this in subclasses to use a custom :class:`SMTPChannel` for
+      managing SMTP clients.
+
 
 DebuggingServer Objects
 -----------------------
@@ -71,3 +79,91 @@
    running this has a good chance to make you into an open relay, so please be
    careful.
 
+SMTPChannel Objects
+-------------------
+
+.. class:: SMTPChannel(server, conn, addr)
+
+   Create a new :class:`SMTPChannel` object which manages the communication
+   between the server and a single SMTP client.
+
+   To use a custom SMTPChannel implementation you need to override the
+   :attr:`SMTPServer.channel_class` of your :class:`SMTPServer`.
+
+   The :class:`SMTPChannel` has the following instance variables:
+
+   .. attribute:: smtp_server
+
+      Holds the :class:`SMTPServer` that spawned this channel.
+
+   .. attribute:: conn
+
+      Holds the socket object connecting to the client.
+
+   .. attribute:: addr
+
+      Holds the address of the client, the second value returned by
+      socket.accept()
+
+   .. attribute:: received_lines
+
+      Holds a list of the line strings (decoded using UTF-8) received from
+      the client. The lines have their "\r\n" line ending translated to "\n".
+
+   .. attribute:: smtp_state
+
+      Holds the current state of the channel. This will be either
+      :attr:`COMMAND` initially and then :attr:`DATA` after the client sends
+      a "DATA" line.
+
+   .. attribute:: seen_greeting
+
+      Holds a string containing the greeting sent by the client in its "HELO".
+
+   .. attribute:: mailfrom
+
+      Holds a string containing the address identified in the "MAIL FROM:" line
+      from the client.
+
+   .. attribute:: rcpttos
+
+      Holds a list of strings containing the addresses identified in the
+      "RCPT TO:" lines from the client.
+
+   .. attribute:: received_data
+
+      Holds a string containing all of the data sent by the client during the
+      DATA state, up to but not including the terminating "\r\n.\r\n".
+
+   .. attribute:: fqdn
+
+      Holds the fully-qualified domain name of the server as returned by
+      ``socket.getfqdn()``.
+
+   .. attribute:: peer
+
+      Holds the name of the client peer as returned by ``conn.getpeername()``
+      where ``conn`` is :attr:`conn`.
+
+   The :class:`SMTPChannel` operates by invoking methods named ``smtp_<command>``
+   upon reception of a command line from the client. Built into the base
+   :class:`SMTPChannel` class are methods for handling the following commands
+   (and responding to them appropriately):
+
+   ======== ===================================================================
+   Command  Action taken
+   ======== ===================================================================
+   HELO     Accepts the greeting from the client and stores it in
+            :attr:`seen_greeting`.
+   NOOP     Takes no action.
+   QUIT     Closes the connection cleanly.
+   MAIL     Accepts the "MAIL FROM:" syntax and stores the supplied address as
+            :attr:`mailfrom`.
+   RCPT     Accepts the "RCPT TO:" syntax and stores the supplied addresses in
+            the :attr:`rcpttos` list.
+   RSET     Resets the :attr:`mailfrom`, :attr:`rcpttos`, and
+            :attr:`received_data`, but not the greeting.
+   DATA     Sets the internal state to :attr:`DATA` and stores remaining lines
+            from the client in :attr:`received_data` until the terminator
+            "\r\n.\r\n" is received.
+   ======== ===================================================================
\ No newline at end of file

Modified: python/branches/import_unicode/Doc/library/socket.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/socket.rst	(original)
+++ python/branches/import_unicode/Doc/library/socket.rst	Fri Jul 30 01:19:37 2010
@@ -748,7 +748,9 @@
    Shut down one or both halves of the connection.  If *how* is :const:`SHUT_RD`,
    further receives are disallowed.  If *how* is :const:`SHUT_WR`, further sends
    are disallowed.  If *how* is :const:`SHUT_RDWR`, further sends and receives are
-   disallowed.
+   disallowed.  Depending on the platform, shutting down one half of the connection
+   can also close the opposite half (e.g. on Mac OS X, ``shutdown(SHUT_WR)`` does
+   not allow further reads on the other end of the connection).
 
 Note that there are no methods :meth:`read` or :meth:`write`; use
 :meth:`~socket.recv` and :meth:`~socket.send` without *flags* argument instead.

Modified: python/branches/import_unicode/Doc/library/sqlite3.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/sqlite3.rst	(original)
+++ python/branches/import_unicode/Doc/library/sqlite3.rst	Fri Jul 30 01:19:37 2010
@@ -136,7 +136,7 @@
    first blank for the column name: the column name would simply be "x".
 
 
-.. function:: connect(database[, timeout, isolation_level, detect_types, factory])
+.. function:: connect(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements])
 
    Opens a connection to the SQLite database file *database*. You can use
    ``":memory:"`` to open a database connection to a database that resides in RAM

Modified: python/branches/import_unicode/Doc/library/stdtypes.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/stdtypes.rst	(original)
+++ python/branches/import_unicode/Doc/library/stdtypes.rst	Fri Jul 30 01:19:37 2010
@@ -2264,10 +2264,19 @@
    buffer protocol.  Builtin objects that support the buffer protocol include
    :class:`bytes` and :class:`bytearray`.
 
-   ``len(view)`` returns the total number of bytes in the memoryview, *view*.
+   A :class:`memoryview` has the notion of an *element*, which is the
+   atomic memory unit handled by the originating object *obj*.  For many
+   simple types such as :class:`bytes` and :class:`bytearray`, an element
+   is a single byte, but other types such as :class:`array.array` may have
+   bigger elements.
+
+   ``len(view)`` returns the total number of elements in the memoryview,
+   *view*.  The :class:`~memoryview.itemsize` attribute will give you the
+   number of bytes in a single element.
 
    A :class:`memoryview` supports slicing to expose its data.  Taking a single
-   index will return a single byte.  Full slicing will result in a subview::
+   index will return a single element as a :class:`bytes` object.  Full
+   slicing will result in a subview::
 
       >>> v = memoryview(b'abcefg')
       >>> v[1]
@@ -2278,11 +2287,8 @@
       <memory at 0x77ab28>
       >>> bytes(v[1:4])
       b'bce'
-      >>> v[3:-1]
-      <memory at 0x744f18>
-      >>> bytes(v[4:-1])
 
-   If the object the memory view is over supports changing its data, the
+   If the object the memoryview is over supports changing its data, the
    memoryview supports slice assignment::
 
       >>> data = bytearray(b'abcefg')
@@ -2302,12 +2308,18 @@
 
    Notice how the size of the memoryview object cannot be changed.
 
-
    :class:`memoryview` has two methods:
 
    .. method:: tobytes()
 
-      Return the data in the buffer as a bytestring.
+      Return the data in the buffer as a bytestring.  This is equivalent to
+      calling the :class:`bytes` constructor on the memoryview. ::
+
+         >>> m = memoryview(b"abc")
+         >>> m.tobytes()
+         b'abc'
+         >>> bytes(m)
+         b'abc'
 
    .. method:: tolist()
 
@@ -2325,7 +2337,15 @@
 
    .. attribute:: itemsize
 
-      The size in bytes of each element of the memoryview.
+      The size in bytes of each element of the memoryview::
+
+         >>> m = memoryview(array.array('H', [1,2,3]))
+         >>> m.itemsize
+         2
+         >>> m[0]
+         b'\x01\x00'
+         >>> len(m[0]) == m.itemsize
+         True
 
    .. attribute:: shape
 

Modified: python/branches/import_unicode/Doc/library/string.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/string.rst	(original)
+++ python/branches/import_unicode/Doc/library/string.rst	Fri Jul 30 01:19:37 2010
@@ -7,13 +7,13 @@
 
 .. index:: module: re
 
-The :mod:`string` module contains a number of useful constants and classes, as
-well as some deprecated legacy functions that are also available as methods on
-strings. In addition, Python's built-in string classes support the sequence type
-methods described in the :ref:`typesseq` section, and also the string-specific
-methods described in the :ref:`string-methods` section. To output formatted
-strings, see the :ref:`string-formatting` section. Also, see the :mod:`re`
-module for string functions based on regular expressions.
+The :mod:`string` module contains a number of useful constants and classes
+for string formatting.  In addition, Python's built-in string classes
+support the sequence type methods described in the :ref:`typesseq`
+section, and also the string-specific methods described in the
+:ref:`string-methods` section.  To output formatted strings, see the
+:ref:`string-formatting` section.  Also, see the :mod:`re` module for
+string functions based on regular expressions.
 
 
 String constants
@@ -710,6 +710,14 @@
   appropriate).  The default value is the regular expression
   ``[_a-z][_a-z0-9]*``.
 
+* *flags* -- The regular expression flags that will be applied when compiling
+  the regular expression used for recognizing substitutions.  The default value
+  is ``re.IGNORECASE``.  Note that ``re.VERBOSE`` will always be added to the
+  flags, so custom *idpattern*\ s must follow conventions for verbose regular
+  expressions.
+
+  .. versionadded:: 3.2
+
 Alternatively, you can provide the entire regular expression pattern by
 overriding the class attribute *pattern*.  If you do this, the value must be a
 regular expression object with four named capturing groups.  The capturing

Modified: python/branches/import_unicode/Doc/library/struct.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/struct.rst	(original)
+++ python/branches/import_unicode/Doc/library/struct.rst	Fri Jul 30 01:19:37 2010
@@ -259,18 +259,16 @@
    In 3.0, some of the integer formats wrapped out-of-range values and
    raised :exc:`DeprecationWarning` instead of :exc:`struct.error`.
 
-
 The ``'p'`` format character encodes a "Pascal string", meaning a short
-variable-length string stored in a fixed number of bytes. The count is the total
-number of bytes stored.  The first byte stored is the length of the string, or
-255, whichever is smaller.  The bytes of the string follow.  If the string
-passed in to :func:`pack` is too long (longer than the count minus 1), only the
-leading count-1 bytes of the string are stored.  If the string is shorter than
-count-1, it is padded with null bytes so that exactly count bytes in all are
-used.  Note that for :func:`unpack`, the ``'p'`` format character consumes count
-bytes, but that the string returned can never contain more than 255 bytes.
-
-
+variable-length string stored in a *fixed number of bytes*, given by the count.
+The first byte stored is the length of the string, or 255, whichever is
+smaller.  The bytes of the string follow.  If the string passed in to
+:func:`pack` is too long (longer than the count minus 1), only the leading
+``count-1`` bytes of the string are stored.  If the string is shorter than
+``count-1``, it is padded with null bytes so that exactly count bytes in all
+are used.  Note that for :func:`unpack`, the ``'p'`` format character consumes
+``count`` bytes, but that the string returned can never contain more than 255
+bytes.
 
 For the ``'?'`` format character, the return value is either :const:`True` or
 :const:`False`. When packing, the truth value of the argument object is used.

Modified: python/branches/import_unicode/Doc/library/subprocess.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/subprocess.rst	(original)
+++ python/branches/import_unicode/Doc/library/subprocess.rst	Fri Jul 30 01:19:37 2010
@@ -575,7 +575,7 @@
    pipe = os.popen(cmd, 'w')
    ...
    rc = pipe.close()
-   if rc is not None and rc % 256:
+   if rc is not None and rc >> 8:
        print("There were some errors")
    ==>
    process = Popen(cmd, 'w', stdin=PIPE)

Modified: python/branches/import_unicode/Doc/library/test.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/test.rst	(original)
+++ python/branches/import_unicode/Doc/library/test.rst	Fri Jul 30 01:19:37 2010
@@ -5,6 +5,13 @@
    :synopsis: Regression tests package containing the testing suite for Python.
 .. sectionauthor:: Brett Cannon <brett at python.org>
 
+.. note::
+    The :mod:`test` package is meant for internal use by Python only. It is
+    documented for the benefit of the core developers of Python. Any use of
+    this package outside of Python's standard library is discouraged as code
+    mentioned here can change or be removed without notice between releases of
+    Python.
+
 
 The :mod:`test` package contains all regression tests for Python as well as the
 modules :mod:`test.support` and :mod:`test.regrtest`.

Modified: python/branches/import_unicode/Doc/library/threading.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/threading.rst	(original)
+++ python/branches/import_unicode/Doc/library/threading.rst	Fri Jul 30 01:19:37 2010
@@ -310,8 +310,8 @@
 
       Return whether the thread is alive.
 
-      Roughly, a thread is alive from the moment the :meth:`start` method
-      returns until its :meth:`run` method terminates. The module function
+      This method returns ``True`` just before the :meth:`run` method starts
+      until just after the :meth:`run` method terminates.  The module function
       :func:`.enumerate` returns a list of all alive threads.
 
    .. attribute:: daemon

Modified: python/branches/import_unicode/Doc/library/tkinter.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/tkinter.rst	(original)
+++ python/branches/import_unicode/Doc/library/tkinter.rst	Fri Jul 30 01:19:37 2010
@@ -9,7 +9,9 @@
 The :mod:`tkinter` package ("Tk interface") is the standard Python interface to
 the Tk GUI toolkit.  Both Tk and :mod:`tkinter` are available on most Unix
 platforms, as well as on Windows systems.  (Tk itself is not part of Python; it
-is maintained at ActiveState.)
+is maintained at ActiveState.) You can check that :mod:`tkinter` is properly
+installed on your system by running ``python -m tkinter`` from the command line;
+this should open a window demonstrating a simple Tk interface.
 
 .. seealso::
 

Modified: python/branches/import_unicode/Doc/library/unittest.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/unittest.rst	(original)
+++ python/branches/import_unicode/Doc/library/unittest.rst	Fri Jul 30 01:19:37 2010
@@ -621,20 +621,20 @@
 
 The following decorators implement test skipping and expected failures:
 
-.. function:: skip(reason)
+.. decorator:: skip(reason)
 
    Unconditionally skip the decorated test.  *reason* should describe why the
    test is being skipped.
 
-.. function:: skipIf(condition, reason)
+.. decorator:: skipIf(condition, reason)
 
    Skip the decorated test if *condition* is true.
 
-.. function:: skipUnless(condition, reason)
+.. decorator:: skipUnless(condition, reason)
 
    Skip the decoratored test unless *condition* is true.
 
-.. function:: expectedFailure
+.. decorator:: expectedFailure
 
    Mark the test as an expected failure.  If the test fails when run, the test
    is not counted as a failure.
@@ -1048,11 +1048,11 @@
       :attr:`exception` attribute.  This can be useful if the intention
       is to perform additional checks on the exception raised::
 
-        with self.assertRaises(SomeException) as cm:
-            do_something()
+         with self.assertRaises(SomeException) as cm:
+             do_something()
 
-        the_exception = cm.exception
-        self.assertEqual(the_exception.error_code, 3)
+         the_exception = cm.exception
+         self.assertEqual(the_exception.error_code, 3)
 
       .. versionchanged:: 3.1
          Added the ability to use :meth:`assertRaises` as a context manager.

Modified: python/branches/import_unicode/Doc/library/urllib.request.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/urllib.request.rst	(original)
+++ python/branches/import_unicode/Doc/library/urllib.request.rst	Fri Jul 30 01:19:37 2010
@@ -638,7 +638,8 @@
    :meth:`unknown_open`.
 
    Note that the implementation of these methods may involve calls of the parent
-   :class:`OpenerDirector` instance's :meth:`.open` and :meth:`.error` methods.
+   :class:`OpenerDirector` instance's :meth:`~OpenerDirector.open` and
+   :meth:`~OpenerDirector.error` methods.
 
 #. Every handler with a method named like :meth:`protocol_response` has that
    method called to post-process the response.

Modified: python/branches/import_unicode/Doc/library/xml.dom.minidom.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/xml.dom.minidom.rst	(original)
+++ python/branches/import_unicode/Doc/library/xml.dom.minidom.rst	Fri Jul 30 01:19:37 2010
@@ -136,18 +136,20 @@
 
 .. method:: Node.toxml(encoding=None)
 
-   Return the XML that the DOM represents as a string.
-
-   With no argument, the XML header does not specify an encoding, and the result is
-   Unicode string if the default encoding cannot represent all characters in the
-   document. Encoding this string in an encoding other than UTF-8 is likely
-   incorrect, since UTF-8 is the default encoding of XML.
-
-   With an explicit *encoding* [1]_ argument, the result is a byte string in the
-   specified encoding. It is recommended that this argument is always specified. To
-   avoid :exc:`UnicodeError` exceptions in case of unrepresentable text data, the
-   encoding argument should be specified as "utf-8".
+   Return a string or byte string containing the XML represented by
+   the DOM node.
 
+   With an explicit *encoding* [1]_ argument, the result is a byte
+   string in the specified encoding.  It is recommended that you
+   always specify an encoding; you may use any encoding you like, but
+   an argument of "utf-8" is the most common choice, avoiding
+   :exc:`UnicodeError` exceptions in case of unrepresentable text
+   data.
+
+   With no *encoding* argument, the result is a Unicode string, and the
+   XML declaration in the resulting string does not specify an
+   encoding. Encoding this string in an encoding other than UTF-8 is
+   likely incorrect, since UTF-8 is the default encoding of XML.
 
 .. method:: Node.toprettyxml(indent="", newl="", encoding="")
 
@@ -155,7 +157,8 @@
    indentation string and defaults to a tabulator; *newl* specifies the string
    emitted at the end of each line and defaults to ``\n``.
 
-   There's also an *encoding* argument; see :meth:`toxml`.
+   The *encoding* argument behaves like the corresponding argument of
+   :meth:`toxml`.
 
 
 .. _dom-example:
@@ -240,7 +243,9 @@
 
 .. rubric:: Footnotes
 
-.. [#] The encoding string included in XML output should conform to the
-   appropriate standards. For example, "UTF-8" is valid, but "UTF8" is
-   not. See http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EncodingDecl
+.. [#] The encoding name included in the XML output should conform to
+   the appropriate standards. For example, "UTF-8" is valid, but
+   "UTF8" is not valid in an XML document's declaration, even though
+   Python accepts it as an encoding name.
+   See http://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EncodingDecl
    and http://www.iana.org/assignments/character-sets .

Modified: python/branches/import_unicode/Doc/library/xml.dom.rst
==============================================================================
--- python/branches/import_unicode/Doc/library/xml.dom.rst	(original)
+++ python/branches/import_unicode/Doc/library/xml.dom.rst	Fri Jul 30 01:19:37 2010
@@ -976,29 +976,24 @@
 Type Mapping
 ^^^^^^^^^^^^
 
-The primitive IDL types used in the DOM specification are mapped to Python types
+The IDL types used in the DOM specification are mapped to Python types
 according to the following table.
 
 +------------------+-------------------------------------------+
 | IDL Type         | Python Type                               |
 +==================+===========================================+
-| ``boolean``      | ``IntegerType`` (with a value of ``0`` or |
-|                  | ``1``)                                    |
+| ``boolean``      | ``bool`` or ``int``                       |
 +------------------+-------------------------------------------+
-| ``int``          | ``IntegerType``                           |
+| ``int``          | ``int``                                   |
 +------------------+-------------------------------------------+
-| ``long int``     | ``IntegerType``                           |
+| ``long int``     | ``int``                                   |
 +------------------+-------------------------------------------+
-| ``unsigned int`` | ``IntegerType``                           |
+| ``unsigned int`` | ``int``                                   |
++------------------+-------------------------------------------+
+| ``DOMString``    | ``str`` or ``bytes``                      |
++------------------+-------------------------------------------+
+| ``null``         | ``None``                                  |
 +------------------+-------------------------------------------+
-
-Additionally, the :class:`DOMString` defined in the recommendation is mapped to
-a bytes or string object.  Applications should be able to handle
-Unicode whenever a string is returned from the DOM.
-
-The IDL ``null`` value is mapped to ``None``, which may be accepted or
-provided by the implementation whenever ``null`` is allowed by the API.
-
 
 .. _dom-accessor-methods:
 

Modified: python/branches/import_unicode/Doc/reference/expressions.rst
==============================================================================
--- python/branches/import_unicode/Doc/reference/expressions.rst	(original)
+++ python/branches/import_unicode/Doc/reference/expressions.rst	Fri Jul 30 01:19:37 2010
@@ -1031,9 +1031,9 @@
   ``x <= y``.  If the corresponding element does not exist, the shorter
   sequence is ordered first (for example, ``[1,2] < [1,2,3]``).
 
-* Mappings (dictionaries) compare equal if and only if their sorted ``(key,
-  value)`` lists compare equal. [#]_ Outcomes other than equality are resolved
-  consistently, but are not otherwise defined. [#]_
+* Mappings (dictionaries) compare equal if and only if they have the same
+  ``(key, value)`` pairs. Order comparisons ``('<', '<=', '>=', '>')``
+  raise :exc:`TypeError`.
 
 * Sets and frozensets define comparison operators to mean subset and superset
   tests.  Those relations do not define total orderings (the two sets ``{1,2}``
@@ -1330,15 +1330,6 @@
    strings in a human recognizable way, compare using
    :func:`unicodedata.normalize`.
 
-.. [#] The implementation computes this efficiently, without constructing lists
-   or sorting.
-
-.. [#] Earlier versions of Python used lexicographic comparison of the sorted (key,
-   value) lists, but this was very expensive for the common case of comparing
-   for equality.  An even earlier version of Python compared dictionaries by
-   identity only, but this caused surprises because people expected to be able
-   to test a dictionary for emptiness by comparing it to ``{}``.
-
 .. [#] Due to automatic garbage-collection, free lists, and the dynamic nature of
    descriptors, you may notice seemingly unusual behaviour in certain uses of
    the :keyword:`is` operator, like those involving comparisons between instance

Modified: python/branches/import_unicode/Doc/tools/sphinxext/indexsidebar.html
==============================================================================
--- python/branches/import_unicode/Doc/tools/sphinxext/indexsidebar.html	(original)
+++ python/branches/import_unicode/Doc/tools/sphinxext/indexsidebar.html	Fri Jul 30 01:19:37 2010
@@ -2,8 +2,7 @@
             <p><a href="{{ pathto('download') }}">Download these documents</a></p>
 	    <h3>Docs for other versions</h3>
 	    <ul>
-	      <li><a href="http://docs.python.org/2.6/">Python 2.6 (stable)</a></li>
-	      <li><a href="http://docs.python.org/2.7/">Python 2.7 (in development)</a></li>
+	      <li><a href="http://docs.python.org/2.7/">Python 2.7 (stable)</a></li>
 	      <li><a href="http://docs.python.org/3.1/">Python 3.1 (stable)</a></li>
               <li><a href="http://www.python.org/doc/versions/">Old versions</a></li>
             </ul>

Modified: python/branches/import_unicode/Doc/tools/sphinxext/pyspecific.py
==============================================================================
--- python/branches/import_unicode/Doc/tools/sphinxext/pyspecific.py	(original)
+++ python/branches/import_unicode/Doc/tools/sphinxext/pyspecific.py	Fri Jul 30 01:19:37 2010
@@ -72,6 +72,32 @@
         return [pnode]
 
 
+# Support for documenting decorators
+
+from sphinx import addnodes
+from sphinx.domains.python import PyModulelevel, PyClassmember
+
+class PyDecoratorMixin(object):
+    def handle_signature(self, sig, signode):
+        ret = super(PyDecoratorMixin, self).handle_signature(sig, signode)
+        signode.insert(0, addnodes.desc_addname('@', '@'))
+        return ret
+
+    def needs_arglist(self):
+        return False
+
+class PyDecoratorFunction(PyDecoratorMixin, PyModulelevel):
+    def run(self):
+        # a decorator function is a function after all
+        self.name = 'py:function'
+        return PyModulelevel.run(self)
+
+class PyDecoratorMethod(PyDecoratorMixin, PyClassmember):
+    def run(self):
+        self.name = 'py:method'
+        return PyClassmember.run(self)
+
+
 # Support for building "topic help" for pydoc
 
 pydoc_topic_labels = [
@@ -147,7 +173,6 @@
 # Support for documenting Opcodes
 
 import re
-from sphinx import addnodes
 
 opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?')
 
@@ -165,6 +190,28 @@
     return opname.strip()
 
 
+pdbcmd_sig_re = re.compile(r'([a-z()!]+)\s*(.*)')
+
+# later...
+#pdbargs_tokens_re = re.compile(r'''[a-zA-Z]+  |  # identifiers
+#                                   [.,:]+     |  # punctuation
+#                                   [\[\]()]   |  # parens
+#                                   \s+           # whitespace
+#                                   ''', re.X)
+
+def parse_pdb_command(env, sig, signode):
+    """Transform a pdb command signature into RST nodes."""
+    m = pdbcmd_sig_re.match(sig)
+    if m is None:
+        raise ValueError
+    name, args = m.groups()
+    fullname = name.replace('(', '').replace(')', '')
+    signode += addnodes.desc_name(name, name)
+    if args:
+        signode += addnodes.desc_addname(' '+args, ' '+args)
+    return fullname
+
+
 def setup(app):
     app.add_role('issue', issue_role)
     app.add_directive('impl-detail', ImplementationDetail)
@@ -172,4 +219,8 @@
     app.add_builder(suspicious.CheckSuspiciousMarkupBuilder)
     app.add_description_unit('opcode', 'opcode', '%s (opcode)',
                              parse_opcode_signature)
+    app.add_description_unit('pdbcommand', 'pdbcmd', '%s (pdb command)',
+                             parse_pdb_command)
     app.add_description_unit('2to3fixer', '2to3fixer', '%s (2to3 fixer)')
+    app.add_directive_to_domain('py', 'decorator', PyDecoratorFunction)
+    app.add_directive_to_domain('py', 'decoratormethod', PyDecoratorMethod)

Modified: python/branches/import_unicode/Doc/tutorial/classes.rst
==============================================================================
--- python/branches/import_unicode/Doc/tutorial/classes.rst	(original)
+++ python/branches/import_unicode/Doc/tutorial/classes.rst	Fri Jul 30 01:19:37 2010
@@ -599,12 +599,12 @@
 possible to access or modify a variable that is considered private.  This can
 even be useful in special circumstances, such as in the debugger.
 
-Notice that code passed to ``exec()``, ``eval()`` or ``execfile()`` does not
-consider the classname of the invoking  class to be the current class; this is
-similar to the effect of the  ``global`` statement, the effect of which is
-likewise restricted to  code that is byte-compiled together.  The same
-restriction applies to ``getattr()``, ``setattr()`` and ``delattr()``, as well
-as when referencing ``__dict__`` directly.
+Notice that code passed to ``exec()`` or ``eval()`` does not consider the
+classname of the invoking class to be the current class; this is similar to the
+effect of the ``global`` statement, the effect of which is likewise restricted
+to code that is byte-compiled together.  The same restriction applies to
+``getattr()``, ``setattr()`` and ``delattr()``, as well as when referencing
+``__dict__`` directly.
 
 
 .. _tut-odds:
@@ -737,7 +737,7 @@
    StopIteration
 
 Having seen the mechanics behind the iterator protocol, it is easy to add
-iterator behavior to your classes.  Define a :meth:`__iter__` method which
+iterator behavior to your classes.  Define an :meth:`__iter__` method which
 returns an object with a :meth:`__next__` method.  If the class defines
 :meth:`__next__`, then :meth:`__iter__` can just return ``self``::
 
@@ -754,7 +754,10 @@
            self.index = self.index - 1
            return self.data[self.index]
 
-   >>> for char in Reverse('spam'):
+   >>> rev = Reverse('spam')
+   >>> iter(rev)
+   <__main__.Reverse object at 0x00A1DB50>
+   >>> for char in rev:
    ...     print(char)
    ...
    m

Modified: python/branches/import_unicode/Doc/tutorial/floatingpoint.rst
==============================================================================
--- python/branches/import_unicode/Doc/tutorial/floatingpoint.rst	(original)
+++ python/branches/import_unicode/Doc/tutorial/floatingpoint.rst	Fri Jul 30 01:19:37 2010
@@ -81,7 +81,7 @@
 values share the same approximation, any one of them could be displayed
 while still preserving the invariant ``eval(repr(x)) == x``.
 
-Historically, the Python prompt and built-in :func:`repr` function would chose
+Historically, the Python prompt and built-in :func:`repr` function would choose
 the one with 17 significant digits, ``0.10000000000000001``.   Starting with
 Python 3.1, Python (on most systems) is now able to choose the shortest of
 these and simply display ``0.1``.

Modified: python/branches/import_unicode/Doc/whatsnew/2.0.rst
==============================================================================
--- python/branches/import_unicode/Doc/whatsnew/2.0.rst	(original)
+++ python/branches/import_unicode/Doc/whatsnew/2.0.rst	Fri Jul 30 01:19:37 2010
@@ -656,7 +656,7 @@
 The change which will probably break the most code is tightening up the
 arguments accepted by some methods.  Some methods would take multiple arguments
 and treat them as a tuple, particularly various list methods such as
-:meth:`.append` and :meth:`.insert`. In earlier versions of Python, if ``L`` is
+:meth:`append` and :meth:`insert`. In earlier versions of Python, if ``L`` is
 a list, ``L.append( 1,2 )`` appends the tuple ``(1,2)`` to the list.  In Python
 2.0 this causes a :exc:`TypeError` exception to be raised, with the message:
 'append requires exactly 1 argument; 2 given'.  The fix is to simply add an

Modified: python/branches/import_unicode/Doc/whatsnew/2.5.rst
==============================================================================
--- python/branches/import_unicode/Doc/whatsnew/2.5.rst	(original)
+++ python/branches/import_unicode/Doc/whatsnew/2.5.rst	Fri Jul 30 01:19:37 2010
@@ -1765,7 +1765,7 @@
 http://effbot.org/zone/element-index.htm.
 
 ElementTree represents an XML document as a tree of element nodes. The text
-content of the document is stored as the :attr:`.text` and :attr:`.tail`
+content of the document is stored as the :attr:`text` and :attr:`tail`
 attributes of  (This is one of the major differences between ElementTree and
 the Document Object Model; in the DOM there are many different types of node,
 including :class:`TextNode`.)

Modified: python/branches/import_unicode/Doc/whatsnew/2.7.rst
==============================================================================
--- python/branches/import_unicode/Doc/whatsnew/2.7.rst	(original)
+++ python/branches/import_unicode/Doc/whatsnew/2.7.rst	Fri Jul 30 01:19:37 2010
@@ -146,7 +146,7 @@
 * Float-to-string and string-to-float conversions now round their
   results more correctly, and :func:`repr` of a floating-point
   number *x* returns a result that's guaranteed to round back to the
-  same number when converted back to a string.
+  same number when converted back to a float.
 * The :ctype:`PyCapsule` type, used to provide a C API for extension modules.
 * The :cfunc:`PyLong_AsLongAndOverflow` C API function.
 

Modified: python/branches/import_unicode/Grammar/Grammar
==============================================================================
--- python/branches/import_unicode/Grammar/Grammar	(original)
+++ python/branches/import_unicode/Grammar/Grammar	Fri Jul 30 01:19:37 2010
@@ -24,13 +24,13 @@
 decorated: decorators (classdef | funcdef)
 funcdef: 'def' NAME parameters ['->' test] ':' suite
 parameters: '(' [typedargslist] ')'
-typedargslist: ((tfpdef ['=' test] ',')*
-                ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
-                | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
+typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [','
+       ['*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef]]
+     |  '*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
 tfpdef: NAME [':' test]
-varargslist: ((vfpdef ['=' test] ',')*
-              ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
-              | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
+varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [','
+       ['*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef]]
+     |  '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
 vfpdef: NAME
 
 stmt: simple_stmt | compound_stmt

Modified: python/branches/import_unicode/Include/Python.h
==============================================================================
--- python/branches/import_unicode/Include/Python.h	(original)
+++ python/branches/import_unicode/Include/Python.h	Fri Jul 30 01:19:37 2010
@@ -136,13 +136,8 @@
 }
 #endif
 
-/* Convert a possibly signed character to a nonnegative int */
-/* XXX This assumes characters are 8 bits wide */
-#ifdef __CHAR_UNSIGNED__
-#define Py_CHARMASK(c)		(c)
-#else
+/* Argument must be a char or an int in [-128, 127] or [0, 255]. */
 #define Py_CHARMASK(c)		((unsigned char)((c) & 0xff))
-#endif
 
 #include "pyfpe.h"
 

Modified: python/branches/import_unicode/Lib/_abcoll.py
==============================================================================
--- python/branches/import_unicode/Lib/_abcoll.py	(original)
+++ python/branches/import_unicode/Lib/_abcoll.py	Fri Jul 30 01:19:37 2010
@@ -480,7 +480,15 @@
         except KeyError:
             pass
 
-    def update(self, other=(), **kwds):
+    def update(*args, **kwds):
+        if len(args) > 2:
+            raise TypeError("update() takes at most 2 positional "
+                            "arguments ({} given)".format(len(args)))
+        elif not args:
+            raise TypeError("update() takes at least 1 argument (0 given)")
+        self = args[0]
+        other = args[1] if len(args) >= 2 else ()
+
         if isinstance(other, Mapping):
             for key in other:
                 self[key] = other[key]

Modified: python/branches/import_unicode/Lib/_strptime.py
==============================================================================
--- python/branches/import_unicode/Lib/_strptime.py	(original)
+++ python/branches/import_unicode/Lib/_strptime.py	Fri Jul 30 01:19:37 2010
@@ -482,8 +482,8 @@
     tt = _strptime(data_string, format)[0]
     return time.struct_time(tt[:9])
 
-def _strptime_datetime(class_, data_string, format="%a %b %d %H:%M:%S %Y"):
-    """Return a class_ instance based on the input string and the
+def _strptime_datetime(cls, data_string, format="%a %b %d %H:%M:%S %Y"):
+    """Return a class cls instance based on the input string and the
     format string."""
     tt, fraction = _strptime(data_string, format)
     gmtoff, tzname = tt[-2:]
@@ -496,4 +496,4 @@
             tz = datetime_timezone(tzdelta)
         args += (tz,)
 
-    return class_(*args)
+    return cls(*args)

Modified: python/branches/import_unicode/Lib/ast.py
==============================================================================
--- python/branches/import_unicode/Lib/ast.py	(original)
+++ python/branches/import_unicode/Lib/ast.py	Fri Jul 30 01:19:37 2010
@@ -50,7 +50,7 @@
     if isinstance(node_or_string, Expression):
         node_or_string = node_or_string.body
     def _convert(node):
-        if isinstance(node, Str):
+        if isinstance(node, (Str, Bytes)):
             return node.s
         elif isinstance(node, Num):
             return node.n
@@ -58,6 +58,8 @@
             return tuple(map(_convert, node.elts))
         elif isinstance(node, List):
             return list(map(_convert, node.elts))
+        elif isinstance(node, Set):
+            return set(map(_convert, node.elts))
         elif isinstance(node, Dict):
             return dict((_convert(k), _convert(v)) for k, v
                         in zip(node.keys, node.values))

Modified: python/branches/import_unicode/Lib/asyncore.py
==============================================================================
--- python/branches/import_unicode/Lib/asyncore.py	(original)
+++ python/branches/import_unicode/Lib/asyncore.py	Fri Jul 30 01:19:37 2010
@@ -607,6 +607,14 @@
         def send(self, *args):
             return os.write(self.fd, *args)
 
+        def getsockopt(self, level, optname, buflen=None):
+            if (level == socket.SOL_SOCKET and
+                optname == socket.SO_ERROR and
+                not buflen):
+                return 0
+            raise NotImplementedError("Only asyncore specific behaviour "
+                                      "implemented.")
+
         read = recv
         write = send
 

Modified: python/branches/import_unicode/Lib/base64.py
==============================================================================
--- python/branches/import_unicode/Lib/base64.py	(original)
+++ python/branches/import_unicode/Lib/base64.py	Fri Jul 30 01:19:37 2010
@@ -241,7 +241,7 @@
         acc += _b32rev[c] << shift
         shift -= 5
         if shift < 0:
-            parts.append(binascii.unhexlify('%010x' % acc))
+            parts.append(binascii.unhexlify(bytes('%010x' % acc, "ascii")))
             acc = 0
             shift = 35
     # Process the last, partial quanta

Modified: python/branches/import_unicode/Lib/configparser.py
==============================================================================
--- python/branches/import_unicode/Lib/configparser.py	(original)
+++ python/branches/import_unicode/Lib/configparser.py	Fri Jul 30 01:19:37 2010
@@ -1,6 +1,6 @@
 """Configuration file parser.
 
-A setup file consists of sections, lead by a "[section]" header,
+A configuration file consists of sections, lead by a "[section]" header,
 and followed by "name: value" entries, with continuations and such in
 the style of RFC 822.
 
@@ -24,67 +24,88 @@
 
     methods:
 
-    __init__(defaults=None)
-        create the parser and specify a dictionary of intrinsic defaults.  The
-        keys must be strings, the values must be appropriate for %()s string
-        interpolation.  Note that `__name__' is always an intrinsic default;
-        its value is the section's name.
+    __init__(defaults=None, dict_type=_default_dict,
+             delimiters=('=', ':'), comment_prefixes=('#', ';'),
+             empty_lines_in_values=True, allow_no_value=False):
+        Create the parser. When `defaults' is given, it is initialized into the
+        dictionary or intrinsic defaults. The keys must be strings, the values
+        must be appropriate for %()s string interpolation.  Note that `__name__'
+        is always an intrinsic default; its value is the section's name.
+
+        When `dict_type' is given, it will be used to create the dictionary
+        objects for the list of sections, for the options within a section, and
+        for the default values.
+
+        When `delimiters' is given, it will be used as the set of substrings
+        that divide keys from values.
+
+        When `comment_prefixes' is given, it will be used as the set of
+        substrings that prefix comments in a line.
+
+        When `empty_lines_in_values' is False (default: True), each empty line
+        marks the end of an option. Otherwise, internal empty lines of
+        a multiline option are kept as part of the value.
+
+        When `allow_no_value' is True (default: False), options without
+        values are accepted; the value presented for these is None.
 
     sections()
-        return all the configuration section names, sans DEFAULT
+        Return all the configuration section names, sans DEFAULT.
 
     has_section(section)
-        return whether the given section exists
+        Return whether the given section exists.
 
     has_option(section, option)
-        return whether the given option exists in the given section
+        Return whether the given option exists in the given section.
 
     options(section)
-        return list of configuration options for the named section
+        Return list of configuration options for the named section.
 
-    read(filenames)
-        read and parse the list of named configuration files, given by
+    read(filenames, encoding=None)
+        Read and parse the list of named configuration files, given by
         name.  A single filename is also allowed.  Non-existing files
         are ignored.  Return list of successfully read files.
 
     readfp(fp, filename=None)
-        read and parse one configuration file, given as a file object.
+        Read and parse one configuration file, given as a file object.
         The filename defaults to fp.name; it is only used in error
         messages (if fp has no `name' attribute, the string `<???>' is used).
 
     get(section, option, raw=False, vars=None)
-        return a string value for the named option.  All % interpolations are
+        Return a string value for the named option.  All % interpolations are
         expanded in the return values, based on the defaults passed into the
         constructor and the DEFAULT section.  Additional substitutions may be
         provided using the `vars' argument, which must be a dictionary whose
         contents override any pre-existing defaults.
 
     getint(section, options)
-        like get(), but convert value to an integer
+        Like get(), but convert value to an integer.
 
     getfloat(section, options)
-        like get(), but convert value to a float
+        Like get(), but convert value to a float.
 
     getboolean(section, options)
-        like get(), but convert value to a boolean (currently case
+        Like get(), but convert value to a boolean (currently case
         insensitively defined as 0, false, no, off for False, and 1, true,
         yes, on for True).  Returns False or True.
 
     items(section, raw=False, vars=None)
-        return a list of tuples with (name, value) for each option
+        Return a list of tuples with (name, value) for each option
         in the section.
 
     remove_section(section)
-        remove the given file section and all its options
+        Remove the given file section and all its options.
 
     remove_option(section, option)
-        remove the given option from the given section
+        Remove the given option from the given section.
 
     set(section, option, value)
-        set the given option
+        Set the given option.
 
-    write(fp)
-        write the configuration state in .ini format
+    write(fp, space_around_delimiters=True)
+        Write the configuration state in .ini format. If
+        `space_around_delimiters' is True (the default), delimiters
+        between keys and values are surrounded by spaces.
 """
 
 try:
@@ -94,6 +115,7 @@
     _default_dict = dict
 
 import re
+import sys
 
 __all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError",
            "InterpolationError", "InterpolationDepthError",
@@ -114,17 +136,19 @@
 
     def _get_message(self):
         """Getter for 'message'; needed only to override deprecation in
-        BaseException."""
+        BaseException.
+        """
         return self.__message
 
     def _set_message(self, value):
         """Setter for 'message'; needed only to override deprecation in
-        BaseException."""
+        BaseException.
+        """
         self.__message = value
 
     # BaseException.message has been deprecated since Python 2.6.  To prevent
-    # DeprecationWarning from popping up over this pre-existing attribute, use
-    # a new property that takes lookup precedence.
+    # DeprecationWarning from popping up over this pre-existing attribute, use a
+    # new property that takes lookup precedence.
     message = property(_get_message, _set_message)
 
     def __init__(self, msg=''):
@@ -136,12 +160,15 @@
 
     __str__ = __repr__
 
+
 class NoSectionError(Error):
     """Raised when no section matches a requested option."""
 
     def __init__(self, section):
         Error.__init__(self, 'No section: %r' % (section,))
         self.section = section
+        self.args = (section, )
+
 
 class DuplicateSectionError(Error):
     """Raised when a section is multiply-created."""
@@ -149,6 +176,8 @@
     def __init__(self, section):
         Error.__init__(self, "Section %r already exists" % section)
         self.section = section
+        self.args = (section, )
+
 
 class NoOptionError(Error):
     """A requested option was not found."""
@@ -158,6 +187,8 @@
                        (option, section))
         self.option = option
         self.section = section
+        self.args = (option, section)
+
 
 class InterpolationError(Error):
     """Base class for interpolation-related exceptions."""
@@ -166,6 +197,8 @@
         Error.__init__(self, msg)
         self.option = option
         self.section = section
+        self.args = (option, section, msg)
+
 
 class InterpolationMissingOptionError(InterpolationError):
     """A string substitution required a setting which was not available."""
@@ -179,11 +212,14 @@
                % (section, option, reference, rawval))
         InterpolationError.__init__(self, option, section, msg)
         self.reference = reference
+        self.args = (option, section, rawval, reference)
+
 
 class InterpolationSyntaxError(InterpolationError):
     """Raised when the source text into which substitutions are made
     does not conform to the required syntax."""
 
+
 class InterpolationDepthError(InterpolationError):
     """Raised when substitutions are nested too deeply."""
 
@@ -194,6 +230,8 @@
                "\trawval : %s\n"
                % (section, option, rawval))
         InterpolationError.__init__(self, option, section, msg)
+        self.args = (option, section, rawval)
+
 
 class ParsingError(Error):
     """Raised when a configuration file does not follow legal syntax."""
@@ -202,11 +240,13 @@
         Error.__init__(self, 'File contains parsing errors: %s' % filename)
         self.filename = filename
         self.errors = []
+        self.args = (filename, )
 
     def append(self, lineno, line):
         self.errors.append((lineno, line))
         self.message += '\n\t[line %2d]: %s' % (lineno, line)
 
+
 class MissingSectionHeaderError(ParsingError):
     """Raised when a key-value pair is found before any section header."""
 
@@ -218,21 +258,76 @@
         self.filename = filename
         self.lineno = lineno
         self.line = line
+        self.args = (filename, lineno, line)
 
 
 class RawConfigParser:
+    """ConfigParser that does not do interpolation."""
+
+    # Regular expressions for parsing section headers and options
+    _SECT_TMPL = r"""
+        \[                                 # [
+        (?P<header>[^]]+)                  # very permissive!
+        \]                                 # ]
+        """
+    _OPT_TMPL = r"""
+        (?P<option>.*?)                    # very permissive!
+        \s*(?P<vi>{delim})\s*              # any number of space/tab,
+                                           # followed by any of the
+                                           # allowed delimiters,
+                                           # followed by any space/tab
+        (?P<value>.*)$                     # everything up to eol
+        """
+    _OPT_NV_TMPL = r"""
+        (?P<option>.*?)                    # very permissive!
+        \s*(?:                             # any number of space/tab,
+        (?P<vi>{delim})\s*                 # optionally followed by
+                                           # any of the allowed
+                                           # delimiters, followed by any
+                                           # space/tab
+        (?P<value>.*))?$                   # everything up to eol
+        """
+
+    # Compiled regular expression for matching sections
+    SECTCRE = re.compile(_SECT_TMPL, re.VERBOSE)
+    # Compiled regular expression for matching options with typical separators
+    OPTCRE = re.compile(_OPT_TMPL.format(delim="=|:"), re.VERBOSE)
+    # Compiled regular expression for matching options with optional values
+    # delimited using typical separators
+    OPTCRE_NV = re.compile(_OPT_NV_TMPL.format(delim="=|:"), re.VERBOSE)
+    # Compiled regular expression for matching leading whitespace in a line
+    NONSPACECRE = re.compile(r"\S")
+    # Select backwards-compatible inline comment character behavior
+    # (; and # are comments at the start of a line, but ; only inline)
+    _COMPATIBLE = object()
+
     def __init__(self, defaults=None, dict_type=_default_dict,
-                 allow_no_value=False):
+                 delimiters=('=', ':'), comment_prefixes=_COMPATIBLE,
+                 empty_lines_in_values=True, allow_no_value=False):
         self._dict = dict_type
         self._sections = self._dict()
         self._defaults = self._dict()
-        if allow_no_value:
-            self._optcre = self.OPTCRE_NV
-        else:
-            self._optcre = self.OPTCRE
         if defaults:
             for key, value in defaults.items():
                 self._defaults[self.optionxform(key)] = value
+        self._delimiters = tuple(delimiters)
+        if delimiters == ('=', ':'):
+            self._optcre = self.OPTCRE_NV if allow_no_value else self.OPTCRE
+        else:
+            delim = "|".join(re.escape(d) for d in delimiters)
+            if allow_no_value:
+                self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=delim),
+                                          re.VERBOSE)
+            else:
+                self._optcre = re.compile(self._OPT_TMPL.format(delim=delim),
+                                          re.VERBOSE)
+        if comment_prefixes is self._COMPATIBLE:
+            self._startonly_comment_prefixes = ('#',)
+            self._comment_prefixes = (';',)
+        else:
+            self._startonly_comment_prefixes = ()
+            self._comment_prefixes = tuple(comment_prefixes or ())
+        self._empty_lines_in_values = empty_lines_in_values
 
     def defaults(self):
         return self._defaults
@@ -274,7 +369,7 @@
             del opts['__name__']
         return list(opts.keys())
 
-    def read(self, filenames):
+    def read(self, filenames, encoding=None):
         """Read and parse a filename or a list of filenames.
 
         Files that cannot be opened are silently ignored; this is
@@ -291,7 +386,7 @@
         read_ok = []
         for filename in filenames:
             try:
-                fp = open(filename)
+                fp = open(filename, encoding=encoding)
             except IOError:
                 continue
             self._read(fp, filename)
@@ -306,7 +401,6 @@
         second argument is the `filename', which if not given, is
         taken from fp.name.  If fp has no `name' attribute, `<???>' is
         used.
-
         """
         if filename is None:
             try:
@@ -367,6 +461,7 @@
 
     def has_option(self, section, option):
         """Check for the existence of a given option in a given section."""
+
         if not section or section == DEFAULTSECT:
             option = self.optionxform(option)
             return option in self._defaults
@@ -379,6 +474,7 @@
 
     def set(self, section, option, value=None):
         """Set an option."""
+
         if not section or section == DEFAULTSECT:
             sectdict = self._defaults
         else:
@@ -388,23 +484,34 @@
                 raise NoSectionError(section)
         sectdict[self.optionxform(option)] = value
 
-    def write(self, fp):
-        """Write an .ini-format representation of the configuration state."""
+    def write(self, fp, space_around_delimiters=True):
+        """Write an .ini-format representation of the configuration state.
+
+        If `space_around_delimiters' is True (the default), delimiters
+        between keys and values are surrounded by spaces.
+        """
+        if space_around_delimiters:
+            d = " {} ".format(self._delimiters[0])
+        else:
+            d = self._delimiters[0]
         if self._defaults:
-            fp.write("[%s]\n" % DEFAULTSECT)
-            for (key, value) in self._defaults.items():
-                fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
-            fp.write("\n")
+            self._write_section(fp, DEFAULTSECT, self._defaults.items(), d)
         for section in self._sections:
-            fp.write("[%s]\n" % section)
-            for (key, value) in self._sections[section].items():
-                if key != "__name__":
-                    if value is None:
-                        fp.write("%s\n" % (key))
-                    else:
-                        fp.write("%s = %s\n" %
-                                 (key, str(value).replace('\n', '\n\t')))
-            fp.write("\n")
+            self._write_section(fp, section,
+                                self._sections[section].items(), d)
+
+    def _write_section(self, fp, section_name, section_items, delimiter):
+        """Write a single section to the specified `fp'."""
+        fp.write("[{}]\n".format(section_name))
+        for key, value in section_items:
+            if key == "__name__":
+                continue
+            if value is not None:
+                value = delimiter + str(value).replace('\n', '\n\t')
+            else:
+                value = ""
+            fp.write("{}{}\n".format(key, value))
+        fp.write("\n")
 
     def remove_option(self, section, option):
         """Remove an option."""
@@ -428,66 +535,66 @@
             del self._sections[section]
         return existed
 
-    #
-    # Regular expressions for parsing section headers and options.
-    #
-    SECTCRE = re.compile(
-        r'\['                                 # [
-        r'(?P<header>[^]]+)'                  # very permissive!
-        r'\]'                                 # ]
-        )
-    OPTCRE = re.compile(
-        r'(?P<option>[^:=\s][^:=]*)'          # very permissive!
-        r'\s*(?P<vi>[:=])\s*'                 # any number of space/tab,
-                                              # followed by separator
-                                              # (either : or =), followed
-                                              # by any # space/tab
-        r'(?P<value>.*)$'                     # everything up to eol
-        )
-    OPTCRE_NV = re.compile(
-        r'(?P<option>[^:=\s][^:=]*)'          # very permissive!
-        r'\s*(?:'                             # any number of space/tab,
-        r'(?P<vi>[:=])\s*'                    # optionally followed by
-                                              # separator (either : or
-                                              # =), followed by any #
-                                              # space/tab
-        r'(?P<value>.*))?$'                   # everything up to eol
-        )
-
     def _read(self, fp, fpname):
-        """Parse a sectioned setup file.
+        """Parse a sectioned configuration file.
 
-        The sections in setup file contains a title line at the top,
-        indicated by a name in square brackets (`[]'), plus key/value
-        options lines, indicated by `name: value' format lines.
-        Continuations are represented by an embedded newline then
-        leading whitespace.  Blank lines, lines beginning with a '#',
-        and just about everything else are ignored.
+        Each section in a configuration file contains a header, indicated by a
+        name in square brackets (`[]'), plus key/value options, indicated by
+        `name' and `value' delimited with a specific substring (`=' or `:' by
+        default).
+
+        Values can span multiple lines, as long as they are indented deeper than
+        the first line of the value. Depending on the parser's mode, blank lines
+        may be treated as parts of multiline values or ignored.
+
+        Configuration files may include comments, prefixed by specific
+        characters (`#' and `;' by default). Comments may appear on their own in
+        an otherwise empty line or may be entered in lines holding values or
+        section names.
         """
-        cursect = None                            # None, or a dictionary
+        cursect = None                        # None, or a dictionary
         optname = None
         lineno = 0
-        e = None                                  # None, or an exception
-        while True:
-            line = fp.readline()
-            if not line:
-                break
-            lineno = lineno + 1
-            # comment or blank line?
-            if line.strip() == '' or line[0] in '#;':
-                continue
-            if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR":
-                # no leading whitespace
+        indent_level = 0
+        e = None                              # None, or an exception
+        for lineno, line in enumerate(fp, start=1):
+            # strip full line comments
+            comment_start = None
+            for prefix in self._startonly_comment_prefixes:
+                if line.strip().startswith(prefix):
+                    comment_start = 0
+                    break
+            # strip inline comments
+            for prefix in self._comment_prefixes:
+                index = line.find(prefix)
+                if index == 0 or (index > 0 and line[index-1].isspace()):
+                    comment_start = index
+                    break
+            value = line[:comment_start].strip()
+            if not value:
+                if self._empty_lines_in_values:
+                    # add empty line to the value, but only if there was no
+                    # comment on the line
+                    if (comment_start is None and
+                        cursect is not None and
+                        optname and
+                        cursect[optname] is not None):
+                        cursect[optname].append('') # newlines added at join
+                else:
+                    # empty line marks end of value
+                    indent_level = sys.maxsize
                 continue
             # continuation line?
-            if line[0].isspace() and cursect is not None and optname:
-                value = line.strip()
-                if value:
-                    cursect[optname] = "%s\n%s" % (cursect[optname], value)
+            first_nonspace = self.NONSPACECRE.search(line)
+            cur_indent_level = first_nonspace.start() if first_nonspace else 0
+            if (cursect is not None and optname and
+                cur_indent_level > indent_level):
+                cursect[optname].append(value)
             # a section header or option header?
             else:
+                indent_level = cur_indent_level
                 # is it a section header?
-                mo = self.SECTCRE.match(line)
+                mo = self.SECTCRE.match(value)
                 if mo:
                     sectname = mo.group('header')
                     if sectname in self._sections:
@@ -505,47 +612,61 @@
                     raise MissingSectionHeaderError(fpname, lineno, line)
                 # an option line?
                 else:
-                    mo = self._optcre.match(line)
+                    mo = self._optcre.match(value)
                     if mo:
                         optname, vi, optval = mo.group('option', 'vi', 'value')
+                        if not optname:
+                            e = self._handle_error(e, fpname, lineno, line)
+                        optname = self.optionxform(optname.rstrip())
                         # This check is fine because the OPTCRE cannot
                         # match if it would set optval to None
                         if optval is not None:
-                            if vi in ('=', ':') and ';' in optval:
-                                # ';' is a comment delimiter only if it follows
-                                # a spacing character
-                                pos = optval.find(';')
-                                if pos != -1 and optval[pos-1].isspace():
-                                    optval = optval[:pos]
                             optval = optval.strip()
-                        # allow empty values
-                        if optval == '""':
-                            optval = ''
-                        optname = self.optionxform(optname.rstrip())
-                        cursect[optname] = optval
+                            # allow empty values
+                            if optval == '""':
+                                optval = ''
+                            cursect[optname] = [optval]
+                        else:
+                            # valueless option handling
+                            cursect[optname] = optval
                     else:
-                        # a non-fatal parsing error occurred.  set up the
+                        # a non-fatal parsing error occurred. set up the
                         # exception but keep going. the exception will be
                         # raised at the end of the file and will contain a
                         # list of all bogus lines
-                        if not e:
-                            e = ParsingError(fpname)
-                        e.append(lineno, repr(line))
+                        e = self._handle_error(e, fpname, lineno, line)
         # if any parsing errors occurred, raise an exception
         if e:
             raise e
+        self._join_multiline_values()
+
+    def _join_multiline_values(self):
+        all_sections = [self._defaults]
+        all_sections.extend(self._sections.values())
+        for options in all_sections:
+            for name, val in options.items():
+                if isinstance(val, list):
+                    options[name] = '\n'.join(val).rstrip()
+
+    def _handle_error(self, exc, fpname, lineno, line):
+        if not exc:
+            exc = ParsingError(fpname)
+        exc.append(lineno, repr(line))
+        return exc
 
 
 class ConfigParser(RawConfigParser):
+    """ConfigParser implementing interpolation."""
 
     def get(self, section, option, raw=False, vars=None):
         """Get an option value for a given section.
 
-        All % interpolations are expanded in the return values, based on the
-        defaults passed into the constructor, unless the optional argument
-        `raw' is true.  Additional substitutions may be provided using the
-        `vars' argument, which must be a dictionary whose contents overrides
-        any pre-existing defaults.
+        If `vars' is provided, it must be a dictionary. The option is looked up
+        in `vars' (if provided), `section', and in `defaults' in that order.
+
+        All % interpolations are expanded in the return values, unless the
+        optional argument `raw' is true.  Values for interpolation keys are
+        looked up in the same manner as the option.
 
         The section DEFAULT is special.
         """
@@ -632,6 +753,7 @@
 
 
 class SafeConfigParser(ConfigParser):
+    """ConfigParser implementing sane interpolation."""
 
     def _interpolate(self, section, option, rawval, vars):
         # do the string interpolation

Modified: python/branches/import_unicode/Lib/ctypes/__init__.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/__init__.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/__init__.py	Fri Jul 30 01:19:37 2010
@@ -259,41 +259,31 @@
 
 from _ctypes import POINTER, pointer, _pointer_type_cache
 
-try:
-    from _ctypes import set_conversion_mode
-except ImportError:
-    pass
-else:
-    if _os.name in ("nt", "ce"):
-        set_conversion_mode("mbcs", "strict")
-    else:
-        set_conversion_mode("ascii", "strict")
-
-    class c_wchar_p(_SimpleCData):
-        _type_ = "Z"
+class c_wchar_p(_SimpleCData):
+    _type_ = "Z"
 
-    class c_wchar(_SimpleCData):
-        _type_ = "u"
+class c_wchar(_SimpleCData):
+    _type_ = "u"
 
-    POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
+POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param
 
-    def create_unicode_buffer(init, size=None):
-        """create_unicode_buffer(aString) -> character array
-        create_unicode_buffer(anInteger) -> character array
-        create_unicode_buffer(aString, anInteger) -> character array
-        """
-        if isinstance(init, (str, bytes)):
-            if size is None:
-                size = len(init)+1
-            buftype = c_wchar * size
-            buf = buftype()
-            buf.value = init
-            return buf
-        elif isinstance(init, int):
-            buftype = c_wchar * init
-            buf = buftype()
-            return buf
-        raise TypeError(init)
+def create_unicode_buffer(init, size=None):
+    """create_unicode_buffer(aString) -> character array
+    create_unicode_buffer(anInteger) -> character array
+    create_unicode_buffer(aString, anInteger) -> character array
+    """
+    if isinstance(init, (str, bytes)):
+        if size is None:
+            size = len(init)+1
+        buftype = c_wchar * size
+        buf = buftype()
+        buf.value = init
+        return buf
+    elif isinstance(init, int):
+        buftype = c_wchar * init
+        buf = buftype()
+        return buf
+    raise TypeError(init)
 
 POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param
 

Modified: python/branches/import_unicode/Lib/ctypes/test/test_arrays.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_arrays.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_arrays.py	Fri Jul 30 01:19:37 2010
@@ -42,7 +42,7 @@
 
         CharArray = ARRAY(c_char, 3)
 
-        ca = CharArray("a", "b", "c")
+        ca = CharArray(b"a", b"b", b"c")
 
         # Should this work? It doesn't:
         # CharArray("abc")
@@ -89,7 +89,7 @@
 
     def test_from_address(self):
         # Failed with 0.9.8, reported by JUrner
-        p = create_string_buffer("foo")
+        p = create_string_buffer(b"foo")
         sz = (c_char * 3).from_address(addressof(p))
         self.assertEqual(sz[:], b"foo")
         self.assertEqual(sz[::], b"foo")

Modified: python/branches/import_unicode/Lib/ctypes/test/test_bitfields.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_bitfields.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_bitfields.py	Fri Jul 30 01:19:37 2010
@@ -37,14 +37,14 @@
             for name in "ABCDEFGHI":
                 b = BITS()
                 setattr(b, name, i)
-                self.assertEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name)))
+                self.assertEqual(getattr(b, name), func(byref(b), name.encode('ascii')))
 
     def test_shorts(self):
         for i in range(256):
             for name in "MNOPQRS":
                 b = BITS()
                 setattr(b, name, i)
-                self.assertEqual((name, i, getattr(b, name)), (name, i, func(byref(b), name)))
+                self.assertEqual(getattr(b, name), func(byref(b), name.encode('ascii')))
 
 signed_int_types = (c_byte, c_short, c_int, c_long, c_longlong)
 unsigned_int_types = (c_ubyte, c_ushort, c_uint, c_ulong, c_ulonglong)

Modified: python/branches/import_unicode/Lib/ctypes/test/test_buffers.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_buffers.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_buffers.py	Fri Jul 30 01:19:37 2010
@@ -9,19 +9,7 @@
         self.assertEqual(sizeof(b), 32 * sizeof(c_char))
         self.assertTrue(type(b[0]) is bytes)
 
-        b = create_string_buffer("abc")
-        self.assertEqual(len(b), 4) # trailing nul char
-        self.assertEqual(sizeof(b), 4 * sizeof(c_char))
-        self.assertTrue(type(b[0]) is bytes)
-        self.assertEqual(b[0], b"a")
-        self.assertEqual(b[:], b"abc\0")
-        self.assertEqual(b[::], b"abc\0")
-        self.assertEqual(b[::-1], b"\0cba")
-        self.assertEqual(b[::2], b"ac")
-        self.assertEqual(b[::5], b"a")
-
-    def test_string_conversion(self):
-        b = create_string_buffer("abc")
+        b = create_string_buffer(b"abc")
         self.assertEqual(len(b), 4) # trailing nul char
         self.assertEqual(sizeof(b), 4 * sizeof(c_char))
         self.assertTrue(type(b[0]) is bytes)

Modified: python/branches/import_unicode/Lib/ctypes/test/test_bytes.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_bytes.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_bytes.py	Fri Jul 30 01:19:37 2010
@@ -11,24 +11,21 @@
         (c_char * 3)(b"a", b"b", b"c")
 
     def test_c_wchar(self):
-        x = c_wchar(b"x")
-        x.value = b"y"
-        c_wchar.from_param(b"x")
-        (c_wchar * 3)(b"a", b"b", b"c")
+        x = c_wchar("x")
+        x.value = "y"
+        c_wchar.from_param("x")
+        (c_wchar * 3)("a", "b", "c")
 
     def test_c_char_p(self):
-        c_char_p("foo bar")
         c_char_p(b"foo bar")
 
     def test_c_wchar_p(self):
         c_wchar_p("foo bar")
-        c_wchar_p(b"foo bar")
 
     def test_struct(self):
         class X(Structure):
             _fields_ = [("a", c_char * 3)]
 
-        X("abc")
         x = X(b"abc")
         self.assertEqual(x.a, b"abc")
         self.assertEqual(type(x.a), bytes)
@@ -37,8 +34,7 @@
         class X(Structure):
             _fields_ = [("a", c_wchar * 3)]
 
-        X("abc")
-        x = X(b"abc")
+        x = X("abc")
         self.assertEqual(x.a, "abc")
         self.assertEqual(type(x.a), str)
 

Modified: python/branches/import_unicode/Lib/ctypes/test/test_callbacks.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_callbacks.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_callbacks.py	Fri Jul 30 01:19:37 2010
@@ -164,7 +164,7 @@
         result = integrate(0.0, 1.0, CALLBACK(func), 10)
         diff = abs(result - 1./3.)
 
-        self.assertTrue(diff < 0.01, "%s not less than 0.01" % diff)
+        self.assertLess(diff, 0.01, "%s not less than 0.01" % diff)
 
     def test_issue_8959_a(self):
         from ctypes.util import find_library

Modified: python/branches/import_unicode/Lib/ctypes/test/test_cast.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_cast.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_cast.py	Fri Jul 30 01:19:37 2010
@@ -33,17 +33,17 @@
     def test_p2a_objects(self):
         array = (c_char_p * 5)()
         self.assertEqual(array._objects, None)
-        array[0] = "foo bar"
+        array[0] = b"foo bar"
         self.assertEqual(array._objects, {'0': b"foo bar"})
 
         p = cast(array, POINTER(c_char_p))
         # array and p share a common _objects attribute
         self.assertTrue(p._objects is array._objects)
         self.assertEqual(array._objects, {'0': b"foo bar", id(array): array})
-        p[0] = "spam spam"
+        p[0] = b"spam spam"
         self.assertEqual(p._objects, {'0': b"spam spam", id(array): array})
         self.assertTrue(array._objects is p._objects)
-        p[1] = "foo bar"
+        p[1] = b"foo bar"
         self.assertEqual(p._objects, {'1': b'foo bar', '0': b"spam spam", id(array): array})
         self.assertTrue(array._objects is p._objects)
 
@@ -71,7 +71,7 @@
 
     def test_char_p(self):
         # This didn't work: bad argument to internal function
-        s = c_char_p("hiho")
+        s = c_char_p(b"hiho")
         self.assertEqual(cast(cast(s, c_void_p), c_char_p).value,
                              b"hiho")
 

Modified: python/branches/import_unicode/Lib/ctypes/test/test_cfuncs.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_cfuncs.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_cfuncs.py	Fri Jul 30 01:19:37 2010
@@ -107,7 +107,7 @@
     def test_ulong_plus(self):
         self._dll.tf_bL.restype = c_ulong
         self._dll.tf_bL.argtypes = (c_char, c_ulong)
-        self.assertEqual(self._dll.tf_bL(' ', 4294967295), 1431655765)
+        self.assertEqual(self._dll.tf_bL(b' ', 4294967295), 1431655765)
         self.assertEqual(self.U(), 4294967295)
 
     def test_longlong(self):

Modified: python/branches/import_unicode/Lib/ctypes/test/test_errno.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_errno.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_errno.py	Fri Jul 30 01:19:37 2010
@@ -19,7 +19,7 @@
 
         libc_open.argtypes = c_char_p, c_int
 
-        self.assertEqual(libc_open("", 0), -1)
+        self.assertEqual(libc_open(b"", 0), -1)
         self.assertEqual(get_errno(), errno.ENOENT)
 
         self.assertEqual(set_errno(32), errno.ENOENT)
@@ -35,7 +35,7 @@
                 else:
                     libc_open = libc.open
                 libc_open.argtypes = c_char_p, c_int
-                self.assertEqual(libc_open("", 0), -1)
+                self.assertEqual(libc_open(b"", 0), -1)
                 self.assertEqual(get_errno(), 0)
 
             t = threading.Thread(target=_worker)

Modified: python/branches/import_unicode/Lib/ctypes/test/test_internals.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_internals.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_internals.py	Fri Jul 30 01:19:37 2010
@@ -70,19 +70,17 @@
         class Y(Structure):
             _fields_ = [("x", X), ("y", X)]
 
-        s1 = "Hello, World"
-        s2 = "Hallo, Welt"
+        s1 = b"Hello, World"
+        s2 = b"Hallo, Welt"
 
         x = X()
         x.a = s1
         x.b = s2
-        self.assertEqual(x._objects, {"0": bytes(s1, "ascii"),
-                                          "1": bytes(s2, "ascii")})
+        self.assertEqual(x._objects, {"0": s1, "1": s2})
 
         y = Y()
         y.x = x
-        self.assertEqual(y._objects, {"0": {"0": bytes(s1, "ascii"),
-                                                "1": bytes(s2, "ascii")}})
+        self.assertEqual(y._objects, {"0": {"0": s1, "1": s2}})
 ##        x = y.x
 ##        del y
 ##        print x._b_base_._objects

Modified: python/branches/import_unicode/Lib/ctypes/test/test_keeprefs.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_keeprefs.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_keeprefs.py	Fri Jul 30 01:19:37 2010
@@ -13,9 +13,9 @@
     def test_ccharp(self):
         x = c_char_p()
         self.assertEquals(x._objects, None)
-        x.value = "abc"
+        x.value = b"abc"
         self.assertEquals(x._objects, b"abc")
-        x = c_char_p("spam")
+        x = c_char_p(b"spam")
         self.assertEquals(x._objects, b"spam")
 
 class StructureTestCase(unittest.TestCase):
@@ -37,8 +37,8 @@
         x = X()
         self.assertEquals(x._objects, None)
 
-        x.a = "spam"
-        x.b = "foo"
+        x.a = b"spam"
+        x.b = b"foo"
         self.assertEquals(x._objects, {"0": b"spam", "1": b"foo"})
 
     def test_struct_struct(self):

Modified: python/branches/import_unicode/Lib/ctypes/test/test_libc.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_libc.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_libc.py	Fri Jul 30 01:19:37 2010
@@ -25,7 +25,7 @@
         def sort(a, b):
             return three_way_cmp(a[0], b[0])
 
-        chars = create_string_buffer("spam, spam, and spam")
+        chars = create_string_buffer(b"spam, spam, and spam")
         lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort))
         self.assertEqual(chars.raw, b"   ,,aaaadmmmnpppsss\x00")
 

Modified: python/branches/import_unicode/Lib/ctypes/test/test_objects.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_objects.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_objects.py	Fri Jul 30 01:19:37 2010
@@ -20,7 +20,7 @@
 The memory block stores pointers to strings, and the strings itself
 assigned from Python must be kept.
 
->>> array[4] = 'foo bar'
+>>> array[4] = b'foo bar'
 >>> array._objects
 {'4': b'foo bar'}
 >>> array[4]
@@ -45,7 +45,7 @@
 <ctypes.test.test_objects.X object at 0x...>
 >>>
 
->>> x.array[0] = 'spam spam spam'
+>>> x.array[0] = b'spam spam spam'
 >>> x._objects
 {'0:2': b'spam spam spam'}
 >>> x.array._b_base_._objects

Modified: python/branches/import_unicode/Lib/ctypes/test/test_parameters.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_parameters.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_parameters.py	Fri Jul 30 01:19:37 2010
@@ -19,7 +19,6 @@
         else:
             set_conversion_mode(*self.prev_conv_mode)
 
-
     def test_subclasses(self):
         from ctypes import c_void_p, c_char_p
         # ctypes 0.9.5 and before did overwrite from_param in SimpleType_new
@@ -58,14 +57,13 @@
         self.assertTrue(c_char_p.from_param(s)._obj is s)
 
         # new in 0.9.1: convert (encode) unicode to ascii
-        self.assertEqual(c_char_p.from_param("123")._obj, b"123")
-        self.assertRaises(UnicodeEncodeError, c_char_p.from_param, "123\377")
-
+        self.assertEqual(c_char_p.from_param(b"123")._obj, b"123")
+        self.assertRaises(TypeError, c_char_p.from_param, "123\377")
         self.assertRaises(TypeError, c_char_p.from_param, 42)
 
         # calling c_char_p.from_param with a c_char_p instance
         # returns the argument itself:
-        a = c_char_p("123")
+        a = c_char_p(b"123")
         self.assertTrue(c_char_p.from_param(a) is a)
 
     def test_cw_strings(self):
@@ -82,7 +80,7 @@
 
             # new in 0.9.1: convert (decode) ascii to unicode
             self.assertEqual(c_wchar_p.from_param("123")._obj, "123")
-        self.assertRaises(UnicodeDecodeError, c_wchar_p.from_param, b"123\377")
+        self.assertRaises(TypeError, c_wchar_p.from_param, b"123\377")
 
         pa = c_wchar_p.from_param(c_wchar_p("123"))
         self.assertEqual(type(pa), c_wchar_p)

Modified: python/branches/import_unicode/Lib/ctypes/test/test_prototypes.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_prototypes.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_prototypes.py	Fri Jul 30 01:19:37 2010
@@ -127,7 +127,7 @@
         self.assertEqual(None, func(c_char_p(None)))
 
         self.assertEqual(b"123", func(c_buffer(b"123")))
-        ca = c_char("a")
+        ca = c_char(b"a")
         self.assertEqual(ord(b"a"), func(pointer(ca))[0])
         self.assertEqual(ord(b"a"), func(byref(ca))[0])
 

Modified: python/branches/import_unicode/Lib/ctypes/test/test_python_api.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_python_api.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_python_api.py	Fri Jul 30 01:19:37 2010
@@ -72,10 +72,10 @@
         PyOS_snprintf.argtypes = POINTER(c_char), c_size_t, c_char_p
 
         buf = c_buffer(256)
-        PyOS_snprintf(buf, sizeof(buf), "Hello from %s", b"ctypes")
+        PyOS_snprintf(buf, sizeof(buf), b"Hello from %s", b"ctypes")
         self.assertEqual(buf.value, b"Hello from ctypes")
 
-        PyOS_snprintf(buf, sizeof(buf), "Hello from %s (%d, %d, %d)", b"ctypes", 1, 2, 3)
+        PyOS_snprintf(buf, sizeof(buf), b"Hello from %s (%d, %d, %d)", b"ctypes", 1, 2, 3)
         self.assertEqual(buf.value, b"Hello from ctypes (1, 2, 3)")
 
         # not enough arguments

Modified: python/branches/import_unicode/Lib/ctypes/test/test_random_things.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_random_things.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_random_things.py	Fri Jul 30 01:19:37 2010
@@ -66,7 +66,7 @@
 
     def test_TypeErrorDivisionError(self):
         cb = CFUNCTYPE(c_int, c_char_p)(callback_func)
-        out = self.capture_stderr(cb, "spam")
+        out = self.capture_stderr(cb, b"spam")
         self.assertEqual(out.splitlines()[-1],
                              "TypeError: "
                              "unsupported operand type(s) for /: 'int' and 'bytes'")

Modified: python/branches/import_unicode/Lib/ctypes/test/test_repr.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_repr.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_repr.py	Fri Jul 30 01:19:37 2010
@@ -22,8 +22,8 @@
             self.assertEqual("<X object at", repr(typ(42))[:12])
 
     def test_char(self):
-        self.assertEqual("c_char(b'x')", repr(c_char('x')))
-        self.assertEqual("<X object at", repr(X('x'))[:12])
+        self.assertEqual("c_char(b'x')", repr(c_char(b'x')))
+        self.assertEqual("<X object at", repr(X(b'x'))[:12])
 
 if __name__ == "__main__":
     unittest.main()

Modified: python/branches/import_unicode/Lib/ctypes/test/test_returnfuncptrs.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_returnfuncptrs.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_returnfuncptrs.py	Fri Jul 30 01:19:37 2010
@@ -28,10 +28,10 @@
         # _CFuncPtr instances are now callable with an integer argument
         # which denotes a function address:
         strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr)
-        self.assertTrue(strchr("abcdef", "b"), "bcdef")
-        self.assertEqual(strchr("abcdef", "x"), None)
-        self.assertRaises(ArgumentError, strchr, "abcdef", 3.0)
-        self.assertRaises(TypeError, strchr, "abcdef")
+        self.assertTrue(strchr(b"abcdef", b"b"), "bcdef")
+        self.assertEqual(strchr(b"abcdef", b"x"), None)
+        self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0)
+        self.assertRaises(TypeError, strchr, b"abcdef")
 
 if __name__ == "__main__":
     unittest.main()

Modified: python/branches/import_unicode/Lib/ctypes/test/test_stringptr.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_stringptr.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_stringptr.py	Fri Jul 30 01:19:37 2010
@@ -14,7 +14,7 @@
 
         # NULL pointer access
         self.assertRaises(ValueError, getattr, x.str, "contents")
-        b = c_buffer("Hello, World")
+        b = c_buffer(b"Hello, World")
         from sys import getrefcount as grc
         self.assertEqual(grc(b), 2)
         x.str = b
@@ -63,8 +63,8 @@
         # So we must keep a reference to buf separately
 
         strchr.restype = POINTER(c_char)
-        buf = c_buffer("abcdef")
-        r = strchr(buf, "c")
+        buf = c_buffer(b"abcdef")
+        r = strchr(buf, b"c")
         x = r[0], r[1], r[2], r[3], r[4]
         self.assertEqual(x, (b"c", b"d", b"e", b"f", b"\000"))
         del buf

Modified: python/branches/import_unicode/Lib/ctypes/test/test_strings.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_strings.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_strings.py	Fri Jul 30 01:19:37 2010
@@ -5,23 +5,23 @@
     def test(self):
         BUF = c_char * 4
 
-        buf = BUF("a", "b", "c")
+        buf = BUF(b"a", b"b", b"c")
         self.assertEqual(buf.value, b"abc")
         self.assertEqual(buf.raw, b"abc\000")
 
-        buf.value = "ABCD"
+        buf.value = b"ABCD"
         self.assertEqual(buf.value, b"ABCD")
         self.assertEqual(buf.raw, b"ABCD")
 
-        buf.value = "x"
+        buf.value = b"x"
         self.assertEqual(buf.value, b"x")
         self.assertEqual(buf.raw, b"x\000CD")
 
-        buf[1] = "Z"
+        buf[1] = b"Z"
         self.assertEqual(buf.value, b"xZCD")
         self.assertEqual(buf.raw, b"xZCD")
 
-        self.assertRaises(ValueError, setattr, buf, "value", "aaaaaaaa")
+        self.assertRaises(ValueError, setattr, buf, "value", b"aaaaaaaa")
         self.assertRaises(TypeError, setattr, buf, "value", 42)
 
     def test_c_buffer_value(self):

Modified: python/branches/import_unicode/Lib/ctypes/test/test_structures.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_structures.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_structures.py	Fri Jul 30 01:19:37 2010
@@ -205,15 +205,15 @@
                         ("age", c_int)]
 
         self.assertRaises(TypeError, Person, 42)
-        self.assertRaises(ValueError, Person, "asldkjaslkdjaslkdj")
+        self.assertRaises(ValueError, Person, b"asldkjaslkdjaslkdj")
         self.assertRaises(TypeError, Person, "Name", "HI")
 
         # short enough
-        self.assertEqual(Person("12345", 5).name, b"12345")
+        self.assertEqual(Person(b"12345", 5).name, b"12345")
         # exact fit
-        self.assertEqual(Person("123456", 5).name, b"123456")
+        self.assertEqual(Person(b"123456", 5).name, b"123456")
         # too long
-        self.assertRaises(ValueError, Person, "1234567", 5)
+        self.assertRaises(ValueError, Person, b"1234567", 5)
 
     def test_conflicting_initializers(self):
         class POINT(Structure):
@@ -267,7 +267,7 @@
                         ("phone", Phone),
                         ("age", c_int)]
 
-        p = Person("Someone", ("1234", "5678"), 5)
+        p = Person(b"Someone", (b"1234", b"5678"), 5)
 
         self.assertEqual(p.name, b"Someone")
         self.assertEqual(p.phone.areacode, b"1234")
@@ -284,8 +284,8 @@
             _fields_ = [("name", c_wchar * 12),
                         ("age", c_int)]
 
-        p = PersonW("Someone")
-        self.assertEqual(p.name, "Someone")
+        p = PersonW("Someone \xe9")
+        self.assertEqual(p.name, "Someone \xe9")
 
         self.assertEqual(PersonW("1234567890").name, "1234567890")
         self.assertEqual(PersonW("12345678901").name, "12345678901")
@@ -304,13 +304,13 @@
                         ("phone", Phone),
                         ("age", c_int)]
 
-        cls, msg = self.get_except(Person, "Someone", (1, 2))
+        cls, msg = self.get_except(Person, b"Someone", (1, 2))
         self.assertEqual(cls, RuntimeError)
         self.assertEqual(msg,
                              "(Phone) <class 'TypeError'>: "
                              "expected string, int found")
 
-        cls, msg = self.get_except(Person, "Someone", ("a", "b", "c"))
+        cls, msg = self.get_except(Person, b"Someone", (b"a", b"b", b"c"))
         self.assertEqual(cls, RuntimeError)
         if issubclass(Exception, object):
             self.assertEqual(msg,

Modified: python/branches/import_unicode/Lib/ctypes/test/test_unicode.py
==============================================================================
--- python/branches/import_unicode/Lib/ctypes/test/test_unicode.py	(original)
+++ python/branches/import_unicode/Lib/ctypes/test/test_unicode.py	Fri Jul 30 01:19:37 2010
@@ -7,122 +7,53 @@
     pass
 else:
     import _ctypes_test
-    dll = ctypes.CDLL(_ctypes_test.__file__)
-    wcslen = dll.my_wcslen
-    wcslen.argtypes = [ctypes.c_wchar_p]
-
 
     class UnicodeTestCase(unittest.TestCase):
-        def setUp(self):
-            self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict")
+        def test_wcslen(self):
+            dll = ctypes.CDLL(_ctypes_test.__file__)
+            wcslen = dll.my_wcslen
+            wcslen.argtypes = [ctypes.c_wchar_p]
 
-        def tearDown(self):
-            ctypes.set_conversion_mode(*self.prev_conv_mode)
-
-        def test_ascii_strict(self):
-            ctypes.set_conversion_mode("ascii", "strict")
-            # no conversions take place with unicode arguments
             self.assertEqual(wcslen("abc"), 3)
             self.assertEqual(wcslen("ab\u2070"), 3)
-            # string args are converted
-            self.assertEqual(wcslen("abc"), 3)
             self.assertRaises(ctypes.ArgumentError, wcslen, b"ab\xe4")
 
-        def test_ascii_replace(self):
-            ctypes.set_conversion_mode("ascii", "replace")
-            self.assertEqual(wcslen("abc"), 3)
-            self.assertEqual(wcslen("ab\u2070"), 3)
-            self.assertEqual(wcslen("abc"), 3)
-            self.assertEqual(wcslen("ab\xe4"), 3)
-
-        def test_ascii_ignore(self):
-            ctypes.set_conversion_mode("ascii", "ignore")
-            self.assertEqual(wcslen("abc"), 3)
-            self.assertEqual(wcslen("ab\u2070"), 3)
-            # ignore error mode skips non-ascii characters
-            self.assertEqual(wcslen("abc"), 3)
-            self.assertEqual(wcslen(b"\xe4\xf6\xfc\xdf"), 0)
-
-        def test_latin1_strict(self):
-            ctypes.set_conversion_mode("latin-1", "strict")
-            self.assertEqual(wcslen("abc"), 3)
-            self.assertEqual(wcslen("ab\u2070"), 3)
-            self.assertEqual(wcslen("abc"), 3)
-            self.assertEqual(wcslen("\xe4\xf6\xfc\xdf"), 4)
-
         def test_buffers(self):
-            ctypes.set_conversion_mode("ascii", "strict")
             buf = ctypes.create_unicode_buffer("abc")
             self.assertEqual(len(buf), 3+1)
 
-            ctypes.set_conversion_mode("ascii", "replace")
-            buf = ctypes.create_unicode_buffer(b"ab\xe4\xf6\xfc")
-            self.assertEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0")
-            self.assertEqual(buf[::], "ab\uFFFD\uFFFD\uFFFD\0")
-            self.assertEqual(buf[::-1], "\0\uFFFD\uFFFD\uFFFDba")
-            self.assertEqual(buf[::2], "a\uFFFD\uFFFD")
+            buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc")
+            self.assertEqual(buf[:], "ab\xe4\xf6\xfc\0")
+            self.assertEqual(buf[::], "ab\xe4\xf6\xfc\0")
+            self.assertEqual(buf[::-1], '\x00\xfc\xf6\xe4ba')
+            self.assertEqual(buf[::2], 'a\xe4\xfc')
             self.assertEqual(buf[6:5:-1], "")
 
-            ctypes.set_conversion_mode("ascii", "ignore")
-            buf = ctypes.create_unicode_buffer(b"ab\xe4\xf6\xfc")
-            # is that correct? not sure.  But with 'ignore', you get what you pay for..
-            self.assertEqual(buf[:], "ab\0\0\0\0")
-            self.assertEqual(buf[::], "ab\0\0\0\0")
-            self.assertEqual(buf[::-1], "\0\0\0\0ba")
-            self.assertEqual(buf[::2], "a\0\0")
-            self.assertEqual(buf[6:5:-1], "")
-
-    import _ctypes_test
     func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p
 
     class StringTestCase(UnicodeTestCase):
         def setUp(self):
-            self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict")
             func.argtypes = [ctypes.c_char_p]
             func.restype = ctypes.c_char_p
 
         def tearDown(self):
-            ctypes.set_conversion_mode(*self.prev_conv_mode)
             func.argtypes = None
             func.restype = ctypes.c_int
 
-        def test_ascii_replace(self):
-            ctypes.set_conversion_mode("ascii", "strict")
-            self.assertEqual(func("abc"), "abc")
-            self.assertEqual(func("abc"), "abc")
-            self.assertRaises(ctypes.ArgumentError, func, "ab\xe4")
-
-        def test_ascii_ignore(self):
-            ctypes.set_conversion_mode("ascii", "ignore")
-            self.assertEqual(func("abc"), b"abc")
-            self.assertEqual(func("abc"), b"abc")
-            self.assertEqual(func("\xe4\xf6\xfc\xdf"), b"")
-
-        def test_ascii_replace(self):
-            ctypes.set_conversion_mode("ascii", "replace")
-            self.assertEqual(func("abc"), b"abc")
-            self.assertEqual(func("abc"), b"abc")
-            self.assertEqual(func("\xe4\xf6\xfc\xdf"), b"????")
+        def test_func(self):
+            self.assertEqual(func(b"abc\xe4"), b"abc\xe4")
 
         def test_buffers(self):
-            ctypes.set_conversion_mode("ascii", "strict")
-            buf = ctypes.create_string_buffer("abc")
+            buf = ctypes.create_string_buffer(b"abc")
             self.assertEqual(len(buf), 3+1)
 
-            ctypes.set_conversion_mode("ascii", "replace")
-            buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc")
-            self.assertEqual(buf[:], b"ab???\0")
-            self.assertEqual(buf[::], b"ab???\0")
-            self.assertEqual(buf[::-1], b"\0???ba")
-            self.assertEqual(buf[::2], b"a??")
+            buf = ctypes.create_string_buffer(b"ab\xe4\xf6\xfc")
+            self.assertEqual(buf[:], b"ab\xe4\xf6\xfc\0")
+            self.assertEqual(buf[::], b"ab\xe4\xf6\xfc\0")
+            self.assertEqual(buf[::-1], b'\x00\xfc\xf6\xe4ba')
+            self.assertEqual(buf[::2], b'a\xe4\xfc')
             self.assertEqual(buf[6:5:-1], b"")
 
-            ctypes.set_conversion_mode("ascii", "ignore")
-            buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc")
-            # is that correct? not sure.  But with 'ignore', you get what you pay for..
-            self.assertEqual(buf[:], b"ab\0\0\0\0")
-            self.assertEqual(buf[::], b"ab\0\0\0\0")
-            self.assertEqual(buf[::-1], b"\0\0\0\0ba")
 
 if __name__ == '__main__':
     unittest.main()

Modified: python/branches/import_unicode/Lib/dbm/__init__.py
==============================================================================
--- python/branches/import_unicode/Lib/dbm/__init__.py	(original)
+++ python/branches/import_unicode/Lib/dbm/__init__.py	Fri Jul 30 01:19:37 2010
@@ -5,12 +5,11 @@
         import dbm
         d = dbm.open(file, 'w', 0o666)
 
-The returned object is a dbm.bsd, dbm.gnu, dbm.ndbm or dbm.dumb
-object, dependent on the type of database being opened (determined by
-the whichdb function) in the case of an existing dbm.  If the dbm does
-not exist and the create or new flag ('c' or 'n') was specified, the
-dbm type will be determined by the availability of the modules (tested
-in the above order).
+The returned object is a dbm.gnu, dbm.ndbm or dbm.dumb object, dependent on the
+type of database being opened (determined by the whichdb function) in the case
+of an existing dbm. If the dbm does not exist and the create or new flag ('c'
+or 'n') was specified, the dbm type will be determined by the availability of
+the modules (tested in the above order).
 
 It has the following interface (key and data are strings):
 
@@ -47,7 +46,7 @@
 class error(Exception):
     pass
 
-_names = ['dbm.bsd', 'dbm.gnu', 'dbm.ndbm', 'dbm.dumb']
+_names = ['dbm.gnu', 'dbm.ndbm', 'dbm.dumb']
 _defaultmod = None
 _modules = {}
 
@@ -168,10 +167,6 @@
     if magic == 0x13579ace:
         return "dbm.gnu"
 
-    ## Check for old Berkeley db hash file format v2
-    #if magic in (0x00061561, 0x61150600):
-    #    return "bsddb185" # not supported anymore
-
     # Later versions of Berkeley db hash file have a 12-byte pad in
     # front of the file type
     try:
@@ -179,10 +174,6 @@
     except struct.error:
         return ""
 
-    ## Check for BSD hash
-    #if magic in (0x00061561, 0x61150600):
-    #    return "dbm.bsd"
-
     # Unknown
     return ""
 

Modified: python/branches/import_unicode/Lib/distutils/archive_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/archive_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/archive_util.py	Fri Jul 30 01:19:37 2010
@@ -14,55 +14,15 @@
 from distutils.dir_util import mkpath
 from distutils import log
 
-try:
-    from pwd import getpwnam
-except ImportError:
-    getpwnam = None
-
-try:
-    from grp import getgrnam
-except ImportError:
-    getgrnam = None
-
-def _get_gid(name):
-    """Returns a gid, given a group name."""
-    if getgrnam is None or name is None:
-        return None
-    try:
-        result = getgrnam(name)
-    except KeyError:
-        result = None
-    if result is not None:
-        return result[2]
-    return None
-
-def _get_uid(name):
-    """Returns an uid, given a user name."""
-    if getpwnam is None or name is None:
-        return None
-    try:
-        result = getpwnam(name)
-    except KeyError:
-        result = None
-    if result is not None:
-        return result[2]
-    return None
-
-def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
-                 owner=None, group=None):
+def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0):
     """Create a (possibly compressed) tar file from all the files under
     'base_dir'.
 
     'compress' must be "gzip" (the default), "compress", "bzip2", or None.
-    (compress will be deprecated in Python 3.2)
-
-    'owner' and 'group' can be used to define an owner and a group for the
-    archive that is being built. If not provided, the current owner and group
-    will be used.
-
+    Both "tar" and the compression utility named by 'compress' must be on
+    the default program search path, so this is probably Unix-specific.
     The output tar file will be named 'base_dir' +  ".tar", possibly plus
     the appropriate compression extension (".gz", ".bz2" or ".Z").
-
     Returns the output filename.
     """
     tar_compression = {'gzip': 'gz', 'bzip2': 'bz2', None: '', 'compress': ''}
@@ -84,23 +44,10 @@
     import tarfile  # late import so Python build itself doesn't break
 
     log.info('Creating tar archive')
-
-    uid = _get_uid(owner)
-    gid = _get_gid(group)
-
-    def _set_uid_gid(tarinfo):
-        if gid is not None:
-            tarinfo.gid = gid
-            tarinfo.gname = group
-        if uid is not None:
-            tarinfo.uid = uid
-            tarinfo.uname = owner
-        return tarinfo
-
     if not dry_run:
         tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
         try:
-            tar.add(base_dir, filter=_set_uid_gid)
+            tar.add(base_dir)
         finally:
             tar.close()
 
@@ -190,7 +137,7 @@
     return None
 
 def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
-                 dry_run=0, owner=None, group=None):
+                 dry_run=0):
     """Create an archive file (eg. zip or tar).
 
     'base_name' is the name of the file to create, minus any format-specific
@@ -203,9 +150,6 @@
     ie. 'base_dir' will be the common prefix of all files and
     directories in the archive.  'root_dir' and 'base_dir' both default
     to the current directory.  Returns the name of the archive file.
-
-    'owner' and 'group' are used when creating a tar archive. By default,
-    uses the current owner and group.
     """
     save_cwd = os.getcwd()
     if root_dir is not None:
@@ -227,11 +171,6 @@
     func = format_info[0]
     for arg, val in format_info[1]:
         kwargs[arg] = val
-
-    if format != 'zip':
-        kwargs['owner'] = owner
-        kwargs['group'] = group
-
     try:
         filename = func(base_name, base_dir, **kwargs)
     finally:

Modified: python/branches/import_unicode/Lib/distutils/bcppcompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/bcppcompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/bcppcompiler.py	Fri Jul 30 01:19:37 2010
@@ -13,11 +13,13 @@
 
 __revision__ = "$Id$"
 
-import os
 
-from distutils.errors import (DistutilsExecError, CompileError, LibError,
-                              LinkError, UnknownFileError)
-from distutils.ccompiler import CCompiler, gen_preprocess_options
+import os
+from distutils.errors import \
+     DistutilsExecError, DistutilsPlatformError, \
+     CompileError, LibError, LinkError, UnknownFileError
+from distutils.ccompiler import \
+     CCompiler, gen_preprocess_options, gen_lib_options
 from distutils.file_util import write_file
 from distutils.dep_util import newer
 from distutils import log

Modified: python/branches/import_unicode/Lib/distutils/ccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/ccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/ccompiler.py	Fri Jul 30 01:19:37 2010
@@ -5,71 +5,15 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
-import re
-
-from distutils.errors import (CompileError, LinkError, UnknownFileError,
-                              DistutilsPlatformError, DistutilsModuleError)
+import sys, os, re
+from distutils.errors import *
 from distutils.spawn import spawn
 from distutils.file_util import move_file
 from distutils.dir_util import mkpath
-from distutils.dep_util import newer_group
+from distutils.dep_util import newer_pairwise, newer_group
 from distutils.util import split_quoted, execute
 from distutils import log
 
-_sysconfig = __import__('sysconfig')
-
-def customize_compiler(compiler):
-    """Do any platform-specific customization of a CCompiler instance.
-
-    Mainly needed on Unix, so we can plug in the information that
-    varies across Unices and is stored in Python's Makefile.
-    """
-    if compiler.compiler_type == "unix":
-        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
-            _sysconfig.get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
-                                       'CCSHARED', 'LDSHARED', 'SO', 'AR',
-                                       'ARFLAGS')
-
-        if 'CC' in os.environ:
-            cc = os.environ['CC']
-        if 'CXX' in os.environ:
-            cxx = os.environ['CXX']
-        if 'LDSHARED' in os.environ:
-            ldshared = os.environ['LDSHARED']
-        if 'CPP' in os.environ:
-            cpp = os.environ['CPP']
-        else:
-            cpp = cc + " -E"           # not always
-        if 'LDFLAGS' in os.environ:
-            ldshared = ldshared + ' ' + os.environ['LDFLAGS']
-        if 'CFLAGS' in os.environ:
-            cflags = opt + ' ' + os.environ['CFLAGS']
-            ldshared = ldshared + ' ' + os.environ['CFLAGS']
-        if 'CPPFLAGS' in os.environ:
-            cpp = cpp + ' ' + os.environ['CPPFLAGS']
-            cflags = cflags + ' ' + os.environ['CPPFLAGS']
-            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
-        if 'AR' in os.environ:
-            ar = os.environ['AR']
-        if 'ARFLAGS' in os.environ:
-            archiver = ar + ' ' + os.environ['ARFLAGS']
-        else:
-            archiver = ar + ' ' + ar_flags
-
-        cc_cmd = cc + ' ' + cflags
-        compiler.set_executables(
-            preprocessor=cpp,
-            compiler=cc_cmd,
-            compiler_so=cc_cmd + ' ' + ccshared,
-            compiler_cxx=cxx,
-            linker_so=ldshared,
-            linker_exe=cc,
-            archiver=archiver)
-
-        compiler.shared_lib_extension = so_ext
-
 class CCompiler:
     """Abstract base class to define the interface that must be implemented
     by real compiler classes.  Also has some utility methods used by
@@ -449,6 +393,22 @@
 
         return output_dir, macros, include_dirs
 
+    def _prep_compile(self, sources, output_dir, depends=None):
+        """Decide which souce files must be recompiled.
+
+        Determine the list of object files corresponding to 'sources',
+        and figure out which ones really need to be recompiled.
+        Return a list of all object files and a dictionary telling
+        which source files can be skipped.
+        """
+        # Get the list of expected output (object) files
+        objects = self.object_filenames(sources, output_dir=output_dir)
+        assert len(objects) == len(sources)
+
+        # Return an empty dict for the "which source files can be skipped"
+        # return value to preserve API compatibility.
+        return objects, {}
+
     def _fix_object_args(self, objects, output_dir):
         """Typecheck and fix up some arguments supplied to various methods.
         Specifically: ensure that 'objects' is a list; if output_dir is
@@ -650,15 +610,26 @@
         """
         pass
 
+
     # values for target_desc parameter in link()
     SHARED_OBJECT = "shared_object"
     SHARED_LIBRARY = "shared_library"
     EXECUTABLE = "executable"
 
-    def link(self, target_desc, objects, output_filename, output_dir=None,
-             libraries=None, library_dirs=None, runtime_library_dirs=None,
-             export_symbols=None, debug=0, extra_preargs=None,
-             extra_postargs=None, build_temp=None, target_lang=None):
+    def link(self,
+             target_desc,
+             objects,
+             output_filename,
+             output_dir=None,
+             libraries=None,
+             library_dirs=None,
+             runtime_library_dirs=None,
+             export_symbols=None,
+             debug=0,
+             extra_preargs=None,
+             extra_postargs=None,
+             build_temp=None,
+             target_lang=None):
         """Link a bunch of stuff together to create an executable or
         shared library file.
 
@@ -707,11 +678,19 @@
 
     # Old 'link_*()' methods, rewritten to use the new 'link()' method.
 
-    def link_shared_lib(self, objects, output_libname, output_dir=None,
-                        libraries=None, library_dirs=None,
-                        runtime_library_dirs=None, export_symbols=None,
-                        debug=0, extra_preargs=None, extra_postargs=None,
-                        build_temp=None, target_lang=None):
+    def link_shared_lib(self,
+                        objects,
+                        output_libname,
+                        output_dir=None,
+                        libraries=None,
+                        library_dirs=None,
+                        runtime_library_dirs=None,
+                        export_symbols=None,
+                        debug=0,
+                        extra_preargs=None,
+                        extra_postargs=None,
+                        build_temp=None,
+                        target_lang=None):
         self.link(CCompiler.SHARED_LIBRARY, objects,
                   self.library_filename(output_libname, lib_type='shared'),
                   output_dir,
@@ -720,11 +699,19 @@
                   extra_preargs, extra_postargs, build_temp, target_lang)
 
 
-    def link_shared_object(self, objects, output_filename, output_dir=None,
-                           libraries=None, library_dirs=None,
-                           runtime_library_dirs=None, export_symbols=None,
-                           debug=0, extra_preargs=None, extra_postargs=None,
-                           build_temp=None, target_lang=None):
+    def link_shared_object(self,
+                           objects,
+                           output_filename,
+                           output_dir=None,
+                           libraries=None,
+                           library_dirs=None,
+                           runtime_library_dirs=None,
+                           export_symbols=None,
+                           debug=0,
+                           extra_preargs=None,
+                           extra_postargs=None,
+                           build_temp=None,
+                           target_lang=None):
         self.link(CCompiler.SHARED_OBJECT, objects,
                   output_filename, output_dir,
                   libraries, library_dirs, runtime_library_dirs,
@@ -732,10 +719,17 @@
                   extra_preargs, extra_postargs, build_temp, target_lang)
 
 
-    def link_executable(self, objects, output_progname, output_dir=None,
-                        libraries=None, library_dirs=None,
-                        runtime_library_dirs=None, debug=0, extra_preargs=None,
-                        extra_postargs=None, target_lang=None):
+    def link_executable(self,
+                        objects,
+                        output_progname,
+                        output_dir=None,
+                        libraries=None,
+                        library_dirs=None,
+                        runtime_library_dirs=None,
+                        debug=0,
+                        extra_preargs=None,
+                        extra_postargs=None,
+                        target_lang=None):
         self.link(CCompiler.EXECUTABLE, objects,
                   self.executable_filename(output_progname), output_dir,
                   libraries, library_dirs, runtime_library_dirs, None,
@@ -917,7 +911,7 @@
     def move_file(self, src, dst):
         return move_file(src, dst, dry_run=self.dry_run)
 
-    def mkpath(self, name, mode=0o777):
+    def mkpath (self, name, mode=0o777):
         mkpath(name, mode, dry_run=self.dry_run)
 
 
@@ -1085,14 +1079,12 @@
     return pp_opts
 
 
-def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
+def gen_lib_options (compiler, library_dirs, runtime_library_dirs, libraries):
     """Generate linker options for searching library directories and
-    linking with specific libraries.
-
-    'libraries' and 'library_dirs' are, respectively, lists of library names
-    (not filenames!) and search directories.  Returns a list of command-line
-    options suitable for use with some compiler (depending on the two format
-    strings passed in).
+    linking with specific libraries.  'libraries' and 'library_dirs' are,
+    respectively, lists of library names (not filenames!) and search
+    directories.  Returns a list of command-line options suitable for use
+    with some compiler (depending on the two format strings passed in).
     """
     lib_opts = []
 
@@ -1102,7 +1094,7 @@
     for dir in runtime_library_dirs:
         opt = compiler.runtime_library_dir_option(dir)
         if isinstance(opt, list):
-            lib_opts.extend(opt)
+            lib_opts = lib_opts + opt
         else:
             lib_opts.append(opt)
 
@@ -1113,14 +1105,14 @@
     # pretty nasty way to arrange your C code.
 
     for lib in libraries:
-        lib_dir, lib_name = os.path.split(lib)
-        if lib_dir != '':
+        (lib_dir, lib_name) = os.path.split(lib)
+        if lib_dir:
             lib_file = compiler.find_library_file([lib_dir], lib_name)
-            if lib_file is not None:
+            if lib_file:
                 lib_opts.append(lib_file)
             else:
                 compiler.warn("no library file corresponding to "
                               "'%s' found (skipping)" % lib)
         else:
-            lib_opts.append(compiler.library_option(lib))
+            lib_opts.append(compiler.library_option (lib))
     return lib_opts

Modified: python/branches/import_unicode/Lib/distutils/cmd.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/cmd.py	(original)
+++ python/branches/import_unicode/Lib/distutils/cmd.py	Fri Jul 30 01:19:37 2010
@@ -367,11 +367,9 @@
         from distutils.spawn import spawn
         spawn(cmd, search_path, dry_run=self.dry_run)
 
-    def make_archive(self, base_name, format, root_dir=None, base_dir=None,
-                     owner=None, group=None):
-        return archive_util.make_archive(base_name, format, root_dir,
-                                         base_dir, dry_run=self.dry_run,
-                                         owner=owner, group=group)
+    def make_archive(self, base_name, format, root_dir=None, base_dir=None):
+        return archive_util.make_archive(base_name, format, root_dir, base_dir,
+                                         dry_run=self.dry_run)
 
     def make_file(self, infiles, outfile, func, args,
                   exec_msg=None, skip_msg=None, level=1):

Modified: python/branches/import_unicode/Lib/distutils/command/bdist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/bdist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/bdist.py	Fri Jul 30 01:19:37 2010
@@ -6,10 +6,9 @@
 __revision__ = "$Id$"
 
 import os
-
-from distutils.util import get_platform
 from distutils.core import Command
-from distutils.errors import DistutilsPlatformError, DistutilsOptionError
+from distutils.errors import *
+from distutils.util import get_platform
 
 
 def show_formats():
@@ -40,12 +39,6 @@
                      "[default: dist]"),
                     ('skip-build', None,
                      "skip rebuilding everything (for testing/debugging)"),
-                    ('owner=', 'u',
-                     "Owner name used when creating a tar file"
-                     " [default: current user]"),
-                    ('group=', 'g',
-                     "Group name used when creating a tar file"
-                     " [default: current group]"),
                    ]
 
     boolean_options = ['skip-build']
@@ -87,8 +80,6 @@
         self.formats = None
         self.dist_dir = None
         self.skip_build = 0
-        self.group = None
-        self.owner = None
 
     def finalize_options(self):
         # have to finalize 'plat_name' before 'bdist_base'
@@ -134,11 +125,6 @@
             if cmd_name not in self.no_format_option:
                 sub_cmd.format = self.formats[i]
 
-            # passing the owner and group names for tar archiving
-            if cmd_name == 'bdist_dumb':
-                sub_cmd.owner = self.owner
-                sub_cmd.group = self.group
-
             # If we're going to need to run this command again, tell it to
             # keep its temporary files around so subsequent runs go faster.
             if cmd_name in commands[i+1:]:

Modified: python/branches/import_unicode/Lib/distutils/command/bdist_dumb.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/bdist_dumb.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/bdist_dumb.py	Fri Jul 30 01:19:37 2010
@@ -7,18 +7,16 @@
 __revision__ = "$Id$"
 
 import os
-
-from sysconfig import get_python_version
-
-from distutils.util import get_platform
 from distutils.core import Command
+from distutils.util import get_platform
 from distutils.dir_util import remove_tree, ensure_relative
-from distutils.errors import DistutilsPlatformError
+from distutils.errors import *
+from distutils.sysconfig import get_python_version
 from distutils import log
 
 class bdist_dumb(Command):
 
-    description = 'create a "dumb" built distribution'
+    description = "create a \"dumb\" built distribution"
 
     user_options = [('bdist-dir=', 'd',
                      "temporary directory for creating the distribution"),
@@ -37,12 +35,6 @@
                     ('relative', None,
                      "build the archive using relative paths"
                      "(default: false)"),
-                    ('owner=', 'u',
-                     "Owner name used when creating a tar file"
-                     " [default: current user]"),
-                    ('group=', 'g',
-                     "Group name used when creating a tar file"
-                     " [default: current group]"),
                    ]
 
     boolean_options = ['keep-temp', 'skip-build', 'relative']
@@ -59,8 +51,6 @@
         self.dist_dir = None
         self.skip_build = 0
         self.relative = 0
-        self.owner = None
-        self.group = None
 
     def finalize_options(self):
         if self.bdist_dir is None:
@@ -118,8 +108,7 @@
 
         # Make the archive
         filename = self.make_archive(pseudoinstall_root,
-                                     self.format, root_dir=archive_root,
-                                     owner=self.owner, group=self.group)
+                                     self.format, root_dir=archive_root)
         if self.distribution.has_ext_modules():
             pyversion = get_python_version()
         else:

Modified: python/branches/import_unicode/Lib/distutils/command/bdist_msi.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/bdist_msi.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/bdist_msi.py	Fri Jul 30 01:19:37 2010
@@ -6,15 +6,15 @@
 """
 Implements the bdist_msi command.
 """
-import sys, os
-from sysconfig import get_python_version, get_platform
 
+import sys, os
 from distutils.core import Command
 from distutils.dir_util import remove_tree
+from distutils.sysconfig import get_python_version
 from distutils.version import StrictVersion
 from distutils.errors import DistutilsOptionError
+from distutils.util import get_platform
 from distutils import log
-
 import msilib
 from msilib import schema, sequence, text
 from msilib import Directory, Feature, Dialog, add_data
@@ -28,6 +28,7 @@
         default, cancel, bitmap=true)"""
         Dialog.__init__(self, *args)
         ruler = self.h - 36
+        bmwidth = 152*ruler/328
         #if kw.get("bitmap", True):
         #    self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin")
         self.line("BottomLine", 0, ruler, self.w, 0)
@@ -418,6 +419,7 @@
         # see "Dialog Style Bits"
         modal = 3      # visible | modal
         modeless = 1   # visible
+        track_disk_space = 32
 
         # UI customization properties
         add_data(db, "Property",

Modified: python/branches/import_unicode/Lib/distutils/command/bdist_rpm.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/bdist_rpm.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/bdist_rpm.py	Fri Jul 30 01:19:37 2010
@@ -5,14 +5,13 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
-
+import sys, os
 from distutils.core import Command
 from distutils.debug import DEBUG
+from distutils.util import get_platform
 from distutils.file_util import write_file
-from distutils.errors import (DistutilsOptionError, DistutilsPlatformError,
-                              DistutilsFileError, DistutilsExecError)
+from distutils.errors import *
+from distutils.sysconfig import get_python_version
 from distutils import log
 
 class bdist_rpm(Command):

Modified: python/branches/import_unicode/Lib/distutils/command/bdist_wininst.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/bdist_wininst.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/bdist_wininst.py	Fri Jul 30 01:19:37 2010
@@ -5,16 +5,13 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
-
-from sysconfig import get_python_version
-
+import sys, os
 from distutils.core import Command
-from distutils.dir_util import remove_tree
-from distutils.errors import DistutilsOptionError, DistutilsPlatformError
-from distutils import log
 from distutils.util import get_platform
+from distutils.dir_util import create_tree, remove_tree
+from distutils.errors import *
+from distutils.sysconfig import get_python_version
+from distutils import log
 
 class bdist_wininst(Command):
 

Modified: python/branches/import_unicode/Lib/distutils/command/build.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/build.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/build.py	Fri Jul 30 01:19:37 2010
@@ -5,15 +5,16 @@
 __revision__ = "$Id$"
 
 import sys, os
-
-from distutils.util import get_platform
 from distutils.core import Command
 from distutils.errors import DistutilsOptionError
+from distutils.util import get_platform
+
 
 def show_compilers():
     from distutils.ccompiler import show_compilers
     show_compilers()
 
+
 class build(Command):
 
     description = "build everything needed to install"
@@ -126,6 +127,7 @@
         for cmd_name in self.get_sub_commands():
             self.run_command(cmd_name)
 
+
     # -- Predicates for the sub-command list ---------------------------
 
     def has_pure_modules(self):
@@ -140,6 +142,7 @@
     def has_scripts(self):
         return self.distribution.has_scripts()
 
+
     sub_commands = [('build_py',      has_pure_modules),
                     ('build_clib',    has_c_libraries),
                     ('build_ext',     has_ext_modules),

Modified: python/branches/import_unicode/Lib/distutils/command/build_clib.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/build_clib.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/build_clib.py	Fri Jul 30 01:19:37 2010
@@ -18,8 +18,8 @@
 
 import os
 from distutils.core import Command
-from distutils.errors import DistutilsSetupError
-from distutils.ccompiler import customize_compiler
+from distutils.errors import *
+from distutils.sysconfig import customize_compiler
 from distutils import log
 
 def show_compilers():

Modified: python/branches/import_unicode/Lib/distutils/command/build_ext.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/build_ext.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/build_ext.py	Fri Jul 30 01:19:37 2010
@@ -7,14 +7,12 @@
 __revision__ = "$Id$"
 
 import sys, os, re
-from warnings import warn
-
-from distutils.util import get_platform
 from distutils.core import Command
 from distutils.errors import *
-from distutils.ccompiler import customize_compiler
+from distutils.sysconfig import customize_compiler, get_python_version
 from distutils.dep_util import newer_group
 from distutils.extension import Extension
+from distutils.util import get_platform
 from distutils import log
 
 # this keeps compatibility from 2.3 to 2.5
@@ -114,39 +112,6 @@
          "list available compilers", show_compilers),
         ]
 
-    # making 'compiler' a property to deprecate
-    # its usage as something else than a compiler type
-    # e.g. like a compiler instance
-    def __init__(self, dist):
-        self._compiler = None
-        Command.__init__(self, dist)
-
-    def __setattr__(self, name, value):
-        # need this to make sure setattr() (used in distutils)
-        # doesn't kill our property
-        if name == 'compiler':
-            self._set_compiler(value)
-        else:
-            self.__dict__[name] = value
-
-    def _set_compiler(self, compiler):
-        if not isinstance(compiler, str) and compiler is not None:
-            # we don't want to allow that anymore in the future
-            warn("'compiler' specifies the compiler type in build_ext. "
-                 "If you want to get the compiler object itself, "
-                 "use 'compiler_obj'", DeprecationWarning)
-        self._compiler = compiler
-
-    def _get_compiler(self):
-        if not isinstance(self._compiler, str) and self._compiler is not None:
-            # we don't want to allow that anymore in the future
-            warn("'compiler' specifies the compiler type in build_ext. "
-                 "If you want to get the compiler object itself, "
-                 "use 'compiler_obj'", DeprecationWarning)
-        return self._compiler
-
-    compiler = property(_get_compiler, _set_compiler)
-
     def initialize_options(self):
         self.extensions = None
         self.build_lib = None
@@ -171,7 +136,8 @@
         self.user = None
 
     def finalize_options(self):
-        _sysconfig = __import__('sysconfig')
+        from distutils import sysconfig
+
         self.set_undefined_options('build',
                                    ('build_lib', 'build_lib'),
                                    ('build_temp', 'build_temp'),
@@ -188,8 +154,8 @@
 
         # Make sure Python's include directories (for Python.h, pyconfig.h,
         # etc.) are in the include search path.
-        py_include = _sysconfig.get_path('include')
-        plat_py_include = _sysconfig.get_path('platinclude')
+        py_include = sysconfig.get_python_inc()
+        plat_py_include = sysconfig.get_python_inc(plat_specific=1)
         if self.include_dirs is None:
             self.include_dirs = self.distribution.include_dirs or []
         if isinstance(self.include_dirs, str):
@@ -261,13 +227,13 @@
         if os.name == 'os2':
             self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
 
-        # for extensions under Cygwin Python's library directory must be
+        # for extensions under Cygwin and AtheOS Python's library directory must be
         # appended to library_dirs
-        if sys.platform[:6] == 'cygwin':
+        if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
                 self.library_dirs.append(os.path.join(sys.prefix, "lib",
-                                  "python" + _sysconfig.get_python_version(),
+                                                      "python" + get_python_version(),
                                                       "config"))
             else:
                 # building python standard extensions
@@ -275,13 +241,13 @@
 
         # for extensions under Linux or Solaris with a shared Python library,
         # Python's library directory must be appended to library_dirs
-        _sysconfig.get_config_var('Py_ENABLE_SHARED')
+        sysconfig.get_config_var('Py_ENABLE_SHARED')
         if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
              or sys.platform.startswith('sunos'))
-            and _sysconfig.get_config_var('Py_ENABLE_SHARED')):
+            and sysconfig.get_config_var('Py_ENABLE_SHARED')):
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
-                self.library_dirs.append(_sysconfig.get_config_var('LIBDIR'))
+                self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
             else:
                 # building python standard extensions
                 self.library_dirs.append('.')
@@ -344,50 +310,38 @@
 
         # Setup the CCompiler object that we'll use to do all the
         # compiling and linking
-
-        # used to prevent the usage of an existing compiler for the
-        # compiler option when calling new_compiler()
-        # this will be removed in 3.3 and 2.8
-        if not isinstance(self._compiler, str):
-            self._compiler = None
-
-        self.compiler_obj = new_compiler(compiler=self._compiler,
-                                         verbose=self.verbose,
-                                         dry_run=self.dry_run,
-                                         force=self.force)
-
-        # used to keep the compiler object reachable with
-        # "self.compiler". this will be removed in 3.3 and 2.8
-        self._compiler = self.compiler_obj
-
-        customize_compiler(self.compiler_obj)
+        self.compiler = new_compiler(compiler=self.compiler,
+                                     verbose=self.verbose,
+                                     dry_run=self.dry_run,
+                                     force=self.force)
+        customize_compiler(self.compiler)
         # If we are cross-compiling, init the compiler now (if we are not
         # cross-compiling, init would not hurt, but people may rely on
         # late initialization of compiler even if they shouldn't...)
         if os.name == 'nt' and self.plat_name != get_platform():
-            self.compiler_obj.initialize(self.plat_name)
+            self.compiler.initialize(self.plat_name)
 
         # And make sure that any compile/link-related options (which might
         # come from the command-line or from the setup script) are set in
         # that CCompiler object -- that way, they automatically apply to
         # all compiling and linking done here.
         if self.include_dirs is not None:
-            self.compiler_obj.set_include_dirs(self.include_dirs)
+            self.compiler.set_include_dirs(self.include_dirs)
         if self.define is not None:
             # 'define' option is a list of (name,value) tuples
             for (name, value) in self.define:
-                self.compiler_obj.define_macro(name, value)
+                self.compiler.define_macro(name, value)
         if self.undef is not None:
             for macro in self.undef:
-                self.compiler_obj.undefine_macro(macro)
+                self.compiler.undefine_macro(macro)
         if self.libraries is not None:
-            self.compiler_obj.set_libraries(self.libraries)
+            self.compiler.set_libraries(self.libraries)
         if self.library_dirs is not None:
-            self.compiler_obj.set_library_dirs(self.library_dirs)
+            self.compiler.set_library_dirs(self.library_dirs)
         if self.rpath is not None:
-            self.compiler_obj.set_runtime_library_dirs(self.rpath)
+            self.compiler.set_runtime_library_dirs(self.rpath)
         if self.link_objects is not None:
-            self.compiler_obj.set_link_objects(self.link_objects)
+            self.compiler.set_link_objects(self.link_objects)
 
         # Now actually compile and link everything.
         self.build_extensions()
@@ -548,13 +502,13 @@
         for undef in ext.undef_macros:
             macros.append((undef,))
 
-        objects = self.compiler_obj.compile(sources,
-                                            output_dir=self.build_temp,
-                                            macros=macros,
-                                            include_dirs=ext.include_dirs,
-                                            debug=self.debug,
-                                            extra_postargs=extra_args,
-                                            depends=ext.depends)
+        objects = self.compiler.compile(sources,
+                                         output_dir=self.build_temp,
+                                         macros=macros,
+                                         include_dirs=ext.include_dirs,
+                                         debug=self.debug,
+                                         extra_postargs=extra_args,
+                                         depends=ext.depends)
 
         # XXX -- this is a Vile HACK!
         #
@@ -575,9 +529,9 @@
         extra_args = ext.extra_link_args or []
 
         # Detect target language, if not provided
-        language = ext.language or self.compiler_obj.detect_language(sources)
+        language = ext.language or self.compiler.detect_language(sources)
 
-        self.compiler_obj.link_shared_object(
+        self.compiler.link_shared_object(
             objects, ext_path,
             libraries=self.get_libraries(ext),
             library_dirs=ext.library_dirs,
@@ -710,13 +664,13 @@
         of the file from which it will be loaded (eg. "foo/bar.so", or
         "foo\bar.pyd").
         """
-        _sysconfig = __import__('sysconfig')
+        from distutils.sysconfig import get_config_var
         ext_path = ext_name.split('.')
         # OS/2 has an 8 character module (extension) limit :-(
         if os.name == "os2":
             ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8]
         # extensions in debug_mode are named 'module_d.pyd' under windows
-        so_ext = _sysconfig.get_config_var('SO')
+        so_ext = get_config_var('SO')
         if os.name == 'nt' and self.debug:
             return os.path.join(*ext_path) + '_d' + so_ext
         return os.path.join(*ext_path) + so_ext
@@ -744,7 +698,7 @@
         # Append '_d' to the python import library on debug builds.
         if sys.platform == "win32":
             from distutils.msvccompiler import MSVCCompiler
-            if not isinstance(self.compiler_obj, MSVCCompiler):
+            if not isinstance(self.compiler, MSVCCompiler):
                 template = "python%d%d"
                 if self.debug:
                     template = template + '_d'
@@ -775,12 +729,28 @@
             # don't extend ext.libraries, it may be shared with other
             # extensions, it is a reference to the original list
             return ext.libraries + [pythonlib]
+        elif sys.platform[:6] == "atheos":
+            from distutils import sysconfig
+
+            template = "python%d.%d"
+            pythonlib = (template %
+                   (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
+            # Get SHLIBS from Makefile
+            extra = []
+            for lib in sysconfig.get_config_var('SHLIBS').split():
+                if lib.startswith('-l'):
+                    extra.append(lib[2:])
+                else:
+                    extra.append(lib)
+            # don't extend ext.libraries, it may be shared with other
+            # extensions, it is a reference to the original list
+            return ext.libraries + [pythonlib, "m"] + extra
         elif sys.platform == 'darwin':
             # Don't use the default code below
             return ext.libraries
         else:
-            _sysconfig = __import__('sysconfig')
-            if _sysconfig.get_config_var('Py_ENABLE_SHARED'):
+            from distutils import sysconfig
+            if sysconfig.get_config_var('Py_ENABLE_SHARED'):
                 template = "python%d.%d"
                 pythonlib = (template %
                              (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))

Modified: python/branches/import_unicode/Lib/distutils/command/build_py.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/build_py.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/build_py.py	Fri Jul 30 01:19:37 2010
@@ -4,16 +4,16 @@
 
 __revision__ = "$Id$"
 
-import os
+import sys, os
 import sys
 from glob import glob
 
 from distutils.core import Command
-from distutils.errors import DistutilsOptionError, DistutilsFileError
+from distutils.errors import *
 from distutils.util import convert_path, Mixin2to3
 from distutils import log
 
-class build_py(Command):
+class build_py (Command):
 
     description = "\"build\" pure Python modules (copy to build directory)"
 
@@ -133,6 +133,7 @@
 
     def build_package_data(self):
         """Copy data files into build directory"""
+        lastdir = None
         for package, src_dir, build_dir, filenames in self.data_files:
             for filename in filenames:
                 target = os.path.join(build_dir, filename)

Modified: python/branches/import_unicode/Lib/distutils/command/build_scripts.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/build_scripts.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/build_scripts.py	Fri Jul 30 01:19:37 2010
@@ -6,6 +6,7 @@
 
 import os, re
 from stat import ST_MODE
+from distutils import sysconfig
 from distutils.core import Command
 from distutils.dep_util import newer
 from distutils.util import convert_path, Mixin2to3
@@ -56,7 +57,6 @@
         ie. starts with "\#!" and contains "python"), then adjust the first
         line to refer to the current Python interpreter as we copy.
         """
-        _sysconfig = __import__('sysconfig')
         self.mkpath(self.build_dir)
         outfiles = []
         updated_files = []
@@ -96,16 +96,16 @@
                 updated_files.append(outfile)
                 if not self.dry_run:
                     outf = open(outfile, "w")
-                    if not _sysconfig.is_python_build():
+                    if not sysconfig.python_build:
                         outf.write("#!%s%s\n" %
                                    (self.executable,
                                     post_interp))
                     else:
                         outf.write("#!%s%s\n" %
                                    (os.path.join(
-                            _sysconfig.get_config_var("BINDIR"),
-                           "python%s%s" % (_sysconfig.get_config_var("VERSION"),
-                                           _sysconfig.get_config_var("EXE"))),
+                            sysconfig.get_config_var("BINDIR"),
+                           "python%s%s" % (sysconfig.get_config_var("VERSION"),
+                                           sysconfig.get_config_var("EXE"))),
                                     post_interp))
                     outf.writelines(f.readlines())
                     outf.close()

Modified: python/branches/import_unicode/Lib/distutils/command/config.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/config.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/config.py	Fri Jul 30 01:19:37 2010
@@ -11,12 +11,11 @@
 
 __revision__ = "$Id$"
 
-import os
-import re
+import sys, os, re
 
 from distutils.core import Command
 from distutils.errors import DistutilsExecError
-from distutils.ccompiler import customize_compiler
+from distutils.sysconfig import customize_compiler
 from distutils import log
 
 LANG_EXT = {"c": ".c", "c++": ".cxx"}

Modified: python/branches/import_unicode/Lib/distutils/command/install.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/install.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/install.py	Fri Jul 30 01:19:37 2010
@@ -7,17 +7,26 @@
 import sys
 import os
 
-from sysconfig import get_config_vars, get_paths, get_path, get_config_var
-
 from distutils import log
 from distutils.core import Command
 from distutils.debug import DEBUG
+from distutils.sysconfig import get_config_vars
 from distutils.errors import DistutilsPlatformError
 from distutils.file_util import write_file
-from distutils.util import convert_path, change_root, get_platform
+from distutils.util import convert_path, subst_vars, change_root
+from distutils.util import get_platform
 from distutils.errors import DistutilsOptionError
 
-# kept for backward compat, will be removed in 3.2
+# this keeps compatibility from 2.3 to 2.5
+if sys.version < "2.6":
+    USER_BASE = None
+    USER_SITE = None
+    HAS_USER_SITE = False
+else:
+    from site import USER_BASE
+    from site import USER_SITE
+    HAS_USER_SITE = True
+
 if sys.version < "2.2":
     WINDOWS_SCHEME = {
         'purelib': '$base',
@@ -50,21 +59,15 @@
         'scripts': '$base/bin',
         'data'   : '$base',
         },
-    'unix_user': {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/include/python$py_version_short/$dist_name',
-        'scripts': '$userbase/bin',
-        'data'   : '$userbase',
-        },
     'nt': WINDOWS_SCHEME,
-    'nt_user': {
-        'purelib': '$usersite',
-        'platlib': '$usersite',
-        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
-        'scripts': '$userbase/Scripts',
-        'data'   : '$userbase',
+    'mac': {
+        'purelib': '$base/Lib/site-packages',
+        'platlib': '$base/Lib/site-packages',
+        'headers': '$base/Include/$dist_name',
+        'scripts': '$base/Scripts',
+        'data'   : '$base',
         },
+
     'os2': {
         'purelib': '$base/Lib/site-packages',
         'platlib': '$base/Lib/site-packages',
@@ -72,26 +75,47 @@
         'scripts': '$base/Scripts',
         'data'   : '$base',
         },
-    'os2_home': {
+    }
+
+# user site schemes
+if HAS_USER_SITE:
+    INSTALL_SCHEMES['nt_user'] = {
+        'purelib': '$usersite',
+        'platlib': '$usersite',
+        'headers': '$userbase/Python$py_version_nodot/Include/$dist_name',
+        'scripts': '$userbase/Scripts',
+        'data'   : '$userbase',
+        }
+
+    INSTALL_SCHEMES['unix_user'] = {
         'purelib': '$usersite',
         'platlib': '$usersite',
         'headers': '$userbase/include/python$py_version_short/$dist_name',
         'scripts': '$userbase/bin',
         'data'   : '$userbase',
-        },
-    }
+        }
+
+    INSTALL_SCHEMES['mac_user'] = {
+        'purelib': '$usersite',
+        'platlib': '$usersite',
+        'headers': '$userbase/$py_version_short/include/$dist_name',
+        'scripts': '$userbase/bin',
+        'data'   : '$userbase',
+        }
 
+    INSTALL_SCHEMES['os2_home'] = {
+        'purelib': '$usersite',
+        'platlib': '$usersite',
+        'headers': '$userbase/include/python$py_version_short/$dist_name',
+        'scripts': '$userbase/bin',
+        'data'   : '$userbase',
+        }
+
+# The keys to an installation scheme; if any new types of files are to be
+# installed, be sure to add an entry to every installation scheme above,
+# and to SCHEME_KEYS here.
 SCHEME_KEYS = ('purelib', 'platlib', 'headers', 'scripts', 'data')
-# end of backward compat
 
-def _subst_vars(s, local_vars):
-    try:
-        return s.format(**local_vars)
-    except KeyError:
-        try:
-            return s.format(**os.environ)
-        except KeyError as var:
-            raise AttributeError('{%s}' % var)
 
 class install(Command):
 
@@ -158,10 +182,11 @@
 
     boolean_options = ['compile', 'force', 'skip-build']
 
-    user_options.append(('user', None,
-                        "install in user site-package '%s'" % \
-                            get_path('purelib', '%s_user' % os.name)))
-    boolean_options.append('user')
+    if HAS_USER_SITE:
+        user_options.append(('user', None,
+                             "install in user site-package '%s'" % USER_SITE))
+        boolean_options.append('user')
+
     negative_opt = {'no-compile' : 'compile'}
 
 
@@ -191,8 +216,8 @@
         self.install_lib = None         # set to either purelib or platlib
         self.install_scripts = None
         self.install_data = None
-        self.install_userbase = get_config_var('userbase')
-        self.install_usersite = get_path('purelib', '%s_user' % os.name)
+        self.install_userbase = USER_BASE
+        self.install_usersite = USER_SITE
 
         self.compile = None
         self.optimize = None
@@ -302,9 +327,7 @@
         # about needing recursive variable expansion (shudder).
 
         py_version = sys.version.split()[0]
-        prefix, exec_prefix, srcdir, projectbase = get_config_vars('prefix', 'exec_prefix',
-                                                      'srcdir', 'projectbase')
-
+        (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix')
         self.config_vars = {'dist_name': self.distribution.get_name(),
                             'dist_version': self.distribution.get_version(),
                             'dist_fullname': self.distribution.get_fullname(),
@@ -315,12 +338,12 @@
                             'prefix': prefix,
                             'sys_exec_prefix': exec_prefix,
                             'exec_prefix': exec_prefix,
-                            'srcdir': srcdir,
-                            'projectbase': projectbase,
                            }
 
-        self.config_vars['userbase'] = self.install_userbase
-        self.config_vars['usersite'] = self.install_usersite
+        if HAS_USER_SITE:
+            self.config_vars['userbase'] = self.install_userbase
+            self.config_vars['usersite'] = self.install_usersite
+
         self.expand_basedirs()
 
         self.dump_dirs("post-expand_basedirs()")
@@ -424,10 +447,10 @@
                 raise DistutilsPlatformError(
                     "User base directory is not specified")
             self.install_base = self.install_platbase = self.install_userbase
-            self.select_scheme("posix_user")
+            self.select_scheme("unix_user")
         elif self.home is not None:
             self.install_base = self.install_platbase = self.home
-            self.select_scheme("posix_home")
+            self.select_scheme("unix_home")
         else:
             if self.prefix is None:
                 if self.exec_prefix is not None:
@@ -443,7 +466,7 @@
 
             self.install_base = self.prefix
             self.install_platbase = self.exec_prefix
-            self.select_scheme("posix_prefix")
+            self.select_scheme("unix_prefix")
 
     def finalize_other(self):
         """Finalizes options for non-posix platforms"""
@@ -455,7 +478,7 @@
             self.select_scheme(os.name + "_user")
         elif self.home is not None:
             self.install_base = self.install_platbase = self.home
-            self.select_scheme("posix_home")
+            self.select_scheme("unix_home")
         else:
             if self.prefix is None:
                 self.prefix = os.path.normpath(sys.prefix)
@@ -470,15 +493,11 @@
     def select_scheme(self, name):
         """Sets the install directories by applying the install schemes."""
         # it's the caller's problem if they supply a bad name!
-        scheme = get_paths(name, expand=False)
-        for key, value in scheme.items():
-            if key == 'platinclude':
-                key = 'headers'
-                value = os.path.join(value, self.distribution.get_name())
+        scheme = INSTALL_SCHEMES[name]
+        for key in SCHEME_KEYS:
             attrname = 'install_' + key
-            if hasattr(self, attrname):
-                if getattr(self, attrname) is None:
-                    setattr(self, attrname, value)
+            if getattr(self, attrname) is None:
+                setattr(self, attrname, scheme[key])
 
     def _expand_attrs(self, attrs):
         for attr in attrs:
@@ -486,7 +505,7 @@
             if val is not None:
                 if os.name == 'posix' or os.name == 'nt':
                     val = os.path.expanduser(val)
-                val = _subst_vars(val, self.config_vars)
+                val = subst_vars(val, self.config_vars)
                 setattr(self, attr, val)
 
     def expand_basedirs(self):

Modified: python/branches/import_unicode/Lib/distutils/command/register.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/register.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/register.py	Fri Jul 30 01:19:37 2010
@@ -7,15 +7,13 @@
 
 __revision__ = "$Id$"
 
-import os
-import string
-import getpass
+import os, string, getpass
 import io
-import urllib.parse
-import urllib.request
+import urllib.parse, urllib.request
 from warnings import warn
 
 from distutils.core import PyPIRCCommand
+from distutils.errors import *
 from distutils import log
 
 class register(PyPIRCCommand):

Modified: python/branches/import_unicode/Lib/distutils/command/sdist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/sdist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/sdist.py	Fri Jul 30 01:19:37 2010
@@ -7,14 +7,14 @@
 import os
 import string
 import sys
+from types import *
 from glob import glob
 from warnings import warn
 
 from distutils.core import Command
 from distutils import dir_util, dep_util, file_util, archive_util
 from distutils.text_file import TextFile
-from distutils.errors import (DistutilsPlatformError, DistutilsOptionError,
-                              DistutilsTemplateError)
+from distutils.errors import *
 from distutils.filelist import FileList
 from distutils import log
 from distutils.util import convert_path
@@ -76,10 +76,6 @@
         ('medata-check', None,
          "Ensure that all required elements of meta-data "
          "are supplied. Warn if any missing. [default]"),
-        ('owner=', 'u',
-         "Owner name used when creating a tar file [default: current user]"),
-        ('group=', 'g',
-         "Group name used when creating a tar file [default: current group]"),
         ]
 
     boolean_options = ['use-defaults', 'prune',
@@ -119,8 +115,6 @@
 
         self.archive_files = None
         self.metadata_check = 1
-        self.owner = None
-        self.group = None
 
     def finalize_options(self):
         if self.manifest is None:
@@ -424,8 +418,7 @@
             self.formats.append(self.formats.pop(self.formats.index('tar')))
 
         for fmt in self.formats:
-            file = self.make_archive(base_name, fmt, base_dir=base_dir,
-                                     owner=self.owner, group=self.group)
+            file = self.make_archive(base_name, fmt, base_dir=base_dir)
             archive_files.append(file)
             self.distribution.dist_files.append(('sdist', '', file))
 

Modified: python/branches/import_unicode/Lib/distutils/command/upload.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/command/upload.py	(original)
+++ python/branches/import_unicode/Lib/distutils/command/upload.py	Fri Jul 30 01:19:37 2010
@@ -1,19 +1,25 @@
 """distutils.command.upload
 
 Implements the Distutils 'upload' subcommand (upload package to PyPI)."""
-import os
-import io
-import socket
-import platform
-from urllib.request import urlopen, Request, HTTPError
-from base64 import standard_b64encode
-from urllib.parse import urlparse
-from hashlib import md5
 
-from distutils.errors import DistutilsOptionError
+from distutils.errors import *
 from distutils.core import PyPIRCCommand
 from distutils.spawn import spawn
 from distutils import log
+import sys
+import os, io
+import socket
+import platform
+import configparser
+import http.client as httpclient
+from base64 import standard_b64encode
+import urllib.parse
+
+# this keeps compatibility for 2.3 and 2.4
+if sys.version < "2.5":
+    from md5 import md5
+else:
+    from hashlib import md5
 
 class upload(PyPIRCCommand):
 
@@ -60,15 +66,6 @@
             self.upload_file(command, pyversion, filename)
 
     def upload_file(self, command, pyversion, filename):
-        # Makes sure the repository URL is compliant
-        schema, netloc, url, params, query, fragments = \
-            urlparse(self.repository)
-        if params or query or fragments:
-            raise AssertionError("Incompatible url %s" % self.repository)
-
-        if schema not in ('http', 'https'):
-            raise AssertionError("unsupported schema " + schema)
-
         # Sign if requested
         if self.sign:
             gpg_args = ["gpg", "--detach-sign", "-a", filename]
@@ -140,10 +137,10 @@
         for key, value in data.items():
             title = '\nContent-Disposition: form-data; name="%s"' % key
             # handle multiple entries for the same name
-            if not isinstance(value, list):
+            if type(value) != type([]):
                 value = [value]
             for value in value:
-                if isinstance(value, tuple):
+                if type(value) is tuple:
                     title += '; filename="%s"' % value[0]
                     value = value[1]
                 else:
@@ -161,30 +158,40 @@
         self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
 
         # build the Request
-        headers = {'Content-type':
-                        'multipart/form-data; boundary=%s' % boundary,
-                   'Content-length': str(len(body)),
-                   'Authorization': auth}
-
-        request = Request(self.repository, data=body,
-                          headers=headers)
-        # send the data
+        # We can't use urllib since we need to send the Basic
+        # auth right with the first request
+        # TODO(jhylton): Can we fix urllib?
+        schema, netloc, url, params, query, fragments = \
+            urllib.parse.urlparse(self.repository)
+        assert not params and not query and not fragments
+        if schema == 'http':
+            http = httpclient.HTTPConnection(netloc)
+        elif schema == 'https':
+            http = httpclient.HTTPSConnection(netloc)
+        else:
+            raise AssertionError("unsupported schema "+schema)
+
+        data = ''
+        loglevel = log.INFO
         try:
-            result = urlopen(request)
-            status = result.getcode()
-            reason = result.msg
+            http.connect()
+            http.putrequest("POST", url)
+            http.putheader('Content-type',
+                           'multipart/form-data; boundary=%s'%boundary)
+            http.putheader('Content-length', str(len(body)))
+            http.putheader('Authorization', auth)
+            http.endheaders()
+            http.send(body)
         except socket.error as e:
             self.announce(str(e), log.ERROR)
             return
-        except HTTPError as e:
-            status = e.code
-            reason = e.msg
 
-        if status == 200:
-            self.announce('Server response (%s): %s' % (status, reason),
+        r = http.getresponse()
+        if r.status == 200:
+            self.announce('Server response (%s): %s' % (r.status, r.reason),
                           log.INFO)
         else:
-            self.announce('Upload failed (%s): %s' % (status, reason),
+            self.announce('Upload failed (%s): %s' % (r.status, r.reason),
                           log.ERROR)
         if self.show_response:
-            self.announce('-'*75, result.read(), '-'*75)
+            self.announce('-'*75, r.read(), '-'*75)

Modified: python/branches/import_unicode/Lib/distutils/config.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/config.py	(original)
+++ python/branches/import_unicode/Lib/distutils/config.py	Fri Jul 30 01:19:37 2010
@@ -4,6 +4,7 @@
 that uses .pypirc in the distutils.command package.
 """
 import os
+import sys
 from configparser import ConfigParser
 
 from distutils.cmd import Command
@@ -59,6 +60,8 @@
         if os.path.exists(rc):
             self.announce('Using PyPI login from %s' % rc)
             repository = self.repository or self.DEFAULT_REPOSITORY
+            realm = self.realm or self.DEFAULT_REALM
+
             config = ConfigParser()
             config.read(rc)
             sections = config.sections()

Modified: python/branches/import_unicode/Lib/distutils/core.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/core.py	(original)
+++ python/branches/import_unicode/Lib/distutils/core.py	Fri Jul 30 01:19:37 2010
@@ -8,12 +8,10 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
+import sys, os
 
 from distutils.debug import DEBUG
-from distutils.errors import (DistutilsSetupError, DistutilsArgError,
-                              DistutilsError, CCompilerError)
+from distutils.errors import *
 from distutils.util import grok_environment_error
 
 # Mainly import these so setup scripts can "from distutils.core import" them.
@@ -33,9 +31,9 @@
    or: %(script)s cmd --help
 """
 
-def gen_usage(script_name):
+def gen_usage (script_name):
     script = os.path.basename(script_name)
-    return USAGE % {'script': script}
+    return USAGE % vars()
 
 
 # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
@@ -58,7 +56,7 @@
                       'extra_objects', 'extra_compile_args', 'extra_link_args',
                       'swig_opts', 'export_symbols', 'depends', 'language')
 
-def setup(**attrs):
+def setup (**attrs):
     """The gateway to the Distutils: do everything your setup script needs
     to do, in a highly flexible and user-driven way.  Briefly: create a
     Distribution instance; find and parse config files; parse the command
@@ -131,9 +129,8 @@
     if _setup_stop_after == "config":
         return dist
 
-    # Parse the command line and override config files; any
-    # command-line errors are the end user's fault, so turn them into
-    # SystemExit to suppress tracebacks.
+    # Parse the command line; any command-line errors are the end user's
+    # fault, so turn them into SystemExit to suppress tracebacks.
     try:
         ok = dist.parse_command_line()
     except DistutilsArgError as msg:
@@ -170,8 +167,10 @@
 
     return dist
 
+# setup ()
 
-def run_setup(script_name, script_args=None, stop_after="run"):
+
+def run_setup (script_name, script_args=None, stop_after="run"):
     """Run a setup script in a somewhat controlled environment, and
     return the Distribution instance that drives things.  This is useful
     if you need to find out the distribution meta-data (passed as
@@ -234,4 +233,7 @@
 
     # I wonder if the setup script's namespace -- g and l -- would be of
     # any interest to callers?
+    #print "_setup_distribution:", _setup_distribution
     return _setup_distribution
+
+# run_setup ()

Modified: python/branches/import_unicode/Lib/distutils/cygwinccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/cygwinccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/cygwinccompiler.py	Fri Jul 30 01:19:37 2010
@@ -50,13 +50,16 @@
 import os
 import sys
 import copy
+from subprocess import Popen, PIPE
 import re
-from warnings import warn
 
+from distutils.ccompiler import gen_preprocess_options, gen_lib_options
 from distutils.unixccompiler import UnixCCompiler
 from distutils.file_util import write_file
 from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
-from distutils.util import get_compiler_versions
+from distutils import log
+from distutils.version import LooseVersion
+from distutils.spawn import find_executable
 
 def get_msvcr():
     """Include the appropriate MSVC runtime library if Python was built
@@ -107,7 +110,7 @@
                 % details)
 
         self.gcc_version, self.ld_version, self.dllwrap_version = \
-            get_compiler_versions()
+            get_versions()
         self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
                          (self.gcc_version,
                           self.ld_version,
@@ -337,7 +340,7 @@
     # XXX since this function also checks sys.version, it's not strictly a
     # "pyconfig.h" check -- should probably be renamed...
 
-    _sysconfig = __import__('sysconfig')
+    from distutils import sysconfig
 
     # if sys.version contains GCC then python was compiled with GCC, and the
     # pyconfig.h file should be OK
@@ -345,7 +348,7 @@
         return CONFIG_H_OK, "sys.version mentions 'GCC'"
 
     # let's see if __GNUC__ is mentioned in python.h
-    fn = _sysconfig.get_config_h_filename()
+    fn = sysconfig.get_config_h_filename()
     try:
         with open(fn) as config_h:
             if "__GNUC__" in config_h.read():
@@ -356,27 +359,33 @@
         return (CONFIG_H_UNCERTAIN,
                 "couldn't read '%s': %s" % (fn, exc.strerror))
 
-class _Deprecated_SRE_Pattern(object):
-    def __init__(self, pattern):
-        self.pattern = pattern
-
-    def __getattr__(self, name):
-        if name in ('findall', 'finditer', 'match', 'scanner', 'search',
-                    'split', 'sub', 'subn'):
-            warn("'distutils.cygwinccompiler.RE_VERSION' is deprecated "
-                 "and will be removed in the next version", DeprecationWarning)
-        return getattr(self.pattern, name)
+RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
 
+def _find_exe_version(cmd):
+    """Find the version of an executable by running `cmd` in the shell.
 
-RE_VERSION = _Deprecated_SRE_Pattern(re.compile('(\d+\.\d+(\.\d+)*)'))
+    If the command is not found, or the output does not match
+    `RE_VERSION`, returns None.
+    """
+    executable = cmd.split()[0]
+    if find_executable(executable) is None:
+        return None
+    out = Popen(cmd, shell=True, stdout=PIPE).stdout
+    try:
+        out_string = out.read()
+    finally:
+        out.close()
+    result = RE_VERSION.search(out_string)
+    if result is None:
+        return None
+    # LooseVersion works with strings
+    # so we need to decode our bytes
+    return LooseVersion(result.group(1).decode())
 
 def get_versions():
     """ Try to find out the versions of gcc, ld and dllwrap.
 
     If not possible it returns None for it.
     """
-    warn("'distutils.cygwinccompiler.get_versions' is deprecated "
-         "use 'distutils.util.get_compiler_versions' instead",
-         DeprecationWarning)
-
-    return get_compiler_versions()
+    commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
+    return tuple([_find_exe_version(cmd) for cmd in commands])

Modified: python/branches/import_unicode/Lib/distutils/dep_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/dep_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/dep_util.py	Fri Jul 30 01:19:37 2010
@@ -9,27 +9,29 @@
 import os
 from distutils.errors import DistutilsFileError
 
-def newer(source, target):
-    """Tells if the target is newer than the source.
 
-    Return true if 'source' exists and is more recently modified than
-    'target', or if 'source' exists and 'target' doesn't.
-
-    Return false if both exist and 'target' is the same age or younger
-    than 'source'. Raise DistutilsFileError if 'source' does not exist.
-
-    Note that this test is not very accurate: files created in the same second
-    will have the same "age".
+def newer (source, target):
+    """Return true if 'source' exists and is more recently modified than
+    'target', or if 'source' exists and 'target' doesn't.  Return false if
+    both exist and 'target' is the same age or younger than 'source'.
+    Raise DistutilsFileError if 'source' does not exist.
     """
     if not os.path.exists(source):
         raise DistutilsFileError("file '%s' does not exist" %
                                  os.path.abspath(source))
     if not os.path.exists(target):
-        return True
+        return 1
+
+    from stat import ST_MTIME
+    mtime1 = os.stat(source)[ST_MTIME]
+    mtime2 = os.stat(target)[ST_MTIME]
+
+    return mtime1 > mtime2
+
+# newer ()
 
-    return os.stat(source).st_mtime > os.stat(target).st_mtime
 
-def newer_pairwise(sources, targets):
+def newer_pairwise (sources, targets):
     """Walk two filename lists in parallel, testing if each source is newer
     than its corresponding target.  Return a pair of lists (sources,
     targets) where source is newer than target, according to the semantics
@@ -41,18 +43,19 @@
     # build a pair of lists (sources, targets) where  source is newer
     n_sources = []
     n_targets = []
-    for source, target in zip(sources, targets):
-        if newer(source, target):
-            n_sources.append(source)
-            n_targets.append(target)
+    for i in range(len(sources)):
+        if newer(sources[i], targets[i]):
+            n_sources.append(sources[i])
+            n_targets.append(targets[i])
 
-    return n_sources, n_targets
+    return (n_sources, n_targets)
+
+# newer_pairwise ()
 
-def newer_group(sources, target, missing='error'):
-    """Return true if 'target' is out-of-date with respect to any file
-    listed in 'sources'.
 
-    In other words, if 'target' exists and is newer
+def newer_group (sources, target, missing='error'):
+    """Return true if 'target' is out-of-date with respect to any file
+    listed in 'sources'.  In other words, if 'target' exists and is newer
     than every file in 'sources', return false; otherwise return true.
     'missing' controls what we do when a source file is missing; the
     default ("error") is to blow up with an OSError from inside 'stat()';
@@ -65,14 +68,14 @@
     """
     # If the target doesn't even exist, then it's definitely out-of-date.
     if not os.path.exists(target):
-        return True
+        return 1
 
     # Otherwise we have to find out the hard way: if *any* source file
     # is more recent than 'target', then 'target' is out-of-date and
     # we can immediately return true.  If we fall through to the end
     # of the loop, then 'target' is up-to-date and we return false.
-    target_mtime = os.stat(target).st_mtime
-
+    from stat import ST_MTIME
+    target_mtime = os.stat(target)[ST_MTIME]
     for source in sources:
         if not os.path.exists(source):
             if missing == 'error':      # blow up when we stat() the file
@@ -80,9 +83,12 @@
             elif missing == 'ignore':   # missing source dropped from
                 continue                #  target's dependency list
             elif missing == 'newer':    # missing source means target is
-                return True             #  out-of-date
+                return 1                #  out-of-date
 
-        if os.stat(source).st_mtime > target_mtime:
-            return True
+        source_mtime = os.stat(source)[ST_MTIME]
+        if source_mtime > target_mtime:
+            return 1
+    else:
+        return 0
 
-    return False
+# newer_group ()

Modified: python/branches/import_unicode/Lib/distutils/dir_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/dir_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/dir_util.py	Fri Jul 30 01:19:37 2010
@@ -4,7 +4,7 @@
 
 __revision__ = "$Id$"
 
-import os
+import os, sys
 from distutils.errors import DistutilsFileError, DistutilsInternalError
 from distutils import log
 

Modified: python/branches/import_unicode/Lib/distutils/dist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/dist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/dist.py	Fri Jul 30 01:19:37 2010
@@ -7,15 +7,13 @@
 __revision__ = "$Id$"
 
 import sys, os, re
-from email import message_from_file
 
 try:
     import warnings
 except ImportError:
     warnings = None
 
-from distutils.errors import (DistutilsOptionError, DistutilsArgError,
-                              DistutilsModuleError, DistutilsClassError)
+from distutils.errors import *
 from distutils.fancy_getopt import FancyGetopt, translate_longopt
 from distutils.util import check_environ, strtobool, rfc822_escape
 from distutils import log
@@ -55,9 +53,7 @@
                       ('quiet', 'q', "run quietly (turns verbosity off)"),
                       ('dry-run', 'n', "don't actually do anything"),
                       ('help', 'h', "show detailed help message"),
-                      ('no-user-cfg', None,
-                       'ignore pydistutils.cfg in your home directory'),
-    ]
+                     ]
 
     # 'common_usage' is a short (2-3 line) string describing the common
     # usage of the setup script.
@@ -264,22 +260,6 @@
                     else:
                         sys.stderr.write(msg + "\n")
 
-        # no-user-cfg is handled before other command line args
-        # because other args override the config files, and this
-        # one is needed before we can load the config files.
-        # If attrs['script_args'] wasn't passed, assume false.
-        #
-        # This also make sure we just look at the global options
-        self.want_user_cfg = True
-
-        if self.script_args is not None:
-            for arg in self.script_args:
-                if not arg.startswith('-'):
-                    break
-                if arg == '--no-user-cfg':
-                    self.want_user_cfg = False
-                    break
-
         self.finalize_options()
 
     def get_option_dict(self, command):
@@ -331,10 +311,7 @@
         Distutils installation directory (ie. where the top-level
         Distutils __inst__.py file lives), a file in the user's home
         directory named .pydistutils.cfg on Unix and pydistutils.cfg
-        on Windows/Mac; and setup.cfg in the current directory.
-
-        The file in the user's home directory can be disabled with the
-        --no-user-cfg option.
+        on Windows/Mac, and setup.cfg in the current directory.
         """
         files = []
         check_environ()
@@ -354,19 +331,15 @@
             user_filename = "pydistutils.cfg"
 
         # And look for the user config file
-        if self.want_user_cfg:
-            user_file = os.path.join(os.path.expanduser('~'), user_filename)
-            if os.path.isfile(user_file):
-                files.append(user_file)
+        user_file = os.path.join(os.path.expanduser('~'), user_filename)
+        if os.path.isfile(user_file):
+            files.append(user_file)
 
         # All platforms support local setup.cfg
         local_file = "setup.cfg"
         if os.path.isfile(local_file):
             files.append(local_file)
 
-        if DEBUG:
-            self.announce("using config files: %s" % ', '.join(files))
-
         return files
 
     def parse_config_files(self, filenames=None):
@@ -1016,80 +989,25 @@
                          "provides", "requires", "obsoletes",
                          )
 
-    def __init__(self, path=None):
-        if path is not None:
-            self.read_pkg_file(open(path))
-        else:
-            self.name = None
-            self.version = None
-            self.author = None
-            self.author_email = None
-            self.maintainer = None
-            self.maintainer_email = None
-            self.url = None
-            self.license = None
-            self.description = None
-            self.long_description = None
-            self.keywords = None
-            self.platforms = None
-            self.classifiers = None
-            self.download_url = None
-            # PEP 314
-            self.provides = None
-            self.requires = None
-            self.obsoletes = None
-
-    def read_pkg_file(self, file):
-        """Reads the metadata values from a file object."""
-        msg = message_from_file(file)
-
-        def _read_field(name):
-            value = msg[name]
-            if value == 'UNKNOWN':
-                return None
-            return value
-
-        def _read_list(name):
-            values = msg.get_all(name, None)
-            if values == []:
-                return None
-            return values
-
-        metadata_version = msg['metadata-version']
-        self.name = _read_field('name')
-        self.version = _read_field('version')
-        self.description = _read_field('summary')
-        # we are filling author only.
-        self.author = _read_field('author')
+    def __init__ (self):
+        self.name = None
+        self.version = None
+        self.author = None
+        self.author_email = None
         self.maintainer = None
-        self.author_email = _read_field('author-email')
         self.maintainer_email = None
-        self.url = _read_field('home-page')
-        self.license = _read_field('license')
-
-        if 'download-url' in msg:
-            self.download_url = _read_field('download-url')
-        else:
-            self.download_url = None
-
-        self.long_description = _read_field('description')
-        self.description = _read_field('summary')
-
-        if 'keywords' in msg:
-            self.keywords = _read_field('keywords').split(',')
-
-        self.platforms = _read_list('platform')
-        self.classifiers = _read_list('classifier')
-
-        # PEP 314 - these fields only exist in 1.1
-        if metadata_version == '1.1':
-            self.requires = _read_list('requires')
-            self.provides = _read_list('provides')
-            self.obsoletes = _read_list('obsoletes')
-        else:
-            self.requires = None
-            self.provides = None
-            self.obsoletes = None
+        self.url = None
+        self.license = None
+        self.description = None
+        self.long_description = None
+        self.keywords = None
+        self.platforms = None
+        self.classifiers = None
+        self.download_url = None
+        # PEP 314
+        self.provides = None
+        self.requires = None
+        self.obsoletes = None
 
     def write_pkg_info(self, base_dir):
         """Write the PKG-INFO file into the release tree.

Modified: python/branches/import_unicode/Lib/distutils/emxccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/emxccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/emxccompiler.py	Fri Jul 30 01:19:37 2010
@@ -21,13 +21,12 @@
 
 __revision__ = "$Id$"
 
-import os, sys, copy
-from warnings import warn
-
+import os,sys,copy
+from distutils.ccompiler import gen_preprocess_options, gen_lib_options
 from distutils.unixccompiler import UnixCCompiler
 from distutils.file_util import write_file
 from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
-from distutils.util import get_compiler_versions
+from distutils import log
 
 class EMXCCompiler (UnixCCompiler):
 
@@ -56,8 +55,8 @@
                 ("Reason: %s." % details) +
                 "Compiling may fail because of undefined preprocessor macros.")
 
-        gcc_version, ld_version, dllwrap_version = get_compiler_versions()
-        self.gcc_version, self.ld_version = gcc_version, ld_version
+        (self.gcc_version, self.ld_version) = \
+            get_versions()
         self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" %
                          (self.gcc_version,
                           self.ld_version) )
@@ -292,11 +291,23 @@
     """ Try to find out the versions of gcc and ld.
         If not possible it returns None for it.
     """
-    warn("'distutils.emxccompiler.get_versions' is deprecated "
-         "use 'distutils.util.get_compiler_versions' instead",
-         DeprecationWarning)
-
+    from distutils.version import StrictVersion
+    from distutils.spawn import find_executable
+    import re
+
+    gcc_exe = find_executable('gcc')
+    if gcc_exe:
+        out = os.popen(gcc_exe + ' -dumpversion','r')
+        out_string = out.read()
+        out.close()
+        result = re.search('(\d+\.\d+\.\d+)', out_string, re.ASCII)
+        if result:
+            gcc_version = StrictVersion(result.group(1))
+        else:
+            gcc_version = None
+    else:
+        gcc_version = None
     # EMX ld has no way of reporting version number, and we use GCC
     # anyway - so we can link OMF DLLs
-    gcc_version, ld_version, dllwrap_version = get_compiler_versions()
-    return gcc_version, None
+    ld_version = None
+    return (gcc_version, ld_version)

Modified: python/branches/import_unicode/Lib/distutils/errors.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/errors.py	(original)
+++ python/branches/import_unicode/Lib/distutils/errors.py	Fri Jul 30 01:19:37 2010
@@ -10,79 +10,90 @@
 
 __revision__ = "$Id$"
 
-class DistutilsError(Exception):
+class DistutilsError (Exception):
     """The root of all Distutils evil."""
+    pass
 
-class DistutilsModuleError(DistutilsError):
+class DistutilsModuleError (DistutilsError):
     """Unable to load an expected module, or to find an expected class
     within some module (in particular, command modules and classes)."""
+    pass
 
-class DistutilsClassError(DistutilsError):
+class DistutilsClassError (DistutilsError):
     """Some command class (or possibly distribution class, if anyone
     feels a need to subclass Distribution) is found not to be holding
     up its end of the bargain, ie. implementing some part of the
     "command "interface."""
+    pass
 
-class DistutilsGetoptError(DistutilsError):
+class DistutilsGetoptError (DistutilsError):
     """The option table provided to 'fancy_getopt()' is bogus."""
+    pass
 
-class DistutilsArgError(DistutilsError):
+class DistutilsArgError (DistutilsError):
     """Raised by fancy_getopt in response to getopt.error -- ie. an
     error in the command line usage."""
+    pass
 
-class DistutilsFileError(DistutilsError):
+class DistutilsFileError (DistutilsError):
     """Any problems in the filesystem: expected file not found, etc.
     Typically this is for problems that we detect before IOError or
     OSError could be raised."""
+    pass
 
-class DistutilsOptionError(DistutilsError):
+class DistutilsOptionError (DistutilsError):
     """Syntactic/semantic errors in command options, such as use of
     mutually conflicting options, or inconsistent options,
     badly-spelled values, etc.  No distinction is made between option
     values originating in the setup script, the command line, config
     files, or what-have-you -- but if we *know* something originated in
     the setup script, we'll raise DistutilsSetupError instead."""
+    pass
 
-class DistutilsSetupError(DistutilsError):
+class DistutilsSetupError (DistutilsError):
     """For errors that can be definitely blamed on the setup script,
     such as invalid keyword arguments to 'setup()'."""
+    pass
 
-class DistutilsPlatformError(DistutilsError):
+class DistutilsPlatformError (DistutilsError):
     """We don't know how to do something on the current platform (but
     we do know how to do it on some platform) -- eg. trying to compile
     C files on a platform not supported by a CCompiler subclass."""
+    pass
 
-class DistutilsExecError(DistutilsError):
+class DistutilsExecError (DistutilsError):
     """Any problems executing an external program (such as the C
     compiler, when compiling C files)."""
+    pass
 
-class DistutilsInternalError(DistutilsError):
+class DistutilsInternalError (DistutilsError):
     """Internal inconsistencies or impossibilities (obviously, this
     should never be seen if the code is working!)."""
+    pass
 
-class DistutilsTemplateError(DistutilsError):
+class DistutilsTemplateError (DistutilsError):
     """Syntax error in a file list template."""
 
 class DistutilsByteCompileError(DistutilsError):
     """Byte compile error."""
 
 # Exception classes used by the CCompiler implementation classes
-class CCompilerError(Exception):
+class CCompilerError (Exception):
     """Some compile/link operation failed."""
 
-class PreprocessError(CCompilerError):
+class PreprocessError (CCompilerError):
     """Failure to preprocess one or more C/C++ files."""
 
-class CompileError(CCompilerError):
+class CompileError (CCompilerError):
     """Failure to compile one or more C/C++ source files."""
 
-class LibError(CCompilerError):
+class LibError (CCompilerError):
     """Failure to create a static library from one or more C/C++ object
     files."""
 
-class LinkError(CCompilerError):
+class LinkError (CCompilerError):
     """Failure to link one or more C/C++ object files into an executable
     or shared library file."""
 
-class UnknownFileError(CCompilerError):
+class UnknownFileError (CCompilerError):
     """Attempt to process an unknown file type."""

Modified: python/branches/import_unicode/Lib/distutils/extension.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/extension.py	(original)
+++ python/branches/import_unicode/Lib/distutils/extension.py	Fri Jul 30 01:19:37 2010
@@ -6,6 +6,7 @@
 __revision__ = "$Id$"
 
 import os
+import sys
 import warnings
 
 # This class is really only used by the "build_ext" command, so it might
@@ -134,17 +135,14 @@
 
 def read_setup_file(filename):
     """Reads a Setup file and returns Extension instances."""
-    warnings.warn('distutils.extensions.read_setup_file is deprecated. '
-                  'It will be removed in the next Python release.')
-    _sysconfig = __import__('sysconfig')
-    from distutils.sysconfig import (expand_makefile_vars,
+    from distutils.sysconfig import (parse_makefile, expand_makefile_vars,
                                      _variable_rx)
 
     from distutils.text_file import TextFile
     from distutils.util import split_quoted
 
     # First pass over the file to gather "VAR = VALUE" assignments.
-    vars = _sysconfig._parse_makefile(filename)
+    vars = parse_makefile(filename)
 
     # Second pass to gobble up the real content: lines of the form
     #   <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
@@ -164,10 +162,7 @@
             file.warn("'%s' lines not handled yet" % line)
             continue
 
-        with warnings.catch_warnings():
-            warnings.simplefilter("ignore")
-            line = expand_makefile_vars(line, vars)
-
+        line = expand_makefile_vars(line, vars)
         words = split_quoted(line)
 
         # NB. this parses a slightly different syntax than the old

Modified: python/branches/import_unicode/Lib/distutils/fancy_getopt.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/fancy_getopt.py	(original)
+++ python/branches/import_unicode/Lib/distutils/fancy_getopt.py	Fri Jul 30 01:19:37 2010
@@ -10,11 +10,9 @@
 
 __revision__ = "$Id$"
 
-import sys
-import string
-import re
+import sys, string, re
 import getopt
-from distutils.errors import DistutilsGetoptError, DistutilsArgError
+from distutils.errors import *
 
 # Much like command_re in distutils.core, this is close to but not quite
 # the same as a Python NAME -- except, in the spirit of most GNU
@@ -446,3 +444,16 @@
         'options' will be initialized to None."""
         for opt in options:
             setattr(self, opt, None)
+
+
+if __name__ == "__main__":
+    text = """\
+Tra-la-la, supercalifragilisticexpialidocious.
+How *do* you spell that odd word, anyways?
+(Someone ask Mary -- she'll know [or she'll
+say, "How should I know?"].)"""
+
+    for w in (10, 20, 30, 40):
+        print("width: %d" % w)
+        print("\n".join(wrap_text(text, w)))
+        print()

Modified: python/branches/import_unicode/Lib/distutils/file_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/file_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/file_util.py	Fri Jul 30 01:19:37 2010
@@ -10,18 +10,17 @@
 from distutils import log
 
 # for generating verbose output in 'copy_file()'
-_copy_action = {None: 'copying',
-                'hard': 'hard linking',
-                'sym': 'symbolically linking'}
+_copy_action = { None:   'copying',
+                 'hard': 'hard linking',
+                 'sym':  'symbolically linking' }
 
 
 def _copy_file_contents(src, dst, buffer_size=16*1024):
-    """Copy the file 'src' to 'dst'.
-
-    Both must be filenames. Any error opening either file, reading from
-    'src', or writing to 'dst', raises DistutilsFileError.  Data is
-    read/written in chunks of 'buffer_size' bytes (default 16k).  No attempt
-    is made to handle anything apart from regular files.
+    """Copy the file 'src' to 'dst'; both must be filenames.  Any error
+    opening either file, reading from 'src', or writing to 'dst', raises
+    DistutilsFileError.  Data is read/written in chunks of 'buffer_size'
+    bytes (default 16k).  No attempt is made to handle anything apart from
+    regular files.
     """
     # Stolen from shutil module in the standard library, but with
     # custom error-handling added.
@@ -69,16 +68,15 @@
 
 def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0,
               link=None, verbose=1, dry_run=0):
-    """Copy a file 'src' to 'dst'.
-
-    If 'dst' is a directory, then 'src' is copied there with the same name;
-    otherwise, it must be a filename.  (If the file exists, it will be
-    ruthlessly clobbered.)  If 'preserve_mode' is true (the default),
-    the file's mode (type and permission bits, or whatever is analogous on
-    the current platform) is copied.  If 'preserve_times' is true (the
-    default), the last-modified and last-access times are copied as well.
-    If 'update' is true, 'src' will only be copied if 'dst' does not exist,
-    or if 'dst' does exist but is older than 'src'.
+    """Copy a file 'src' to 'dst'.  If 'dst' is a directory, then 'src' is
+    copied there with the same name; otherwise, it must be a filename.  (If
+    the file exists, it will be ruthlessly clobbered.)  If 'preserve_mode'
+    is true (the default), the file's mode (type and permission bits, or
+    whatever is analogous on the current platform) is copied.  If
+    'preserve_times' is true (the default), the last-modified and
+    last-access times are copied as well.  If 'update' is true, 'src' will
+    only be copied if 'dst' does not exist, or if 'dst' does exist but is
+    older than 'src'.
 
     'link' allows you to make hard links (os.link) or symbolic links
     (os.symlink) instead of copying: set it to "hard" or "sym"; if it is
@@ -132,6 +130,15 @@
     if dry_run:
         return (dst, 1)
 
+    # On Mac OS, use the native file copy routine
+    if os.name == 'mac':
+        import macostools
+        try:
+            macostools.copy(src, dst, 0, preserve_times)
+        except os.error as exc:
+            raise DistutilsFileError(
+                  "could not copy '%s' to '%s': %s" % (src, dst, exc.args[-1]))
+
     # If linking (hard or symbolic), use the appropriate system call
     # (Unix only, of course, but that's the caller's responsibility)
     elif link == 'hard':
@@ -159,12 +166,13 @@
 
 
 # XXX I suspect this is Unix-specific -- need porting help!
-def move_file(src, dst, verbose=1, dry_run=0):
-    """Move a file 'src' to 'dst'.
-
-    If 'dst' is a directory, the file will be moved into it with the same
-    name; otherwise, 'src' is just renamed to 'dst'.  Return the new
-    full name of the file.
+def move_file (src, dst,
+               verbose=1,
+               dry_run=0):
+
+    """Move a file 'src' to 'dst'.  If 'dst' is a directory, the file will
+    be moved into it with the same name; otherwise, 'src' is just renamed
+    to 'dst'.  Return the new full name of the file.
 
     Handles cross-device moves on Unix using 'copy_file()'.  What about
     other systems???
@@ -221,7 +229,7 @@
     return dst
 
 
-def write_file(filename, contents):
+def write_file (filename, contents):
     """Create a file with the specified name and write 'contents' (a
     sequence of strings without line terminators) to it.
     """

Modified: python/branches/import_unicode/Lib/distutils/filelist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/filelist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/filelist.py	Fri Jul 30 01:19:37 2010
@@ -108,7 +108,7 @@
         # defined: it's the first word of the line.  Which of the other
         # three are defined depends on the action; it'll be either
         # patterns, (dir and patterns), or (dir_pattern).
-        action, patterns, dir, dir_pattern = self._parse_template_line(line)
+        (action, patterns, dir, dir_pattern) = self._parse_template_line(line)
 
         # OK, now we know that the action is valid and we have the
         # right number of words on the line for that action -- so we
@@ -175,15 +175,15 @@
             raise DistutilsInternalError(
                   "this cannot happen: invalid action '%s'" % action)
 
+
     # -- Filtering/selection methods -----------------------------------
 
     def include_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
         """Select strings (presumably filenames) from 'self.files' that
-        match 'pattern', a Unix-style wildcard (glob) pattern.
-
-        Patterns are not quite the same as implemented by the 'fnmatch'
-        module: '*' and '?'  match non-special characters, where "special"
-        is platform-dependent: slash on Unix; colon, slash, and backslash on
+        match 'pattern', a Unix-style wildcard (glob) pattern.  Patterns
+        are not quite the same as implemented by the 'fnmatch' module: '*'
+        and '?'  match non-special characters, where "special" is platform-
+        dependent: slash on Unix; colon, slash, and backslash on
         DOS/Windows; and colon on Mac OS.
 
         If 'anchor' is true (the default), then the pattern match is more
@@ -220,13 +220,13 @@
         return files_found
 
 
-    def exclude_pattern(self, pattern, anchor=1, prefix=None, is_regex=0):
+    def exclude_pattern (self, pattern,
+                         anchor=1, prefix=None, is_regex=0):
         """Remove strings (presumably filenames) from 'files' that match
-        'pattern'.
-
-        Other parameters are the same as for 'include_pattern()', above.
-        The list 'self.files' is modified in place. Return 1 if files are
-        found.
+        'pattern'.  Other parameters are the same as for
+        'include_pattern()', above.
+        The list 'self.files' is modified in place.
+        Return True if files are found, False otherwise.
         """
         files_found = False
         pattern_re = translate_pattern(pattern, anchor, prefix, is_regex)
@@ -275,11 +275,10 @@
 
 
 def glob_to_re(pattern):
-    """Translate a shell-like glob pattern to a regular expression.
-
-    Return a string containing the regex.  Differs from
-    'fnmatch.translate()' in that '*' does not match "special characters"
-    (which are platform-specific).
+    """Translate a shell-like glob pattern to a regular expression; return
+    a string containing the regex.  Differs from 'fnmatch.translate()' in
+    that '*' does not match "special characters" (which are
+    platform-specific).
     """
     pattern_re = fnmatch.translate(pattern)
 
@@ -297,9 +296,7 @@
 
 def translate_pattern(pattern, anchor=1, prefix=None, is_regex=0):
     """Translate a shell-like wildcard pattern to a compiled regular
-    expression.
-
-    Return the compiled regex.  If 'is_regex' true,
+    expression.  Return the compiled regex.  If 'is_regex' true,
     then 'pattern' is directly compiled to a regex (if it's a string)
     or just returned as-is (assumes it's a regex object).
     """
@@ -317,7 +314,7 @@
     if prefix is not None:
         # ditch end of pattern character
         empty_pattern = glob_to_re('')
-        prefix_re = glob_to_re(prefix)[:-len(empty_pattern)]
+        prefix_re = (glob_to_re(prefix))[:-len(empty_pattern)]
         pattern_re = "^" + os.path.join(prefix_re, ".*" + pattern_re)
     else:                               # no prefix -- respect anchor flag
         if anchor:

Modified: python/branches/import_unicode/Lib/distutils/msvc9compiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/msvc9compiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/msvc9compiler.py	Fri Jul 30 01:19:37 2010
@@ -19,9 +19,10 @@
 import sys
 import re
 
-from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
-                              CompileError, LibError, LinkError)
-from distutils.ccompiler import CCompiler, gen_lib_options
+from distutils.errors import DistutilsExecError, DistutilsPlatformError, \
+                             CompileError, LibError, LinkError
+from distutils.ccompiler import CCompiler, gen_preprocess_options, \
+                                gen_lib_options
 from distutils import log
 from distutils.util import get_platform
 

Modified: python/branches/import_unicode/Lib/distutils/msvccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/msvccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/msvccompiler.py	Fri Jul 30 01:19:37 2010
@@ -10,12 +10,12 @@
 
 __revision__ = "$Id$"
 
-import sys
-import os
-
-from distutils.errors import (DistutilsExecError, DistutilsPlatformError,
-                              CompileError, LibError, LinkError)
-from distutils.ccompiler import CCompiler, gen_lib_options
+import sys, os
+from distutils.errors import \
+     DistutilsExecError, DistutilsPlatformError, \
+     CompileError, LibError, LinkError
+from distutils.ccompiler import \
+     CCompiler, gen_preprocess_options, gen_lib_options
 from distutils import log
 
 _can_read_reg = False
@@ -124,7 +124,7 @@
                 self.set_macro("FrameworkSDKDir", net, "sdkinstallrootv1.1")
             else:
                 self.set_macro("FrameworkSDKDir", net, "sdkinstallroot")
-        except KeyError:
+        except KeyError as exc: #
             raise DistutilsPlatformError(
             """Python was built with Visual Studio 2003;
 extensions must be built with a compiler than can generate compatible binaries.

Modified: python/branches/import_unicode/Lib/distutils/sysconfig.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/sysconfig.py	(original)
+++ python/branches/import_unicode/Lib/distutils/sysconfig.py	Fri Jul 30 01:19:37 2010
@@ -7,9 +7,6 @@
 
 Written by:   Fred L. Drake, Jr.
 Email:        <fdrake at acm.org>
-
-**This module has been moved out of Distutils and will be removed from
-Python in the next version (3.3)**
 """
 
 __revision__ = "$Id$"
@@ -17,45 +14,51 @@
 import io
 import os
 import re
-from warnings import warn
-
-from distutils.errors import DistutilsPlatformError
+import sys
 
-# importing sysconfig from Lib
-# to avoid this module to shadow it
-_sysconfig = __import__('sysconfig')
-
-# names defined here to keep backward compatibility
-# for APIs that were relocated
-get_python_version = _sysconfig.get_python_version
-get_config_h_filename = _sysconfig.get_config_h_filename
-parse_config_h = _sysconfig.parse_config_h
-get_config_vars = _sysconfig.get_config_vars
-get_config_var = _sysconfig.get_config_var
-from distutils.ccompiler import customize_compiler
-
-_DEPRECATION_MSG = ("distutils.sysconfig.%s is deprecated. "
-                    "Use the APIs provided by the sysconfig module instead")
-
-def _get_project_base():
-    return _sysconfig._PROJECT_BASE
-
-project_base = _get_project_base()
-
-class _DeprecatedBool(int):
-    def __nonzero__(self):
-        warn(_DEPRECATION_MSG % 'get_python_version', DeprecationWarning)
-        return super(_DeprecatedBool, self).__nonzero__()
+from .errors import DistutilsPlatformError
 
+# These are needed in a couple of spots, so just compute them once.
+PREFIX = os.path.normpath(sys.prefix)
+EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
+
+# Path to the base directory of the project. On Windows the binary may
+# live in project/PCBuild9.  If we're dealing with an x64 Windows build,
+# it'll live in project/PCbuild/amd64.
+project_base = os.path.dirname(os.path.abspath(sys.executable))
+if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
+    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
+# PC/VS7.1
+if os.name == "nt" and "\\pc\\v" in project_base[-10:].lower():
+    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
+                                                os.path.pardir))
+# PC/AMD64
+if os.name == "nt" and "\\pcbuild\\amd64" in project_base[-14:].lower():
+    project_base = os.path.abspath(os.path.join(project_base, os.path.pardir,
+                                                os.path.pardir))
+
+# python_build: (Boolean) if true, we're either building Python or
+# building an extension with an un-installed Python, so we use
+# different (hard-wired) directories.
+# Setup.local is available for Makefile builds including VPATH builds,
+# Setup.dist is available on Windows
 def _python_build():
-    return _DeprecatedBool(_sysconfig.is_python_build())
-
+    for fn in ("Setup.dist", "Setup.local"):
+        if os.path.isfile(os.path.join(project_base, "Modules", fn)):
+            return True
+    return False
 python_build = _python_build()
 
-def get_python_inc(plat_specific=0, prefix=None):
-    """This function is deprecated.
+def get_python_version():
+    """Return a string containing the major and minor Python version,
+    leaving off the patchlevel.  Sample return values could be '1.5'
+    or '2.2'.
+    """
+    return sys.version[:3]
+
 
-    Return the directory containing installed Python header files.
+def get_python_inc(plat_specific=0, prefix=None):
+    """Return the directory containing installed Python header files.
 
     If 'plat_specific' is false (the default), this is the path to the
     non-platform-specific header files, i.e. Python.h and so on;
@@ -65,22 +68,39 @@
     If 'prefix' is supplied, use it instead of sys.prefix or
     sys.exec_prefix -- i.e., ignore 'plat_specific'.
     """
-    warn(_DEPRECATION_MSG % 'get_python_inc', DeprecationWarning)
-    get_path = _sysconfig.get_path
-
-    if prefix is not None:
-        vars = {'base': prefix}
-        return get_path('include', vars=vars)
-
-    if not plat_specific:
-        return get_path('include')
+    if prefix is None:
+        prefix = plat_specific and EXEC_PREFIX or PREFIX
+    if os.name == "posix":
+        if python_build:
+            # Assume the executable is in the build directory.  The
+            # pyconfig.h file should be in the same directory.  Since
+            # the build directory may not be the source directory, we
+            # must use "srcdir" from the makefile to find the "Include"
+            # directory.
+            base = os.path.dirname(os.path.abspath(sys.executable))
+            if plat_specific:
+                return base
+            else:
+                incdir = os.path.join(get_config_var('srcdir'), 'Include')
+                return os.path.normpath(incdir)
+        return os.path.join(prefix, "include", "python" + get_python_version())
+    elif os.name == "nt":
+        return os.path.join(prefix, "include")
+    elif os.name == "mac":
+        if plat_specific:
+            return os.path.join(prefix, "Mac", "Include")
+        else:
+            return os.path.join(prefix, "Include")
+    elif os.name == "os2":
+        return os.path.join(prefix, "Include")
     else:
-        return get_path('platinclude')
+        raise DistutilsPlatformError(
+            "I don't know where Python installs its C header files "
+            "on platform '%s'" % os.name)
 
-def get_python_lib(plat_specific=False, standard_lib=False, prefix=None):
-    """This function is deprecated.
 
-    Return the directory containing the Python library (standard or
+def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
+    """Return the directory containing the Python library (standard or
     site additions).
 
     If 'plat_specific' is true, return the directory containing
@@ -93,33 +113,149 @@
     If 'prefix' is supplied, use it instead of sys.prefix or
     sys.exec_prefix -- i.e., ignore 'plat_specific'.
     """
-    warn(_DEPRECATION_MSG % 'get_python_lib', DeprecationWarning)
-    vars = {}
-    get_path = _sysconfig.get_path
-    if prefix is not None:
-        if plat_specific:
-            vars['platbase'] = prefix
+    if prefix is None:
+        prefix = plat_specific and EXEC_PREFIX or PREFIX
+
+    if os.name == "posix":
+        libpython = os.path.join(prefix,
+                                 "lib", "python" + get_python_version())
+        if standard_lib:
+            return libpython
+        else:
+            return os.path.join(libpython, "site-packages")
+    elif os.name == "nt":
+        if standard_lib:
+            return os.path.join(prefix, "Lib")
         else:
-            vars['base'] = prefix
-    if standard_lib:
+            if get_python_version() < "2.2":
+                return prefix
+            else:
+                return os.path.join(prefix, "Lib", "site-packages")
+    elif os.name == "mac":
         if plat_specific:
-            return get_path('platstdlib', vars=vars)
+            if standard_lib:
+                return os.path.join(prefix, "Lib", "lib-dynload")
+            else:
+                return os.path.join(prefix, "Lib", "site-packages")
         else:
-            return get_path('stdlib', vars=vars)
+            if standard_lib:
+                return os.path.join(prefix, "Lib")
+            else:
+                return os.path.join(prefix, "Lib", "site-packages")
+    elif os.name == "os2":
+        if standard_lib:
+            return os.path.join(prefix, "Lib")
+        else:
+            return os.path.join(prefix, "Lib", "site-packages")
     else:
-        if plat_specific:
-            return get_path('platlib', vars=vars)
+        raise DistutilsPlatformError(
+            "I don't know where Python installs its library "
+            "on platform '%s'" % os.name)
+
+
+def customize_compiler(compiler):
+    """Do any platform-specific customization of a CCompiler instance.
+
+    Mainly needed on Unix, so we can plug in the information that
+    varies across Unices and is stored in Python's Makefile.
+    """
+    if compiler.compiler_type == "unix":
+        (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \
+            get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS',
+                            'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS')
+
+        if 'CC' in os.environ:
+            cc = os.environ['CC']
+        if 'CXX' in os.environ:
+            cxx = os.environ['CXX']
+        if 'LDSHARED' in os.environ:
+            ldshared = os.environ['LDSHARED']
+        if 'CPP' in os.environ:
+            cpp = os.environ['CPP']
         else:
-            return get_path('purelib', vars=vars)
+            cpp = cc + " -E"           # not always
+        if 'LDFLAGS' in os.environ:
+            ldshared = ldshared + ' ' + os.environ['LDFLAGS']
+        if 'CFLAGS' in os.environ:
+            cflags = opt + ' ' + os.environ['CFLAGS']
+            ldshared = ldshared + ' ' + os.environ['CFLAGS']
+        if 'CPPFLAGS' in os.environ:
+            cpp = cpp + ' ' + os.environ['CPPFLAGS']
+            cflags = cflags + ' ' + os.environ['CPPFLAGS']
+            ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
+        if 'AR' in os.environ:
+            ar = os.environ['AR']
+        if 'ARFLAGS' in os.environ:
+            archiver = ar + ' ' + os.environ['ARFLAGS']
+        else:
+            archiver = ar + ' ' + ar_flags
+
+        cc_cmd = cc + ' ' + cflags
+        compiler.set_executables(
+            preprocessor=cpp,
+            compiler=cc_cmd,
+            compiler_so=cc_cmd + ' ' + ccshared,
+            compiler_cxx=cxx,
+            linker_so=ldshared,
+            linker_exe=cc,
+            archiver=archiver)
+
+        compiler.shared_lib_extension = so_ext
+
+
+def get_config_h_filename():
+    """Return full pathname of installed pyconfig.h file."""
+    if python_build:
+        if os.name == "nt":
+            inc_dir = os.path.join(project_base, "PC")
+        else:
+            inc_dir = project_base
+    else:
+        inc_dir = get_python_inc(plat_specific=1)
+    if get_python_version() < '2.2':
+        config_h = 'config.h'
+    else:
+        # The name of the config.h file changed in 2.2
+        config_h = 'pyconfig.h'
+    return os.path.join(inc_dir, config_h)
+
 
 def get_makefile_filename():
-    """This function is deprecated.
+    """Return full pathname of installed Makefile from the Python build."""
+    if python_build:
+        return os.path.join(os.path.dirname(sys.executable), "Makefile")
+    lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
+    return os.path.join(lib_dir, "config", "Makefile")
+
+
+def parse_config_h(fp, g=None):
+    """Parse a config.h-style file.
 
-    Return full pathname of installed Makefile from the Python build.
+    A dictionary containing name/value pairs is returned.  If an
+    optional dictionary is passed in as the second argument, it is
+    used instead of a new dictionary.
     """
+    if g is None:
+        g = {}
+    define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
+    undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
+    #
+    while True:
+        line = fp.readline()
+        if not line:
+            break
+        m = define_rx.match(line)
+        if m:
+            n, v = m.group(1, 2)
+            try: v = int(v)
+            except ValueError: pass
+            g[n] = v
+        else:
+            m = undef_rx.match(line)
+            if m:
+                g[m.group(1)] = 0
+    return g
 
-    warn(_DEPRECATION_MSG % 'get_makefile_filename', DeprecationWarning)
-    return _sysconfig._get_makefile_filename()
 
 # Regexes needed for parsing Makefile (and similar syntaxes,
 # like old-style Setup files).
@@ -128,29 +264,114 @@
 _findvar2_rx = re.compile(r"\${([A-Za-z][A-Za-z0-9_]*)}")
 
 def parse_makefile(fn, g=None):
-    """This function is deprecated.
-
-    Parse a Makefile-style file.
+    """Parse a Makefile-style file.
 
     A dictionary containing name/value pairs is returned.  If an
     optional dictionary is passed in as the second argument, it is
     used instead of a new dictionary.
     """
-    warn(_DEPRECATION_MSG % 'parse_makefile', DeprecationWarning)
-    return _sysconfig._parse_makefile(fn, g)
+    from distutils.text_file import TextFile
+    fp = TextFile(fn, strip_comments=1, skip_blanks=1, join_lines=1)
+
+    if g is None:
+        g = {}
+    done = {}
+    notdone = {}
+
+    while True:
+        line = fp.readline()
+        if line is None: # eof
+            break
+        m = _variable_rx.match(line)
+        if m:
+            n, v = m.group(1, 2)
+            v = v.strip()
+            # `$$' is a literal `$' in make
+            tmpv = v.replace('$$', '')
+
+            if "$" in tmpv:
+                notdone[n] = v
+            else:
+                try:
+                    v = int(v)
+                except ValueError:
+                    # insert literal `$'
+                    done[n] = v.replace('$$', '$')
+                else:
+                    done[n] = v
+
+    # Variables with a 'PY_' prefix in the makefile. These need to
+    # be made available without that prefix through sysconfig.
+    # Special care is needed to ensure that variable expansion works, even
+    # if the expansion uses the name without a prefix.
+    renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
+
+    # do variable interpolation here
+    while notdone:
+        for name in list(notdone):
+            value = notdone[name]
+            m = _findvar1_rx.search(value) or _findvar2_rx.search(value)
+            if m:
+                n = m.group(1)
+                found = True
+                if n in done:
+                    item = str(done[n])
+                elif n in notdone:
+                    # get it on a subsequent round
+                    found = False
+                elif n in os.environ:
+                    # do it like make: fall back to environment
+                    item = os.environ[n]
+
+                elif n in renamed_variables:
+                    if name.startswith('PY_') and name[3:] in renamed_variables:
+                        item = ""
+
+                    elif 'PY_' + n in notdone:
+                        found = False
+
+                    else:
+                        item = str(done['PY_' + n])
+                else:
+                    done[n] = item = ""
+                if found:
+                    after = value[m.end():]
+                    value = value[:m.start()] + item + after
+                    if "$" in after:
+                        notdone[name] = value
+                    else:
+                        try: value = int(value)
+                        except ValueError:
+                            done[name] = value.strip()
+                        else:
+                            done[name] = value
+                        del notdone[name]
+
+                        if name.startswith('PY_') \
+                            and name[3:] in renamed_variables:
+
+                            name = name[3:]
+                            if name not in done:
+                                done[name] = value
+            else:
+                # bogus variable reference; just drop it since we can't deal
+                del notdone[name]
+
+    fp.close()
+
+    # save the results in the global dictionary
+    g.update(done)
+    return g
 
-def expand_makefile_vars(s, vars):
-    """This function is deprecated.
 
-    Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
+def expand_makefile_vars(s, vars):
+    """Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
     'string' according to 'vars' (a dictionary mapping variable names to
     values).  Variables not present in 'vars' are silently expanded to the
     empty string.  The variable values in 'vars' should not contain further
     variable expansions; if 'vars' is the output of 'parse_makefile()',
     you're fine.  Returns a variable-expanded version of 's'.
     """
-    warn('this function will be removed in then next version of Python',
-         DeprecationWarning)
 
     # This algorithm does multiple expansion, so if vars['foo'] contains
     # "${bar}", it will expand ${foo} to ${bar}, and then expand
@@ -166,3 +387,220 @@
         else:
             break
     return s
+
+
+_config_vars = None
+
+def _init_posix():
+    """Initialize the module as appropriate for POSIX systems."""
+    g = {}
+    # load the installed Makefile:
+    try:
+        filename = get_makefile_filename()
+        parse_makefile(filename, g)
+    except IOError as msg:
+        my_msg = "invalid Python installation: unable to open %s" % filename
+        if hasattr(msg, "strerror"):
+            my_msg = my_msg + " (%s)" % msg.strerror
+
+        raise DistutilsPlatformError(my_msg)
+
+    # load the installed pyconfig.h:
+    try:
+        filename = get_config_h_filename()
+        parse_config_h(io.open(filename), g)
+    except IOError as msg:
+        my_msg = "invalid Python installation: unable to open %s" % filename
+        if hasattr(msg, "strerror"):
+            my_msg = my_msg + " (%s)" % msg.strerror
+
+        raise DistutilsPlatformError(my_msg)
+
+    # On MacOSX we need to check the setting of the environment variable
+    # MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
+    # it needs to be compatible.
+    # If it isn't set we set it to the configure-time value
+    if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
+        cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
+        cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
+        if cur_target == '':
+            cur_target = cfg_target
+            os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
+        elif [int(x) for x in cfg_target.split('.')] > [int(x) for x in cur_target.split('.')]:
+            my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure'
+                % (cur_target, cfg_target))
+            raise DistutilsPlatformError(my_msg)
+
+    # On AIX, there are wrong paths to the linker scripts in the Makefile
+    # -- these paths are relative to the Python source, but when installed
+    # the scripts are in another directory.
+    if python_build:
+        g['LDSHARED'] = g['BLDSHARED']
+
+    elif get_python_version() < '2.1':
+        # The following two branches are for 1.5.2 compatibility.
+        if sys.platform == 'aix4':          # what about AIX 3.x ?
+            # Linker script is in the config directory, not in Modules as the
+            # Makefile says.
+            python_lib = get_python_lib(standard_lib=1)
+            ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
+            python_exp = os.path.join(python_lib, 'config', 'python.exp')
+
+            g['LDSHARED'] = "%s %s -bI:%s" % (ld_so_aix, g['CC'], python_exp)
+
+    global _config_vars
+    _config_vars = g
+
+
+def _init_nt():
+    """Initialize the module as appropriate for NT"""
+    g = {}
+    # set basic install directories
+    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
+    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
+
+    # XXX hmmm.. a normal install puts include files here
+    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
+
+    g['SO'] = '.pyd'
+    g['EXE'] = ".exe"
+    g['VERSION'] = get_python_version().replace(".", "")
+    g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
+
+    global _config_vars
+    _config_vars = g
+
+
+def _init_mac():
+    """Initialize the module as appropriate for Macintosh systems"""
+    g = {}
+    # set basic install directories
+    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
+    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
+
+    # XXX hmmm.. a normal install puts include files here
+    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
+
+    import MacOS
+    if not hasattr(MacOS, 'runtimemodel'):
+        g['SO'] = '.ppc.slb'
+    else:
+        g['SO'] = '.%s.slb' % MacOS.runtimemodel
+
+    # XXX are these used anywhere?
+    g['install_lib'] = os.path.join(EXEC_PREFIX, "Lib")
+    g['install_platlib'] = os.path.join(EXEC_PREFIX, "Mac", "Lib")
+
+    # These are used by the extension module build
+    g['srcdir'] = ':'
+    global _config_vars
+    _config_vars = g
+
+
+def _init_os2():
+    """Initialize the module as appropriate for OS/2"""
+    g = {}
+    # set basic install directories
+    g['LIBDEST'] = get_python_lib(plat_specific=0, standard_lib=1)
+    g['BINLIBDEST'] = get_python_lib(plat_specific=1, standard_lib=1)
+
+    # XXX hmmm.. a normal install puts include files here
+    g['INCLUDEPY'] = get_python_inc(plat_specific=0)
+
+    g['SO'] = '.pyd'
+    g['EXE'] = ".exe"
+
+    global _config_vars
+    _config_vars = g
+
+
+def get_config_vars(*args):
+    """With no arguments, return a dictionary of all configuration
+    variables relevant for the current platform.  Generally this includes
+    everything needed to build extensions and install both pure modules and
+    extensions.  On Unix, this means every variable defined in Python's
+    installed Makefile; on Windows and Mac OS it's a much smaller set.
+
+    With arguments, return a list of values that result from looking up
+    each argument in the configuration variable dictionary.
+    """
+    global _config_vars
+    if _config_vars is None:
+        func = globals().get("_init_" + os.name)
+        if func:
+            func()
+        else:
+            _config_vars = {}
+
+        # Normalized versions of prefix and exec_prefix are handy to have;
+        # in fact, these are the standard versions used most places in the
+        # Distutils.
+        _config_vars['prefix'] = PREFIX
+        _config_vars['exec_prefix'] = EXEC_PREFIX
+
+        # Convert srcdir into an absolute path if it appears necessary.
+        # Normally it is relative to the build directory.  However, during
+        # testing, for example, we might be running a non-installed python
+        # from a different directory.
+        if python_build and os.name == "posix":
+            base = os.path.dirname(os.path.abspath(sys.executable))
+            if (not os.path.isabs(_config_vars['srcdir']) and
+                base != os.getcwd()):
+                # srcdir is relative and we are not in the same directory
+                # as the executable. Assume executable is in the build
+                # directory and make srcdir absolute.
+                srcdir = os.path.join(base, _config_vars['srcdir'])
+                _config_vars['srcdir'] = os.path.normpath(srcdir)
+
+        if sys.platform == 'darwin':
+            kernel_version = os.uname()[2] # Kernel version (8.4.3)
+            major_version = int(kernel_version.split('.')[0])
+
+            if major_version < 8:
+                # On Mac OS X before 10.4, check if -arch and -isysroot
+                # are in CFLAGS or LDFLAGS and remove them if they are.
+                # This is needed when building extensions on a 10.3 system
+                # using a universal build of python.
+                for key in ('LDFLAGS', 'BASECFLAGS',
+                        # a number of derived variables. These need to be
+                        # patched up as well.
+                        'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
+                    flags = _config_vars[key]
+                    flags = re.sub('-arch\s+\w+\s', ' ', flags, re.ASCII)
+                    flags = re.sub('-isysroot [^ \t]*', ' ', flags)
+                    _config_vars[key] = flags
+
+            else:
+
+                # Allow the user to override the architecture flags using
+                # an environment variable.
+                # NOTE: This name was introduced by Apple in OSX 10.5 and
+                # is used by several scripting languages distributed with
+                # that OS release.
+
+                if 'ARCHFLAGS' in os.environ:
+                    arch = os.environ['ARCHFLAGS']
+                    for key in ('LDFLAGS', 'BASECFLAGS',
+                        # a number of derived variables. These need to be
+                        # patched up as well.
+                        'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
+
+                        flags = _config_vars[key]
+                        flags = re.sub('-arch\s+\w+\s', ' ', flags)
+                        flags = flags + ' ' + arch
+                        _config_vars[key] = flags
+
+    if args:
+        vals = []
+        for name in args:
+            vals.append(_config_vars.get(name))
+        return vals
+    else:
+        return _config_vars
+
+def get_config_var(name):
+    """Return the value of a single variable using the dictionary
+    returned by 'get_config_vars()'.  Equivalent to
+    get_config_vars().get(name)
+    """
+    return get_config_vars().get(name)

Modified: python/branches/import_unicode/Lib/distutils/tests/support.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/support.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/support.py	Fri Jul 30 01:19:37 2010
@@ -3,19 +3,11 @@
 import shutil
 import tempfile
 from copy import deepcopy
-import warnings
 
 from distutils import log
 from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
 from distutils.core import Distribution
 
-def capture_warnings(func):
-    def _capture_warnings(*args, **kw):
-        with warnings.catch_warnings():
-            warnings.simplefilter("ignore")
-            return func(*args, **kw)
-    return _capture_warnings
-
 class LoggingSilencer(object):
 
     def setUp(self):
@@ -63,8 +55,6 @@
         super().tearDown()
         while self.tempdirs:
             d = self.tempdirs.pop()
-            if not os.path.exists(d):
-                continue
             shutil.rmtree(d, os.name in ('nt', 'cygwin'))
 
     def mkdtemp(self):

Modified: python/branches/import_unicode/Lib/distutils/tests/test_archive_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_archive_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_archive_util.py	Fri Jul 30 01:19:37 2010
@@ -15,30 +15,15 @@
 from test.support import check_warnings
 
 try:
-    import grp
-    import pwd
-    UID_GID_SUPPORT = True
-except ImportError:
-    UID_GID_SUPPORT = False
-
-try:
     import zipfile
     ZIP_SUPPORT = True
 except ImportError:
     ZIP_SUPPORT = find_executable('zip')
 
-# some tests will fail if zlib is not available
-try:
-    import zlib
-except ImportError:
-    zlib = None
-
-
 class ArchiveUtilTestCase(support.TempdirManager,
                           support.LoggingSilencer,
                           unittest.TestCase):
 
-    @unittest.skipUnless(zlib, "requires zlib")
     def test_make_tarball(self):
         # creating something to tar
         tmpdir = self.mkdtemp()
@@ -49,7 +34,7 @@
 
         tmpdir2 = self.mkdtemp()
         unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
-                            "source and target should be on same drive")
+                            "Source and target should be on same drive")
 
         base_name = os.path.join(tmpdir2, 'archive')
 
@@ -99,7 +84,6 @@
         base_name = os.path.join(tmpdir2, 'archive')
         return tmpdir, tmpdir2, base_name
 
-    @unittest.skipUnless(zlib, "Requires zlib")
     @unittest.skipUnless(find_executable('tar') and find_executable('gzip'),
                          'Need the tar command to run')
     def test_tarfile_vs_tar(self):
@@ -185,7 +169,6 @@
         self.assertTrue(not os.path.exists(tarball))
         self.assertEquals(len(w.warnings), 1)
 
-    @unittest.skipUnless(zlib, "Requires zlib")
     @unittest.skipUnless(ZIP_SUPPORT, 'Need zip support to run')
     def test_make_zipfile(self):
         # creating something to tar
@@ -210,59 +193,6 @@
         base_name = os.path.join(tmpdir, 'archive')
         self.assertRaises(ValueError, make_archive, base_name, 'xxx')
 
-    @unittest.skipUnless(zlib, "Requires zlib")
-    def test_make_archive_owner_group(self):
-        # testing make_archive with owner and group, with various combinations
-        # this works even if there's not gid/uid support
-        if UID_GID_SUPPORT:
-            group = grp.getgrgid(0)[0]
-            owner = pwd.getpwuid(0)[0]
-        else:
-            group = owner = 'root'
-
-        base_dir, root_dir, base_name =  self._create_files()
-        base_name = os.path.join(self.mkdtemp() , 'archive')
-        res = make_archive(base_name, 'zip', root_dir, base_dir, owner=owner,
-                           group=group)
-        self.assertTrue(os.path.exists(res))
-
-        res = make_archive(base_name, 'zip', root_dir, base_dir)
-        self.assertTrue(os.path.exists(res))
-
-        res = make_archive(base_name, 'tar', root_dir, base_dir,
-                           owner=owner, group=group)
-        self.assertTrue(os.path.exists(res))
-
-        res = make_archive(base_name, 'tar', root_dir, base_dir,
-                           owner='kjhkjhkjg', group='oihohoh')
-        self.assertTrue(os.path.exists(res))
-
-    @unittest.skipUnless(zlib, "Requires zlib")
-    @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
-    def test_tarfile_root_owner(self):
-        tmpdir, tmpdir2, base_name =  self._create_files()
-        old_dir = os.getcwd()
-        os.chdir(tmpdir)
-        group = grp.getgrgid(0)[0]
-        owner = pwd.getpwuid(0)[0]
-        try:
-            archive_name = make_tarball(base_name, 'dist', compress=None,
-                                        owner=owner, group=group)
-        finally:
-            os.chdir(old_dir)
-
-        # check if the compressed tarball was created
-        self.assertTrue(os.path.exists(archive_name))
-
-        # now checks the rights
-        archive = tarfile.open(archive_name)
-        try:
-            for member in archive.getmembers():
-                self.assertEquals(member.uid, 0)
-                self.assertEquals(member.gid, 0)
-        finally:
-            archive.close()
-
     def test_make_archive_cwd(self):
         current_dir = os.getcwd()
         def _breaks(*args, **kw):

Modified: python/branches/import_unicode/Lib/distutils/tests/test_bdist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_bdist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_bdist.py	Fri Jul 30 01:19:37 2010
@@ -5,8 +5,6 @@
 import tempfile
 import shutil
 
-from test.support import run_unittest
-
 from distutils.core import Distribution
 from distutils.command.bdist import bdist
 from distutils.tests import support
@@ -42,4 +40,4 @@
     return unittest.makeSuite(BuildTestCase)
 
 if __name__ == '__main__':
-    run_unittest(test_suite())
+    test_support.run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_bdist_dumb.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_bdist_dumb.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_bdist_dumb.py	Fri Jul 30 01:19:37 2010
@@ -4,15 +4,6 @@
 import sys
 import os
 
-# zlib is not used here, but if it's not available
-# test_simple_built will fail
-try:
-    import zlib
-except ImportError:
-    zlib = None
-
-from test.support import run_unittest
-
 from distutils.core import Distribution
 from distutils.command.bdist_dumb import bdist_dumb
 from distutils.tests import support
@@ -42,7 +33,6 @@
         sys.argv[:] = self.old_sys_argv[1]
         super(BuildDumbTestCase, self).tearDown()
 
-    @unittest.skipUnless(zlib, "requires zlib")
     def test_simple_built(self):
 
         # let's create a simple package
@@ -83,23 +73,8 @@
         # now let's check what we have in the zip file
         # XXX to be done
 
-    def test_finalize_options(self):
-        pkg_dir, dist = self.create_dist()
-        os.chdir(pkg_dir)
-        cmd = bdist_dumb(dist)
-        self.assertEquals(cmd.bdist_dir, None)
-        cmd.finalize_options()
-
-        # bdist_dir is initialized to bdist_base/dumb if not set
-        base = cmd.get_finalized_command('bdist').bdist_base
-        self.assertEquals(cmd.bdist_dir, os.path.join(base, 'dumb'))
-
-        # the format is set to a default value depending on the os.name
-        default = cmd.default_format[os.name]
-        self.assertEquals(cmd.format, default)
-
 def test_suite():
     return unittest.makeSuite(BuildDumbTestCase)
 
 if __name__ == '__main__':
-    run_unittest(test_suite())
+    test_support.run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_bdist_rpm.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_bdist_rpm.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_bdist_rpm.py	Fri Jul 30 01:19:37 2010
@@ -6,8 +6,6 @@
 import tempfile
 import shutil
 
-from test.support import run_unittest
-
 from distutils.core import Distribution
 from distutils.command.bdist_rpm import bdist_rpm
 from distutils.tests import support
@@ -124,4 +122,4 @@
     return unittest.makeSuite(BuildRpmTestCase)
 
 if __name__ == '__main__':
-    run_unittest(test_suite())
+    test_support.run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_bdist_wininst.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_bdist_wininst.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_bdist_wininst.py	Fri Jul 30 01:19:37 2010
@@ -1,8 +1,6 @@
 """Tests for distutils.command.bdist_wininst."""
 import unittest
 
-from test.support import run_unittest
-
 from distutils.command.bdist_wininst import bdist_wininst
 from distutils.tests import support
 
@@ -29,4 +27,4 @@
     return unittest.makeSuite(BuildWinInstTestCase)
 
 if __name__ == '__main__':
-    run_unittest(test_suite())
+    test_support.run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_build_clib.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_build_clib.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_build_clib.py	Fri Jul 30 01:19:37 2010
@@ -120,7 +120,8 @@
         # before we run the command, we want to make sure
         # all commands are present on the system
         # by creating a compiler and checking its executables
-        from distutils.ccompiler import new_compiler, customize_compiler
+        from distutils.ccompiler import new_compiler
+        from distutils.sysconfig import customize_compiler
 
         compiler = new_compiler()
         customize_compiler(compiler)

Modified: python/branches/import_unicode/Lib/distutils/tests/test_build_ext.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_build_ext.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_build_ext.py	Fri Jul 30 01:19:37 2010
@@ -3,13 +3,10 @@
 import tempfile
 import shutil
 from io import StringIO
-import warnings
-from test.support import check_warnings
-from test.support import captured_stdout
 
 from distutils.core import Extension, Distribution
 from distutils.command.build_ext import build_ext
-import sysconfig
+from distutils import sysconfig
 from distutils.tests.support import TempdirManager
 from distutils.tests.support import LoggingSilencer
 from distutils.extension import Extension
@@ -25,23 +22,19 @@
 
 def _get_source_filename():
     srcdir = sysconfig.get_config_var('srcdir')
-    if srcdir is None:
-        return os.path.join(sysconfig.project_base, 'Modules', 'xxmodule.c')
     return os.path.join(srcdir, 'Modules', 'xxmodule.c')
 
-_XX_MODULE_PATH = _get_source_filename()
-
-class BuildExtTestCase(TempdirManager, LoggingSilencer, unittest.TestCase):
-
+class BuildExtTestCase(TempdirManager,
+                       LoggingSilencer,
+                       unittest.TestCase):
     def setUp(self):
         # Create a simple test environment
         # Note that we're making changes to sys.path
         super(BuildExtTestCase, self).setUp()
         self.tmp_dir = self.mkdtemp()
-        if os.path.exists(_XX_MODULE_PATH):
-            self.sys_path = sys.path[:]
-            sys.path.append(self.tmp_dir)
-            shutil.copy(_XX_MODULE_PATH, self.tmp_dir)
+        self.sys_path = sys.path, sys.path[:]
+        sys.path.append(self.tmp_dir)
+        shutil.copy(_get_source_filename(), self.tmp_dir)
         if sys.version > "2.6":
             import site
             self.old_user_base = site.USER_BASE
@@ -49,19 +42,6 @@
             from distutils.command import build_ext
             build_ext.USER_BASE = site.USER_BASE
 
-    def tearDown(self):
-        # Get everything back to normal
-        if os.path.exists(_XX_MODULE_PATH):
-            support.unload('xx')
-            sys.path[:] = self.sys_path
-            # XXX on Windows the test leaves a directory
-            # with xx module in TEMP
-        shutil.rmtree(self.tmp_dir, os.name == 'nt' or
-                                    sys.platform == 'cygwin')
-        super(BuildExtTestCase, self).tearDown()
-
-    @unittest.skipIf(not os.path.exists(_XX_MODULE_PATH),
-                     'xxmodule.c not found')
     def test_build_ext(self):
         global ALREADY_TESTED
         xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
@@ -104,23 +84,35 @@
         self.assertTrue(isinstance(xx.Null(), xx.Null))
         self.assertTrue(isinstance(xx.Str(), xx.Str))
 
+    def tearDown(self):
+        # Get everything back to normal
+        support.unload('xx')
+        sys.path = self.sys_path[0]
+        sys.path[:] = self.sys_path[1]
+        if sys.version > "2.6":
+            import site
+            site.USER_BASE = self.old_user_base
+            from distutils.command import build_ext
+            build_ext.USER_BASE = self.old_user_base
+        super(BuildExtTestCase, self).tearDown()
+
     def test_solaris_enable_shared(self):
         dist = Distribution({'name': 'xx'})
         cmd = build_ext(dist)
         old = sys.platform
 
         sys.platform = 'sunos' # fooling finalize_options
-        from sysconfig import _CONFIG_VARS
-        old_var = _CONFIG_VARS.get('Py_ENABLE_SHARED')
-        _CONFIG_VARS['Py_ENABLE_SHARED'] = 1
+        from distutils.sysconfig import  _config_vars
+        old_var = _config_vars.get('Py_ENABLE_SHARED')
+        _config_vars['Py_ENABLE_SHARED'] = 1
         try:
             cmd.ensure_finalized()
         finally:
             sys.platform = old
             if old_var is None:
-                del _CONFIG_VARS['Py_ENABLE_SHARED']
+                del _config_vars['Py_ENABLE_SHARED']
             else:
-                _CONFIG_VARS['Py_ENABLE_SHARED'] = old_var
+                _config_vars['Py_ENABLE_SHARED'] = old_var
 
         # make sure we get some library dirs under solaris
         self.assertTrue(len(cmd.library_dirs) > 0)
@@ -182,10 +174,11 @@
         cmd = build_ext(dist)
         cmd.finalize_options()
 
-        py_include = sysconfig.get_path('include')
+        from distutils import sysconfig
+        py_include = sysconfig.get_python_inc()
         self.assertTrue(py_include in cmd.include_dirs)
 
-        plat_py_include = sysconfig.get_path('platinclude')
+        plat_py_include = sysconfig.get_python_inc(plat_specific=1)
         self.assertTrue(plat_py_include in cmd.include_dirs)
 
         # make sure cmd.libraries is turned into a list
@@ -336,6 +329,7 @@
         self.assertEquals(so_dir, other_tmp_dir)
 
         cmd.inplace = 0
+        cmd.compiler = None
         cmd.run()
         so_file = cmd.get_outputs()[0]
         self.assertTrue(os.path.exists(so_file))
@@ -404,26 +398,6 @@
         wanted = os.path.join(curdir, 'twisted', 'runner', 'portmap' + ext)
         self.assertEquals(wanted, path)
 
-    def test_compiler_deprecation_warning(self):
-        dist = Distribution()
-        cmd = build_ext(dist)
-
-        class MyCompiler(object):
-            def do_something(self):
-                pass
-
-        with check_warnings() as w:
-            warnings.simplefilter("always")
-            cmd.compiler = MyCompiler()
-            self.assertEquals(len(w.warnings), 1)
-            cmd.compile = 'unix'
-            self.assertEquals(len(w.warnings), 1)
-            cmd.compiler = MyCompiler()
-            cmd.compiler.do_something()
-            # two more warnings genereated by the get
-            # and the set
-            self.assertEquals(len(w.warnings), 3)
-
 def test_suite():
     src = _get_source_filename()
     if not os.path.exists(src):

Modified: python/branches/import_unicode/Lib/distutils/tests/test_build_py.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_build_py.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_build_py.py	Fri Jul 30 01:19:37 2010
@@ -16,7 +16,7 @@
                       support.LoggingSilencer,
                       unittest.TestCase):
 
-    def _setup_package_data(self):
+    def test_package_data(self):
         sources = self.mkdtemp()
         f = open(os.path.join(sources, "__init__.py"), "w")
         f.write("# Pretend this is a package.")
@@ -52,18 +52,9 @@
         self.assertEqual(len(cmd.get_outputs()), 3)
         pkgdest = os.path.join(destination, "pkg")
         files = os.listdir(pkgdest)
-        return files
-
-    def test_package_data(self):
-        files = self._setup_package_data()
         self.assertTrue("__init__.py" in files)
-        self.assertTrue("README.txt" in files)
-
-    @unittest.skipIf(sys.flags.optimize >= 2,
-                     "pyc files are not written with -O2 and above")
-    def test_package_data_pyc(self):
-        files = self._setup_package_data()
         self.assertTrue("__init__.pyc" in files)
+        self.assertTrue("README.txt" in files)
 
     def test_empty_package_dir (self):
         # See SF 1668596/1720897.

Modified: python/branches/import_unicode/Lib/distutils/tests/test_build_scripts.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_build_scripts.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_build_scripts.py	Fri Jul 30 01:19:37 2010
@@ -5,7 +5,7 @@
 
 from distutils.command.build_scripts import build_scripts
 from distutils.core import Distribution
-import sysconfig
+from distutils import sysconfig
 
 from distutils.tests import support
 
@@ -91,12 +91,12 @@
         # --with-suffix=3`, python is compiled okay but the build scripts
         # failed when writing the name of the executable
         old = sysconfig.get_config_vars().get('VERSION')
-        sysconfig._CONFIG_VARS['VERSION'] = 4
+        sysconfig._config_vars['VERSION'] = 4
         try:
             cmd.run()
         finally:
             if old is not None:
-                sysconfig._CONFIG_VARS['VERSION'] = old
+                sysconfig._config_vars['VERSION'] = old
 
         built = os.listdir(target)
         for name in expected:

Deleted: python/branches/import_unicode/Lib/distutils/tests/test_ccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_ccompiler.py	Fri Jul 30 01:19:37 2010
+++ (empty file)
@@ -1,81 +0,0 @@
-"""Tests for distutils.ccompiler."""
-import os
-import unittest
-from test.support import captured_stdout
-
-from distutils.ccompiler import (gen_lib_options, CCompiler,
-                                 get_default_compiler, customize_compiler)
-from distutils import debug
-from distutils.tests import support
-
-class FakeCompiler(object):
-    def library_dir_option(self, dir):
-        return "-L" + dir
-
-    def runtime_library_dir_option(self, dir):
-        return ["-cool", "-R" + dir]
-
-    def find_library_file(self, dirs, lib, debug=0):
-        return 'found'
-
-    def library_option(self, lib):
-        return "-l" + lib
-
-class CCompilerTestCase(support.EnvironGuard, unittest.TestCase):
-
-    def test_gen_lib_options(self):
-        compiler = FakeCompiler()
-        libdirs = ['lib1', 'lib2']
-        runlibdirs = ['runlib1']
-        libs = [os.path.join('dir', 'name'), 'name2']
-
-        opts = gen_lib_options(compiler, libdirs, runlibdirs, libs)
-        wanted = ['-Llib1', '-Llib2', '-cool', '-Rrunlib1', 'found',
-                  '-lname2']
-        self.assertEquals(opts, wanted)
-
-    def test_debug_print(self):
-
-        class MyCCompiler(CCompiler):
-            executables = {}
-
-        compiler = MyCCompiler()
-        with captured_stdout() as stdout:
-            compiler.debug_print('xxx')
-        stdout.seek(0)
-        self.assertEquals(stdout.read(), '')
-
-        debug.DEBUG = True
-        try:
-            with captured_stdout() as stdout:
-                compiler.debug_print('xxx')
-            stdout.seek(0)
-            self.assertEquals(stdout.read(), 'xxx\n')
-        finally:
-            debug.DEBUG = False
-
-    def test_customize_compiler(self):
-
-        # not testing if default compiler is not unix
-        if get_default_compiler() != 'unix':
-            return
-
-        os.environ['AR'] = 'my_ar'
-        os.environ['ARFLAGS'] = '-arflags'
-
-        # make sure AR gets caught
-        class compiler:
-            compiler_type = 'unix'
-
-            def set_executables(self, **kw):
-                self.exes = kw
-
-        comp = compiler()
-        customize_compiler(comp)
-        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
-
-def test_suite():
-    return unittest.makeSuite(CCompilerTestCase)
-
-if __name__ == "__main__":
-    unittest.main(defaultTest="test_suite")

Modified: python/branches/import_unicode/Lib/distutils/tests/test_cmd.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_cmd.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_cmd.py	Fri Jul 30 01:19:37 2010
@@ -1,7 +1,7 @@
 """Tests for distutils.cmd."""
 import unittest
 import os
-from test.support import captured_stdout, run_unittest
+from test.support import captured_stdout
 
 from distutils.cmd import Command
 from distutils.dist import Distribution
@@ -124,4 +124,4 @@
     return unittest.makeSuite(CommandTestCase)
 
 if __name__ == '__main__':
-    run_unittest(test_suite())
+    test_support.run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_cygwinccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_cygwinccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_cygwinccompiler.py	Fri Jul 30 01:19:37 2010
@@ -2,21 +2,29 @@
 import unittest
 import sys
 import os
+from io import BytesIO
 import subprocess
-import warnings
-import sysconfig
-
-from test.support import check_warnings, run_unittest
-from test.support import captured_stdout
 
 from distutils import cygwinccompiler
 from distutils.cygwinccompiler import (CygwinCCompiler, check_config_h,
                                        CONFIG_H_OK, CONFIG_H_NOTOK,
                                        CONFIG_H_UNCERTAIN, get_versions,
-                                       get_msvcr, RE_VERSION)
-from distutils.util import get_compiler_versions
+                                       get_msvcr)
 from distutils.tests import support
 
+class FakePopen(object):
+    test_class = None
+
+    def __init__(self, cmd, shell, stdout):
+        self.cmd = cmd.split()[0]
+        exes = self.test_class._exes
+        if self.cmd in exes:
+            # issue #6438 in Python 3.x, Popen returns bytes
+            self.stdout = BytesIO(exes[self.cmd])
+        else:
+            self.stdout = os.popen(cmd, 'r')
+
+
 class CygwinCCompilerTestCase(support.TempdirManager,
                               unittest.TestCase):
 
@@ -24,17 +32,32 @@
         super(CygwinCCompilerTestCase, self).setUp()
         self.version = sys.version
         self.python_h = os.path.join(self.mkdtemp(), 'python.h')
+        from distutils import sysconfig
         self.old_get_config_h_filename = sysconfig.get_config_h_filename
         sysconfig.get_config_h_filename = self._get_config_h_filename
+        self.old_find_executable = cygwinccompiler.find_executable
+        cygwinccompiler.find_executable = self._find_executable
+        self._exes = {}
+        self.old_popen = cygwinccompiler.Popen
+        FakePopen.test_class = self
+        cygwinccompiler.Popen = FakePopen
 
     def tearDown(self):
         sys.version = self.version
+        from distutils import sysconfig
         sysconfig.get_config_h_filename = self.old_get_config_h_filename
+        cygwinccompiler.find_executable = self.old_find_executable
+        cygwinccompiler.Popen = self.old_popen
         super(CygwinCCompilerTestCase, self).tearDown()
 
     def _get_config_h_filename(self):
         return self.python_h
 
+    def _find_executable(self, name):
+        if name in self._exes:
+            return name
+        return None
+
     def test_check_config_h(self):
 
         # check_config_h looks for "GCC" in sys.version first
@@ -58,6 +81,40 @@
         self.write_file(self.python_h, 'xxx __GNUC__ xxx')
         self.assertEquals(check_config_h()[0], CONFIG_H_OK)
 
+    def test_get_versions(self):
+
+        # get_versions calls distutils.spawn.find_executable on
+        # 'gcc', 'ld' and 'dllwrap'
+        self.assertEquals(get_versions(), (None, None, None))
+
+        # Let's fake we have 'gcc' and it returns '3.4.5'
+        self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF'
+        res = get_versions()
+        self.assertEquals(str(res[0]), '3.4.5')
+
+        # and let's see what happens when the version
+        # doesn't match the regular expression
+        # (\d+\.\d+(\.\d+)*)
+        self._exes['gcc'] = b'very strange output'
+        res = get_versions()
+        self.assertEquals(res[0], None)
+
+        # same thing for ld
+        self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
+        res = get_versions()
+        self.assertEquals(str(res[1]), '2.17.50')
+        self._exes['ld'] = b'@(#)PROGRAM:ld  PROJECT:ld64-77'
+        res = get_versions()
+        self.assertEquals(res[1], None)
+
+        # and dllwrap
+        self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
+        res = get_versions()
+        self.assertEquals(str(res[2]), '2.17.50')
+        self._exes['dllwrap'] = b'Cheese Wrap'
+        res = get_versions()
+        self.assertEquals(res[2], None)
+
     def test_get_msvcr(self):
 
         # none
@@ -90,23 +147,8 @@
                        '[MSC v.1999 32 bits (Intel)]')
         self.assertRaises(ValueError, get_msvcr)
 
-
-    def test_get_version_deprecated(self):
-        with check_warnings() as w:
-            warnings.simplefilter("always")
-            # make sure get_compiler_versions and get_versions
-            # returns the same thing
-            self.assertEquals(get_compiler_versions(), get_versions())
-            # make sure using get_version() generated a warning
-            self.assertEquals(len(w.warnings), 1)
-            # make sure any usage of RE_VERSION will also
-            # generate a warning, but till works
-            version = RE_VERSION.search('1.2').group(1)
-            self.assertEquals(version, '1.2')
-            self.assertEquals(len(w.warnings), 2)
-
 def test_suite():
     return unittest.makeSuite(CygwinCCompilerTestCase)
 
 if __name__ == '__main__':
-    run_unittest(test_suite())
+    test_support.run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_dist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_dist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_dist.py	Fri Jul 30 01:19:37 2010
@@ -7,9 +7,8 @@
 import warnings
 import textwrap
 
-from distutils.dist import Distribution, fix_help_options, DistributionMetadata
+from distutils.dist import Distribution, fix_help_options
 from distutils.cmd import Command
-import distutils.dist
 
 from test.support import TESTFN, captured_stdout
 from distutils.tests import support
@@ -38,8 +37,7 @@
         return self._config_files
 
 
-class DistributionTestCase(support.TempdirManager,
-                           support.LoggingSilencer,
+class DistributionTestCase(support.LoggingSilencer,
                            support.EnvironGuard,
                            unittest.TestCase):
 
@@ -60,27 +58,6 @@
         d.parse_command_line()
         return d
 
-    def test_debug_mode(self):
-        with open(TESTFN, "w") as f:
-            f.write("[global]")
-            f.write("command_packages = foo.bar, splat")
-
-        files = [TESTFN]
-        sys.argv.append("build")
-
-        with captured_stdout() as stdout:
-            self.create_distribution(files)
-        stdout.seek(0)
-        self.assertEquals(stdout.read(), '')
-        distutils.dist.DEBUG = True
-        try:
-            with captured_stdout() as stdout:
-                self.create_distribution(files)
-            stdout.seek(0)
-            self.assertEquals(stdout.read(), '')
-        finally:
-            distutils.dist.DEBUG = False
-
     def test_command_packages_unspecified(self):
         sys.argv.append("build")
         d = self.create_distribution()
@@ -182,35 +159,6 @@
         kwargs = {'level': 'ok2'}
         self.assertRaises(ValueError, dist.announce, args, kwargs)
 
-    def test_find_config_files_disable(self):
-        # Ticket #1180: Allow user to disable their home config file.
-        temp_home = self.mkdtemp()
-        if os.name == 'posix':
-            user_filename = os.path.join(temp_home, ".pydistutils.cfg")
-        else:
-            user_filename = os.path.join(temp_home, "pydistutils.cfg")
-
-        with open(user_filename, 'w') as f:
-            f.write('[distutils]\n')
-
-        def _expander(path):
-            return temp_home
-
-        old_expander = os.path.expanduser
-        os.path.expanduser = _expander
-        try:
-            d = distutils.dist.Distribution()
-            all_files = d.find_config_files()
-
-            d = distutils.dist.Distribution(attrs={'script_args':
-                                            ['--no-user-cfg']})
-            files = d.find_config_files()
-        finally:
-            os.path.expanduser = old_expander
-
-        # make sure --no-user-cfg disables the user cfg file
-        self.assertEquals(len(all_files)-1, len(files))
-
 class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
                        unittest.TestCase):
 
@@ -364,38 +312,11 @@
                  "version": "1.0",
                  "long_description": long_desc}
 
-        dist = distutils.dist.Distribution(attrs)
+        dist = Distribution(attrs)
         meta = self.format_metadata(dist)
         meta = meta.replace('\n' + 8 * ' ', '\n')
         self.assertTrue(long_desc in meta)
 
-    def test_read_metadata(self):
-        attrs = {"name": "package",
-                 "version": "1.0",
-                 "long_description": "desc",
-                 "description": "xxx",
-                 "download_url": "http://example.com",
-                 "keywords": ['one', 'two'],
-                 "requires": ['foo']}
-
-        dist = Distribution(attrs)
-        metadata = dist.metadata
-
-        # write it then reloads it
-        PKG_INFO = io.StringIO()
-        metadata.write_pkg_file(PKG_INFO)
-        PKG_INFO.seek(0)
-        metadata.read_pkg_file(PKG_INFO)
-
-        self.assertEquals(metadata.name, "package")
-        self.assertEquals(metadata.version, "1.0")
-        self.assertEquals(metadata.description, "xxx")
-        self.assertEquals(metadata.download_url, 'http://example.com')
-        self.assertEquals(metadata.keywords, ['one', 'two'])
-        self.assertEquals(metadata.platforms, ['UNKNOWN'])
-        self.assertEquals(metadata.obsoletes, None)
-        self.assertEquals(metadata.requires, ['foo'])
-
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(DistributionTestCase))

Deleted: python/branches/import_unicode/Lib/distutils/tests/test_emxccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_emxccompiler.py	Fri Jul 30 01:19:37 2010
+++ (empty file)
@@ -1,33 +0,0 @@
-"""Tests for distutils.emxccompiler."""
-import unittest
-import sys
-import os
-import warnings
-
-from test.support import check_warnings, run_unittest
-from test.support import captured_stdout
-
-from distutils.emxccompiler import get_versions
-from distutils.util import get_compiler_versions
-from distutils.tests import support
-
-class EmxCCompilerTestCase(support.TempdirManager,
-                           unittest.TestCase):
-
-    def test_get_version_deprecated(self):
-        with check_warnings() as w:
-            warnings.simplefilter("always")
-            # make sure get_compiler_versions and get_versions
-            # returns the same gcc
-            gcc, ld, dllwrap = get_compiler_versions()
-            emx_gcc, emx_ld = get_versions()
-            self.assertEquals(gcc, emx_gcc)
-
-            # make sure using get_version() generated a warning
-            self.assertEquals(len(w.warnings), 1)
-
-def test_suite():
-    return unittest.makeSuite(EmxCCompilerTestCase)
-
-if __name__ == '__main__':
-    run_unittest(test_suite())

Modified: python/branches/import_unicode/Lib/distutils/tests/test_extension.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_extension.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_extension.py	Fri Jul 30 01:19:37 2010
@@ -1,16 +1,13 @@
 """Tests for distutils.extension."""
-import os
-import sys
 import unittest
+import os
 import warnings
 
 from test.support import check_warnings
 from distutils.extension import read_setup_file, Extension
-from distutils.tests.support import capture_warnings
 
 class ExtensionTestCase(unittest.TestCase):
 
-    @capture_warnings
     def test_read_setup_file(self):
         # trying to read a Setup file
         # (sample extracted from the PyGame project)
@@ -33,22 +30,16 @@
 
         self.assertEquals(names, wanted)
 
-    @unittest.skipIf(sys.flags.optimize >= 2,
-                     "Assertions are omitted with -O2 and above")
-    def test_extension_init_assertions(self):
-        # The first argument, which is the name, must be a string.
+    def test_extension_init(self):
+        # the first argument, which is the name, must be a string
         self.assertRaises(AssertionError, Extension, 1, [])
+        ext = Extension('name', [])
+        self.assertEquals(ext.name, 'name')
 
         # the second argument, which is the list of files, must
         # be a list of strings
         self.assertRaises(AssertionError, Extension, 'name', 'file')
         self.assertRaises(AssertionError, Extension, 'name', ['file', 1])
-
-    def test_extension_init(self):
-        ext = Extension('name', [])
-        self.assertEquals(ext.name, 'name')
-
-
         ext = Extension('name', ['file1', 'file2'])
         self.assertEquals(ext.sources, ['file1', 'file2'])
 

Modified: python/branches/import_unicode/Lib/distutils/tests/test_file_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_file_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_file_util.py	Fri Jul 30 01:19:37 2010
@@ -3,7 +3,7 @@
 import os
 import shutil
 
-from distutils.file_util import move_file, write_file, copy_file
+from distutils.file_util import move_file
 from distutils import log
 from distutils.tests import support
 
@@ -55,21 +55,6 @@
         wanted = ['moving %s -> %s' % (self.source, self.target_dir)]
         self.assertEquals(self._logs, wanted)
 
-    def test_write_file(self):
-        lines = ['a', 'b', 'c']
-        dir = self.mkdtemp()
-        foo = os.path.join(dir, 'foo')
-        write_file(foo, lines)
-        content = [line.strip() for line in open(foo).readlines()]
-        self.assertEquals(content, lines)
-
-    def test_copy_file(self):
-        src_dir = self.mkdtemp()
-        foo = os.path.join(src_dir, 'foo')
-        write_file(foo, 'content')
-        dst_dir = self.mkdtemp()
-        copy_file(foo, dst_dir)
-        self.assertTrue(os.path.exists(os.path.join(dst_dir, 'foo')))
 
 def test_suite():
     return unittest.makeSuite(FileUtilTestCase)

Modified: python/branches/import_unicode/Lib/distutils/tests/test_filelist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_filelist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_filelist.py	Fri Jul 30 01:19:37 2010
@@ -1,25 +1,10 @@
 """Tests for distutils.filelist."""
-from os.path import join
 import unittest
-from test.support import captured_stdout
 
 from distutils.filelist import glob_to_re, FileList
+from test.support import captured_stdout
 from distutils import debug
 
-MANIFEST_IN = """\
-include ok
-include xo
-exclude xo
-include foo.tmp
-global-include *.x
-global-include *.txt
-global-exclude *.tmp
-recursive-include f *.oo
-recursive-exclude global *.x
-graft dir
-prune dir3
-"""
-
 class FileListTestCase(unittest.TestCase):
 
     def test_glob_to_re(self):
@@ -34,34 +19,6 @@
         self.assertEquals(glob_to_re('foo????'), r'foo[^/][^/][^/][^/]\Z(?ms)')
         self.assertEquals(glob_to_re(r'foo\\??'), r'foo\\\\[^/][^/]\Z(?ms)')
 
-    def test_process_template_line(self):
-        # testing  all MANIFEST.in template patterns
-        file_list = FileList()
-
-        # simulated file list
-        file_list.allfiles = ['foo.tmp', 'ok', 'xo', 'four.txt',
-                              join('global', 'one.txt'),
-                              join('global', 'two.txt'),
-                              join('global', 'files.x'),
-                              join('global', 'here.tmp'),
-                              join('f', 'o', 'f.oo'),
-                              join('dir', 'graft-one'),
-                              join('dir', 'dir2', 'graft2'),
-                              join('dir3', 'ok'),
-                              join('dir3', 'sub', 'ok.txt')
-                              ]
-
-        for line in MANIFEST_IN.split('\n'):
-            if line.strip() == '':
-                continue
-            file_list.process_template_line(line)
-
-        wanted = ['ok', 'four.txt', join('global', 'one.txt'),
-                  join('global', 'two.txt'), join('f', 'o', 'f.oo'),
-                  join('dir', 'graft-one'), join('dir', 'dir2', 'graft2')]
-
-        self.assertEquals(file_list.files, wanted)
-
     def test_debug_print(self):
         file_list = FileList()
         with captured_stdout() as stdout:

Modified: python/branches/import_unicode/Lib/distutils/tests/test_install.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_install.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_install.py	Fri Jul 30 01:19:37 2010
@@ -5,14 +5,12 @@
 import sys
 import unittest
 import site
-import sysconfig
-from sysconfig import (get_scheme_names, _CONFIG_VARS, _INSTALL_SCHEMES,
-                       get_config_var, get_path)
 
 from test.support import captured_stdout
 
 from distutils.command.install import install
 from distutils.command import install as install_module
+from distutils.command.install import INSTALL_SCHEMES
 from distutils.core import Distribution
 from distutils.errors import DistutilsOptionError
 
@@ -38,23 +36,9 @@
             build_lib=os.path.join(builddir, "lib"),
             )
 
-
-
-        posix_prefix = _INSTALL_SCHEMES['posix_prefix']
-        old_posix_prefix = posix_prefix['platinclude']
-        posix_prefix['platinclude'] = \
-                '{platbase}/include/python{py_version_short}'
-
-        posix_home = _INSTALL_SCHEMES['posix_home']
-        old_posix_home = posix_home['platinclude']
-        posix_home['platinclude'] = '{base}/include/python'
-        try:
-            cmd = install(dist)
-            cmd.home = destination
-            cmd.ensure_finalized()
-        finally:
-            posix_home['platinclude'] = old_posix_home
-            posix_prefix['platinclude'] = old_posix_prefix
+        cmd = install(dist)
+        cmd.home = destination
+        cmd.ensure_finalized()
 
         self.assertEqual(cmd.install_base, destination)
         self.assertEqual(cmd.install_platbase, destination)
@@ -79,19 +63,18 @@
             return
 
         # preparing the environement for the test
-        self.old_user_base = get_config_var('userbase')
-        self.old_user_site = get_path('purelib', '%s_user' % os.name)
+        self.old_user_base = site.USER_BASE
+        self.old_user_site = site.USER_SITE
         self.tmpdir = self.mkdtemp()
         self.user_base = os.path.join(self.tmpdir, 'B')
         self.user_site = os.path.join(self.tmpdir, 'S')
-        _CONFIG_VARS['userbase'] = self.user_base
-        scheme = _INSTALL_SCHEMES['%s_user' % os.name]
-        scheme['purelib'] = self.user_site
+        site.USER_BASE = self.user_base
+        site.USER_SITE = self.user_site
+        install_module.USER_BASE = self.user_base
+        install_module.USER_SITE = self.user_site
 
         def _expanduser(path):
-            if path[0] == '~':
-                path = os.path.normpath(self.tmpdir) + path[1:]
-            return path
+            return self.tmpdir
         self.old_expand = os.path.expanduser
         os.path.expanduser = _expanduser
 
@@ -99,17 +82,19 @@
             # this is the actual test
             self._test_user_site()
         finally:
-            _CONFIG_VARS['userbase'] = self.old_user_base
-            scheme['purelib'] = self.old_user_site
+            site.USER_BASE = self.old_user_base
+            site.USER_SITE = self.old_user_site
+            install_module.USER_BASE = self.old_user_base
+            install_module.USER_SITE = self.old_user_site
             os.path.expanduser = self.old_expand
 
     def _test_user_site(self):
-        schemes = get_scheme_names()
-        for key in ('nt_user', 'posix_user', 'os2_home'):
-            self.assertTrue(key in schemes)
+        for key in ('nt_user', 'unix_user', 'os2_home'):
+            self.assertTrue(key in INSTALL_SCHEMES)
 
         dist = Distribution({'name': 'xx'})
         cmd = install(dist)
+
         # making sure the user option is there
         options = [name for name, short, lable in
                    cmd.user_options]
@@ -200,7 +185,7 @@
         with open(cmd.record) as f:
             self.assertEquals(len(f.readlines()), 1)
 
-    def _test_debug_mode(self):
+    def test_debug_mode(self):
         # this covers the code called when DEBUG is set
         old_logs_len = len(self.logs)
         install_module.DEBUG = True

Modified: python/branches/import_unicode/Lib/distutils/tests/test_install_lib.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_install_lib.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_install_lib.py	Fri Jul 30 01:19:37 2010
@@ -1,6 +1,6 @@
 """Tests for distutils.command.install_data."""
-import os
 import sys
+import os
 import unittest
 
 from distutils.command.install_lib import install_lib
@@ -31,7 +31,9 @@
         cmd.finalize_options()
         self.assertEquals(cmd.optimize, 2)
 
-    def _setup_byte_compile(self):
+    @unittest.skipUnless(not sys.dont_write_bytecode,
+                         'byte-compile not supported')
+    def test_byte_compile(self):
         pkg_dir, dist = self.create_dist()
         cmd = install_lib(dist)
         cmd.compile = cmd.optimize = 1
@@ -39,15 +41,8 @@
         f = os.path.join(pkg_dir, 'foo.py')
         self.write_file(f, '# python file')
         cmd.byte_compile([f])
-        return pkg_dir
-
-    @unittest.skipIf(sys.dont_write_bytecode, 'byte-compile not enabled')
-    def test_byte_compile(self):
-        pkg_dir = self._setup_byte_compile()
-        if sys.flags.optimize < 1:
-            self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
-        else:
-            self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
+        self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyc')))
+        self.assertTrue(os.path.exists(os.path.join(pkg_dir, 'foo.pyo')))
 
     def test_get_outputs(self):
         pkg_dir, dist = self.create_dist()

Modified: python/branches/import_unicode/Lib/distutils/tests/test_register.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_register.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_register.py	Fri Jul 30 01:19:37 2010
@@ -202,10 +202,10 @@
         self.assertRaises(DistutilsSetupError, cmd.run)
 
         # we don't test the reSt feature if docutils
-        # is not installed or we our on py3k
+        # is not installed
         try:
             import docutils
-        except Exception:
+        except ImportError:
             return
 
         # metadata are OK but long_description is broken

Modified: python/branches/import_unicode/Lib/distutils/tests/test_sdist.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_sdist.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_sdist.py	Fri Jul 30 01:19:37 2010
@@ -3,22 +3,6 @@
 import unittest
 import shutil
 import zipfile
-import tarfile
-
-# zlib is not used here, but if it's not available
-# the tests that use zipfile may fail
-try:
-    import zlib
-except ImportError:
-    zlib = None
-
-try:
-    import grp
-    import pwd
-    UID_GID_SUPPORT = True
-except ImportError:
-    UID_GID_SUPPORT = False
-
 from os.path import join
 import sys
 import tempfile
@@ -95,7 +79,6 @@
         cmd.warn = _warn
         return dist, cmd
 
-    @unittest.skipUnless(zlib, "requires zlib")
     def test_prune_file_list(self):
         # this test creates a package with some vcs dirs in it
         # and launch sdist to make sure they get pruned
@@ -137,7 +120,6 @@
         # making sure everything has been pruned correctly
         self.assertEquals(len(content), 4)
 
-    @unittest.skipUnless(zlib, "requires zlib")
     def test_make_distribution(self):
 
         # check if tar and gzip are installed
@@ -174,7 +156,6 @@
         self.assertEquals(result,
                 ['fake-1.0.tar', 'fake-1.0.tar.gz'])
 
-    @unittest.skipUnless(zlib, "requires zlib")
     def test_add_defaults(self):
 
         # http://bugs.python.org/issue2279
@@ -236,7 +217,6 @@
         manifest = open(join(self.tmp_dir, 'MANIFEST')).read()
         self.assertEquals(manifest, MANIFEST % {'sep': os.sep})
 
-    @unittest.skipUnless(zlib, "requires zlib")
     def test_metadata_check_option(self):
         # testing the `medata-check` option
         dist, cmd = self.get_cmd(metadata={})
@@ -296,55 +276,6 @@
         cmd.formats = 'supazipa'
         self.assertRaises(DistutilsOptionError, cmd.finalize_options)
 
-    @unittest.skipUnless(zlib, "requires zlib")
-    @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
-    def test_make_distribution_owner_group(self):
-
-        # check if tar and gzip are installed
-        if (find_executable('tar') is None or
-            find_executable('gzip') is None):
-            return
-
-        # now building a sdist
-        dist, cmd = self.get_cmd()
-
-        # creating a gztar and specifying the owner+group
-        cmd.formats = ['gztar']
-        cmd.owner = pwd.getpwuid(0)[0]
-        cmd.group = grp.getgrgid(0)[0]
-        cmd.ensure_finalized()
-        cmd.run()
-
-        # making sure we have the good rights
-        archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
-        archive = tarfile.open(archive_name)
-        try:
-            for member in archive.getmembers():
-                self.assertEquals(member.uid, 0)
-                self.assertEquals(member.gid, 0)
-        finally:
-            archive.close()
-
-        # building a sdist again
-        dist, cmd = self.get_cmd()
-
-        # creating a gztar
-        cmd.formats = ['gztar']
-        cmd.ensure_finalized()
-        cmd.run()
-
-        # making sure we have the good rights
-        archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz')
-        archive = tarfile.open(archive_name)
-
-        # note that we are not testing the group ownership here
-        # because, depending on the platforms and the container
-        # rights (see #7408)
-        try:
-            for member in archive.getmembers():
-                self.assertEquals(member.uid, os.getuid())
-        finally:
-            archive.close()
 
     def test_get_file_list(self):
         # make sure MANIFEST is recalculated

Modified: python/branches/import_unicode/Lib/distutils/tests/test_sysconfig.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_sysconfig.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_sysconfig.py	Fri Jul 30 01:19:37 2010
@@ -2,9 +2,9 @@
 import os
 import test
 import unittest
-import shutil
 
 from distutils import sysconfig
+from distutils.ccompiler import get_default_compiler
 from distutils.tests import support
 from test.support import TESTFN, run_unittest
 
@@ -26,7 +26,10 @@
         elif os.path.isdir(TESTFN):
             shutil.rmtree(TESTFN)
 
-    @support.capture_warnings
+    def test_get_config_h_filename(self):
+        config_h = sysconfig.get_config_h_filename()
+        self.assertTrue(os.path.isfile(config_h), config_h)
+
     def test_get_python_lib(self):
         lib_dir = sysconfig.get_python_lib()
         # XXX doesn't work on Linux when Python was never installed before
@@ -34,11 +37,7 @@
         # test for pythonxx.lib?
         self.assertNotEqual(sysconfig.get_python_lib(),
                             sysconfig.get_python_lib(prefix=TESTFN))
-        _sysconfig = __import__('sysconfig')
-        res = sysconfig.get_python_lib(True, True)
-        self.assertEquals(_sysconfig.get_path('platstdlib'), res)
 
-    @support.capture_warnings
     def test_get_python_inc(self):
         inc_dir = sysconfig.get_python_inc()
         # This is not much of a test.  We make sure Python.h exists
@@ -48,7 +47,31 @@
         python_h = os.path.join(inc_dir, "Python.h")
         self.assertTrue(os.path.isfile(python_h), python_h)
 
-    @support.capture_warnings
+    def test_get_config_vars(self):
+        cvars = sysconfig.get_config_vars()
+        self.assertTrue(isinstance(cvars, dict))
+        self.assertTrue(cvars)
+
+    def test_customize_compiler(self):
+
+        # not testing if default compiler is not unix
+        if get_default_compiler() != 'unix':
+            return
+
+        os.environ['AR'] = 'my_ar'
+        os.environ['ARFLAGS'] = '-arflags'
+
+        # make sure AR gets caught
+        class compiler:
+            compiler_type = 'unix'
+
+            def set_executables(self, **kw):
+                self.exes = kw
+
+        comp = compiler()
+        sysconfig.customize_compiler(comp)
+        self.assertEquals(comp.exes['archiver'], 'my_ar -arflags')
+
     def test_parse_makefile_base(self):
         self.makefile = TESTFN
         fd = open(self.makefile, 'w')
@@ -70,6 +93,15 @@
                               'OTHER': 'foo'})
 
 
+    def test_sysconfig_module(self):
+        import sysconfig as global_sysconfig
+        self.assertEquals(global_sysconfig.get_config_var('CFLAGS'), sysconfig.get_config_var('CFLAGS'))
+        self.assertEquals(global_sysconfig.get_config_var('LDFLAGS'), sysconfig.get_config_var('LDFLAGS'))
+        self.assertEquals(global_sysconfig.get_config_var('LDSHARED'),sysconfig.get_config_var('LDSHARED'))
+        self.assertEquals(global_sysconfig.get_config_var('CC'), sysconfig.get_config_var('CC'))
+
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(SysconfigTestCase))

Modified: python/branches/import_unicode/Lib/distutils/tests/test_unixccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_unixccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_unixccompiler.py	Fri Jul 30 01:19:37 2010
@@ -1,8 +1,8 @@
 """Tests for distutils.unixccompiler."""
 import sys
 import unittest
-import sysconfig
 
+from distutils import sysconfig
 from distutils.unixccompiler import UnixCCompiler
 
 class UnixCCompilerTestCase(unittest.TestCase):
@@ -114,14 +114,6 @@
         sysconfig.get_config_var = gcv
         self.assertEqual(self.cc.rpath_foo(), '-R/foo')
 
-        # AIX C/C++ linker
-        sys.platform = 'aix'
-        def gcv(v):
-            return 'xxx'
-        sysconfig.get_config_var = gcv
-        self.assertEqual(self.cc.rpath_foo(), '-blibpath:/foo')
-
-
 def test_suite():
     return unittest.makeSuite(UnixCCompilerTestCase)
 

Modified: python/branches/import_unicode/Lib/distutils/tests/test_upload.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_upload.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_upload.py	Fri Jul 30 01:19:37 2010
@@ -2,8 +2,8 @@
 import sys
 import os
 import unittest
+import http.client as httpclient
 
-from distutils.command import upload as upload_mod
 from distutils.command.upload import upload
 from distutils.core import Distribution
 
@@ -38,37 +38,48 @@
 [server1]
 username:me
 """
+class Response(object):
+    def __init__(self, status=200, reason='OK'):
+        self.status = status
+        self.reason = reason
 
-class FakeOpen(object):
+class FakeConnection(object):
 
-    def __init__(self, url):
-        self.url = url
-        if not isinstance(url, str):
-            self.req = url
-        else:
-            self.req = None
-        self.msg = 'OK'
+    def __init__(self):
+        self.requests = []
+        self.headers = []
+        self.body = ''
 
-    def getcode(self):
-        return 200
+    def __call__(self, netloc):
+        return self
 
+    def connect(self):
+        pass
+    endheaders = connect
+
+    def putrequest(self, method, url):
+        self.requests.append((method, url))
+
+    def putheader(self, name, value):
+        self.headers.append((name, value))
+
+    def send(self, body):
+        self.body = body
+
+    def getresponse(self):
+        return Response()
 
 class uploadTestCase(PyPIRCCommandTestCase):
 
     def setUp(self):
         super(uploadTestCase, self).setUp()
-        self.old_open = upload_mod.urlopen
-        upload_mod.urlopen = self._urlopen
-        self.last_open = None
+        self.old_class = httpclient.HTTPConnection
+        self.conn = httpclient.HTTPConnection = FakeConnection()
 
     def tearDown(self):
-        upload_mod.urlopen = self.old_open
+        httpclient.HTTPConnection = self.old_class
         super(uploadTestCase, self).tearDown()
 
-    def _urlopen(self, url):
-        self.last_open = FakeOpen(url)
-        return self.last_open
-
     def test_finalize_options(self):
 
         # new format
@@ -113,15 +124,13 @@
         cmd.run()
 
         # what did we send ?
-        headers = dict(self.last_open.req.headers)
+        headers = dict(self.conn.headers)
         self.assertEquals(headers['Content-length'], '2087')
         self.assertTrue(headers['Content-type'].startswith('multipart/form-data'))
-        self.assertEquals(self.last_open.req.get_method(), 'POST')
-        self.assertEquals(self.last_open.req.get_full_url(),
-                          'http://pypi.python.org/pypi')
-        self.assertTrue(b'xxx' in self.last_open.req.data)
-        auth = self.last_open.req.headers['Authorization']
-        self.assertFalse('\n' in auth)
+        self.assertFalse('\n' in headers['Authorization'])
+
+        self.assertEquals(self.conn.requests, [('POST', '/pypi')])
+        self.assert_((b'xxx') in self.conn.body)
 
 def test_suite():
     return unittest.makeSuite(uploadTestCase)

Modified: python/branches/import_unicode/Lib/distutils/tests/test_util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/tests/test_util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/tests/test_util.py	Fri Jul 30 01:19:37 2010
@@ -3,33 +3,15 @@
 import sys
 import unittest
 from copy import copy
-from io import BytesIO
-import subprocess
 
-from sysconfig import get_config_vars, get_platform
 from distutils.errors import DistutilsPlatformError, DistutilsByteCompileError
-from distutils.util import (convert_path, change_root,
+from distutils.util import (get_platform, convert_path, change_root,
                             check_environ, split_quoted, strtobool,
-                            rfc822_escape, get_compiler_versions,
-                            _find_exe_version, _MAC_OS_X_LD_VERSION,
-                            byte_compile)
-from distutils import util
+                            rfc822_escape, byte_compile)
+from distutils import util # used to patch _environ_checked
+from distutils.sysconfig import get_config_vars
+from distutils import sysconfig
 from distutils.tests import support
-from distutils.version import LooseVersion
-
-class FakePopen(object):
-    test_class = None
-    def __init__(self, cmd, shell, stdout, stderr):
-        self.cmd = cmd.split()[0]
-        exes = self.test_class._exes
-        if self.cmd not in exes:
-            # we don't want to call the system, returning an empty
-            # output so it doesn't match
-            self.stdout = BytesIO()
-            self.stderr = BytesIO()
-        else:
-            self.stdout = BytesIO(exes[self.cmd])
-            self.stderr = BytesIO()
 
 class UtilTestCase(support.EnvironGuard, unittest.TestCase):
 
@@ -43,7 +25,7 @@
         self.join = os.path.join
         self.isabs = os.path.isabs
         self.splitdrive = os.path.splitdrive
-        #self._config_vars = copy(sysconfig._config_vars)
+        self._config_vars = copy(sysconfig._config_vars)
 
         # patching os.uname
         if hasattr(os, 'uname'):
@@ -52,17 +34,8 @@
         else:
             self.uname = None
             self._uname = None
-        os.uname = self._get_uname
 
-        # patching POpen
-        self.old_find_executable = util.find_executable
-        util.find_executable = self._find_executable
-        self._exes = {}
-        self.old_popen = subprocess.Popen
-        self.old_stdout  = sys.stdout
-        self.old_stderr = sys.stderr
-        FakePopen.test_class = self
-        subprocess.Popen = FakePopen
+        os.uname = self._get_uname
 
     def tearDown(self):
         # getting back the environment
@@ -77,11 +50,7 @@
             os.uname = self.uname
         else:
             del os.uname
-        #sysconfig._config_vars = copy(self._config_vars)
-        util.find_executable = self.old_find_executable
-        subprocess.Popen = self.old_popen
-        sys.old_stdout  = self.old_stdout
-        sys.old_stderr = self.old_stderr
+        sysconfig._config_vars = copy(self._config_vars)
         super(UtilTestCase, self).tearDown()
 
     def _set_uname(self, uname):
@@ -91,11 +60,103 @@
         return self._uname
 
     def test_get_platform(self):
-        platform = util.get_platform()
-        self.assertEquals(platform, get_platform())
-        util.set_platform('MyOwnPlatform')
-        self.assertEquals('MyOwnPlatform', util.get_platform())
-        util.set_platform(platform)
+
+        # windows XP, 32bits
+        os.name = 'nt'
+        sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
+                       '[MSC v.1310 32 bit (Intel)]')
+        sys.platform = 'win32'
+        self.assertEquals(get_platform(), 'win32')
+
+        # windows XP, amd64
+        os.name = 'nt'
+        sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
+                       '[MSC v.1310 32 bit (Amd64)]')
+        sys.platform = 'win32'
+        self.assertEquals(get_platform(), 'win-amd64')
+
+        # windows XP, itanium
+        os.name = 'nt'
+        sys.version = ('2.4.4 (#71, Oct 18 2006, 08:34:43) '
+                       '[MSC v.1310 32 bit (Itanium)]')
+        sys.platform = 'win32'
+        self.assertEquals(get_platform(), 'win-ia64')
+
+        # macbook
+        os.name = 'posix'
+        sys.version = ('2.5 (r25:51918, Sep 19 2006, 08:49:13) '
+                       '\n[GCC 4.0.1 (Apple Computer, Inc. build 5341)]')
+        sys.platform = 'darwin'
+        self._set_uname(('Darwin', 'macziade', '8.11.1',
+                   ('Darwin Kernel Version 8.11.1: '
+                    'Wed Oct 10 18:23:28 PDT 2007; '
+                    'root:xnu-792.25.20~1/RELEASE_I386'), 'i386'))
+        os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.3'
+
+        get_config_vars()['CFLAGS'] = ('-fno-strict-aliasing -DNDEBUG -g '
+                                       '-fwrapv -O3 -Wall -Wstrict-prototypes')
+
+        cursize = sys.maxsize
+        sys.maxsize = (2 ** 31)-1
+        try:
+            self.assertEquals(get_platform(), 'macosx-10.3-i386')
+        finally:
+            sys.maxsize = cursize
+
+        # macbook with fat binaries (fat, universal or fat64)
+        os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.4'
+        get_config_vars()['CFLAGS'] = ('-arch ppc -arch i386 -isysroot '
+                                       '/Developer/SDKs/MacOSX10.4u.sdk  '
+                                       '-fno-strict-aliasing -fno-common '
+                                       '-dynamic -DNDEBUG -g -O3')
+
+        self.assertEquals(get_platform(), 'macosx-10.4-fat')
+
+        get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch i386 -isysroot '
+                                       '/Developer/SDKs/MacOSX10.4u.sdk  '
+                                       '-fno-strict-aliasing -fno-common '
+                                       '-dynamic -DNDEBUG -g -O3')
+
+        self.assertEquals(get_platform(), 'macosx-10.4-intel')
+
+        get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc -arch i386 -isysroot '
+                                       '/Developer/SDKs/MacOSX10.4u.sdk  '
+                                       '-fno-strict-aliasing -fno-common '
+                                       '-dynamic -DNDEBUG -g -O3')
+        self.assertEquals(get_platform(), 'macosx-10.4-fat3')
+
+        get_config_vars()['CFLAGS'] = ('-arch ppc64 -arch x86_64 -arch ppc -arch i386 -isysroot '
+                                       '/Developer/SDKs/MacOSX10.4u.sdk  '
+                                       '-fno-strict-aliasing -fno-common '
+                                       '-dynamic -DNDEBUG -g -O3')
+        self.assertEquals(get_platform(), 'macosx-10.4-universal')
+
+        get_config_vars()['CFLAGS'] = ('-arch x86_64 -arch ppc64 -isysroot '
+                                       '/Developer/SDKs/MacOSX10.4u.sdk  '
+                                       '-fno-strict-aliasing -fno-common '
+                                       '-dynamic -DNDEBUG -g -O3')
+
+        self.assertEquals(get_platform(), 'macosx-10.4-fat64')
+
+        for arch in ('ppc', 'i386', 'x86_64', 'ppc64'):
+            get_config_vars()['CFLAGS'] = ('-arch %s -isysroot '
+                                           '/Developer/SDKs/MacOSX10.4u.sdk  '
+                                           '-fno-strict-aliasing -fno-common '
+                                           '-dynamic -DNDEBUG -g -O3'%(arch,))
+
+            self.assertEquals(get_platform(), 'macosx-10.4-%s'%(arch,))
+
+        # linux debian sarge
+        os.name = 'posix'
+        sys.version = ('2.3.5 (#1, Jul  4 2007, 17:28:59) '
+                       '\n[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]')
+        sys.platform = 'linux2'
+        self._set_uname(('Linux', 'aglae', '2.6.21.1dedibox-r7',
+                    '#1 Mon Apr 30 17:25:38 CEST 2007', 'i686'))
+
+        self.assertEquals(get_platform(), 'linux-i686')
+
+        # XXX more platforms to tests here
 
     def test_convert_path(self):
         # linux/mac
@@ -199,70 +260,6 @@
                   'header%(8s)s') % {'8s': '\n'+8*' '}
         self.assertEquals(res, wanted)
 
-    def test_find_exe_version(self):
-        # the ld version scheme under MAC OS is:
-        #   ^@(#)PROGRAM:ld  PROJECT:ld64-VERSION
-        #
-        # where VERSION is a 2-digit number for major
-        # revisions. For instance under Leopard, it's
-        # currently 77
-        #
-        # Dots are used when branching is done.
-        #
-        # The SnowLeopard ld64 is currently 95.2.12
-
-        for output, version in ((b'@(#)PROGRAM:ld  PROJECT:ld64-77', '77'),
-                                (b'@(#)PROGRAM:ld  PROJECT:ld64-95.2.12',
-                                 '95.2.12')):
-            result = _MAC_OS_X_LD_VERSION.search(output)
-            self.assertEquals(result.group(1).decode(), version)
-
-    def _find_executable(self, name):
-        if name in self._exes:
-            return name
-        return None
-
-    def test_get_compiler_versions(self):
-        # get_versions calls distutils.spawn.find_executable on
-        # 'gcc', 'ld' and 'dllwrap'
-        self.assertEquals(get_compiler_versions(), (None, None, None))
-
-        # Let's fake we have 'gcc' and it returns '3.4.5'
-        self._exes['gcc'] = b'gcc (GCC) 3.4.5 (mingw special)\nFSF'
-        res = get_compiler_versions()
-        self.assertEquals(str(res[0]), '3.4.5')
-
-        # and let's see what happens when the version
-        # doesn't match the regular expression
-        # (\d+\.\d+(\.\d+)*)
-        self._exes['gcc'] = b'very strange output'
-        res = get_compiler_versions()
-        self.assertEquals(res[0], None)
-
-        # same thing for ld
-        if sys.platform != 'darwin':
-            self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
-            res = get_compiler_versions()
-            self.assertEquals(str(res[1]), '2.17.50')
-            self._exes['ld'] = b'@(#)PROGRAM:ld  PROJECT:ld64-77'
-            res = get_compiler_versions()
-            self.assertEquals(res[1], None)
-        else:
-            self._exes['ld'] = b'GNU ld version 2.17.50 20060824'
-            res = get_compiler_versions()
-            self.assertEquals(res[1], None)
-            self._exes['ld'] = b'@(#)PROGRAM:ld  PROJECT:ld64-77'
-            res = get_compiler_versions()
-            self.assertEquals(str(res[1]), '77')
-
-        # and dllwrap
-        self._exes['dllwrap'] = b'GNU dllwrap 2.17.50 20060824\nFSF'
-        res = get_compiler_versions()
-        self.assertEquals(str(res[2]), '2.17.50')
-        self._exes['dllwrap'] = b'Cheese Wrap'
-        res = get_compiler_versions()
-        self.assertEquals(res[2], None)
-
     def test_dont_write_bytecode(self):
         # makes sure byte_compile raise a DistutilsError
         # if sys.dont_write_bytecode is True

Modified: python/branches/import_unicode/Lib/distutils/text_file.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/text_file.py	(original)
+++ python/branches/import_unicode/Lib/distutils/text_file.py	Fri Jul 30 01:19:37 2010
@@ -6,8 +6,8 @@
 
 __revision__ = "$Id$"
 
-import sys
-import io
+import sys, os, io
+
 
 class TextFile:
     """Provides a file-like object that takes care of all the things you

Modified: python/branches/import_unicode/Lib/distutils/unixccompiler.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/unixccompiler.py	(original)
+++ python/branches/import_unicode/Lib/distutils/unixccompiler.py	Fri Jul 30 01:19:37 2010
@@ -17,6 +17,7 @@
 
 import os, sys, re
 
+from distutils import sysconfig
 from distutils.dep_util import newer
 from distutils.ccompiler import \
      CCompiler, gen_preprocess_options, gen_lib_options
@@ -24,7 +25,6 @@
      DistutilsExecError, CompileError, LibError, LinkError
 from distutils import log
 
-
 # XXX Things not currently handled:
 #   * optimization/debug/warning flags; we just use whatever's in Python's
 #     Makefile and live with it.  Is this adequate?  If not, we might
@@ -74,7 +74,7 @@
 
     if 'ARCHFLAGS' in os.environ and not stripArch:
         # User specified different -arch flags in the environ,
-        # see also the sysconfig
+        # see also distutils.sysconfig
         compiler_so = compiler_so + os.environ['ARCHFLAGS'].split()
 
     if stripSysroot:
@@ -281,9 +281,7 @@
         # this time, there's no way to determine this information from
         # the configuration data stored in the Python installation, so
         # we use this hack.
-        _sysconfig = __import__('sysconfig')
-
-        compiler = os.path.basename(_sysconfig.get_config_var("CC"))
+        compiler = os.path.basename(sysconfig.get_config_var("CC"))
         if sys.platform[:6] == "darwin":
             # MacOSX's linker doesn't understand the -R flag at all
             return "-L" + dir
@@ -293,24 +291,23 @@
             return ["+s", "-L" + dir]
         elif sys.platform[:7] == "irix646" or sys.platform[:6] == "osf1V5":
             return ["-rpath", dir]
-        elif self._is_gcc(compiler):
-            # gcc on non-GNU systems does not need -Wl, but can
-            # use it anyway.  Since distutils has always passed in
-            # -Wl whenever gcc was used in the past it is probably
-            # safest to keep doing so.
-            if _sysconfig.get_config_var("GNULD") == "yes":
-                # GNU ld needs an extra option to get a RUNPATH
-                # instead of just an RPATH.
-                return "-Wl,--enable-new-dtags,-R" + dir
-            else:
-                return "-Wl,-R" + dir
-        elif sys.platform[:3] == "aix":
-            return "-blibpath:" + dir
         else:
-            # No idea how --enable-new-dtags would be passed on to
-            # ld if this system was using GNU ld.  Don't know if a
-            # system like this even exists.
-            return "-R" + dir
+            if self._is_gcc(compiler):
+                # gcc on non-GNU systems does not need -Wl, but can
+                # use it anyway.  Since distutils has always passed in
+                # -Wl whenever gcc was used in the past it is probably
+                # safest to keep doing so.
+                if sysconfig.get_config_var("GNULD") == "yes":
+                    # GNU ld needs an extra option to get a RUNPATH
+                    # instead of just an RPATH.
+                    return "-Wl,--enable-new-dtags,-R" + dir
+                else:
+                    return "-Wl,-R" + dir
+            else:
+                # No idea how --enable-new-dtags would be passed on to
+                # ld if this system was using GNU ld.  Don't know if a
+                # system like this even exists.
+                return "-R" + dir
 
     def library_option(self, lib):
         return "-l" + lib
@@ -324,8 +321,7 @@
             # On OSX users can specify an alternate SDK using
             # '-isysroot', calculate the SDK root if it is specified
             # (and use it further on)
-            _sysconfig = __import__('sysconfig')
-            cflags = _sysconfig.get_config_var('CFLAGS')
+            cflags = sysconfig.get_config_var('CFLAGS')
             m = re.search(r'-isysroot\s+(\S+)', cflags)
             if m is None:
                 sysroot = '/'

Modified: python/branches/import_unicode/Lib/distutils/util.py
==============================================================================
--- python/branches/import_unicode/Lib/distutils/util.py	(original)
+++ python/branches/import_unicode/Lib/distutils/util.py	Fri Jul 30 01:19:37 2010
@@ -7,40 +7,182 @@
 __revision__ = "$Id$"
 
 import sys, os, string, re
-
 from distutils.errors import DistutilsPlatformError
 from distutils.dep_util import newer
-from distutils.spawn import spawn, find_executable
+from distutils.spawn import spawn
 from distutils import log
-from distutils.version import LooseVersion
 from distutils.errors import DistutilsByteCompileError
 
-_sysconfig = __import__('sysconfig')
-_PLATFORM = None
+def get_platform ():
+    """Return a string that identifies the current platform.  This is used
+    mainly to distinguish platform-specific build directories and
+    platform-specific built distributions.  Typically includes the OS name
+    and version and the architecture (as supplied by 'os.uname()'),
+    although the exact information included depends on the OS; eg. for IRIX
+    the architecture isn't particularly important (IRIX only runs on SGI
+    hardware), but for Linux the kernel version isn't particularly
+    important.
+
+    Examples of returned values:
+       linux-i586
+       linux-alpha (?)
+       solaris-2.6-sun4u
+       irix-5.3
+       irix64-6.2
+
+    Windows will return one of:
+       win-amd64 (64bit Windows on AMD64 (aka x86_64, Intel64, EM64T, etc)
+       win-ia64 (64bit Windows on Itanium)
+       win32 (all others - specifically, sys.platform is returned)
+
+    For other non-POSIX platforms, currently just returns 'sys.platform'.
+    """
+    if os.name == 'nt':
+        # sniff sys.version for architecture.
+        prefix = " bit ("
+        i = sys.version.find(prefix)
+        if i == -1:
+            return sys.platform
+        j = sys.version.find(")", i)
+        look = sys.version[i+len(prefix):j].lower()
+        if look == 'amd64':
+            return 'win-amd64'
+        if look == 'itanium':
+            return 'win-ia64'
+        return sys.platform
+
+    if os.name != "posix" or not hasattr(os, 'uname'):
+        # XXX what about the architecture? NT is Intel or Alpha,
+        # Mac OS is M68k or PPC, etc.
+        return sys.platform
+
+    # Try to distinguish various flavours of Unix
+
+    (osname, host, release, version, machine) = os.uname()
+
+    # Convert the OS name to lowercase, remove '/' characters
+    # (to accommodate BSD/OS), and translate spaces (for "Power Macintosh")
+    osname = osname.lower().replace('/', '')
+    machine = machine.replace(' ', '_')
+    machine = machine.replace('/', '-')
+
+    if osname[:5] == "linux":
+        # At least on Linux/Intel, 'machine' is the processor --
+        # i386, etc.
+        # XXX what about Alpha, SPARC, etc?
+        return  "%s-%s" % (osname, machine)
+    elif osname[:5] == "sunos":
+        if release[0] >= "5":           # SunOS 5 == Solaris 2
+            osname = "solaris"
+            release = "%d.%s" % (int(release[0]) - 3, release[2:])
+        # fall through to standard osname-release-machine representation
+    elif osname[:4] == "irix":              # could be "irix64"!
+        return "%s-%s" % (osname, release)
+    elif osname[:3] == "aix":
+        return "%s-%s.%s" % (osname, version, release)
+    elif osname[:6] == "cygwin":
+        osname = "cygwin"
+        rel_re = re.compile (r'[\d.]+', re.ASCII)
+        m = rel_re.match(release)
+        if m:
+            release = m.group()
+    elif osname[:6] == "darwin":
+        #
+        # For our purposes, we'll assume that the system version from
+        # distutils' perspective is what MACOSX_DEPLOYMENT_TARGET is set
+        # to. This makes the compatibility story a bit more sane because the
+        # machine is going to compile and link as if it were
+        # MACOSX_DEPLOYMENT_TARGET.
+        from distutils.sysconfig import get_config_vars
+        cfgvars = get_config_vars()
+
+        macver = os.environ.get('MACOSX_DEPLOYMENT_TARGET')
+        if not macver:
+            macver = cfgvars.get('MACOSX_DEPLOYMENT_TARGET')
+
+        if 1:
+            # Always calculate the release of the running machine,
+            # needed to determine if we can build fat binaries or not.
+
+            macrelease = macver
+            # Get the system version. Reading this plist is a documented
+            # way to get the system version (see the documentation for
+            # the Gestalt Manager)
+            try:
+                f = open('/System/Library/CoreServices/SystemVersion.plist')
+            except IOError:
+                # We're on a plain darwin box, fall back to the default
+                # behaviour.
+                pass
+            else:
+                m = re.search(
+                        r'<key>ProductUserVisibleVersion</key>\s*' +
+                        r'<string>(.*?)</string>', f.read())
+                f.close()
+                if m is not None:
+                    macrelease = '.'.join(m.group(1).split('.')[:2])
+                # else: fall back to the default behaviour
+
+        if not macver:
+            macver = macrelease
+
+        if macver:
+            from distutils.sysconfig import get_config_vars
+            release = macver
+            osname = "macosx"
+
+            if (macrelease + '.') >= '10.4.' and \
+                    '-arch' in get_config_vars().get('CFLAGS', '').strip():
+                # The universal build will build fat binaries, but not on
+                # systems before 10.4
+                #
+                # Try to detect 4-way universal builds, those have machine-type
+                # 'universal' instead of 'fat'.
+
+                machine = 'fat'
+                cflags = get_config_vars().get('CFLAGS')
+
+                archs = re.findall('-arch\s+(\S+)', cflags)
+                archs = tuple(sorted(set(archs)))
+
+                if len(archs) == 1:
+                    machine = archs[0]
+                elif archs == ('i386', 'ppc'):
+                    machine = 'fat'
+                elif archs == ('i386', 'x86_64'):
+                    machine = 'intel'
+                elif archs == ('i386', 'ppc', 'x86_64'):
+                    machine = 'fat3'
+                elif archs == ('ppc64', 'x86_64'):
+                    machine = 'fat64'
+                elif archs == ('i386', 'ppc', 'ppc64', 'x86_64'):
+                    machine = 'universal'
+                else:
+                    raise ValueError(
+                       "Don't know machine value for archs=%r"%(archs,))
 
-def get_platform():
-    """Return a string that identifies the current platform.
+            elif machine == 'i386':
+                # On OSX the machine type returned by uname is always the
+                # 32-bit variant, even if the executable architecture is
+                # the 64-bit variant
+                if sys.maxsize >= 2**32:
+                    machine = 'x86_64'
 
-    By default, will return the value returned by sysconfig.get_platform(),
-    but it can be changed by calling set_platform().
-    """
-    global _PLATFORM
-    if _PLATFORM is None:
-        _PLATFORM = _sysconfig.get_platform()
-    return _PLATFORM
+            elif machine in ('PowerPC', 'Power_Macintosh'):
+                # Pick a sane name for the PPC architecture.
+                machine = 'ppc'
 
-def set_platform(identifier):
-    """Sets the platform string identifier returned by get_platform().
+                # See 'i386' case
+                if sys.maxsize >= 2**32:
+                    machine = 'ppc64'
 
-    Note that this change doesn't impact the value returned by
-    sysconfig.get_platform() and is local to Distutils
-    """
-    global _PLATFORM
-    _PLATFORM = identifier
+    return "%s-%s-%s" % (osname, release, machine)
+
+# get_platform ()
 
-def convert_path(pathname):
-    """Return 'pathname' as a name that will work on the native filesystem.
 
+def convert_path (pathname):
+    """Return 'pathname' as a name that will work on the native filesystem,
     i.e. split it on '/' and put it back together again using the current
     directory separator.  Needed because filenames in the setup script are
     always supplied in Unix style, and have to be converted to the local
@@ -64,12 +206,12 @@
         return os.curdir
     return os.path.join(*paths)
 
+# convert_path ()
 
-def change_root(new_root, pathname):
-    """Return 'pathname' with 'new_root' prepended.
 
-    If 'pathname' is relative, this is equivalent to
-    "os.path.join(new_root,pathname)".
+def change_root (new_root, pathname):
+    """Return 'pathname' with 'new_root' prepended.  If 'pathname' is
+    relative, this is equivalent to "os.path.join(new_root,pathname)".
     Otherwise, it requires making 'pathname' relative and then joining the
     two, which is tricky on DOS/Windows and Mac OS.
     """
@@ -91,16 +233,23 @@
             path = path[1:]
         return os.path.join(new_root, path)
 
-    else:
-        raise DistutilsPlatformError("nothing known about "
-                                     "platform '%s'" % os.name)
+    elif os.name == 'mac':
+        if not os.path.isabs(pathname):
+            return os.path.join(new_root, pathname)
+        else:
+            # Chop off volume name from start of path
+            elements = pathname.split(":", 1)
+            pathname = ":" + elements[1]
+            return os.path.join(new_root, pathname)
 
-_environ_checked = 0
+    else:
+        raise DistutilsPlatformError("nothing known about platform '%s'" % os.name)
 
-def check_environ():
-    """Ensure that 'os.environ' has all the environment variables needed.
 
-    We guarantee that users can use in config files, command-line options,
+_environ_checked = 0
+def check_environ ():
+    """Ensure that 'os.environ' has all the environment variables we
+    guarantee that users can use in config files, command-line options,
     etc.  Currently this includes:
       HOME - user's home directory (Unix only)
       PLAT - description of the current platform, including hardware
@@ -115,14 +264,14 @@
         os.environ['HOME'] = pwd.getpwuid(os.getuid())[5]
 
     if 'PLAT' not in os.environ:
-        os.environ['PLAT'] = _sysconfig.get_platform()
+        os.environ['PLAT'] = get_platform()
 
     _environ_checked = 1
 
-def subst_vars(s, local_vars):
-    """Perform shell/Perl-style variable substitution on 'string'.
 
-    Every occurrence of '$' followed by a name is considered a variable, and
+def subst_vars (s, local_vars):
+    """Perform shell/Perl-style variable substitution on 'string'.  Every
+    occurrence of '$' followed by a name is considered a variable, and
     variable is substituted by the value found in the 'local_vars'
     dictionary, or in 'os.environ' if it's not in 'local_vars'.
     'os.environ' is first checked/augmented to guarantee that it contains
@@ -142,11 +291,12 @@
     except KeyError as var:
         raise ValueError("invalid variable '$%s'" % var)
 
-def grok_environment_error(exc, prefix="error: "):
-    """Generate a useful error message from an EnvironmentError.
+# subst_vars ()
+
 
-    This will generate an IOError or an OSError exception object.
-    Handles Python 1.5.1 and 1.5.2 styles, and
+def grok_environment_error (exc, prefix="error: "):
+    """Generate a useful error message from an EnvironmentError (IOError or
+    OSError) exception object.  Handles Python 1.5.1 and 1.5.2 styles, and
     does what it can to deal with exception objects that don't have a
     filename (which happens when the error is due to a two-file operation,
     such as 'rename()' or 'link()'.  Returns the error message as a string
@@ -165,20 +315,18 @@
 
     return error
 
+
 # Needed by 'split_quoted()'
 _wordchars_re = _squote_re = _dquote_re = None
-
 def _init_regex():
     global _wordchars_re, _squote_re, _dquote_re
     _wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
     _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
     _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
 
-def split_quoted(s):
+def split_quoted (s):
     """Split a string up according to Unix shell-like rules for quotes and
-    backslashes.
-
-    In short: words are delimited by spaces, as long as those
+    backslashes.  In short: words are delimited by spaces, as long as those
     spaces are not escaped by a backslash, or inside a quoted string.
     Single and double quotes are equivalent, and the quote characters can
     be backslash-escaped.  The backslash is stripped from any two-character
@@ -186,6 +334,7 @@
     characters are stripped from any quoted string.  Returns a list of
     words.
     """
+
     # This is a nice algorithm for splitting up a single string, since it
     # doesn't require character-by-character examination.  It was a little
     # bit of a brain-bender to get it working right, though...
@@ -233,12 +382,13 @@
 
     return words
 
+# split_quoted ()
 
-def execute(func, args, msg=None, verbose=0, dry_run=0):
-    """Perform some action that affects the outside world.
 
-    eg. by writing to the filesystem).  Such actions are special because
-    they are disabled by the 'dry_run' flag.  This method takes care of all
+def execute (func, args, msg=None, verbose=0, dry_run=0):
+    """Perform some action that affects the outside world (eg.  by
+    writing to the filesystem).  Such actions are special because they
+    are disabled by the 'dry_run' flag.  This method takes care of all
     that bureaucracy for you; all you have to do is supply the
     function to call and an argument tuple for it (to embody the
     "external action" being performed), and an optional message to
@@ -254,7 +404,7 @@
         func(*args)
 
 
-def strtobool(val):
+def strtobool (val):
     """Convert a string representation of truth to true (1) or false (0).
 
     True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
@@ -270,13 +420,15 @@
         raise ValueError("invalid truth value %r" % (val,))
 
 
-def byte_compile(py_files, optimize=0, force=0, prefix=None, base_dir=None,
-                  verbose=1, dry_run=0, direct=None):
+def byte_compile (py_files,
+                  optimize=0, force=0,
+                  prefix=None, base_dir=None,
+                  verbose=1, dry_run=0,
+                  direct=None):
     """Byte-compile a collection of Python source files to either .pyc
-    or .pyo files in the same directory.
-
-    'py_files' is a list of files to compile; any files that don't end in
-    ".py" are silently skipped. 'optimize' must be one of the following:
+    or .pyo files in the same directory.  'py_files' is a list of files
+    to compile; any files that don't end in ".py" are silently skipped.
+    'optimize' must be one of the following:
       0 - don't optimize (generate .pyc)
       1 - normal optimization (like "python -O")
       2 - extra optimization (like "python -OO")
@@ -392,8 +544,8 @@
             dfile = file
             if prefix:
                 if file[:len(prefix)] != prefix:
-                    raise ValueError("invalid prefix: filename %r doesn't "
-                                     "start with %r" % (file, prefix))
+                    raise ValueError("invalid prefix: filename %r doesn't start with %r"
+                           % (file, prefix))
                 dfile = dfile[len(prefix):]
             if base_dir:
                 dfile = os.path.join(base_dir, dfile)
@@ -408,8 +560,9 @@
                     log.debug("skipping byte-compilation of %s to %s",
                               file, cfile_base)
 
+# byte_compile ()
 
-def rfc822_escape(header):
+def rfc822_escape (header):
     """Return a version of the string escaped for inclusion in an
     RFC-822 header, by ensuring there are 8 spaces space after each newline.
     """
@@ -417,56 +570,6 @@
     sep = '\n' + 8 * ' '
     return sep.join(lines)
 
-_RE_VERSION = re.compile(b'(\d+\.\d+(\.\d+)*)')
-_MAC_OS_X_LD_VERSION = re.compile(b'^@\(#\)PROGRAM:ld  PROJECT:ld64-((\d+)(\.\d+)*)')
-
-def _find_ld_version():
-    """Finds the ld version. The version scheme differs under Mac OSX."""
-    if sys.platform == 'darwin':
-        return _find_exe_version('ld -v', _MAC_OS_X_LD_VERSION)
-    else:
-        return _find_exe_version('ld -v')
-
-def _find_exe_version(cmd, pattern=_RE_VERSION):
-    """Find the version of an executable by running `cmd` in the shell.
-
-    `pattern` is a compiled regular expression. If not provided, default
-    to _RE_VERSION. If the command is not found, or the output does not
-    match the mattern, returns None.
-    """
-    from subprocess import Popen, PIPE
-    executable = cmd.split()[0]
-    if find_executable(executable) is None:
-        return None
-    pipe = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
-    try:
-        stdout, stderr = pipe.stdout.read(), pipe.stderr.read()
-    finally:
-        pipe.stdout.close()
-        pipe.stderr.close()
-    # some commands like ld under MacOS X, will give the
-    # output in the stderr, rather than stdout.
-    if stdout != b'':
-        out_string = stdout
-    else:
-        out_string = stderr
-
-    result = pattern.search(out_string)
-    if result is None:
-        return None
-    return LooseVersion(result.group(1).decode())
-
-def get_compiler_versions():
-    """Returns a tuple providing the versions of gcc, ld and dllwrap
-
-    For each command, if a command is not found, None is returned.
-    Otherwise a LooseVersion instance is returned.
-    """
-    gcc = _find_exe_version('gcc -dumpversion')
-    ld = _find_ld_version()
-    dllwrap = _find_exe_version('dllwrap --version')
-    return gcc, ld, dllwrap
-
 # 2to3 support
 
 def run_2to3(files, fixer_names=None, options=None, explicit=None):

Modified: python/branches/import_unicode/Lib/email/base64mime.py
==============================================================================
--- python/branches/import_unicode/Lib/email/base64mime.py	(original)
+++ python/branches/import_unicode/Lib/email/base64mime.py	Fri Jul 30 01:19:37 2010
@@ -74,12 +74,12 @@
 
 
 def body_encode(s, maxlinelen=76, eol=NL):
-    """Encode a string with base64.
+    r"""Encode a string with base64.
 
     Each line will be wrapped at, at most, maxlinelen characters (defaults to
     76 characters).
 
-    Each line of encoded text will end with eol, which defaults to "\\n".  Set
+    Each line of encoded text will end with eol, which defaults to "\n".  Set
     this to "\r\n" if you will be using the result of this function directly
     in an email.
     """

Modified: python/branches/import_unicode/Lib/email/feedparser.py
==============================================================================
--- python/branches/import_unicode/Lib/email/feedparser.py	(original)
+++ python/branches/import_unicode/Lib/email/feedparser.py	Fri Jul 30 01:19:37 2010
@@ -104,6 +104,10 @@
         # data after the final RE.  In the case of a NL/CR terminated string,
         # this is the empty string.
         self._partial = parts.pop()
+        #GAN 29Mar09  bugs 1555570, 1721862  Confusion at 8K boundary ending with \r:
+        # is there a \n to follow later?
+        if not self._partial and parts and parts[-1].endswith('\r'):
+            self._partial = parts.pop(-2)+parts.pop()
         # parts is a list of strings, alternating between the line contents
         # and the eol character(s).  Gather up a list of lines after
         # re-attaching the newlines.

Modified: python/branches/import_unicode/Lib/email/message.py
==============================================================================
--- python/branches/import_unicode/Lib/email/message.py	(original)
+++ python/branches/import_unicode/Lib/email/message.py	Fri Jul 30 01:19:37 2010
@@ -198,17 +198,19 @@
             return None
         cte = self.get('content-transfer-encoding', '').lower()
         if cte == 'quoted-printable':
+            if isinstance(payload, str):
+                payload = payload.encode('ascii')
             return utils._qdecode(payload)
         elif cte == 'base64':
             try:
                 if isinstance(payload, str):
-                    payload = payload.encode('raw-unicode-escape')
+                    payload = payload.encode('ascii')
                 return base64.b64decode(payload)
             except binascii.Error:
                 # Incorrect padding
                 pass
         elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
-            in_file = BytesIO(payload.encode('raw-unicode-escape'))
+            in_file = BytesIO(payload.encode('ascii'))
             out_file = BytesIO()
             try:
                 uu.decode(in_file, out_file, quiet=True)

Modified: python/branches/import_unicode/Lib/email/test/test_email.py
==============================================================================
--- python/branches/import_unicode/Lib/email/test/test_email.py	(original)
+++ python/branches/import_unicode/Lib/email/test/test_email.py	Fri Jul 30 01:19:37 2010
@@ -2454,6 +2454,39 @@
 -Me
 """)
 
+    def test_pushCR_LF(self):
+        '''FeedParser BufferedSubFile.push() assumed it received complete
+           line endings.  A CR ending one push() followed by a LF starting
+           the next push() added an empty line.
+        '''
+        imt = [
+            ("a\r \n",  2),
+            ("b",       0),
+            ("c\n",     1),
+            ("",        0),
+            ("d\r\n",   1),
+            ("e\r",     0),
+            ("\nf",     1),
+            ("\r\n",    1),
+          ]
+        from email.feedparser import BufferedSubFile, NeedMoreData
+        bsf = BufferedSubFile()
+        om = []
+        nt = 0
+        for il, n in imt:
+            bsf.push(il)
+            nt += n
+            n1 = 0
+            while True:
+                ol = bsf.readline()
+                if ol == NeedMoreData:
+                    break
+                om.append(ol)
+                n1 += 1
+            self.assertTrue(n == n1)
+        self.assertTrue(len(om) == nt)
+        self.assertTrue(''.join([il for il, n in imt]) == ''.join(om))
+
 
 
 class TestParsers(TestEmailBase):

Modified: python/branches/import_unicode/Lib/fnmatch.py
==============================================================================
--- python/branches/import_unicode/Lib/fnmatch.py	(original)
+++ python/branches/import_unicode/Lib/fnmatch.py	Fri Jul 30 01:19:37 2010
@@ -9,13 +9,22 @@
 The function translate(PATTERN) returns a regular expression
 corresponding to PATTERN.  (It does not compile it.)
 """
-
+import os
+import posixpath
 import re
 
-__all__ = ["filter", "fnmatch","fnmatchcase","translate"]
+__all__ = ["filter", "fnmatch", "fnmatchcase", "purge", "translate"]
 
 _cache = {}  # Maps text patterns to compiled regexen.
 _cacheb = {}  # Ditto for bytes patterns.
+_MAXCACHE = 100  # Maximum size of caches.
+
+
+def purge():
+    """Clear the pattern cache."""
+    _cache.clear()
+    _cacheb.clear()
+
 
 def fnmatch(name, pat):
     """Test whether FILENAME matches PATTERN.
@@ -32,12 +41,11 @@
     if the operating system requires it.
     If you don't want this, use fnmatchcase(FILENAME, PATTERN).
     """
-
-    import os
     name = os.path.normcase(name)
     pat = os.path.normcase(pat)
     return fnmatchcase(name, pat)
 
+
 def _compile_pattern(pat):
     cache = _cacheb if isinstance(pat, bytes) else _cache
     regex = cache.get(pat)
@@ -48,12 +56,14 @@
             res = bytes(res_str, 'ISO-8859-1')
         else:
             res = translate(pat)
+        if len(cache) >= _MAXCACHE:
+            cache.clear()
         cache[pat] = regex = re.compile(res)
     return regex.match
 
+
 def filter(names, pat):
-    """Return the subset of the list NAMES that match PAT"""
-    import os,posixpath
+    """Return the subset of the list NAMES that match PAT."""
     result = []
     pat = os.path.normcase(pat)
     match = _compile_pattern(pat)
@@ -68,16 +78,17 @@
                 result.append(name)
     return result
 
+
 def fnmatchcase(name, pat):
     """Test whether FILENAME matches PATTERN, including case.
 
     This is a version of fnmatch() which doesn't case-normalize
     its arguments.
     """
-
     match = _compile_pattern(pat)
     return match(name) is not None
 
+
 def translate(pat):
     """Translate a shell PATTERN to a regular expression.
 

Modified: python/branches/import_unicode/Lib/getopt.py
==============================================================================
--- python/branches/import_unicode/Lib/getopt.py	(original)
+++ python/branches/import_unicode/Lib/getopt.py	Fri Jul 30 01:19:37 2010
@@ -156,7 +156,7 @@
             if not args:
                 raise GetoptError('option --%s requires argument' % opt, opt)
             optarg, args = args[0], args[1:]
-    elif optarg:
+    elif optarg is not None:
         raise GetoptError('option --%s must not have an argument' % opt, opt)
     opts.append(('--' + opt, optarg or ''))
     return opts, args

Modified: python/branches/import_unicode/Lib/http/client.py
==============================================================================
--- python/branches/import_unicode/Lib/http/client.py	(original)
+++ python/branches/import_unicode/Lib/http/client.py	Fri Jul 30 01:19:37 2010
@@ -734,11 +734,6 @@
             else:
                 raise NotConnected()
 
-        # send the data to the server. if we get a broken pipe, then close
-        # the socket. we want to reconnect when somebody tries to send again.
-        #
-        # NOTE: we DO propagate the error, though, because we cannot simply
-        #       ignore the error... the caller will know if they can retry.
         if self.debuglevel > 0:
             print("send:", repr(str))
         blocksize = 8192

Modified: python/branches/import_unicode/Lib/http/cookiejar.py
==============================================================================
--- python/branches/import_unicode/Lib/http/cookiejar.py	(original)
+++ python/branches/import_unicode/Lib/http/cookiejar.py	Fri Jul 30 01:19:37 2010
@@ -609,17 +609,14 @@
     return req_host, erhn
 
 def request_path(request):
-    """request-URI, as defined by RFC 2965."""
+    """Path component of request-URI, as defined by RFC 2965."""
     url = request.get_full_url()
-    path, parameters, query, frag = urllib.parse.urlparse(url)[2:]
-    if parameters:
-        path = "%s;%s" % (path, parameters)
-    path = escape_path(path)
-    req_path = urllib.parse.urlunparse(("", "", path, "", query, frag))
-    if not req_path.startswith("/"):
+    parts = urllib.parse.urlsplit(url)
+    path = escape_path(parts.path)
+    if not path.startswith("/"):
         # fix bad RFC 2396 absoluteURI
-        req_path = "/"+req_path
-    return req_path
+        path = "/" + path
+    return path
 
 def request_port(request):
     host = request.get_host()

Modified: python/branches/import_unicode/Lib/idlelib/PyShell.py
==============================================================================
--- python/branches/import_unicode/Lib/idlelib/PyShell.py	(original)
+++ python/branches/import_unicode/Lib/idlelib/PyShell.py	Fri Jul 30 01:19:37 2010
@@ -548,7 +548,7 @@
         This method is called from the subprocess, and by returning from this
         method we allow the subprocess to unblock.  After a bit the shell
         requests the subprocess to open the remote stack viewer which returns a
-        static object looking at the last exceptiopn.  It is queried through
+        static object looking at the last exception.  It is queried through
         the RPC mechanism.
 
         """

Modified: python/branches/import_unicode/Lib/importlib/test/benchmark.py
==============================================================================
--- python/branches/import_unicode/Lib/importlib/test/benchmark.py	(original)
+++ python/branches/import_unicode/Lib/importlib/test/benchmark.py	Fri Jul 30 01:19:37 2010
@@ -1,13 +1,16 @@
-"""Benchmark some basic import use-cases."""
-# XXX
-#    - Bench from source (turn off bytecode generation)
-#    - Bench from bytecode (remove existence of source)
-#    - Bench bytecode generation
-#    - Bench extensions
+"""Benchmark some basic import use-cases.
+
+The assumption is made that this benchmark is run in a fresh interpreter and
+thus has no external changes made to import-related attributes in sys.
+
+"""
 from . import util
 from .source import util as source_util
+import decimal
 import imp
 import importlib
+import os
+import py_compile
 import sys
 import timeit
 
@@ -30,9 +33,9 @@
             # One execution too far
             if total_time > seconds:
                 count -= 1
-        yield count
+        yield count // seconds
 
-def from_cache(repeat):
+def from_cache(seconds, repeat):
     """sys.modules"""
     name = '<benchmark import>'
     module = imp.new_module(name)
@@ -40,31 +43,117 @@
     module.__package__ = ''
     with util.uncache(name):
         sys.modules[name] = module
-        for result in bench(name, repeat=repeat):
+        for result in bench(name, repeat=repeat, seconds=seconds):
             yield result
 
 
-def builtin_mod(repeat):
+def builtin_mod(seconds, repeat):
     """Built-in module"""
     name = 'errno'
     if name in sys.modules:
         del sys.modules[name]
-    for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat):
+    # Relying on built-in importer being implicit.
+    for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
+                        seconds=seconds):
+        yield result
+
+
+def source_wo_bytecode(seconds, repeat):
+    """Source w/o bytecode: simple"""
+    sys.dont_write_bytecode = True
+    try:
+        name = '__importlib_test_benchmark__'
+        # Clears out sys.modules and puts an entry at the front of sys.path.
+        with source_util.create_modules(name) as mapping:
+            assert not os.path.exists(imp.cache_from_source(mapping[name]))
+            for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
+                                seconds=seconds):
+                yield result
+    finally:
+        sys.dont_write_bytecode = False
+
+
+def decimal_wo_bytecode(seconds, repeat):
+    """Source w/o bytecode: decimal"""
+    name = 'decimal'
+    decimal_bytecode = imp.cache_from_source(decimal.__file__)
+    if os.path.exists(decimal_bytecode):
+        os.unlink(decimal_bytecode)
+    sys.dont_write_bytecode = True
+    try:
+        for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
+                            seconds=seconds):
+            yield result
+    finally:
+        sys.dont_write_bytecode = False
+
+
+def source_writing_bytecode(seconds, repeat):
+    """Source writing bytecode: simple"""
+    assert not sys.dont_write_bytecode
+    name = '__importlib_test_benchmark__'
+    with source_util.create_modules(name) as mapping:
+        def cleanup():
+            sys.modules.pop(name)
+            os.unlink(imp.cache_from_source(mapping[name]))
+        for result in bench(name, cleanup, repeat=repeat, seconds=seconds):
+            assert not os.path.exists(imp.cache_from_source(mapping[name]))
+            yield result
+
+
+def decimal_writing_bytecode(seconds, repeat):
+    """Source writing bytecode: decimal"""
+    assert not sys.dont_write_bytecode
+    name = 'decimal'
+    def cleanup():
+        sys.modules.pop(name)
+        os.unlink(imp.cache_from_source(decimal.__file__))
+    for result in bench(name, cleanup, repeat=repeat, seconds=seconds):
+        yield result
+
+
+def source_using_bytecode(seconds, repeat):
+    """Bytecode w/ source: simple"""
+    name = '__importlib_test_benchmark__'
+    with source_util.create_modules(name) as mapping:
+        py_compile.compile(mapping[name])
+        assert os.path.exists(imp.cache_from_source(mapping[name]))
+        for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
+                            seconds=seconds):
+            yield result
+
+
+def decimal_using_bytecode(seconds, repeat):
+    """Bytecode w/ source: decimal"""
+    name = 'decimal'
+    py_compile.compile(decimal.__file__)
+    for result in bench(name, lambda: sys.modules.pop(name), repeat=repeat,
+                        seconds=seconds):
         yield result
 
 
-def main(import_, repeat=3):
+def main(import_):
     __builtins__.__import__ = import_
-    benchmarks = from_cache, builtin_mod
+    benchmarks = (from_cache, builtin_mod,
+                  source_using_bytecode, source_wo_bytecode,
+                  source_writing_bytecode,
+                  decimal_using_bytecode, decimal_writing_bytecode,
+                  decimal_wo_bytecode,)
+    seconds = 1
+    seconds_plural = 's' if seconds > 1 else ''
+    repeat = 3
+    header = "Measuring imports/second over {} second{}, best out of {}\n"
+    print(header.format(seconds, seconds_plural, repeat))
     for benchmark in benchmarks:
         print(benchmark.__doc__, "[", end=' ')
         sys.stdout.flush()
         results = []
-        for result in benchmark(repeat):
+        for result in benchmark(seconds=seconds, repeat=repeat):
             results.append(result)
             print(result, end=' ')
             sys.stdout.flush()
-        print("]", "best is", max(results))
+        assert not sys.dont_write_bytecode
+        print("]", "best is", format(max(results), ',d'))
 
 
 if __name__ == '__main__':
@@ -75,7 +164,7 @@
                         default=False, help="use the built-in __import__")
     options, args = parser.parse_args()
     if args:
-        raise RuntimeError("unrecognized args: {0}".format(args))
+        raise RuntimeError("unrecognized args: {}".format(args))
     import_ = __import__
     if not options.builtin:
         import_ = importlib.__import__

Modified: python/branches/import_unicode/Lib/json/encoder.py
==============================================================================
--- python/branches/import_unicode/Lib/json/encoder.py	(original)
+++ python/branches/import_unicode/Lib/json/encoder.py	Fri Jul 30 01:19:37 2010
@@ -397,7 +397,7 @@
             yield 'true'
         elif o is False:
             yield 'false'
-        elif isinstance(o, (int, int)):
+        elif isinstance(o, int):
             yield str(o)
         elif isinstance(o, float):
             yield _floatstr(o)

Modified: python/branches/import_unicode/Lib/json/tests/test_fail.py
==============================================================================
--- python/branches/import_unicode/Lib/json/tests/test_fail.py	(original)
+++ python/branches/import_unicode/Lib/json/tests/test_fail.py	Fri Jul 30 01:19:37 2010
@@ -74,3 +74,12 @@
                 pass
             else:
                 self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc))
+
+    def test_non_string_keys_dict(self):
+        data = {'a' : 1, (1, 2) : 2}
+
+        #This is for c encoder
+        self.assertRaises(TypeError, json.dumps, data)
+
+        #This is for python encoder
+        self.assertRaises(TypeError, json.dumps, data, indent=True)

Modified: python/branches/import_unicode/Lib/ntpath.py
==============================================================================
--- python/branches/import_unicode/Lib/ntpath.py	(original)
+++ python/branches/import_unicode/Lib/ntpath.py	Fri Jul 30 01:19:37 2010
@@ -275,7 +275,7 @@
     # set i to index beyond p's last slash
     i = len(p)
     while i and p[i-1] not in seps:
-        i = i - 1
+        i -= 1
     head, tail = p[:i], p[i:]  # now tail has no slashes
     # remove trailing slashes from head, unless it's all slashes
     head2 = head
@@ -366,7 +366,7 @@
         return path
     i, n = 1, len(path)
     while i < n and path[i] not in _get_bothseps(path):
-        i = i + 1
+        i += 1
 
     if 'HOME' in os.environ:
         userhome = os.environ['HOME']
@@ -435,21 +435,21 @@
             pathlen = len(path)
             try:
                 index = path.index(c)
-                res = res + c + path[:index + 1]
+                res += c + path[:index + 1]
             except ValueError:
-                res = res + path
+                res += path
                 index = pathlen - 1
         elif c == percent:  # variable or '%'
             if path[index + 1:index + 2] == percent:
-                res = res + c
-                index = index + 1
+                res += c
+                index += 1
             else:
                 path = path[index+1:]
                 pathlen = len(path)
                 try:
                     index = path.index(percent)
                 except ValueError:
-                    res = res + percent + path
+                    res += percent + path
                     index = pathlen - 1
                 else:
                     var = path[:index]
@@ -461,11 +461,11 @@
                         value = '%' + var + '%'
                     if isinstance(path, bytes):
                         value = value.encode('ascii')
-                    res = res + value
+                    res += value
         elif c == dollar:  # variable or '$$'
             if path[index + 1:index + 2] == dollar:
-                res = res + c
-                index = index + 1
+                res += c
+                index += 1
             elif path[index + 1:index + 2] == brace:
                 path = path[index+2:]
                 pathlen = len(path)
@@ -483,23 +483,23 @@
                         value = '${' + var + '}'
                     if isinstance(path, bytes):
                         value = value.encode('ascii')
-                    res = res + value
+                    res += value
                 except ValueError:
                     if isinstance(path, bytes):
-                        res = res + b'${' + path
+                        res += b'${' + path
                     else:
-                        res = res + '${' + path
+                        res += '${' + path
                     index = pathlen - 1
             else:
                 var = ''
-                index = index + 1
+                index += 1
                 c = path[index:index + 1]
                 while c and c in varchars:
                     if isinstance(path, bytes):
-                        var = var + c.decode('ascii')
+                        var += c.decode('ascii')
                     else:
-                        var = var + c
-                    index = index + 1
+                        var += c
+                    index += 1
                     c = path[index:index + 1]
                 if var in os.environ:
                     value = os.environ[var]
@@ -507,12 +507,12 @@
                     value = '$' + var
                 if isinstance(path, bytes):
                     value = value.encode('ascii')
-                res = res + value
+                res += value
                 if c:
-                    index = index - 1
+                    index -= 1
         else:
-            res = res + c
-        index = index + 1
+            res += c
+        index += 1
     return res
 
 
@@ -529,7 +529,7 @@
 
     # collapse initial backslashes
     if path.startswith(sep):
-        prefix = prefix + sep
+        prefix += sep
         path = path.lstrip(sep)
 
     comps = path.split(sep)

Modified: python/branches/import_unicode/Lib/os.py
==============================================================================
--- python/branches/import_unicode/Lib/os.py	(original)
+++ python/branches/import_unicode/Lib/os.py	Fri Jul 30 01:19:37 2010
@@ -446,7 +446,9 @@
         return len(self.data)
 
     def __repr__(self):
-        return 'environ({!r})'.format(self.data)
+        return 'environ({{{}}})'.format(', '.join(
+            ('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
+            for key, value in self.data.items())))
 
     def copy(self):
         return dict(self)
@@ -531,7 +533,8 @@
         The optional second argument can specify an alternate default.
         key, default and the result are bytes."""
         return environb.get(key, default)
-    __all__.append("getenvb")
+
+    __all__.extend(("environb", "getenvb"))
 
 def fsencode(value):
     """Encode value for use in the file system, environment variables

Deleted: python/branches/import_unicode/Lib/pdb.doc
==============================================================================
--- python/branches/import_unicode/Lib/pdb.doc	Fri Jul 30 01:19:37 2010
+++ (empty file)
@@ -1,202 +0,0 @@
-The Python Debugger Pdb
-=======================
-
-To use the debugger in its simplest form:
-
-        >>> import pdb
-        >>> pdb.run('<a statement>')
-
-The debugger's prompt is '(Pdb) '.  This will stop in the first
-function call in <a statement>.
-
-Alternatively, if a statement terminated with an unhandled exception,
-you can use pdb's post-mortem facility to inspect the contents of the
-traceback:
-
-        >>> <a statement>
-        <exception traceback>
-        >>> import pdb
-        >>> pdb.pm()
-
-The commands recognized by the debugger are listed in the next
-section.  Most can be abbreviated as indicated; e.g., h(elp) means
-that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel',
-nor as 'H' or 'Help' or 'HELP').  Optional arguments are enclosed in
-square brackets.
-
-A blank line repeats the previous command literally, except for
-'list', where it lists the next 11 lines.
-
-Commands that the debugger doesn't recognize are assumed to be Python
-statements and are executed in the context of the program being
-debugged.  Python statements can also be prefixed with an exclamation
-point ('!').  This is a powerful way to inspect the program being
-debugged; it is even possible to change variables.  When an exception
-occurs in such a statement, the exception name is printed but the
-debugger's state is not changed.
-
-The debugger supports aliases, which can save typing.  And aliases can
-have parameters (see the alias help entry) which allows one a certain
-level of adaptability to the context under examination.
-
-Multiple commands may be entered on a single line, separated by the
-pair ';;'.  No intelligence is applied to separating the commands; the
-input is split at the first ';;', even if it is in the middle of a
-quoted string.
-
-If a file ".pdbrc" exists in your home directory or in the current
-directory, it is read in and executed as if it had been typed at the
-debugger prompt.  This is particularly useful for aliases.  If both
-files exist, the one in the home directory is read first and aliases
-defined there can be overriden by the local file.
-
-Aside from aliases, the debugger is not directly programmable; but it
-is implemented as a class from which you can derive your own debugger
-class, which you can make as fancy as you like.
-
-
-Debugger commands
-=================
-
-h(elp)
-        Without argument, print the list of available commands.  With
-        a command name as argument, print help about that command
-        (this is currently not implemented).
-
-w(here)
-        Print a stack trace, with the most recent frame at the bottom.
-        An arrow indicates the "current frame", which determines the
-        context of most commands.
-
-d(own) [ count ]
-        Move the current frame count (default one) levels down in the
-        stack trace (to a newer frame).
-
-u(p) [ count ]
-        Move the current frame count (default one) levels up in the
-        stack trace (to an older frame).
-
-b(reak) [ ([filename:]lineno | function) [, condition] ]
-        With a filename:line number argument, set a break there.  If
-        filename is omitted, use the current file.  With a function
-        name, set a break at the first executable line of that
-        function.  Without argument, list all breaks.  Each breakpoint
-        is assigned a number to which all the other breakpoint
-        commands refer.
-
-        The condition argument, if present, is a string which must
-        evaluate to true in order for the breakpoint to be honored.
-
-tbreak [ ([filename:]lineno | function) [, condition] ]
-        Temporary breakpoint, which is removed automatically when it
-        is first hit.  The arguments are the same as break.
-
-cl(ear) [bpnumber [bpnumber ...] ]
-        With a space separated list of breakpoint numbers, clear those
-        breakpoints.  Without argument, clear all breaks (but first
-        ask confirmation).
-
-disable bpnumber [bpnumber ...]
-        Disables the breakpoints given as a space separated list of
-        breakpoint numbers.  Disabling a breakpoint means it cannot
-        cause the program to stop execution, but unlike clearing a
-        breakpoint, it remains in the list of breakpoints and can be
-        (re-)enabled.
-
-enable bpnumber [bpnumber ...]
-        Enables the breakpoints specified.
-
-ignore bpnumber count
-        Sets the ignore count for the given breakpoint number.  If
-        count is omitted, the ignore count is set to 0.  A breakpoint
-        becomes active when the ignore count is zero.  When non-zero,
-        the count is decremented each time the breakpoint is reached
-        and the breakpoint is not disabled and any associated
-        condition evaluates to true.
-
-condition bpnumber condition
-        condition is an expression which must evaluate to true before
-        the breakpoint is honored.  If condition is absent, any
-        existing condition is removed; i.e., the breakpoint is made
-        unconditional.
-
-s(tep)
-        Execute the current line, stop at the first possible occasion
-        (either in a function that is called or in the current function).
-
-n(ext)
-        Continue execution until the next line in the current function
-        is reached or it returns.
-
-unt(il)
-        Continue execution until the line with a number greater than the 
-        current one is reached or until the current frame returns.
-
-r(eturn)
-        Continue execution until the current function returns.
-
-run [args...]
-        Restart the debugged python program. If a string is supplied it is
-        splitted with "shlex", and the result is used as the new sys.argv.
-        History, breakpoints, actions and debugger options are preserved.
-        "restart" is an alias for "run".
-
-c(ont(inue))
-        Continue execution, only stop when a breakpoint is encountered.
-
-l(ist) [first [,last]]
-        List source code for the current file.
-        Without arguments, list 11 lines around the current line
-        or continue the previous listing.
-        With one argument, list 11 lines starting at that line.
-        With two arguments, list the given range;
-        if the second argument is less than the first, it is a count.
-
-a(rgs)
-        Print the argument list of the current function.
-
-p expression
-        Print the value of the expression.
-
-(!) statement
-        Execute the (one-line) statement in the context of the current
-        stack frame.  The exclamation point can be omitted unless the
-        first word of the statement resembles a debugger command.  To
-        assign to a global variable you must always prefix the command
-        with a 'global' command, e.g.:
-        (Pdb) global list_options; list_options = ['-l']
-        (Pdb)
-
-
-whatis arg
-         Prints the type of the argument.
-
-alias [name [command]]
-        Creates an alias called 'name' that executes 'command'.  The
-        command must *not* be enclosed in quotes.  Replaceable
-        parameters can be indicated by %1, %2, and so on, while %* is
-        replaced by all the parameters.  If no command is given, the
-        current alias for name is shown. If no name is given, all
-        aliases are listed.
-
-        Aliases may be nested and can contain anything that can be
-        legally typed at the pdb prompt.  Note!  You *can* override
-        internal pdb commands with aliases!  Those internal commands
-        are then hidden until the alias is removed.  Aliasing is
-        recursively applied to the first word of the command line; all
-        other words in the line are left alone.
-
-        As an example, here are two useful aliases (especially when
-        placed in the .pdbrc file):
-
-        #Print instance variables (usage "pi classInst")
-        alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]
-        #Print instance variables in self
-        alias ps pi self
-                
-unalias name
-        Deletes the specified alias.
-
-q(uit)
-        Quit from the debugger.
-        The program being executed is aborted.

Modified: python/branches/import_unicode/Lib/pdb.py
==============================================================================
--- python/branches/import_unicode/Lib/pdb.py	(original)
+++ python/branches/import_unicode/Lib/pdb.py	Fri Jul 30 01:19:37 2010
@@ -1,8 +1,217 @@
 #! /usr/bin/env python3
 
-"""A Python debugger."""
-
-# (See pdb.doc for documentation.)
+"""
+The Python Debugger Pdb
+=======================
+
+To use the debugger in its simplest form:
+
+        >>> import pdb
+        >>> pdb.run('<a statement>')
+
+The debugger's prompt is '(Pdb) '.  This will stop in the first
+function call in <a statement>.
+
+Alternatively, if a statement terminated with an unhandled exception,
+you can use pdb's post-mortem facility to inspect the contents of the
+traceback:
+
+        >>> <a statement>
+        <exception traceback>
+        >>> import pdb
+        >>> pdb.pm()
+
+The commands recognized by the debugger are listed in the next
+section.  Most can be abbreviated as indicated; e.g., h(elp) means
+that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel',
+nor as 'H' or 'Help' or 'HELP').  Optional arguments are enclosed in
+square brackets.  Alternatives in the command syntax are separated
+by a vertical bar (|).
+
+A blank line repeats the previous command literally, except for
+'list', where it lists the next 11 lines.
+
+Commands that the debugger doesn't recognize are assumed to be Python
+statements and are executed in the context of the program being
+debugged.  Python statements can also be prefixed with an exclamation
+point ('!').  This is a powerful way to inspect the program being
+debugged; it is even possible to change variables or call functions.
+When an exception occurs in such a statement, the exception name is
+printed but the debugger's state is not changed.
+
+The debugger supports aliases, which can save typing.  And aliases can
+have parameters (see the alias help entry) which allows one a certain
+level of adaptability to the context under examination.
+
+Multiple commands may be entered on a single line, separated by the
+pair ';;'.  No intelligence is applied to separating the commands; the
+input is split at the first ';;', even if it is in the middle of a
+quoted string.
+
+If a file ".pdbrc" exists in your home directory or in the current
+directory, it is read in and executed as if it had been typed at the
+debugger prompt.  This is particularly useful for aliases.  If both
+files exist, the one in the home directory is read first and aliases
+defined there can be overriden by the local file.
+
+Aside from aliases, the debugger is not directly programmable; but it
+is implemented as a class from which you can derive your own debugger
+class, which you can make as fancy as you like.
+
+
+Debugger commands
+=================
+
+h(elp)
+        Without argument, print the list of available commands.  With
+        a command name as argument, print help about that command.
+
+w(here)
+        Print a stack trace, with the most recent frame at the bottom.
+        An arrow indicates the "current frame", which determines the
+        context of most commands.
+
+d(own) [ count ]
+        Move the current frame count (default one) levels down in the
+        stack trace (to a newer frame).
+
+u(p) [ count ]
+        Move the current frame count (default one) levels up in the
+        stack trace (to an older frame).
+
+b(reak) [ ([filename:]lineno | function) [, condition] ]
+        With a filename:lineno argument, set a break there.  If
+        filename is omitted, use the current file.  With a function
+        name, set a break at the first executable line of that
+        function.  Without argument, list all breaks.  Each breakpoint
+        is assigned a number to which all the other breakpoint
+        commands refer.
+
+        The condition argument, if present, is a string which must
+        evaluate to true in order for the breakpoint to be honored.
+
+tbreak [ ([filename:]lineno | function) [, condition] ]
+        Temporary breakpoint, which is removed automatically when it
+        is first hit.  The arguments are the same as for break.
+
+cl(ear) [bpnumber [bpnumber ...] ]
+        With a space separated list of breakpoint numbers, clear those
+        breakpoints.  Without argument, clear all breaks (but first
+        ask confirmation).
+
+disable bpnumber [bpnumber ...]
+        Disable the breakpoints given as a space separated list of
+        breakpoint numbers.  Disabling a breakpoint means it cannot
+        cause the program to stop execution, but unlike clearing a
+        breakpoint, it remains in the list of breakpoints and can be
+        (re-)enabled.
+
+enable bpnumber [bpnumber ...]
+        Enable the breakpoints specified.
+
+ignore bpnumber [count]
+        Set the ignore count for the given breakpoint number.  If
+        count is omitted, the ignore count is set to 0.  A breakpoint
+        becomes active when the ignore count is zero.  When non-zero,
+        the count is decremented each time the breakpoint is reached
+        and the breakpoint is not disabled and any associated
+        condition evaluates to true.
+
+condition bpnumber [condition]
+        Set a new condition for the breakpoint, an expression which
+        must evaluate to true before the breakpoint is honored.  If
+        condition is absent, any existing condition is removed; i.e.,
+        the breakpoint is made unconditional.
+
+commands [bpnumber]
+        Specify a list of commands for the breakpoint.  Type a line
+        containing just 'end' to terminate the commands.  The commands
+        are executed when the breakpoint is hit.
+
+        With no breakpoint number argument, refers to the last
+        breakpoint set.
+
+s(tep)
+        Execute the current line, stop at the first possible occasion
+        (either in a function that is called or in the current
+        function).
+
+n(ext)
+        Continue execution until the next line in the current function
+        is reached or it returns.
+
+unt(il)
+        Continue execution until the line with a number greater than
+        the current one is reached or until the current frame returns.
+
+r(eturn)
+        Continue execution until the current function returns.
+
+run [args...]
+        Restart the debugged python program. If a string is supplied
+        it is splitted with "shlex", and the result is used as the new
+        sys.argv.  History, breakpoints, actions and debugger options
+        are preserved.  "restart" is an alias for "run".
+
+c(ont(inue))
+        Continue execution, only stop when a breakpoint is encountered.
+
+l(ist) [first [,last]]
+        List source code for the current file.
+        Without arguments, list 11 lines around the current line
+        or continue the previous listing.
+        With one argument, list 11 lines starting at that line.
+        With two arguments, list the given range;
+        if the second argument is less than the first, it is a count.
+
+a(rgs)
+        Print the argument list of the current function.
+
+p expression
+        Print the value of the expression.
+
+(!) statement
+        Execute the (one-line) statement in the context of the current
+        stack frame.  The exclamation point can be omitted unless the
+        first word of the statement resembles a debugger command.  To
+        assign to a global variable you must always prefix the command
+        with a 'global' command, e.g.:
+        (Pdb) global list_options; list_options = ['-l']
+        (Pdb)
+
+
+whatis arg
+        Print the type of the argument.
+
+alias [name [command]]
+        Creates an alias called 'name' that executes 'command'.  The
+        command must *not* be enclosed in quotes.  Replaceable
+        parameters can be indicated by %1, %2, and so on, while %* is
+        replaced by all the parameters.  If no command is given, the
+        current alias for name is shown. If no name is given, all
+        aliases are listed.
+
+        Aliases may be nested and can contain anything that can be
+        legally typed at the pdb prompt.  Note!  You *can* override
+        internal pdb commands with aliases!  Those internal commands
+        are then hidden until the alias is removed.  Aliasing is
+        recursively applied to the first word of the command line; all
+        other words in the line are left alone.
+
+        As an example, here are two useful aliases (especially when
+        placed in the .pdbrc file):
+
+        # Print instance variables (usage "pi classInst")
+        alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k]
+        # Print instance variables in self
+        alias ps pi self
+
+unalias name
+        Delete the specified alias.
+
+q(uit)
+        Quit from the debugger. The program being executed is aborted.
+"""
 
 import sys
 import linecache
@@ -905,7 +1114,7 @@
                                                      prompt_prefix), file=self.stdout)
 
 
-    # Help methods (derived from pdb.doc)
+    # Help methods (derived from docstring)
 
     def help_help(self):
         self.help_h()
@@ -914,7 +1123,7 @@
         print("""h(elp)
 Without argument, print the list of available commands.
 With a command name as argument, print help about that command
-"help pdb" pipes the full documentation file to the $PAGER
+"help pdb" shows the full pdb documentation
 "help exec" gives help on the ! command""", file=self.stdout)
 
     def help_where(self):
@@ -1281,15 +1490,8 @@
 
 # print help
 def help():
-    for dirname in sys.path:
-        fullname = os.path.join(dirname, 'pdb.doc')
-        if os.path.exists(fullname):
-            sts = os.system('${PAGER-more} '+fullname)
-            if sts: print('*** Pager exit status:', sts)
-            break
-    else:
-        print('Sorry, can\'t find the help file "pdb.doc"', end=' ')
-        print('along the Python search path')
+    import pydoc
+    pydoc.pager(__doc__)
 
 def main():
     if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):

Modified: python/branches/import_unicode/Lib/pickle.py
==============================================================================
--- python/branches/import_unicode/Lib/pickle.py	(original)
+++ python/branches/import_unicode/Lib/pickle.py	Fri Jul 30 01:19:37 2010
@@ -1034,19 +1034,15 @@
     def _instantiate(self, klass, k):
         args = tuple(self.stack[k+1:])
         del self.stack[k:]
-        instantiated = False
-        if (not args and
-                isinstance(klass, type) and
-                not hasattr(klass, "__getinitargs__")):
-            value = _EmptyClass()
-            value.__class__ = klass
-            instantiated = True
-        if not instantiated:
+        if (args or not isinstance(klass, type) or
+            hasattr(klass, "__getinitargs__")):
             try:
                 value = klass(*args)
             except TypeError as err:
                 raise TypeError("in constructor for %s: %s" %
                                 (klass.__name__, str(err)), sys.exc_info()[2])
+        else:
+            value = klass.__new__(klass)
         self.append(value)
 
     def load_inst(self):
@@ -1239,14 +1235,7 @@
         raise _Stop(value)
     dispatch[STOP[0]] = load_stop
 
-# Helper class for load_inst/load_obj
-
-class _EmptyClass:
-    pass
-
-# Encode/decode longs in linear time.
-
-import binascii as _binascii
+# Encode/decode longs.
 
 def encode_long(x):
     r"""Encode a long to a two's complement little-endian binary string.
@@ -1333,4 +1322,26 @@
     return doctest.testmod()
 
 if __name__ == "__main__":
-    _test()
+    import sys, argparse
+    parser = argparse.ArgumentParser(
+        description='display contents of the pickle files')
+    parser.add_argument(
+        'pickle_file', type=argparse.FileType('br'),
+        nargs='*', help='the pickle file')
+    parser.add_argument(
+        '-t', '--test', action='store_true',
+        help='run self-test suite')
+    parser.add_argument(
+        '-v', action='store_true',
+        help='run verbosely; only affects self-test run')
+    args = parser.parse_args()
+    if args.test:
+        _test()
+    else:
+        if not args.pickle_file:
+            parser.print_help()
+        else:
+            import pprint
+            for f in args.pickle_file:
+                obj = load(f)
+                pprint.pprint(obj)

Modified: python/branches/import_unicode/Lib/pickletools.py
==============================================================================
--- python/branches/import_unicode/Lib/pickletools.py	(original)
+++ python/branches/import_unicode/Lib/pickletools.py	Fri Jul 30 01:19:37 2010
@@ -733,7 +733,7 @@
 
 pyinteger_or_bool = StackObject(
                         name='int_or_bool',
-                        obtype=(int, int, bool),
+                        obtype=(int, bool),
                         doc="A Python integer object (short or long), or "
                             "a Python bool.")
 
@@ -1250,10 +1250,11 @@
       stack_before=[anyobject],
       stack_after=[pytuple],
       proto=2,
-      doc="""One-tuple.
+      doc="""Build a one-tuple out of the topmost item on the stack.
 
       This code pops one value off the stack and pushes a tuple of
-      length 1 whose one item is that value back onto it.  IOW:
+      length 1 whose one item is that value back onto it.  In other
+      words:
 
           stack[-1] = tuple(stack[-1:])
       """),
@@ -1264,10 +1265,11 @@
       stack_before=[anyobject, anyobject],
       stack_after=[pytuple],
       proto=2,
-      doc="""One-tuple.
+      doc="""Build a two-tuple out of the top two items on the stack.
 
-      This code pops two values off the stack and pushes a tuple
-      of length 2 whose items are those values back onto it.  IOW:
+      This code pops two values off the stack and pushes a tuple of
+      length 2 whose items are those values back onto it.  In other
+      words:
 
           stack[-2:] = [tuple(stack[-2:])]
       """),
@@ -1278,10 +1280,11 @@
       stack_before=[anyobject, anyobject, anyobject],
       stack_after=[pytuple],
       proto=2,
-      doc="""One-tuple.
+      doc="""Build a three-tuple out of the top three items on the stack.
 
-      This code pops three values off the stack and pushes a tuple
-      of length 3 whose items are those values back onto it.  IOW:
+      This code pops three values off the stack and pushes a tuple of
+      length 3 whose items are those values back onto it.  In other
+      words:
 
           stack[-3:] = [tuple(stack[-3:])]
       """),
@@ -1904,7 +1907,7 @@
 ##############################################################################
 # A symbolic pickle disassembler.
 
-def dis(pickle, out=None, memo=None, indentlevel=4):
+def dis(pickle, out=None, memo=None, indentlevel=4, annotate=0):
     """Produce a symbolic disassembly of a pickle.
 
     'pickle' is a file-like object, or string, containing a (at least one)
@@ -1920,9 +1923,15 @@
     to proceed across multiple pickles that were all created by the same
     pickler with the same memo.  Ordinarily you don't need to worry about this.
 
-    Optional arg indentlevel is the number of blanks by which to indent
+    Optional arg 'indentlevel' is the number of blanks by which to indent
     a new MARK level.  It defaults to 4.
 
+    Optional arg 'annotate' if nonzero instructs dis() to add short
+    description of the opcode on each line of disassembled output.
+    The value given to 'annotate' must be an integer and is used as a
+    hint for the column where annotation should start.  The default
+    value is 0, meaning no annotations.
+
     In addition to printing the disassembly, some sanity checks are made:
 
     + All embedded opcode arguments "make sense".
@@ -1950,6 +1959,7 @@
     markstack = []      # bytecode positions of MARK opcodes
     indentchunk = ' ' * indentlevel
     errormsg = None
+    annocol = annotate  # columnt hint for annotations
     for opcode, arg, pos in genops(pickle):
         if pos is not None:
             print("%5d:" % pos, end=' ', file=out)
@@ -2017,6 +2027,13 @@
                 line += ' ' + repr(arg)
             if markmsg:
                 line += ' ' + markmsg
+        if annotate:
+            line += ' ' * (annocol - len(line))
+            # make a mild effort to align annotations
+            annocol = len(line)
+            if annocol > 50:
+                annocol = annotate
+            line += ' ' + opcode.doc.split('\n', 1)[0]
         print(line, file=out)
 
         if errormsg:
@@ -2290,6 +2307,22 @@
    12: h    BINGET     1
    14: .    STOP
 highest protocol among opcodes = 2
+
+Try protocol 3 with annotations:
+
+>>> dis(pickle.dumps(T, 3), annotate=1)
+    0: \x80 PROTO      3 Protocol version indicator.
+    2: ]    EMPTY_LIST   Push an empty list.
+    3: q    BINPUT     0 Store the stack top into the memo.  The stack is not popped.
+    5: h    BINGET     0 Read an object from the memo and push it on the stack.
+    7: \x85 TUPLE1       Build a one-tuple out of the topmost item on the stack.
+    8: q    BINPUT     1 Store the stack top into the memo.  The stack is not popped.
+   10: a    APPEND       Append an object to a list.
+   11: 0    POP          Discard the top stack item, shrinking the stack by one item.
+   12: h    BINGET     1 Read an object from the memo and push it on the stack.
+   14: .    STOP         Stop the unpickling machine.
+highest protocol among opcodes = 2
+
 """
 
 _memo_test = r"""
@@ -2346,6 +2379,9 @@
         '-l', '--indentlevel', default=4, type=int,
         help='the number of blanks by which to indent a new MARK level')
     parser.add_argument(
+        '-a', '--annotate',  action='store_true',
+        help='annotate each line with a short opcode description')
+    parser.add_argument(
         '-p', '--preamble', default="==> {name} <==",
         help='if more than one pickle file is specified, print this before'
         ' each disassembly')
@@ -2359,14 +2395,15 @@
     if args.test:
         _test()
     else:
+        annotate = 30 if args.annotate else 0
         if not args.pickle_file:
             parser.print_help()
         elif len(args.pickle_file) == 1:
-            dis(args.pickle_file[0], args.output,
-                indentlevel=args.indentlevel)
+            dis(args.pickle_file[0], args.output, None,
+                args.indentlevel, annotate)
         else:
             memo = {} if args.memo else None
             for f in args.pickle_file:
                 preamble = args.preamble.format(name=f.name)
                 args.output.write(preamble + '\n')
-                dis(f, args.output, memo, args.indentlevel)
+                dis(f, args.output, memo, args.indentlevel, annotate)

Modified: python/branches/import_unicode/Lib/platform.py
==============================================================================
--- python/branches/import_unicode/Lib/platform.py	(original)
+++ python/branches/import_unicode/Lib/platform.py	Fri Jul 30 01:19:37 2010
@@ -724,27 +724,19 @@
 
     return hex(bcd)[2:]
 
-def mac_ver(release='',versioninfo=('','',''),machine=''):
-
-    """ Get MacOS version information and return it as tuple (release,
-        versioninfo, machine) with versioninfo being a tuple (version,
-        dev_stage, non_release_version).
-
-        Entries which cannot be determined are set to the paramter values
-        which default to ''. All tuple entries are strings.
-
+def _mac_ver_gestalt():
+    """
         Thanks to Mark R. Levinson for mailing documentation links and
         code examples for this function. Documentation for the
         gestalt() API is available online at:
 
            http://www.rgaros.nl/gestalt/
-
     """
     # Check whether the version info module is available
     try:
         import _gestalt
     except ImportError:
-        return release,versioninfo,machine
+        return None
     # Get the infos
     sysv, sysa = _mac_ver_lookup(('sysv','sysa'))
     # Decode the infos
@@ -768,6 +760,53 @@
         machine = {0x1: '68k',
                    0x2: 'PowerPC',
                    0xa: 'i386'}.get(sysa,'')
+
+    return release,versioninfo,machine
+
+def _mac_ver_xml():
+    fn = '/System/Library/CoreServices/SystemVersion.plist'
+    if not os.path.exists(fn):
+        return None
+
+    try:
+        import plistlib
+    except ImportError:
+        return None
+
+    pl = plistlib.readPlist(fn)
+    release = pl['ProductVersion']
+    versioninfo=('', '', '')
+    machine = os.uname()[4]
+    if machine == 'ppc':
+        # for compatibility with the gestalt based code
+        machine = 'PowerPC'
+
+    return release,versioninfo,machine
+
+
+def mac_ver(release='',versioninfo=('','',''),machine=''):
+
+    """ Get MacOS version information and return it as tuple (release,
+        versioninfo, machine) with versioninfo being a tuple (version,
+        dev_stage, non_release_version).
+
+        Entries which cannot be determined are set to the paramter values
+        which default to ''. All tuple entries are strings.
+    """
+
+    # First try reading the information from an XML file which should
+    # always be present
+    info = _mac_ver_xml()
+    if info is not None:
+        return info
+
+    # If that doesn't work for some reason fall back to reading the
+    # information using gestalt calls.
+    info = _mac_ver_gestalt()
+    if info is not None:
+        return info
+
+    # If that also doesn't work return the default values
     return release,versioninfo,machine
 
 def _java_getprop(name,default):

Modified: python/branches/import_unicode/Lib/re.py
==============================================================================
--- python/branches/import_unicode/Lib/re.py	(original)
+++ python/branches/import_unicode/Lib/re.py	Fri Jul 30 01:19:37 2010
@@ -254,7 +254,40 @@
 
 _pattern_type = type(sre_compile.compile("", 0))
 
-_MAXCACHE = 100
+_MAXCACHE = 500
+
+def _shrink_cache(cache_dict, max_length, divisor=5):
+    """Make room in the given cache.
+
+    Args:
+        cache_dict: The cache dictionary to modify.
+        max_length: Maximum # of entries in cache_dict before it is shrunk.
+        divisor: Cache will shrink to max_length - 1/divisor*max_length items.
+    """
+    # Toss out a fraction of the entries at random to make room for new ones.
+    # A random algorithm was chosen as opposed to simply cache_dict.popitem()
+    # as popitem could penalize the same regular expression repeatedly based
+    # on its internal hash value.  Being random should spread the cache miss
+    # love around.
+    cache_keys = tuple(cache_dict.keys())
+    overage = len(cache_keys) - max_length
+    if overage < 0:
+        # Cache is already within limits.  Normally this should not happen
+        # but it could due to multithreading.
+        return
+    number_to_toss = max_length // divisor + overage
+    # The import is done here to avoid a circular depencency.
+    import random
+    if not hasattr(random, 'sample'):
+        # Do nothing while resolving the circular dependency:
+        #  re->random->warnings->tokenize->string->re
+        return
+    for doomed_key in random.sample(cache_keys, number_to_toss):
+        try:
+            del cache_dict[doomed_key]
+        except KeyError:
+            # Ignore problems if the cache changed from another thread.
+            pass
 
 def _compile(*key):
     # internal: compile pattern
@@ -272,7 +305,7 @@
         raise TypeError("first argument must be string or compiled pattern")
     p = sre_compile.compile(pattern, flags)
     if len(_cache) >= _MAXCACHE:
-        _cache.clear()
+        _shrink_cache(_cache, _MAXCACHE)
     _cache[cachekey] = p
     return p
 
@@ -284,7 +317,7 @@
     repl, pattern = key
     p = sre_parse.parse_template(repl, pattern)
     if len(_cache_repl) >= _MAXCACHE:
-        _cache_repl.clear()
+        _shrink_cache(_cache_repl, _MAXCACHE)
     _cache_repl[key] = p
     return p
 

Modified: python/branches/import_unicode/Lib/smtpd.py
==============================================================================
--- python/branches/import_unicode/Lib/smtpd.py	(original)
+++ python/branches/import_unicode/Lib/smtpd.py	Fri Jul 30 01:19:37 2010
@@ -78,6 +78,7 @@
 import socket
 import asyncore
 import asynchat
+from warnings import warn
 
 __all__ = ["SMTPServer","DebuggingServer","PureProxy","MailmanProxy"]
 
@@ -111,35 +112,157 @@
 
     def __init__(self, server, conn, addr):
         asynchat.async_chat.__init__(self, conn)
-        self.__server = server
-        self.__conn = conn
-        self.__addr = addr
-        self.__line = []
-        self.__state = self.COMMAND
-        self.__greeting = 0
-        self.__mailfrom = None
-        self.__rcpttos = []
-        self.__data = ''
-        self.__fqdn = socket.getfqdn()
-        self.__peer = conn.getpeername()
-        print('Peer:', repr(self.__peer), file=DEBUGSTREAM)
-        self.push('220 %s %s' % (self.__fqdn, __version__))
+        self.smtp_server = server
+        self.conn = conn
+        self.addr = addr
+        self.received_lines = []
+        self.smtp_state = self.COMMAND
+        self.seen_greeting = ''
+        self.mailfrom = None
+        self.rcpttos = []
+        self.received_data = ''
+        self.fqdn = socket.getfqdn()
+        self.peer = conn.getpeername()
+        print('Peer:', repr(self.peer), file=DEBUGSTREAM)
+        self.push('220 %s %s' % (self.fqdn, __version__))
         self.set_terminator(b'\r\n')
 
+    # properties for backwards-compatibility
+    @property
+    def __server(self):
+        warn("Access to __server attribute on SMTPChannel is deprecated, "
+            "use 'smtp_server' instead", PendingDeprecationWarning, 2)
+        return self.smtp_server
+    @__server.setter
+    def __server(self, value):
+        warn("Setting __server attribute on SMTPChannel is deprecated, "
+            "set 'smtp_server' instead", PendingDeprecationWarning, 2)
+        self.smtp_server = value
+
+    @property
+    def __line(self):
+        warn("Access to __line attribute on SMTPChannel is deprecated, "
+            "use 'received_lines' instead", PendingDeprecationWarning, 2)
+        return self.received_lines
+    @__line.setter
+    def __line(self, value):
+        warn("Setting __line attribute on SMTPChannel is deprecated, "
+            "set 'received_lines' instead", PendingDeprecationWarning, 2)
+        self.received_lines = value
+
+    @property
+    def __state(self):
+        warn("Access to __state attribute on SMTPChannel is deprecated, "
+            "use 'smtp_state' instead", PendingDeprecationWarning, 2)
+        return self.smtp_state
+    @__state.setter
+    def __state(self, value):
+        warn("Setting __state attribute on SMTPChannel is deprecated, "
+            "set 'smtp_state' instead", PendingDeprecationWarning, 2)
+        self.smtp_state = value
+
+    @property
+    def __greeting(self):
+        warn("Access to __greeting attribute on SMTPChannel is deprecated, "
+            "use 'seen_greeting' instead", PendingDeprecationWarning, 2)
+        return self.seen_greeting
+    @__greeting.setter
+    def __greeting(self, value):
+        warn("Setting __greeting attribute on SMTPChannel is deprecated, "
+            "set 'seen_greeting' instead", PendingDeprecationWarning, 2)
+        self.seen_greeting = value
+
+    @property
+    def __mailfrom(self):
+        warn("Access to __mailfrom attribute on SMTPChannel is deprecated, "
+            "use 'mailfrom' instead", PendingDeprecationWarning, 2)
+        return self.mailfrom
+    @__mailfrom.setter
+    def __mailfrom(self, value):
+        warn("Setting __mailfrom attribute on SMTPChannel is deprecated, "
+            "set 'mailfrom' instead", PendingDeprecationWarning, 2)
+        self.mailfrom = value
+
+    @property
+    def __rcpttos(self):
+        warn("Access to __rcpttos attribute on SMTPChannel is deprecated, "
+            "use 'rcpttos' instead", PendingDeprecationWarning, 2)
+        return self.rcpttos
+    @__rcpttos.setter
+    def __rcpttos(self, value):
+        warn("Setting __rcpttos attribute on SMTPChannel is deprecated, "
+            "set 'rcpttos' instead", PendingDeprecationWarning, 2)
+        self.rcpttos = value
+
+    @property
+    def __data(self):
+        warn("Access to __data attribute on SMTPChannel is deprecated, "
+            "use 'received_data' instead", PendingDeprecationWarning, 2)
+        return self.received_data
+    @__data.setter
+    def __data(self, value):
+        warn("Setting __data attribute on SMTPChannel is deprecated, "
+            "set 'received_data' instead", PendingDeprecationWarning, 2)
+        self.received_data = value
+
+    @property
+    def __fqdn(self):
+        warn("Access to __fqdn attribute on SMTPChannel is deprecated, "
+            "use 'fqdn' instead", PendingDeprecationWarning, 2)
+        return self.fqdn
+    @__fqdn.setter
+    def __fqdn(self, value):
+        warn("Setting __fqdn attribute on SMTPChannel is deprecated, "
+            "set 'fqdn' instead", PendingDeprecationWarning, 2)
+        self.fqdn = value
+
+    @property
+    def __peer(self):
+        warn("Access to __peer attribute on SMTPChannel is deprecated, "
+            "use 'peer' instead", PendingDeprecationWarning, 2)
+        return self.peer
+    @__peer.setter
+    def __peer(self, value):
+        warn("Setting __peer attribute on SMTPChannel is deprecated, "
+            "set 'peer' instead", PendingDeprecationWarning, 2)
+        self.peer = value
+
+    @property
+    def __conn(self):
+        warn("Access to __conn attribute on SMTPChannel is deprecated, "
+            "use 'conn' instead", PendingDeprecationWarning, 2)
+        return self.conn
+    @__conn.setter
+    def __conn(self, value):
+        warn("Setting __conn attribute on SMTPChannel is deprecated, "
+            "set 'conn' instead", PendingDeprecationWarning, 2)
+        self.conn = value
+
+    @property
+    def __addr(self):
+        warn("Access to __addr attribute on SMTPChannel is deprecated, "
+            "use 'addr' instead", PendingDeprecationWarning, 2)
+        return self.addr
+    @__addr.setter
+    def __addr(self, value):
+        warn("Setting __addr attribute on SMTPChannel is deprecated, "
+            "set 'addr' instead", PendingDeprecationWarning, 2)
+        self.addr = value
+
     # Overrides base class for convenience
     def push(self, msg):
         asynchat.async_chat.push(self, bytes(msg + '\r\n', 'ascii'))
 
     # Implementation of base class abstract method
     def collect_incoming_data(self, data):
-        self.__line.append(str(data, "utf8"))
+        self.received_lines.append(str(data, "utf8"))
 
     # Implementation of base class abstract method
     def found_terminator(self):
-        line = EMPTYSTRING.join(self.__line)
+        line = EMPTYSTRING.join(self.received_lines)
         print('Data:', repr(line), file=DEBUGSTREAM)
-        self.__line = []
-        if self.__state == self.COMMAND:
+        self.received_lines = []
+        if self.smtp_state == self.COMMAND:
             if not line:
                 self.push('500 Error: bad syntax')
                 return
@@ -158,7 +281,7 @@
             method(arg)
             return
         else:
-            if self.__state != self.DATA:
+            if self.smtp_state != self.DATA:
                 self.push('451 Internal confusion')
                 return
             # Remove extraneous carriage returns and de-transparency according
@@ -169,14 +292,14 @@
                     data.append(text[1:])
                 else:
                     data.append(text)
-            self.__data = NEWLINE.join(data)
-            status = self.__server.process_message(self.__peer,
-                                                   self.__mailfrom,
-                                                   self.__rcpttos,
-                                                   self.__data)
-            self.__rcpttos = []
-            self.__mailfrom = None
-            self.__state = self.COMMAND
+            self.received_data = NEWLINE.join(data)
+            status = self.__server.process_message(self.peer,
+                                                   self.mailfrom,
+                                                   self.rcpttos,
+                                                   self.received_data)
+            self.rcpttos = []
+            self.mailfrom = None
+            self.smtp_state = self.COMMAND
             self.set_terminator(b'\r\n')
             if not status:
                 self.push('250 Ok')
@@ -188,11 +311,11 @@
         if not arg:
             self.push('501 Syntax: HELO hostname')
             return
-        if self.__greeting:
+        if self.seen_greeting:
             self.push('503 Duplicate HELO/EHLO')
         else:
-            self.__greeting = arg
-            self.push('250 %s' % self.__fqdn)
+            self.seen_greeting = arg
+            self.push('250 %s' % self.fqdn)
 
     def smtp_NOOP(self, arg):
         if arg:
@@ -225,24 +348,24 @@
         if not address:
             self.push('501 Syntax: MAIL FROM:<address>')
             return
-        if self.__mailfrom:
+        if self.mailfrom:
             self.push('503 Error: nested MAIL command')
             return
-        self.__mailfrom = address
-        print('sender:', self.__mailfrom, file=DEBUGSTREAM)
+        self.mailfrom = address
+        print('sender:', self.mailfrom, file=DEBUGSTREAM)
         self.push('250 Ok')
 
     def smtp_RCPT(self, arg):
         print('===> RCPT', arg, file=DEBUGSTREAM)
-        if not self.__mailfrom:
+        if not self.mailfrom:
             self.push('503 Error: need MAIL command')
             return
         address = self.__getaddr('TO:', arg) if arg else None
         if not address:
             self.push('501 Syntax: RCPT TO: <address>')
             return
-        self.__rcpttos.append(address)
-        print('recips:', self.__rcpttos, file=DEBUGSTREAM)
+        self.rcpttos.append(address)
+        print('recips:', self.rcpttos, file=DEBUGSTREAM)
         self.push('250 Ok')
 
     def smtp_RSET(self, arg):
@@ -250,26 +373,29 @@
             self.push('501 Syntax: RSET')
             return
         # Resets the sender, recipients, and data, but not the greeting
-        self.__mailfrom = None
-        self.__rcpttos = []
-        self.__data = ''
-        self.__state = self.COMMAND
+        self.mailfrom = None
+        self.rcpttos = []
+        self.received_data = ''
+        self.smtp_state = self.COMMAND
         self.push('250 Ok')
 
     def smtp_DATA(self, arg):
-        if not self.__rcpttos:
+        if not self.rcpttos:
             self.push('503 Error: need RCPT command')
             return
         if arg:
             self.push('501 Syntax: DATA')
             return
-        self.__state = self.DATA
+        self.smtp_state = self.DATA
         self.set_terminator(b'\r\n.\r\n')
         self.push('354 End data with <CR><LF>.<CR><LF>')
 
 
 
 class SMTPServer(asyncore.dispatcher):
+    # SMTPChannel class to use for managing client connections
+    channel_class = SMTPChannel
+
     def __init__(self, localaddr, remoteaddr):
         self._localaddr = localaddr
         self._remoteaddr = remoteaddr
@@ -291,7 +417,7 @@
     def handle_accept(self):
         conn, addr = self.accept()
         print('Incoming connection from %s' % repr(addr), file=DEBUGSTREAM)
-        channel = SMTPChannel(self, conn, addr)
+        channel = self.channel_class(self, conn, addr)
 
     # API for "doing something useful with the message"
     def process_message(self, peer, mailfrom, rcpttos, data):

Modified: python/branches/import_unicode/Lib/sndhdr.py
==============================================================================
--- python/branches/import_unicode/Lib/sndhdr.py	(original)
+++ python/branches/import_unicode/Lib/sndhdr.py	Fri Jul 30 01:19:37 2010
@@ -57,12 +57,12 @@
 
 def test_aifc(h, f):
     import aifc
-    if h.startswith(b'FORM'):
+    if not h.startswith(b'FORM'):
         return None
     if h[8:12] == b'AIFC':
         fmt = 'aifc'
     elif h[8:12] == b'AIFF':
-        fmt = b'aiff'
+        fmt = 'aiff'
     else:
         return None
     f.seek(0)
@@ -123,7 +123,7 @@
 
 
 def test_voc(h, f):
-    if h.startswith(b'Creative Voice File\032'):
+    if not h.startswith(b'Creative Voice File\032'):
         return None
     sbseek = get_short_le(h[20:22])
     rate = 0
@@ -150,7 +150,7 @@
 
 
 def test_8svx(h, f):
-    if h.startswith(b'FORM') or h[8:12] != b'8SVX':
+    if not h.startswith(b'FORM') or h[8:12] != b'8SVX':
         return None
     # Should decode it to get #channels -- assume always 1
     return '8svx', 0, 1, 0, 8

Modified: python/branches/import_unicode/Lib/socket.py
==============================================================================
--- python/branches/import_unicode/Lib/socket.py	(original)
+++ python/branches/import_unicode/Lib/socket.py	Fri Jul 30 01:19:37 2010
@@ -252,10 +252,6 @@
         self._sock._decref_socketios()
         self._sock = None
 
-    def __del__(self):
-        if not self.closed:
-            self._sock._decref_socketios()
-
 
 def getfqdn(name=''):
     """Get fully qualified domain name from name.

Modified: python/branches/import_unicode/Lib/string.py
==============================================================================
--- python/branches/import_unicode/Lib/string.py	(original)
+++ python/branches/import_unicode/Lib/string.py	Fri Jul 30 01:19:37 2010
@@ -81,7 +81,7 @@
                 'delim' : _re.escape(cls.delimiter),
                 'id'    : cls.idpattern,
                 }
-        cls.pattern = _re.compile(pattern, _re.IGNORECASE | _re.VERBOSE)
+        cls.pattern = _re.compile(pattern, cls.flags | _re.VERBOSE)
 
 
 class Template(metaclass=_TemplateMetaclass):
@@ -89,6 +89,7 @@
 
     delimiter = '$'
     idpattern = r'[_a-z][_a-z0-9]*'
+    flags = _re.IGNORECASE
 
     def __init__(self, template):
         self.template = template

Modified: python/branches/import_unicode/Lib/subprocess.py
==============================================================================
--- python/branches/import_unicode/Lib/subprocess.py	(original)
+++ python/branches/import_unicode/Lib/subprocess.py	Fri Jul 30 01:19:37 2010
@@ -1073,6 +1073,8 @@
 
             if shell:
                 args = ["/bin/sh", "-c"] + args
+                if executable:
+                    args[0] = executable
 
             if executable is None:
                 executable = args[0]

Modified: python/branches/import_unicode/Lib/sysconfig.py
==============================================================================
--- python/branches/import_unicode/Lib/sysconfig.py	(original)
+++ python/branches/import_unicode/Lib/sysconfig.py	Fri Jul 30 01:19:37 2010
@@ -225,6 +225,12 @@
     # do variable interpolation here
     variables = list(notdone.keys())
 
+    # Variables with a 'PY_' prefix in the makefile. These need to
+    # be made available without that prefix through sysconfig.
+    # Special care is needed to ensure that variable expansion works, even
+    # if the expansion uses the name without a prefix.
+    renamed_variables = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS')
+
     while len(variables) > 0:
         for name in tuple(variables):
             value = notdone[name]
@@ -240,8 +246,20 @@
                 elif n in os.environ:
                     # do it like make: fall back to environment
                     item = os.environ[n]
+
+                elif n in renamed_variables:
+                    if name.startswith('PY_') and name[3:] in renamed_variables:
+                        item = ""
+
+                    elif 'PY_' + n in notdone:
+                        found = False
+
+                    else:
+                        item = str(done['PY_' + n])
+
                 else:
                     done[n] = item = ""
+
                 if found:
                     after = value[m.end():]
                     value = value[:m.start()] + item + after
@@ -255,6 +273,15 @@
                         else:
                             done[name] = value
                         variables.remove(name)
+
+                        if name.startswith('PY_') \
+                                and name[3:] in renamed_variables:
+
+                            name = name[3:]
+                            if name not in done:
+                                done[name] = value
+
+
             else:
                 # bogus variable reference; just drop it since we can't deal
                 variables.remove(name)
@@ -653,8 +680,7 @@
                 cflags = get_config_vars().get('CFLAGS')
 
                 archs = re.findall('-arch\s+(\S+)', cflags)
-                archs.sort()
-                archs = tuple(archs)
+                archs = tuple(sorted(set(archs)))
 
                 if len(archs) == 1:
                     machine = archs[0]

Modified: python/branches/import_unicode/Lib/tarfile.py
==============================================================================
--- python/branches/import_unicode/Lib/tarfile.py	(original)
+++ python/branches/import_unicode/Lib/tarfile.py	Fri Jul 30 01:19:37 2010
@@ -55,6 +55,15 @@
 except ImportError:
     grp = pwd = None
 
+# os.symlink on Windows prior to 6.0 raises NotImplementedError
+symlink_exception = (AttributeError, NotImplementedError)
+try:
+    # WindowsError (1314) will be raised if the caller does not hold the
+    # SeCreateSymbolicLinkPrivilege privilege
+    symlink_exception += (WindowsError,)
+except NameError:
+    pass
+
 # from tarfile import *
 __all__ = ["TarFile", "TarInfo", "is_tarfile", "TarError"]
 
@@ -2283,17 +2292,16 @@
                     os.link(tarinfo._link_target, targetpath)
                 else:
                     self._extract_mem
-        except (AttributeError, NotImplementedError, WindowsError):
-            # AttributeError if no os.symlink
-            # NotImplementedError if on Windows XP
-            # WindowsError (1314) if the required privilege is not held by the client
+        except symlink_exception:
             if tarinfo.issym():
-                linkpath = os.path.join(os.path.dirname(tarinfo.name),tarinfo.linkname)
+                linkpath = os.path.join(os.path.dirname(tarinfo.name),
+                                        tarinfo.linkname)
             else:
                 linkpath = tarinfo.linkname
         else:
             try:
-                self._extract_member(self._find_link_target(tarinfo), targetpath)
+                self._extract_member(self._find_link_target(tarinfo),
+                                     targetpath)
             except KeyError:
                 raise ExtractError("unable to resolve link inside archive")
 

Modified: python/branches/import_unicode/Lib/test/pickletester.py
==============================================================================
--- python/branches/import_unicode/Lib/test/pickletester.py	(original)
+++ python/branches/import_unicode/Lib/test/pickletester.py	Fri Jul 30 01:19:37 2010
@@ -65,9 +65,21 @@
     def __eq__(self, other):
         return self.__dict__ == other.__dict__
 
+class D(C):
+    def __init__(self, arg):
+        pass
+
+class E(C):
+    def __getinitargs__(self):
+        return ()
+
 import __main__
 __main__.C = C
 C.__module__ = "__main__"
+__main__.D = D
+D.__module__ = "__main__"
+__main__.E = E
+E.__module__ = "__main__"
 
 class myint(int):
     def __init__(self, x):
@@ -425,6 +437,63 @@
     def test_load_from_data2(self):
         self.assertEqual(self._testdata, self.loads(DATA2))
 
+    def test_load_classic_instance(self):
+        # See issue5180.  Test loading 2.x pickles that
+        # contain an instance of old style class.
+        for X, args in [(C, ()), (D, ('x',)), (E, ())]:
+            xname = X.__name__.encode('ascii')
+            # Protocol 0 (text mode pickle):
+            """
+            0: (    MARK
+            1: i        INST       '__main__ X' (MARK at 0)
+            15: p    PUT        0
+            18: (    MARK
+            19: d        DICT       (MARK at 18)
+            20: p    PUT        1
+            23: b    BUILD
+            24: .    STOP
+            """
+            pickle0 = (b"(i__main__\n"
+                       b"X\n"
+                       b"p0\n"
+                       b"(dp1\nb.").replace(b'X', xname)
+            self.assertEqual(X(*args), self.loads(pickle0))
+
+            # Protocol 1 (binary mode pickle)
+            """
+            0: (    MARK
+            1: c        GLOBAL     '__main__ X'
+            15: q        BINPUT     0
+            17: o        OBJ        (MARK at 0)
+            18: q    BINPUT     1
+            20: }    EMPTY_DICT
+            21: q    BINPUT     2
+            23: b    BUILD
+            24: .    STOP
+            """
+            pickle1 = (b'(c__main__\n'
+                       b'X\n'
+                       b'q\x00oq\x01}q\x02b.').replace(b'X', xname)
+            self.assertEqual(X(*args), self.loads(pickle1))
+
+            # Protocol 2 (pickle2 = b'\x80\x02' + pickle1)
+            """
+            0: \x80 PROTO      2
+            2: (    MARK
+            3: c        GLOBAL     '__main__ X'
+            17: q        BINPUT     0
+            19: o        OBJ        (MARK at 2)
+            20: q    BINPUT     1
+            22: }    EMPTY_DICT
+            23: q    BINPUT     2
+            25: b    BUILD
+            26: .    STOP
+            """
+            pickle2 = (b'\x80\x02(c__main__\n'
+                       b'X\n'
+                       b'q\x00oq\x01}q\x02b.').replace(b'X', xname)
+            self.assertEqual(X(*args), self.loads(pickle2))
+
     # There are gratuitous differences between pickles produced by
     # pickle and cPickle, largely because cPickle starts PUT indices at
     # 1 and pickle starts them at 0.  See XXX comment in cPickle's put2() --

Modified: python/branches/import_unicode/Lib/test/script_helper.py
==============================================================================
--- python/branches/import_unicode/Lib/test/script_helper.py	(original)
+++ python/branches/import_unicode/Lib/test/script_helper.py	Fri Jul 30 01:19:37 2010
@@ -79,7 +79,7 @@
             name_in_zip = os.path.basename(script_name)
     zip_file.write(script_name, name_in_zip)
     zip_file.close()
-    #if test.test_support.verbose:
+    #if test.support.verbose:
     #    zip_file = zipfile.ZipFile(zip_name, 'r')
     #    print 'Contents of %r:' % zip_name
     #    zip_file.printdir()
@@ -114,7 +114,7 @@
     zip_file.close()
     for name in unlink:
         os.unlink(name)
-    #if test.test_support.verbose:
+    #if test.support.verbose:
     #    zip_file = zipfile.ZipFile(zip_name, 'r')
     #    print 'Contents of %r:' % zip_name
     #    zip_file.printdir()

Modified: python/branches/import_unicode/Lib/test/support.py
==============================================================================
--- python/branches/import_unicode/Lib/test/support.py	(original)
+++ python/branches/import_unicode/Lib/test/support.py	Fri Jul 30 01:19:37 2010
@@ -109,7 +109,7 @@
         orig_modules[name] = sys.modules[name]
     except KeyError:
         saved = False
-    sys.modules[name] = 0
+    sys.modules[name] = None
     return saved
 
 

Modified: python/branches/import_unicode/Lib/test/symlink_support.py
==============================================================================
--- python/branches/import_unicode/Lib/test/symlink_support.py	(original)
+++ python/branches/import_unicode/Lib/test/symlink_support.py	Fri Jul 30 01:19:37 2010
@@ -12,7 +12,8 @@
 GetCurrentProcess = ctypes.windll.kernel32.GetCurrentProcess
 GetCurrentProcess.restype = wintypes.HANDLE
 OpenProcessToken = ctypes.windll.advapi32.OpenProcessToken
-OpenProcessToken.argtypes = (wintypes.HANDLE, wintypes.DWORD, ctypes.POINTER(wintypes.HANDLE))
+OpenProcessToken.argtypes = (wintypes.HANDLE, wintypes.DWORD,
+                             ctypes.POINTER(wintypes.HANDLE))
 OpenProcessToken.restype = wintypes.BOOL
 
 class LUID(ctypes.Structure):
@@ -91,7 +92,8 @@
 
     def get_array(self):
         array_type = LUID_AND_ATTRIBUTES*self.count
-        privileges = ctypes.cast(self.privileges, ctypes.POINTER(array_type)).contents
+        privileges = ctypes.cast(self.privileges,
+                                 ctypes.POINTER(array_type)).contents
         return privileges
 
     def __iter__(self):
@@ -133,7 +135,8 @@
 def get_symlink_luid():
     "Get the LUID for the SeCreateSymbolicLinkPrivilege"
     symlink_luid = LUID()
-    res = LookupPrivilegeValue(None, "SeCreateSymbolicLinkPrivilege", symlink_luid)
+    res = LookupPrivilegeValue(None, "SeCreateSymbolicLinkPrivilege",
+                               symlink_luid)
     if not res > 0:
         raise RuntimeError("Couldn't lookup privilege value")
     return symlink_luid

Modified: python/branches/import_unicode/Lib/test/test_array.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_array.py	(original)
+++ python/branches/import_unicode/Lib/test/test_array.py	Fri Jul 30 01:19:37 2010
@@ -326,6 +326,17 @@
                 f.close()
             support.unlink(support.TESTFN)
 
+    def test_fromfile_ioerror(self):
+        # Issue #5395: Check if fromfile raises a proper IOError
+        # instead of EOFError.
+        a = array.array(self.typecode)
+        f = open(support.TESTFN, 'wb')
+        try:
+            self.assertRaises(IOError, a.fromfile, f, len(self.example))
+        finally:
+            f.close()
+            support.unlink(support.TESTFN)
+
     def test_filewrite(self):
         a = array.array(self.typecode, 2*self.example)
         f = open(support.TESTFN, 'wb')

Modified: python/branches/import_unicode/Lib/test/test_ast.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_ast.py	(original)
+++ python/branches/import_unicode/Lib/test/test_ast.py	Fri Jul 30 01:19:37 2010
@@ -285,6 +285,8 @@
         self.assertEqual(ast.literal_eval('[1, 2, 3]'), [1, 2, 3])
         self.assertEqual(ast.literal_eval('{"foo": 42}'), {"foo": 42})
         self.assertEqual(ast.literal_eval('(True, False, None)'), (True, False, None))
+        self.assertEqual(ast.literal_eval('{1, 2, 3}'), {1, 2, 3})
+        self.assertEqual(ast.literal_eval('b"hi"'), b"hi")
         self.assertRaises(ValueError, ast.literal_eval, 'foo()')
 
     def test_literal_eval_issue4907(self):

Modified: python/branches/import_unicode/Lib/test/test_asyncore.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_asyncore.py	(original)
+++ python/branches/import_unicode/Lib/test/test_asyncore.py	Fri Jul 30 01:19:37 2010
@@ -118,65 +118,65 @@
     # http://mail.python.org/pipermail/python-list/2001-October/109973.html)
     # These constants should be present as long as poll is available
 
-    if hasattr(select, 'poll'):
-        def test_readwrite(self):
-            # Check that correct methods are called by readwrite()
-
-            attributes = ('read', 'expt', 'write', 'closed', 'error_handled')
-
-            expected = (
-                (select.POLLIN, 'read'),
-                (select.POLLPRI, 'expt'),
-                (select.POLLOUT, 'write'),
-                (select.POLLERR, 'closed'),
-                (select.POLLHUP, 'closed'),
-                (select.POLLNVAL, 'closed'),
-                )
-
-            class testobj:
-                def __init__(self):
-                    self.read = False
-                    self.write = False
-                    self.closed = False
-                    self.expt = False
-                    self.error_handled = False
-
-                def handle_read_event(self):
-                    self.read = True
-
-                def handle_write_event(self):
-                    self.write = True
-
-                def handle_close(self):
-                    self.closed = True
-
-                def handle_expt_event(self):
-                    self.expt = True
-
-                def handle_error(self):
-                    self.error_handled = True
-
-            for flag, expectedattr in expected:
-                tobj = testobj()
-                self.assertEqual(getattr(tobj, expectedattr), False)
-                asyncore.readwrite(tobj, flag)
-
-                # Only the attribute modified by the routine we expect to be
-                # called should be True.
-                for attr in attributes:
-                    self.assertEqual(getattr(tobj, attr), attr==expectedattr)
-
-                # check that ExitNow exceptions in the object handler method
-                # bubbles all the way up through asyncore readwrite call
-                tr1 = exitingdummy()
-                self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag)
-
-                # check that an exception other than ExitNow in the object handler
-                # method causes the handle_error method to get called
-                tr2 = crashingdummy()
-                self.assertEqual(tr2.error_handled, False)
-                asyncore.readwrite(tr2, flag)
-                self.assertEqual(tr2.error_handled, True)
+    @unittest.skipUnless(hasattr(select, 'poll'), 'select.poll required')
+    def test_readwrite(self):
+        # Check that correct methods are called by readwrite()
+
+        attributes = ('read', 'expt', 'write', 'closed', 'error_handled')
+
+        expected = (
+            (select.POLLIN, 'read'),
+            (select.POLLPRI, 'expt'),
+            (select.POLLOUT, 'write'),
+            (select.POLLERR, 'closed'),
+            (select.POLLHUP, 'closed'),
+            (select.POLLNVAL, 'closed'),
+            )
+
+        class testobj:
+            def __init__(self):
+                self.read = False
+                self.write = False
+                self.closed = False
+                self.expt = False
+                self.error_handled = False
+
+            def handle_read_event(self):
+                self.read = True
+
+            def handle_write_event(self):
+                self.write = True
+
+            def handle_close(self):
+                self.closed = True
+
+            def handle_expt_event(self):
+                self.expt = True
+
+            def handle_error(self):
+                self.error_handled = True
+
+        for flag, expectedattr in expected:
+            tobj = testobj()
+            self.assertEqual(getattr(tobj, expectedattr), False)
+            asyncore.readwrite(tobj, flag)
+
+            # Only the attribute modified by the routine we expect to be
+            # called should be True.
+            for attr in attributes:
+                self.assertEqual(getattr(tobj, attr), attr==expectedattr)
+
+            # check that ExitNow exceptions in the object handler method
+            # bubbles all the way up through asyncore readwrite call
+            tr1 = exitingdummy()
+            self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag)
+
+            # check that an exception other than ExitNow in the object handler
+            # method causes the handle_error method to get called
+            tr2 = crashingdummy()
+            self.assertEqual(tr2.error_handled, False)
+            asyncore.readwrite(tr2, flag)
+            self.assertEqual(tr2.error_handled, True)
 
     def test_closeall(self):
         self.closeall_check(False)
@@ -259,7 +259,7 @@
             sys.stderr = stderr
 
         lines = fp.getvalue().splitlines()
-        self.assertEquals(lines, ['log: %s' % l1, 'log: %s' % l2])
+        self.assertEqual(lines, ['log: %s' % l1, 'log: %s' % l2])
 
     def test_log_info(self):
         d = asyncore.dispatcher()
@@ -281,7 +281,7 @@
         lines = fp.getvalue().splitlines()
         expected = ['EGGS: %s' % l1, 'info: %s' % l2, 'SPAM: %s' % l3]
 
-        self.assertEquals(lines, expected)
+        self.assertEqual(lines, expected)
 
     def test_unhandled(self):
         d = asyncore.dispatcher()
@@ -306,7 +306,7 @@
                     'warning: unhandled write event',
                     'warning: unhandled connect event',
                     'warning: unhandled accept event']
-        self.assertEquals(lines, expected)
+        self.assertEqual(lines, expected)
 
     def test_issue_8594(self):
         # XXX - this test is supposed to be removed in next major Python
@@ -322,7 +322,7 @@
             warnings.simplefilter("always")
             family = d.family
             self.assertEqual(family, socket.AF_INET)
-            self.assertTrue(len(w) == 1)
+            self.assertEqual(len(w), 1)
             self.assertTrue(issubclass(w[0].category, DeprecationWarning))
 
     def test_strerror(self):
@@ -331,7 +331,7 @@
         if hasattr(os, 'strerror'):
             self.assertEqual(err, os.strerror(errno.EPERM))
         err = asyncore._strerror(-1)
-        self.assertTrue("unknown error" in err.lower())
+        self.assertIn("unknown error", err.lower())
 
 
 class dispatcherwithsend_noread(asyncore.dispatcher_with_send):
@@ -394,38 +394,52 @@
 class DispatcherWithSendTests_UsePoll(DispatcherWithSendTests):
     usepoll = True
 
-if hasattr(asyncore, 'file_wrapper'):
-    class FileWrapperTest(unittest.TestCase):
-        def setUp(self):
-            self.d = b"It's not dead, it's sleeping!"
-            open(TESTFN, 'wb').write(self.d)
-
-        def tearDown(self):
-            unlink(TESTFN)
-
-        def test_recv(self):
-            fd = os.open(TESTFN, os.O_RDONLY)
-            w = asyncore.file_wrapper(fd)
-            os.close(fd)
-
-            self.assertNotEqual(w.fd, fd)
-            self.assertNotEqual(w.fileno(), fd)
-            self.assertEqual(w.recv(13), b"It's not dead")
-            self.assertEqual(w.read(6), b", it's")
-            w.close()
-            self.assertRaises(OSError, w.read, 1)
-
-        def test_send(self):
-            d1 = b"Come again?"
-            d2 = b"I want to buy some cheese."
-            fd = os.open(TESTFN, os.O_WRONLY | os.O_APPEND)
-            w = asyncore.file_wrapper(fd)
-            os.close(fd)
-
-            w.write(d1)
-            w.send(d2)
-            w.close()
-            self.assertEqual(open(TESTFN, 'rb').read(), self.d + d1 + d2)
+ at unittest.skipUnless(hasattr(asyncore, 'file_wrapper'),
+                     'asyncore.file_wrapper required')
+class FileWrapperTest(unittest.TestCase):
+    def setUp(self):
+        self.d = b"It's not dead, it's sleeping!"
+        open(TESTFN, 'wb').write(self.d)
+
+    def tearDown(self):
+        unlink(TESTFN)
+
+    def test_recv(self):
+        fd = os.open(TESTFN, os.O_RDONLY)
+        w = asyncore.file_wrapper(fd)
+        os.close(fd)
+
+        self.assertNotEqual(w.fd, fd)
+        self.assertNotEqual(w.fileno(), fd)
+        self.assertEqual(w.recv(13), b"It's not dead")
+        self.assertEqual(w.read(6), b", it's")
+        w.close()
+        self.assertRaises(OSError, w.read, 1)
+
+    def test_send(self):
+        d1 = b"Come again?"
+        d2 = b"I want to buy some cheese."
+        fd = os.open(TESTFN, os.O_WRONLY | os.O_APPEND)
+        w = asyncore.file_wrapper(fd)
+        os.close(fd)
+
+        w.write(d1)
+        w.send(d2)
+        w.close()
+        self.assertEqual(open(TESTFN, 'rb').read(), self.d + d1 + d2)
+
+    @unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'),
+                         'asyncore.file_dispatcher required')
+    def test_dispatcher(self):
+        fd = os.open(TESTFN, os.O_RDONLY)
+        data = []
+        class FileDispatcher(asyncore.file_dispatcher):
+            def handle_read(self):
+                data.append(self.recv(29))
+        s = FileDispatcher(fd)
+        os.close(fd)
+        asyncore.loop(timeout=0.01, use_poll=True, count=2)
+        self.assertEqual(b"".join(data), self.d)
 
 
 class BaseTestHandler(asyncore.dispatcher):
@@ -692,18 +706,15 @@
 class TestAPI_UseSelect(BaseTestAPI):
     use_poll = False
 
+ at unittest.skipUnless(hasattr(select, 'poll'), 'select.poll required')
 class TestAPI_UsePoll(BaseTestAPI):
     use_poll = True
 
 
 def test_main():
     tests = [HelperFunctionTests, DispatcherTests, DispatcherWithSendTests,
-             DispatcherWithSendTests_UsePoll, TestAPI_UseSelect]
-    if hasattr(asyncore, 'file_wrapper'):
-        tests.append(FileWrapperTest)
-    if hasattr(select, 'poll'):
-        tests.append(TestAPI_UsePoll)
-
+             DispatcherWithSendTests_UsePoll, TestAPI_UseSelect,
+             TestAPI_UsePoll, FileWrapperTest]
     run_unittest(*tests)
 
 if __name__ == "__main__":

Modified: python/branches/import_unicode/Lib/test/test_binascii.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_binascii.py	(original)
+++ python/branches/import_unicode/Lib/test/test_binascii.py	Fri Jul 30 01:19:37 2010
@@ -55,7 +55,7 @@
                              "{!r} != {!r}".format(fb, fa, res, raw))
             self.assertIsInstance(res, bytes)
             self.assertIsInstance(a, bytes)
-            self.assertLess(max(c for c in a), 128)
+            self.assertLess(max(a), 128)
         self.assertIsInstance(binascii.crc_hqx(raw, 0), int)
         self.assertIsInstance(binascii.crc32(raw), int)
 
@@ -167,7 +167,7 @@
     def test_qp(self):
         # A test for SF bug 534347 (segfaults without the proper fix)
         try:
-            binascii.a2b_qp("", **{1:1})
+            binascii.a2b_qp(b"", **{1:1})
         except TypeError:
             pass
         else:
@@ -179,12 +179,10 @@
         self.assertEqual(binascii.a2b_qp(b"=00\r\n=00"), b"\x00\r\n\x00")
         self.assertEqual(
             binascii.b2a_qp(b"\xff\r\n\xff\n\xff"),
-            b"=FF\r\n=FF\r\n=FF"
-        )
+            b"=FF\r\n=FF\r\n=FF")
         self.assertEqual(
             binascii.b2a_qp(b"0"*75+b"\xff\r\n\xff\r\n\xff"),
-            b"0"*75+b"=\r\n=FF\r\n=FF\r\n=FF"
-        )
+            b"0"*75+b"=\r\n=FF\r\n=FF\r\n=FF")
 
         self.assertEqual(binascii.b2a_qp(b'\0\n'), b'=00\n')
         self.assertEqual(binascii.b2a_qp(b'\0\n', quotetabs=True), b'=00\n')
@@ -210,13 +208,15 @@
             except Exception as err:
                 self.fail("{}({!r}) raises {!r}".format(func, empty, err))
 
-    def test_no_binary_strings(self):
-        # b2a_ must not accept strings
-        for f in (binascii.b2a_uu, binascii.b2a_base64,
-                  binascii.b2a_hqx, binascii.b2a_qp,
-                  binascii.hexlify, binascii.rlecode_hqx,
-                  binascii.crc_hqx, binascii.crc32):
-            self.assertRaises(TypeError, f, "test")
+    def test_unicode_strings(self):
+        # Unicode strings are not accepted.
+        for func in all_functions:
+            try:
+                self.assertRaises(TypeError, getattr(binascii, func), "test")
+            except Exception as err:
+                self.fail('{}("test") raises {!r}'.format(func, err))
+        # crc_hqx needs 2 arguments
+        self.assertRaises(TypeError, binascii.crc_hqx, "test", 0)
 
 
 class ArrayBinASCIITest(BinASCIITest):

Modified: python/branches/import_unicode/Lib/test/test_binop.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_binop.py	(original)
+++ python/branches/import_unicode/Lib/test/test_binop.py	Fri Jul 30 01:19:37 2010
@@ -16,7 +16,7 @@
 
 def isnum(x):
     """Test whether an object is an instance of a built-in numeric type."""
-    for T in int, int, float, complex:
+    for T in int, float, complex:
         if isinstance(x, T):
             return 1
     return 0

Modified: python/branches/import_unicode/Lib/test/test_calendar.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_calendar.py	(original)
+++ python/branches/import_unicode/Lib/test/test_calendar.py	Fri Jul 30 01:19:37 2010
@@ -389,6 +389,34 @@
             tuple = time.gmtime(secs)
             self.assertEqual(secs, calendar.timegm(tuple))
 
+class MonthRangeTestCase(unittest.TestCase):
+    def test_january(self):
+        # Tests valid lower boundary case.
+        self.assertEqual(calendar.monthrange(2004,1), (3,31))
+
+    def test_february_leap(self):
+        # Tests February during leap year.
+        self.assertEqual(calendar.monthrange(2004,2), (6,29))
+
+    def test_february_nonleap(self):
+        # Tests February in non-leap year.
+        self.assertEqual(calendar.monthrange(2010,2), (0,28))
+
+    def test_december(self):
+        # Tests valid upper boundary case.
+        self.assertEqual(calendar.monthrange(2004,12), (2,31))
+
+    def test_zeroth_month(self):
+        # Tests low invalid boundary case.
+        with self.assertRaises(calendar.IllegalMonthError):
+            calendar.monthrange(2004, 0)
+
+    def test_thirteenth_month(self):
+        # Tests high invalid boundary case.
+        with self.assertRaises(calendar.IllegalMonthError):
+            calendar.monthrange(2004, 13)
+
+
 def test_main():
     support.run_unittest(
         OutputTestCase,
@@ -396,6 +424,7 @@
         MondayTestCase,
         SundayTestCase,
         TimegmTestCase,
+        MonthRangeTestCase,
     )
 
 

Modified: python/branches/import_unicode/Lib/test/test_cfgparser.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_cfgparser.py	(original)
+++ python/branches/import_unicode/Lib/test/test_cfgparser.py	Fri Jul 30 01:19:37 2010
@@ -1,7 +1,9 @@
+import collections
 import configparser
 import io
+import os
 import unittest
-import collections
+import textwrap
 
 from test import support
 
@@ -22,15 +24,26 @@
     def itervalues(self): return iter(self.values())
 
 
-class TestCaseBase(unittest.TestCase):
+class CfgParserTestCaseClass(unittest.TestCase):
     allow_no_value = False
+    delimiters = ('=', ':')
+    comment_prefixes = (';', '#')
+    empty_lines_in_values = True
+    dict_type = configparser._default_dict
 
     def newconfig(self, defaults=None):
+        arguments = dict(
+            allow_no_value=self.allow_no_value,
+            delimiters=self.delimiters,
+            comment_prefixes=self.comment_prefixes,
+            empty_lines_in_values=self.empty_lines_in_values,
+            dict_type=self.dict_type,
+        )
         if defaults is None:
-            self.cf = self.config_class(allow_no_value=self.allow_no_value)
+            self.cf = self.config_class(**arguments)
         else:
             self.cf = self.config_class(defaults,
-                                        allow_no_value=self.allow_no_value)
+                                        **arguments)
         return self.cf
 
     def fromstring(self, string, defaults=None):
@@ -39,27 +52,33 @@
         cf.readfp(sio)
         return cf
 
+class BasicTestCase(CfgParserTestCaseClass):
+
     def test_basic(self):
-        config_string = (
-            "[Foo Bar]\n"
-            "foo=bar\n"
-            "[Spacey Bar]\n"
-            "foo = bar\n"
-            "[Commented Bar]\n"
-            "foo: bar ; comment\n"
-            "[Long Line]\n"
-            "foo: this line is much, much longer than my editor\n"
-            "   likes it.\n"
-            "[Section\\with$weird%characters[\t]\n"
-            "[Internationalized Stuff]\n"
-            "foo[bg]: Bulgarian\n"
-            "foo=Default\n"
-            "foo[en]=English\n"
-            "foo[de]=Deutsch\n"
-            "[Spaces]\n"
-            "key with spaces : value\n"
-            "another with spaces = splat!\n"
-            )
+        config_string = """\
+[Foo Bar]
+foo{0[0]}bar
+[Spacey Bar]
+foo {0[0]} bar
+[Spacey Bar From The Beginning]
+  foo {0[0]} bar
+  baz {0[0]} qwe
+[Commented Bar]
+foo{0[1]} bar {1[1]} comment
+baz{0[0]}qwe {1[0]}another one
+[Long Line]
+foo{0[1]} this line is much, much longer than my editor
+   likes it.
+[Section\\with$weird%characters[\t]
+[Internationalized Stuff]
+foo[bg]{0[1]} Bulgarian
+foo{0[0]}Default
+foo[en]{0[0]}English
+foo[de]{0[0]}Deutsch
+[Spaces]
+key with spaces {0[1]} value
+another with spaces {0[0]} splat!
+""".format(self.delimiters, self.comment_prefixes)
         if self.allow_no_value:
             config_string += (
                 "[NoValue]\n"
@@ -69,13 +88,14 @@
         cf = self.fromstring(config_string)
         L = cf.sections()
         L.sort()
-        E = [r'Commented Bar',
-             r'Foo Bar',
-             r'Internationalized Stuff',
-             r'Long Line',
-             r'Section\with$weird%characters[' '\t',
-             r'Spaces',
-             r'Spacey Bar',
+        E = ['Commented Bar',
+             'Foo Bar',
+             'Internationalized Stuff',
+             'Long Line',
+             'Section\\with$weird%characters[\t',
+             'Spaces',
+             'Spacey Bar',
+             'Spacey Bar From The Beginning',
              ]
         if self.allow_no_value:
             E.append(r'NoValue')
@@ -88,7 +108,10 @@
         # http://www.python.org/sf/583248
         eq(cf.get('Foo Bar', 'foo'), 'bar')
         eq(cf.get('Spacey Bar', 'foo'), 'bar')
+        eq(cf.get('Spacey Bar From The Beginning', 'foo'), 'bar')
+        eq(cf.get('Spacey Bar From The Beginning', 'baz'), 'qwe')
         eq(cf.get('Commented Bar', 'foo'), 'bar')
+        eq(cf.get('Commented Bar', 'baz'), 'qwe')
         eq(cf.get('Spaces', 'key with spaces'), 'value')
         eq(cf.get('Spaces', 'another with spaces'), 'splat!')
         if self.allow_no_value:
@@ -107,8 +130,9 @@
                     "remove_option() failed to report non-existence of option"
                     " that was removed")
 
-        self.assertRaises(configparser.NoSectionError,
-                          cf.remove_option, 'No Such Section', 'foo')
+        with self.assertRaises(configparser.NoSectionError) as cm:
+            cf.remove_option('No Such Section', 'foo')
+        self.assertEqual(cm.exception.args, ('No Such Section',))
 
         eq(cf.get('Long Line', 'foo'),
            'this line is much, much longer than my editor\nlikes it.')
@@ -138,12 +162,14 @@
 
         # SF bug #432369:
         cf = self.fromstring(
-            "[MySection]\nOption: first line\n\tsecond line\n")
+            "[MySection]\nOption{} first line\n\tsecond line\n".format(
+                self.delimiters[0]))
         eq(cf.options("MySection"), ["option"])
         eq(cf.get("MySection", "Option"), "first line\nsecond line")
 
         # SF bug #561822:
-        cf = self.fromstring("[section]\nnekey=nevalue\n",
+        cf = self.fromstring("[section]\n"
+                             "nekey{}nevalue\n".format(self.delimiters[0]),
                              defaults={"key":"value"})
         self.assertTrue(cf.has_option("section", "Key"))
 
@@ -161,33 +187,41 @@
     def test_parse_errors(self):
         self.newconfig()
         self.parse_error(configparser.ParsingError,
-                         "[Foo]\n  extra-spaces: splat\n")
+                         "[Foo]\n"
+                         "{}val-without-opt-name\n".format(self.delimiters[0]))
         self.parse_error(configparser.ParsingError,
-                         "[Foo]\n  extra-spaces= splat\n")
-        self.parse_error(configparser.ParsingError,
-                         "[Foo]\n:value-without-option-name\n")
-        self.parse_error(configparser.ParsingError,
-                         "[Foo]\n=value-without-option-name\n")
-        self.parse_error(configparser.MissingSectionHeaderError,
-                         "No Section!\n")
+                         "[Foo]\n"
+                         "{}val-without-opt-name\n".format(self.delimiters[1]))
+        e = self.parse_error(configparser.MissingSectionHeaderError,
+                             "No Section!\n")
+        self.assertEqual(e.args, ('<???>', 1, "No Section!\n"))
+        if not self.allow_no_value:
+            e = self.parse_error(configparser.ParsingError,
+                                "[Foo]\n  wrong-indent\n")
+            self.assertEqual(e.args, ('<???>',))
 
     def parse_error(self, exc, src):
         sio = io.StringIO(src)
-        self.assertRaises(exc, self.cf.readfp, sio)
+        with self.assertRaises(exc) as cm:
+            self.cf.readfp(sio)
+        return cm.exception
 
     def test_query_errors(self):
         cf = self.newconfig()
         self.assertEqual(cf.sections(), [],
                          "new ConfigParser should have no defined sections")
         self.assertFalse(cf.has_section("Foo"),
-                    "new ConfigParser should have no acknowledged sections")
-        self.assertRaises(configparser.NoSectionError,
-                          cf.options, "Foo")
-        self.assertRaises(configparser.NoSectionError,
-                          cf.set, "foo", "bar", "value")
-        self.get_error(configparser.NoSectionError, "foo", "bar")
+                         "new ConfigParser should have no acknowledged "
+                         "sections")
+        with self.assertRaises(configparser.NoSectionError):
+            cf.options("Foo")
+        with self.assertRaises(configparser.NoSectionError):
+            cf.set("foo", "bar", "value")
+        e = self.get_error(configparser.NoSectionError, "foo", "bar")
+        self.assertEqual(e.args, ("foo",))
         cf.add_section("foo")
-        self.get_error(configparser.NoOptionError, "foo", "bar")
+        e = self.get_error(configparser.NoOptionError, "foo", "bar")
+        self.assertEqual(e.args, ("bar", "foo"))
 
     def get_error(self, exc, section, option):
         try:
@@ -201,21 +235,21 @@
     def test_boolean(self):
         cf = self.fromstring(
             "[BOOLTEST]\n"
-            "T1=1\n"
-            "T2=TRUE\n"
-            "T3=True\n"
-            "T4=oN\n"
-            "T5=yes\n"
-            "F1=0\n"
-            "F2=FALSE\n"
-            "F3=False\n"
-            "F4=oFF\n"
-            "F5=nO\n"
-            "E1=2\n"
-            "E2=foo\n"
-            "E3=-1\n"
-            "E4=0.1\n"
-            "E5=FALSE AND MORE"
+            "T1{equals}1\n"
+            "T2{equals}TRUE\n"
+            "T3{equals}True\n"
+            "T4{equals}oN\n"
+            "T5{equals}yes\n"
+            "F1{equals}0\n"
+            "F2{equals}FALSE\n"
+            "F3{equals}False\n"
+            "F4{equals}oFF\n"
+            "F5{equals}nO\n"
+            "E1{equals}2\n"
+            "E2{equals}foo\n"
+            "E3{equals}-1\n"
+            "E4{equals}0.1\n"
+            "E5{equals}FALSE AND MORE".format(equals=self.delimiters[0])
             )
         for x in range(1, 5):
             self.assertTrue(cf.getboolean('BOOLTEST', 't%d' % x))
@@ -226,17 +260,24 @@
     def test_weird_errors(self):
         cf = self.newconfig()
         cf.add_section("Foo")
-        self.assertRaises(configparser.DuplicateSectionError,
-                          cf.add_section, "Foo")
+        with self.assertRaises(configparser.DuplicateSectionError) as cm:
+            cf.add_section("Foo")
+        self.assertEqual(cm.exception.args, ("Foo",))
 
     def test_write(self):
         config_string = (
             "[Long Line]\n"
-            "foo: this line is much, much longer than my editor\n"
+            "foo{0[0]} this line is much, much longer than my editor\n"
             "   likes it.\n"
             "[DEFAULT]\n"
-            "foo: another very\n"
+            "foo{0[1]} another very\n"
             " long line\n"
+            "[Long Line - With Comments!]\n"
+            "test {0[1]} we        {comment} can\n"
+            "            also      {comment} place\n"
+            "            comments  {comment} in\n"
+            "            multiline {comment} values"
+            "\n".format(self.delimiters, comment=self.comment_prefixes[0])
             )
         if self.allow_no_value:
             config_string += (
@@ -249,13 +290,19 @@
         cf.write(output)
         expect_string = (
             "[DEFAULT]\n"
-            "foo = another very\n"
+            "foo {equals} another very\n"
             "\tlong line\n"
             "\n"
             "[Long Line]\n"
-            "foo = this line is much, much longer than my editor\n"
+            "foo {equals} this line is much, much longer than my editor\n"
             "\tlikes it.\n"
             "\n"
+            "[Long Line - With Comments!]\n"
+            "test {equals} we\n"
+            "\talso\n"
+            "\tcomments\n"
+            "\tmultiline\n"
+            "\n".format(equals=self.delimiters[0])
             )
         if self.allow_no_value:
             expect_string += (
@@ -267,7 +314,7 @@
 
     def test_set_string_types(self):
         cf = self.fromstring("[sect]\n"
-                             "option1=foo\n")
+                             "option1{eq}foo\n".format(eq=self.delimiters[0]))
         # Check that we don't get an exception when setting values in
         # an existing section using strings:
         class mystr(str):
@@ -280,6 +327,9 @@
         cf.set("sect", "option2", "splat")
 
     def test_read_returns_file_list(self):
+        if self.delimiters[0] != '=':
+            # skip reading the file if we're using an incompatible format
+            return
         file1 = support.findfile("cfgparser.1")
         # check when we pass a mix of readable and non-readable files:
         cf = self.newconfig()
@@ -304,48 +354,53 @@
     def get_interpolation_config(self):
         return self.fromstring(
             "[Foo]\n"
-            "bar=something %(with1)s interpolation (1 step)\n"
-            "bar9=something %(with9)s lots of interpolation (9 steps)\n"
-            "bar10=something %(with10)s lots of interpolation (10 steps)\n"
-            "bar11=something %(with11)s lots of interpolation (11 steps)\n"
-            "with11=%(with10)s\n"
-            "with10=%(with9)s\n"
-            "with9=%(with8)s\n"
-            "with8=%(With7)s\n"
-            "with7=%(WITH6)s\n"
-            "with6=%(with5)s\n"
-            "With5=%(with4)s\n"
-            "WITH4=%(with3)s\n"
-            "with3=%(with2)s\n"
-            "with2=%(with1)s\n"
-            "with1=with\n"
+            "bar{equals}something %(with1)s interpolation (1 step)\n"
+            "bar9{equals}something %(with9)s lots of interpolation (9 steps)\n"
+            "bar10{equals}something %(with10)s lots of interpolation (10 steps)\n"
+            "bar11{equals}something %(with11)s lots of interpolation (11 steps)\n"
+            "with11{equals}%(with10)s\n"
+            "with10{equals}%(with9)s\n"
+            "with9{equals}%(with8)s\n"
+            "with8{equals}%(With7)s\n"
+            "with7{equals}%(WITH6)s\n"
+            "with6{equals}%(with5)s\n"
+            "With5{equals}%(with4)s\n"
+            "WITH4{equals}%(with3)s\n"
+            "with3{equals}%(with2)s\n"
+            "with2{equals}%(with1)s\n"
+            "with1{equals}with\n"
             "\n"
             "[Mutual Recursion]\n"
-            "foo=%(bar)s\n"
-            "bar=%(foo)s\n"
+            "foo{equals}%(bar)s\n"
+            "bar{equals}%(foo)s\n"
             "\n"
             "[Interpolation Error]\n"
-            "name=%(reference)s\n",
+            "name{equals}%(reference)s\n".format(equals=self.delimiters[0]),
             # no definition for 'reference'
             defaults={"getname": "%(__name__)s"})
 
     def check_items_config(self, expected):
         cf = self.fromstring(
             "[section]\n"
-            "name = value\n"
-            "key: |%(name)s| \n"
-            "getdefault: |%(default)s|\n"
-            "getname: |%(__name__)s|",
+            "name {0[0]} value\n"
+            "key{0[1]} |%(name)s| \n"
+            "getdefault{0[1]} |%(default)s|\n"
+            "getname{0[1]} |%(__name__)s|".format(self.delimiters),
             defaults={"default": "<default>"})
         L = list(cf.items("section"))
         L.sort()
         self.assertEqual(L, expected)
 
 
-class ConfigParserTestCase(TestCaseBase):
+class ConfigParserTestCase(BasicTestCase):
     config_class = configparser.ConfigParser
 
     def test_interpolation(self):
+        rawval = {
+            configparser.ConfigParser: ("something %(with11)s "
+                                        "lots of interpolation (11 steps)"),
+            configparser.SafeConfigParser: "%(with1)s",
+        }
         cf = self.get_interpolation_config()
         eq = self.assertEqual
         eq(cf.get("Foo", "getname"), "Foo")
@@ -354,15 +409,22 @@
            "something with lots of interpolation (9 steps)")
         eq(cf.get("Foo", "bar10"),
            "something with lots of interpolation (10 steps)")
-        self.get_error(configparser.InterpolationDepthError, "Foo", "bar11")
+        e = self.get_error(configparser.InterpolationDepthError, "Foo", "bar11")
+        self.assertEqual(e.args, ("bar11", "Foo", rawval[self.config_class]))
 
     def test_interpolation_missing_value(self):
+        rawval = {
+            configparser.ConfigParser: '%(reference)s',
+            configparser.SafeConfigParser: '',
+        }
         self.get_interpolation_config()
-        e = self.get_error(configparser.InterpolationError,
+        e = self.get_error(configparser.InterpolationMissingOptionError,
                            "Interpolation Error", "name")
         self.assertEqual(e.reference, "reference")
         self.assertEqual(e.section, "Interpolation Error")
         self.assertEqual(e.option, "name")
+        self.assertEqual(e.args, ('name', 'Interpolation Error',
+                                  rawval[self.config_class], 'reference'))
 
     def test_items(self):
         self.check_items_config([('default', '<default>'),
@@ -392,8 +454,39 @@
         self.assertRaises(ValueError, cf.get, 'non-string',
                           'string_with_interpolation', raw=False)
 
+class ConfigParserTestCaseNonStandardDelimiters(ConfigParserTestCase):
+    delimiters = (':=', '$')
+    comment_prefixes = ('//', '"')
+
+class MultilineValuesTestCase(BasicTestCase):
+    config_class = configparser.ConfigParser
+    wonderful_spam = ("I'm having spam spam spam spam "
+                      "spam spam spam beaked beans spam "
+                      "spam spam and spam!").replace(' ', '\t\n')
+
+    def setUp(self):
+        cf = self.newconfig()
+        for i in range(100):
+            s = 'section{}'.format(i)
+            cf.add_section(s)
+            for j in range(10):
+                cf.set(s, 'lovely_spam{}'.format(j), self.wonderful_spam)
+        with open(support.TESTFN, 'w') as f:
+            cf.write(f)
+
+    def tearDown(self):
+        os.unlink(support.TESTFN)
+
+    def test_dominating_multiline_values(self):
+        # We're reading from file because this is where the code changed
+        # during performance updates in Python 3.2
+        cf_from_file = self.newconfig()
+        with open(support.TESTFN) as f:
+            cf_from_file.readfp(f)
+        self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'),
+                         self.wonderful_spam.replace('\t\n', '\n'))
 
-class RawConfigParserTestCase(TestCaseBase):
+class RawConfigParserTestCase(BasicTestCase):
     config_class = configparser.RawConfigParser
 
     def test_interpolation(self):
@@ -427,6 +520,28 @@
                          [0, 1, 1, 2, 3, 5, 8, 13])
         self.assertEqual(cf.get('non-string', 'dict'), {'pi': 3.14159})
 
+class RawConfigParserTestCaseNonStandardDelimiters(RawConfigParserTestCase):
+    delimiters = (':=', '$')
+    comment_prefixes = ('//', '"')
+
+class RawConfigParserTestSambaConf(BasicTestCase):
+    config_class = configparser.RawConfigParser
+    comment_prefixes = ('#', ';', '//', '----')
+    empty_lines_in_values = False
+
+    def test_reading(self):
+        smbconf = support.findfile("cfgparser.2")
+        # check when we pass a mix of readable and non-readable files:
+        cf = self.newconfig()
+        parsed_files = cf.read([smbconf, "nonexistent-file"], encoding='utf-8')
+        self.assertEqual(parsed_files, [smbconf])
+        sections = ['global', 'homes', 'printers',
+                    'print$', 'pdf-generator', 'tmp', 'Agustin']
+        self.assertEqual(cf.sections(), sections)
+        self.assertEqual(cf.get("global", "workgroup"), "MDKGROUP")
+        self.assertEqual(cf.getint("global", "max log size"), 50)
+        self.assertEqual(cf.get("global", "hosts allow"), "127.")
+        self.assertEqual(cf.get("tmp", "echo command"), "cat %s; rm %s")
 
 class SafeConfigParserTestCase(ConfigParserTestCase):
     config_class = configparser.SafeConfigParser
@@ -434,16 +549,17 @@
     def test_safe_interpolation(self):
         # See http://www.python.org/sf/511737
         cf = self.fromstring("[section]\n"
-                             "option1=xxx\n"
-                             "option2=%(option1)s/xxx\n"
-                             "ok=%(option1)s/%%s\n"
-                             "not_ok=%(option2)s/%%s")
+                             "option1{eq}xxx\n"
+                             "option2{eq}%(option1)s/xxx\n"
+                             "ok{eq}%(option1)s/%%s\n"
+                             "not_ok{eq}%(option2)s/%%s".format(
+                                 eq=self.delimiters[0]))
         self.assertEqual(cf.get("section", "ok"), "xxx/%s")
         self.assertEqual(cf.get("section", "not_ok"), "xxx/xxx/%s")
 
     def test_set_malformatted_interpolation(self):
         cf = self.fromstring("[sect]\n"
-                             "option1=foo\n")
+                             "option1{eq}foo\n".format(eq=self.delimiters[0]))
 
         self.assertEqual(cf.get('sect', "option1"), "foo")
 
@@ -459,7 +575,7 @@
 
     def test_set_nonstring_types(self):
         cf = self.fromstring("[sect]\n"
-                             "option1=foo\n")
+                             "option1{eq}foo\n".format(eq=self.delimiters[0]))
         # Check that we get a TypeError when setting non-string values
         # in an existing section:
         self.assertRaises(TypeError, cf.set, "sect", "option1", 1)
@@ -477,15 +593,56 @@
         cf = self.newconfig()
         self.assertRaises(ValueError, cf.add_section, "DEFAULT")
 
+class SafeConfigParserTestCaseNonStandardDelimiters(SafeConfigParserTestCase):
+    delimiters = (':=', '$')
+    comment_prefixes = ('//', '"')
 
 class SafeConfigParserTestCaseNoValue(SafeConfigParserTestCase):
     allow_no_value = True
 
+class SafeConfigParserTestCaseTrickyFile(CfgParserTestCaseClass):
+    config_class = configparser.SafeConfigParser
+    delimiters = {'='}
+    comment_prefixes = {'#'}
+    allow_no_value = True
+
+    def test_cfgparser_dot_3(self):
+        tricky = support.findfile("cfgparser.3")
+        cf = self.newconfig()
+        self.assertEqual(len(cf.read(tricky, encoding='utf-8')), 1)
+        self.assertEqual(cf.sections(), ['strange',
+                                         'corruption',
+                                         'yeah, sections can be '
+                                         'indented as well',
+                                         'another one!',
+                                         'no values here',
+                                         'tricky interpolation',
+                                         'more interpolation'])
+        #self.assertEqual(cf.getint('DEFAULT', 'go', vars={'interpolate': '-1'}),
+        #                 -1)
+        self.assertEqual(len(cf.get('strange', 'other').split('\n')), 4)
+        self.assertEqual(len(cf.get('corruption', 'value').split('\n')), 10)
+        longname = 'yeah, sections can be indented as well'
+        self.assertFalse(cf.getboolean(longname, 'are they subsections'))
+        self.assertEquals(cf.get(longname, 'lets use some Unicode'),
+                                           '片仮名')
+        self.assertEqual(len(cf.items('another one!')), 5) # 4 in section and
+                                                           # `go` from DEFAULT
+        with self.assertRaises(configparser.InterpolationMissingOptionError):
+            cf.items('no values here')
+        self.assertEqual(cf.get('tricky interpolation', 'lets'), 'do this')
+        self.assertEqual(cf.get('tricky interpolation', 'lets'),
+                         cf.get('tricky interpolation', 'go'))
+        self.assertEqual(cf.get('more interpolation', 'lets'), 'go shopping')
+
+    def test_unicode_failure(self):
+        tricky = support.findfile("cfgparser.3")
+        cf = self.newconfig()
+        with self.assertRaises(UnicodeDecodeError):
+            cf.read(tricky, encoding='ascii')
 
 class SortedTestCase(RawConfigParserTestCase):
-    def newconfig(self, defaults=None):
-        self.cf = self.config_class(defaults=defaults, dict_type=SortedDict)
-        return self.cf
+    dict_type = SortedDict
 
     def test_sorted(self):
         self.fromstring("[b]\n"
@@ -507,13 +664,40 @@
                           "o4 = 1\n\n")
 
 
+class CompatibleTestCase(CfgParserTestCaseClass):
+    config_class = configparser.RawConfigParser
+    comment_prefixes = configparser.RawConfigParser._COMPATIBLE
+
+    def test_comment_handling(self):
+        config_string = textwrap.dedent("""\
+        [Commented Bar]
+        baz=qwe ; a comment
+        foo: bar # not a comment!
+        # but this is a comment
+        ; another comment
+        quirk: this;is not a comment
+        ; a space must precede a comment character
+        """)
+        cf = self.fromstring(config_string)
+        self.assertEqual(cf.get('Commented Bar', 'foo'), 'bar # not a comment!')
+        self.assertEqual(cf.get('Commented Bar', 'baz'), 'qwe')
+        self.assertEqual(cf.get('Commented Bar', 'quirk'), 'this;is not a comment')
+
+
 def test_main():
     support.run_unittest(
         ConfigParserTestCase,
+        ConfigParserTestCaseNonStandardDelimiters,
+        MultilineValuesTestCase,
         RawConfigParserTestCase,
+        RawConfigParserTestCaseNonStandardDelimiters,
+        RawConfigParserTestSambaConf,
         SafeConfigParserTestCase,
-        SortedTestCase,
+        SafeConfigParserTestCaseNonStandardDelimiters,
         SafeConfigParserTestCaseNoValue,
+        SafeConfigParserTestCaseTrickyFile,
+        SortedTestCase,
+        CompatibleTestCase,
         )
 
 

Modified: python/branches/import_unicode/Lib/test/test_cmath.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_cmath.py	(original)
+++ python/branches/import_unicode/Lib/test/test_cmath.py	Fri Jul 30 01:19:37 2010
@@ -442,6 +442,15 @@
         self.assertCEqual(rect(1, pi/2), (0, 1.))
         self.assertCEqual(rect(1, -pi/2), (0, -1.))
 
+    def test_isfinite(self):
+        real_vals = [float('-inf'), -2.3, -0.0,
+                     0.0, 2.3, float('inf'), float('nan')]
+        for x in real_vals:
+            for y in real_vals:
+                z = complex(x, y)
+                self.assertEqual(cmath.isfinite(z),
+                                  math.isfinite(x) and math.isfinite(y))
+
     def test_isnan(self):
         self.assertFalse(cmath.isnan(1))
         self.assertFalse(cmath.isnan(1j))

Modified: python/branches/import_unicode/Lib/test/test_collections.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_collections.py	(original)
+++ python/branches/import_unicode/Lib/test/test_collections.py	Fri Jul 30 01:19:37 2010
@@ -758,6 +758,19 @@
         od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5)
         self.assertEqual(list(od.items()), pairs)                                   # mixed input
 
+        # Issue 9137: Named argument called 'other' or 'self'
+        # shouldn't be treated specially.
+        od = OrderedDict()
+        od.update(self=23)
+        self.assertEqual(list(od.items()), [('self', 23)])
+        od = OrderedDict()
+        od.update(other={})
+        self.assertEqual(list(od.items()), [('other', {})])
+        od = OrderedDict()
+        od.update(red=5, blue=6, other=7, self=8)
+        self.assertEqual(sorted(list(od.items())),
+                         [('blue', 6), ('other', 7), ('red', 5), ('self', 8)])
+
         # Make sure that direct calls to update do not clear previous contents
         # add that updates items are not moved to the end
         d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])

Modified: python/branches/import_unicode/Lib/test/test_datetime.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_datetime.py	(original)
+++ python/branches/import_unicode/Lib/test/test_datetime.py	Fri Jul 30 01:19:37 2010
@@ -1,3668 +1,42 @@
-"""Test date/time type.
-
-See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
-"""
-
-import sys
-import pickle
 import unittest
-
-from operator import lt, le, gt, ge, eq, ne, truediv, floordiv, mod
-
-from test import support
-
-from datetime import MINYEAR, MAXYEAR
-from datetime import timedelta
-from datetime import tzinfo
-from datetime import time
-from datetime import timezone
-from datetime import date, datetime
-import time as _time
-
-pickle_choices = [(pickle, pickle, proto)
-                  for proto in range(pickle.HIGHEST_PROTOCOL + 1)]
-assert len(pickle_choices) == pickle.HIGHEST_PROTOCOL + 1
-
-# An arbitrary collection of objects of non-datetime types, for testing
-# mixed-type comparisons.
-OTHERSTUFF = (10, 34.5, "abc", {}, [], ())
-
-
-# XXX Copied from test_float.
-INF = float("inf")
-NAN = float("nan")
-
-# decorator for skipping tests on non-IEEE 754 platforms
-requires_IEEE_754 = unittest.skipUnless(
-    float.__getformat__("double").startswith("IEEE"),
-    "test requires IEEE 754 doubles")
-
-
-#############################################################################
-# module tests
-
-class TestModule(unittest.TestCase):
-
-    def test_constants(self):
-        import datetime
-        self.assertEqual(datetime.MINYEAR, 1)
-        self.assertEqual(datetime.MAXYEAR, 9999)
-
-#############################################################################
-# tzinfo tests
-
-class FixedOffset(tzinfo):
-
-    def __init__(self, offset, name, dstoffset=42):
-        if isinstance(offset, int):
-            offset = timedelta(minutes=offset)
-        if isinstance(dstoffset, int):
-            dstoffset = timedelta(minutes=dstoffset)
-        self.__offset = offset
-        self.__name = name
-        self.__dstoffset = dstoffset
-    def __repr__(self):
-        return self.__name.lower()
-    def utcoffset(self, dt):
-        return self.__offset
-    def tzname(self, dt):
-        return self.__name
-    def dst(self, dt):
-        return self.__dstoffset
-
-class PicklableFixedOffset(FixedOffset):
-
-    def __init__(self, offset=None, name=None, dstoffset=None):
-        FixedOffset.__init__(self, offset, name, dstoffset)
-
-class TestTZInfo(unittest.TestCase):
-
-    def test_non_abstractness(self):
-        # In order to allow subclasses to get pickled, the C implementation
-        # wasn't able to get away with having __init__ raise
-        # NotImplementedError.
-        useless = tzinfo()
-        dt = datetime.max
-        self.assertRaises(NotImplementedError, useless.tzname, dt)
-        self.assertRaises(NotImplementedError, useless.utcoffset, dt)
-        self.assertRaises(NotImplementedError, useless.dst, dt)
-
-    def test_subclass_must_override(self):
-        class NotEnough(tzinfo):
-            def __init__(self, offset, name):
-                self.__offset = offset
-                self.__name = name
-        self.assertTrue(issubclass(NotEnough, tzinfo))
-        ne = NotEnough(3, "NotByALongShot")
-        self.assertIsInstance(ne, tzinfo)
-
-        dt = datetime.now()
-        self.assertRaises(NotImplementedError, ne.tzname, dt)
-        self.assertRaises(NotImplementedError, ne.utcoffset, dt)
-        self.assertRaises(NotImplementedError, ne.dst, dt)
-
-    def test_normal(self):
-        fo = FixedOffset(3, "Three")
-        self.assertIsInstance(fo, tzinfo)
-        for dt in datetime.now(), None:
-            self.assertEqual(fo.utcoffset(dt), timedelta(minutes=3))
-            self.assertEqual(fo.tzname(dt), "Three")
-            self.assertEqual(fo.dst(dt), timedelta(minutes=42))
-
-    def test_pickling_base(self):
-        # There's no point to pickling tzinfo objects on their own (they
-        # carry no data), but they need to be picklable anyway else
-        # concrete subclasses can't be pickled.
-        orig = tzinfo.__new__(tzinfo)
-        self.assertTrue(type(orig) is tzinfo)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertTrue(type(derived) is tzinfo)
-
-    def test_pickling_subclass(self):
-        # Make sure we can pickle/unpickle an instance of a subclass.
-        offset = timedelta(minutes=-300)
-        for otype, args in [
-            (PicklableFixedOffset, (offset, 'cookie')),
-            (timezone, (offset,)),
-            (timezone, (offset, "EST"))]:
-            orig = otype(*args)
-            oname = orig.tzname(None)
-            self.assertIsInstance(orig, tzinfo)
-            self.assertIs(type(orig), otype)
-            self.assertEqual(orig.utcoffset(None), offset)
-            self.assertEqual(orig.tzname(None), oname)
-            for pickler, unpickler, proto in pickle_choices:
-                green = pickler.dumps(orig, proto)
-                derived = unpickler.loads(green)
-                self.assertIsInstance(derived, tzinfo)
-                self.assertIs(type(derived), otype)
-                self.assertEqual(derived.utcoffset(None), offset)
-                self.assertEqual(derived.tzname(None), oname)
-
-class TestTimeZone(unittest.TestCase):
-
-    def setUp(self):
-        self.ACDT = timezone(timedelta(hours=9.5), 'ACDT')
-        self.EST = timezone(-timedelta(hours=5), 'EST')
-        self.DT = datetime(2010, 1, 1)
-
-    def test_str(self):
-        for tz in [self.ACDT, self.EST, timezone.utc,
-                   timezone.min, timezone.max]:
-            self.assertEqual(str(tz), tz.tzname(None))
-
-    def test_repr(self):
-        import datetime
-        for tz in [self.ACDT, self.EST, timezone.utc,
-                   timezone.min, timezone.max]:
-            # test round-trip
-            tzrep = repr(tz)
-            self.assertEqual(tz, eval(tzrep))
-
-
-    def test_class_members(self):
-        limit = timedelta(hours=23, minutes=59)
-        self.assertEqual(timezone.utc.utcoffset(None), ZERO)
-        self.assertEqual(timezone.min.utcoffset(None), -limit)
-        self.assertEqual(timezone.max.utcoffset(None), limit)
-
-
-    def test_constructor(self):
-        self.assertEqual(timezone.utc, timezone(timedelta(0)))
-        # invalid offsets
-        for invalid in [timedelta(microseconds=1), timedelta(1, 1),
-                        timedelta(seconds=1), timedelta(1), -timedelta(1)]:
-            self.assertRaises(ValueError, timezone, invalid)
-            self.assertRaises(ValueError, timezone, -invalid)
-
-        with self.assertRaises(TypeError): timezone(None)
-        with self.assertRaises(TypeError): timezone(42)
-        with self.assertRaises(TypeError): timezone(ZERO, None)
-        with self.assertRaises(TypeError): timezone(ZERO, 42)
-        with self.assertRaises(TypeError): timezone(ZERO, 'ABC', 'extra')
-
-    def test_inheritance(self):
-        self.assertIsInstance(timezone.utc, tzinfo)
-        self.assertIsInstance(self.EST, tzinfo)
-
-    def test_utcoffset(self):
-        dummy = self.DT
-        for h in [0, 1.5, 12]:
-            offset = h * HOUR
-            self.assertEqual(offset, timezone(offset).utcoffset(dummy))
-            self.assertEqual(-offset, timezone(-offset).utcoffset(dummy))
-
-        with self.assertRaises(TypeError): self.EST.utcoffset('')
-        with self.assertRaises(TypeError): self.EST.utcoffset(5)
-
-
-    def test_dst(self):
-        self.assertEqual(None, timezone.utc.dst(self.DT))
-
-        with self.assertRaises(TypeError): self.EST.dst('')
-        with self.assertRaises(TypeError): self.EST.dst(5)
-
-    def test_tzname(self):
-        self.assertEqual('UTC+00:00', timezone(ZERO).tzname(None))
-        self.assertEqual('UTC-05:00', timezone(-5 * HOUR).tzname(None))
-        self.assertEqual('UTC+09:30', timezone(9.5 * HOUR).tzname(None))
-        self.assertEqual('UTC-00:01', timezone(timedelta(minutes=-1)).tzname(None))
-        self.assertEqual('XYZ', timezone(-5 * HOUR, 'XYZ').tzname(None))
-
-        with self.assertRaises(TypeError): self.EST.tzname('')
-        with self.assertRaises(TypeError): self.EST.tzname(5)
-
-    def test_fromutc(self):
-        with self.assertRaises(ValueError):
-            timezone.utc.fromutc(self.DT)
-        with self.assertRaises(TypeError):
-            timezone.utc.fromutc('not datetime')
-        for tz in [self.EST, self.ACDT, Eastern]:
-            utctime = self.DT.replace(tzinfo=tz)
-            local = tz.fromutc(utctime)
-            self.assertEqual(local - utctime, tz.utcoffset(local))
-            self.assertEqual(local,
-                             self.DT.replace(tzinfo=timezone.utc))
-
-    def test_comparison(self):
-        self.assertNotEqual(timezone(ZERO), timezone(HOUR))
-        self.assertEqual(timezone(HOUR), timezone(HOUR))
-        self.assertEqual(timezone(-5 * HOUR), timezone(-5 * HOUR, 'EST'))
-        with self.assertRaises(TypeError): timezone(ZERO) < timezone(ZERO)
-        self.assertIn(timezone(ZERO), {timezone(ZERO)})
-
-    def test_aware_datetime(self):
-        # test that timezone instances can be used by datetime
-        t = datetime(1, 1, 1)
-        for tz in [timezone.min, timezone.max, timezone.utc]:
-            self.assertEqual(tz.tzname(t),
-                             t.replace(tzinfo=tz).tzname())
-            self.assertEqual(tz.utcoffset(t),
-                             t.replace(tzinfo=tz).utcoffset())
-            self.assertEqual(tz.dst(t),
-                             t.replace(tzinfo=tz).dst())
-
-#############################################################################
-# Base clase for testing a particular aspect of timedelta, time, date and
-# datetime comparisons.
-
-class HarmlessMixedComparison:
-    # Test that __eq__ and __ne__ don't complain for mixed-type comparisons.
-
-    # Subclasses must define 'theclass', and theclass(1, 1, 1) must be a
-    # legit constructor.
-
-    def test_harmless_mixed_comparison(self):
-        me = self.theclass(1, 1, 1)
-
-        self.assertFalse(me == ())
-        self.assertTrue(me != ())
-        self.assertFalse(() == me)
-        self.assertTrue(() != me)
-
-        self.assertIn(me, [1, 20, [], me])
-        self.assertIn([], [me, 1, 20, []])
-
-    def test_harmful_mixed_comparison(self):
-        me = self.theclass(1, 1, 1)
-
-        self.assertRaises(TypeError, lambda: me < ())
-        self.assertRaises(TypeError, lambda: me <= ())
-        self.assertRaises(TypeError, lambda: me > ())
-        self.assertRaises(TypeError, lambda: me >= ())
-
-        self.assertRaises(TypeError, lambda: () < me)
-        self.assertRaises(TypeError, lambda: () <= me)
-        self.assertRaises(TypeError, lambda: () > me)
-        self.assertRaises(TypeError, lambda: () >= me)
-
-#############################################################################
-# timedelta tests
-
-class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
-
-    theclass = timedelta
-
-    def test_constructor(self):
-        eq = self.assertEqual
-        td = timedelta
-
-        # Check keyword args to constructor
-        eq(td(), td(weeks=0, days=0, hours=0, minutes=0, seconds=0,
-                    milliseconds=0, microseconds=0))
-        eq(td(1), td(days=1))
-        eq(td(0, 1), td(seconds=1))
-        eq(td(0, 0, 1), td(microseconds=1))
-        eq(td(weeks=1), td(days=7))
-        eq(td(days=1), td(hours=24))
-        eq(td(hours=1), td(minutes=60))
-        eq(td(minutes=1), td(seconds=60))
-        eq(td(seconds=1), td(milliseconds=1000))
-        eq(td(milliseconds=1), td(microseconds=1000))
-
-        # Check float args to constructor
-        eq(td(weeks=1.0/7), td(days=1))
-        eq(td(days=1.0/24), td(hours=1))
-        eq(td(hours=1.0/60), td(minutes=1))
-        eq(td(minutes=1.0/60), td(seconds=1))
-        eq(td(seconds=0.001), td(milliseconds=1))
-        eq(td(milliseconds=0.001), td(microseconds=1))
-
-    def test_computations(self):
-        eq = self.assertEqual
-        td = timedelta
-
-        a = td(7) # One week
-        b = td(0, 60) # One minute
-        c = td(0, 0, 1000) # One millisecond
-        eq(a+b+c, td(7, 60, 1000))
-        eq(a-b, td(6, 24*3600 - 60))
-        eq(b.__rsub__(a), td(6, 24*3600 - 60))
-        eq(-a, td(-7))
-        eq(+a, td(7))
-        eq(-b, td(-1, 24*3600 - 60))
-        eq(-c, td(-1, 24*3600 - 1, 999000))
-        eq(abs(a), a)
-        eq(abs(-a), a)
-        eq(td(6, 24*3600), a)
-        eq(td(0, 0, 60*1000000), b)
-        eq(a*10, td(70))
-        eq(a*10, 10*a)
-        eq(a*10, 10*a)
-        eq(b*10, td(0, 600))
-        eq(10*b, td(0, 600))
-        eq(b*10, td(0, 600))
-        eq(c*10, td(0, 0, 10000))
-        eq(10*c, td(0, 0, 10000))
-        eq(c*10, td(0, 0, 10000))
-        eq(a*-1, -a)
-        eq(b*-2, -b-b)
-        eq(c*-2, -c+-c)
-        eq(b*(60*24), (b*60)*24)
-        eq(b*(60*24), (60*b)*24)
-        eq(c*1000, td(0, 1))
-        eq(1000*c, td(0, 1))
-        eq(a//7, td(1))
-        eq(b//10, td(0, 6))
-        eq(c//1000, td(0, 0, 1))
-        eq(a//10, td(0, 7*24*360))
-        eq(a//3600000, td(0, 0, 7*24*1000))
-        eq(a/0.5, td(14))
-        eq(b/0.5, td(0, 120))
-        eq(a/7, td(1))
-        eq(b/10, td(0, 6))
-        eq(c/1000, td(0, 0, 1))
-        eq(a/10, td(0, 7*24*360))
-        eq(a/3600000, td(0, 0, 7*24*1000))
-
-        # Multiplication by float
-        us = td(microseconds=1)
-        eq((3*us) * 0.5, 2*us)
-        eq((5*us) * 0.5, 2*us)
-        eq(0.5 * (3*us), 2*us)
-        eq(0.5 * (5*us), 2*us)
-        eq((-3*us) * 0.5, -2*us)
-        eq((-5*us) * 0.5, -2*us)
-
-        # Division by int and float
-        eq((3*us) / 2, 2*us)
-        eq((5*us) / 2, 2*us)
-        eq((-3*us) / 2.0, -2*us)
-        eq((-5*us) / 2.0, -2*us)
-        eq((3*us) / -2, -2*us)
-        eq((5*us) / -2, -2*us)
-        eq((3*us) / -2.0, -2*us)
-        eq((5*us) / -2.0, -2*us)
-        for i in range(-10, 10):
-            eq((i*us/3)//us, round(i/3))
-        for i in range(-10, 10):
-            eq((i*us/-3)//us, round(i/-3))
-
-    def test_disallowed_computations(self):
-        a = timedelta(42)
-
-        # Add/sub ints or floats should be illegal
-        for i in 1, 1.0:
-            self.assertRaises(TypeError, lambda: a+i)
-            self.assertRaises(TypeError, lambda: a-i)
-            self.assertRaises(TypeError, lambda: i+a)
-            self.assertRaises(TypeError, lambda: i-a)
-
-        # Division of int by timedelta doesn't make sense.
-        # Division by zero doesn't make sense.
-        zero = 0
-        self.assertRaises(TypeError, lambda: zero // a)
-        self.assertRaises(ZeroDivisionError, lambda: a // zero)
-        self.assertRaises(ZeroDivisionError, lambda: a / zero)
-        self.assertRaises(ZeroDivisionError, lambda: a / 0.0)
-        self.assertRaises(TypeError, lambda: a / '')
-
-    @requires_IEEE_754
-    def test_disallowed_special(self):
-        a = timedelta(42)
-        self.assertRaises(ValueError, a.__mul__, NAN)
-        self.assertRaises(ValueError, a.__truediv__, NAN)
-
-    def test_basic_attributes(self):
-        days, seconds, us = 1, 7, 31
-        td = timedelta(days, seconds, us)
-        self.assertEqual(td.days, days)
-        self.assertEqual(td.seconds, seconds)
-        self.assertEqual(td.microseconds, us)
-
-    def test_total_seconds(self):
-        td = timedelta(days=365)
-        self.assertEqual(td.total_seconds(), 31536000.0)
-        for total_seconds in [123456.789012, -123456.789012, 0.123456, 0, 1e6]:
-            td = timedelta(seconds=total_seconds)
-            self.assertEqual(td.total_seconds(), total_seconds)
-        # Issue8644: Test that td.total_seconds() has the same
-        # accuracy as td / timedelta(seconds=1).
-        for ms in [-1, -2, -123]:
-            td = timedelta(microseconds=ms)
-            self.assertEqual(td.total_seconds(), td / timedelta(seconds=1))
-
-    def test_carries(self):
-        t1 = timedelta(days=100,
-                       weeks=-7,
-                       hours=-24*(100-49),
-                       minutes=-3,
-                       seconds=12,
-                       microseconds=(3*60 - 12) * 1e6 + 1)
-        t2 = timedelta(microseconds=1)
-        self.assertEqual(t1, t2)
-
-    def test_hash_equality(self):
-        t1 = timedelta(days=100,
-                       weeks=-7,
-                       hours=-24*(100-49),
-                       minutes=-3,
-                       seconds=12,
-                       microseconds=(3*60 - 12) * 1000000)
-        t2 = timedelta()
-        self.assertEqual(hash(t1), hash(t2))
-
-        t1 += timedelta(weeks=7)
-        t2 += timedelta(days=7*7)
-        self.assertEqual(t1, t2)
-        self.assertEqual(hash(t1), hash(t2))
-
-        d = {t1: 1}
-        d[t2] = 2
-        self.assertEqual(len(d), 1)
-        self.assertEqual(d[t1], 2)
-
-    def test_pickling(self):
-        args = 12, 34, 56
-        orig = timedelta(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_compare(self):
-        t1 = timedelta(2, 3, 4)
-        t2 = timedelta(2, 3, 4)
-        self.assertEqual(t1, t2)
-        self.assertTrue(t1 <= t2)
-        self.assertTrue(t1 >= t2)
-        self.assertTrue(not t1 != t2)
-        self.assertTrue(not t1 < t2)
-        self.assertTrue(not t1 > t2)
-
-        for args in (3, 3, 3), (2, 4, 4), (2, 3, 5):
-            t2 = timedelta(*args)   # this is larger than t1
-            self.assertTrue(t1 < t2)
-            self.assertTrue(t2 > t1)
-            self.assertTrue(t1 <= t2)
-            self.assertTrue(t2 >= t1)
-            self.assertTrue(t1 != t2)
-            self.assertTrue(t2 != t1)
-            self.assertTrue(not t1 == t2)
-            self.assertTrue(not t2 == t1)
-            self.assertTrue(not t1 > t2)
-            self.assertTrue(not t2 < t1)
-            self.assertTrue(not t1 >= t2)
-            self.assertTrue(not t2 <= t1)
-
-        for badarg in OTHERSTUFF:
-            self.assertEqual(t1 == badarg, False)
-            self.assertEqual(t1 != badarg, True)
-            self.assertEqual(badarg == t1, False)
-            self.assertEqual(badarg != t1, True)
-
-            self.assertRaises(TypeError, lambda: t1 <= badarg)
-            self.assertRaises(TypeError, lambda: t1 < badarg)
-            self.assertRaises(TypeError, lambda: t1 > badarg)
-            self.assertRaises(TypeError, lambda: t1 >= badarg)
-            self.assertRaises(TypeError, lambda: badarg <= t1)
-            self.assertRaises(TypeError, lambda: badarg < t1)
-            self.assertRaises(TypeError, lambda: badarg > t1)
-            self.assertRaises(TypeError, lambda: badarg >= t1)
-
-    def test_str(self):
-        td = timedelta
-        eq = self.assertEqual
-
-        eq(str(td(1)), "1 day, 0:00:00")
-        eq(str(td(-1)), "-1 day, 0:00:00")
-        eq(str(td(2)), "2 days, 0:00:00")
-        eq(str(td(-2)), "-2 days, 0:00:00")
-
-        eq(str(td(hours=12, minutes=58, seconds=59)), "12:58:59")
-        eq(str(td(hours=2, minutes=3, seconds=4)), "2:03:04")
-        eq(str(td(weeks=-30, hours=23, minutes=12, seconds=34)),
-           "-210 days, 23:12:34")
-
-        eq(str(td(milliseconds=1)), "0:00:00.001000")
-        eq(str(td(microseconds=3)), "0:00:00.000003")
-
-        eq(str(td(days=999999999, hours=23, minutes=59, seconds=59,
-                   microseconds=999999)),
-           "999999999 days, 23:59:59.999999")
-
-    def test_repr(self):
-        name = 'datetime.' + self.theclass.__name__
-        self.assertEqual(repr(self.theclass(1)),
-                         "%s(1)" % name)
-        self.assertEqual(repr(self.theclass(10, 2)),
-                         "%s(10, 2)" % name)
-        self.assertEqual(repr(self.theclass(-10, 2, 400000)),
-                         "%s(-10, 2, 400000)" % name)
-
-    def test_roundtrip(self):
-        for td in (timedelta(days=999999999, hours=23, minutes=59,
-                             seconds=59, microseconds=999999),
-                   timedelta(days=-999999999),
-                   timedelta(days=-999999999, seconds=1),
-                   timedelta(days=1, seconds=2, microseconds=3)):
-
-            # Verify td -> string -> td identity.
-            s = repr(td)
-            self.assertTrue(s.startswith('datetime.'))
-            s = s[9:]
-            td2 = eval(s)
-            self.assertEqual(td, td2)
-
-            # Verify identity via reconstructing from pieces.
-            td2 = timedelta(td.days, td.seconds, td.microseconds)
-            self.assertEqual(td, td2)
-
-    def test_resolution_info(self):
-        self.assertIsInstance(timedelta.min, timedelta)
-        self.assertIsInstance(timedelta.max, timedelta)
-        self.assertIsInstance(timedelta.resolution, timedelta)
-        self.assertTrue(timedelta.max > timedelta.min)
-        self.assertEqual(timedelta.min, timedelta(-999999999))
-        self.assertEqual(timedelta.max, timedelta(999999999, 24*3600-1, 1e6-1))
-        self.assertEqual(timedelta.resolution, timedelta(0, 0, 1))
-
-    def test_overflow(self):
-        tiny = timedelta.resolution
-
-        td = timedelta.min + tiny
-        td -= tiny  # no problem
-        self.assertRaises(OverflowError, td.__sub__, tiny)
-        self.assertRaises(OverflowError, td.__add__, -tiny)
-
-        td = timedelta.max - tiny
-        td += tiny  # no problem
-        self.assertRaises(OverflowError, td.__add__, tiny)
-        self.assertRaises(OverflowError, td.__sub__, -tiny)
-
-        self.assertRaises(OverflowError, lambda: -timedelta.max)
-
-        day = timedelta(1)
-        self.assertRaises(OverflowError, day.__mul__, 10**9)
-        self.assertRaises(OverflowError, day.__mul__, 1e9)
-        self.assertRaises(OverflowError, day.__truediv__, 1e-20)
-        self.assertRaises(OverflowError, day.__truediv__, 1e-10)
-        self.assertRaises(OverflowError, day.__truediv__, 9e-10)
-
-    @requires_IEEE_754
-    def _test_overflow_special(self):
-        day = timedelta(1)
-        self.assertRaises(OverflowError, day.__mul__, INF)
-        self.assertRaises(OverflowError, day.__mul__, -INF)
-
-    def test_microsecond_rounding(self):
-        td = timedelta
-        eq = self.assertEqual
-
-        # Single-field rounding.
-        eq(td(milliseconds=0.4/1000), td(0))    # rounds to 0
-        eq(td(milliseconds=-0.4/1000), td(0))    # rounds to 0
-        eq(td(milliseconds=0.6/1000), td(microseconds=1))
-        eq(td(milliseconds=-0.6/1000), td(microseconds=-1))
-
-        # Rounding due to contributions from more than one field.
-        us_per_hour = 3600e6
-        us_per_day = us_per_hour * 24
-        eq(td(days=.4/us_per_day), td(0))
-        eq(td(hours=.2/us_per_hour), td(0))
-        eq(td(days=.4/us_per_day, hours=.2/us_per_hour), td(microseconds=1))
-
-        eq(td(days=-.4/us_per_day), td(0))
-        eq(td(hours=-.2/us_per_hour), td(0))
-        eq(td(days=-.4/us_per_day, hours=-.2/us_per_hour), td(microseconds=-1))
-
-    def test_massive_normalization(self):
-        td = timedelta(microseconds=-1)
-        self.assertEqual((td.days, td.seconds, td.microseconds),
-                         (-1, 24*3600-1, 999999))
-
-    def test_bool(self):
-        self.assertTrue(timedelta(1))
-        self.assertTrue(timedelta(0, 1))
-        self.assertTrue(timedelta(0, 0, 1))
-        self.assertTrue(timedelta(microseconds=1))
-        self.assertTrue(not timedelta(0))
-
-    def test_subclass_timedelta(self):
-
-        class T(timedelta):
-            @staticmethod
-            def from_td(td):
-                return T(td.days, td.seconds, td.microseconds)
-
-            def as_hours(self):
-                sum = (self.days * 24 +
-                       self.seconds / 3600.0 +
-                       self.microseconds / 3600e6)
-                return round(sum)
-
-        t1 = T(days=1)
-        self.assertTrue(type(t1) is T)
-        self.assertEqual(t1.as_hours(), 24)
-
-        t2 = T(days=-1, seconds=-3600)
-        self.assertTrue(type(t2) is T)
-        self.assertEqual(t2.as_hours(), -25)
-
-        t3 = t1 + t2
-        self.assertTrue(type(t3) is timedelta)
-        t4 = T.from_td(t3)
-        self.assertTrue(type(t4) is T)
-        self.assertEqual(t3.days, t4.days)
-        self.assertEqual(t3.seconds, t4.seconds)
-        self.assertEqual(t3.microseconds, t4.microseconds)
-        self.assertEqual(str(t3), str(t4))
-        self.assertEqual(t4.as_hours(), -1)
-
-    def test_division(self):
-        t = timedelta(hours=1, minutes=24, seconds=19)
-        second = timedelta(seconds=1)
-        self.assertEqual(t / second, 5059.0)
-        self.assertEqual(t // second, 5059)
-
-        t = timedelta(minutes=2, seconds=30)
-        minute = timedelta(minutes=1)
-        self.assertEqual(t / minute, 2.5)
-        self.assertEqual(t // minute, 2)
-
-        zerotd = timedelta(0)
-        self.assertRaises(ZeroDivisionError, truediv, t, zerotd)
-        self.assertRaises(ZeroDivisionError, floordiv, t, zerotd)
-
-        # self.assertRaises(TypeError, truediv, t, 2)
-        # note: floor division of a timedelta by an integer *is*
-        # currently permitted.
-
-    def test_remainder(self):
-        t = timedelta(minutes=2, seconds=30)
-        minute = timedelta(minutes=1)
-        r = t % minute
-        self.assertEqual(r, timedelta(seconds=30))
-
-        t = timedelta(minutes=-2, seconds=30)
-        r = t %  minute
-        self.assertEqual(r, timedelta(seconds=30))
-
-        zerotd = timedelta(0)
-        self.assertRaises(ZeroDivisionError, mod, t, zerotd)
-
-        self.assertRaises(TypeError, mod, t, 10)
-
-    def test_divmod(self):
-        t = timedelta(minutes=2, seconds=30)
-        minute = timedelta(minutes=1)
-        q, r = divmod(t, minute)
-        self.assertEqual(q, 2)
-        self.assertEqual(r, timedelta(seconds=30))
-
-        t = timedelta(minutes=-2, seconds=30)
-        q, r = divmod(t, minute)
-        self.assertEqual(q, -2)
-        self.assertEqual(r, timedelta(seconds=30))
-
-        zerotd = timedelta(0)
-        self.assertRaises(ZeroDivisionError, divmod, t, zerotd)
-
-        self.assertRaises(TypeError, divmod, t, 10)
-
-
-#############################################################################
-# date tests
-
-class TestDateOnly(unittest.TestCase):
-    # Tests here won't pass if also run on datetime objects, so don't
-    # subclass this to test datetimes too.
-
-    def test_delta_non_days_ignored(self):
-        dt = date(2000, 1, 2)
-        delta = timedelta(days=1, hours=2, minutes=3, seconds=4,
-                          microseconds=5)
-        days = timedelta(delta.days)
-        self.assertEqual(days, timedelta(1))
-
-        dt2 = dt + delta
-        self.assertEqual(dt2, dt + days)
-
-        dt2 = delta + dt
-        self.assertEqual(dt2, dt + days)
-
-        dt2 = dt - delta
-        self.assertEqual(dt2, dt - days)
-
-        delta = -delta
-        days = timedelta(delta.days)
-        self.assertEqual(days, timedelta(-2))
-
-        dt2 = dt + delta
-        self.assertEqual(dt2, dt + days)
-
-        dt2 = delta + dt
-        self.assertEqual(dt2, dt + days)
-
-        dt2 = dt - delta
-        self.assertEqual(dt2, dt - days)
-
-class SubclassDate(date):
-    sub_var = 1
-
-class TestDate(HarmlessMixedComparison, unittest.TestCase):
-    # Tests here should pass for both dates and datetimes, except for a
-    # few tests that TestDateTime overrides.
-
-    theclass = date
-
-    def test_basic_attributes(self):
-        dt = self.theclass(2002, 3, 1)
-        self.assertEqual(dt.year, 2002)
-        self.assertEqual(dt.month, 3)
-        self.assertEqual(dt.day, 1)
-
-    def test_roundtrip(self):
-        for dt in (self.theclass(1, 2, 3),
-                   self.theclass.today()):
-            # Verify dt -> string -> date identity.
-            s = repr(dt)
-            self.assertTrue(s.startswith('datetime.'))
-            s = s[9:]
-            dt2 = eval(s)
-            self.assertEqual(dt, dt2)
-
-            # Verify identity via reconstructing from pieces.
-            dt2 = self.theclass(dt.year, dt.month, dt.day)
-            self.assertEqual(dt, dt2)
-
-    def test_ordinal_conversions(self):
-        # Check some fixed values.
-        for y, m, d, n in [(1, 1, 1, 1),      # calendar origin
-                           (1, 12, 31, 365),
-                           (2, 1, 1, 366),
-                           # first example from "Calendrical Calculations"
-                           (1945, 11, 12, 710347)]:
-            d = self.theclass(y, m, d)
-            self.assertEqual(n, d.toordinal())
-            fromord = self.theclass.fromordinal(n)
-            self.assertEqual(d, fromord)
-            if hasattr(fromord, "hour"):
-            # if we're checking something fancier than a date, verify
-            # the extra fields have been zeroed out
-                self.assertEqual(fromord.hour, 0)
-                self.assertEqual(fromord.minute, 0)
-                self.assertEqual(fromord.second, 0)
-                self.assertEqual(fromord.microsecond, 0)
-
-        # Check first and last days of year spottily across the whole
-        # range of years supported.
-        for year in range(MINYEAR, MAXYEAR+1, 7):
-            # Verify (year, 1, 1) -> ordinal -> y, m, d is identity.
-            d = self.theclass(year, 1, 1)
-            n = d.toordinal()
-            d2 = self.theclass.fromordinal(n)
-            self.assertEqual(d, d2)
-            # Verify that moving back a day gets to the end of year-1.
-            if year > 1:
-                d = self.theclass.fromordinal(n-1)
-                d2 = self.theclass(year-1, 12, 31)
-                self.assertEqual(d, d2)
-                self.assertEqual(d2.toordinal(), n-1)
-
-        # Test every day in a leap-year and a non-leap year.
-        dim = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
-        for year, isleap in (2000, True), (2002, False):
-            n = self.theclass(year, 1, 1).toordinal()
-            for month, maxday in zip(range(1, 13), dim):
-                if month == 2 and isleap:
-                    maxday += 1
-                for day in range(1, maxday+1):
-                    d = self.theclass(year, month, day)
-                    self.assertEqual(d.toordinal(), n)
-                    self.assertEqual(d, self.theclass.fromordinal(n))
-                    n += 1
-
-    def test_extreme_ordinals(self):
-        a = self.theclass.min
-        a = self.theclass(a.year, a.month, a.day)  # get rid of time parts
-        aord = a.toordinal()
-        b = a.fromordinal(aord)
-        self.assertEqual(a, b)
-
-        self.assertRaises(ValueError, lambda: a.fromordinal(aord - 1))
-
-        b = a + timedelta(days=1)
-        self.assertEqual(b.toordinal(), aord + 1)
-        self.assertEqual(b, self.theclass.fromordinal(aord + 1))
-
-        a = self.theclass.max
-        a = self.theclass(a.year, a.month, a.day)  # get rid of time parts
-        aord = a.toordinal()
-        b = a.fromordinal(aord)
-        self.assertEqual(a, b)
-
-        self.assertRaises(ValueError, lambda: a.fromordinal(aord + 1))
-
-        b = a - timedelta(days=1)
-        self.assertEqual(b.toordinal(), aord - 1)
-        self.assertEqual(b, self.theclass.fromordinal(aord - 1))
-
-    def test_bad_constructor_arguments(self):
-        # bad years
-        self.theclass(MINYEAR, 1, 1)  # no exception
-        self.theclass(MAXYEAR, 1, 1)  # no exception
-        self.assertRaises(ValueError, self.theclass, MINYEAR-1, 1, 1)
-        self.assertRaises(ValueError, self.theclass, MAXYEAR+1, 1, 1)
-        # bad months
-        self.theclass(2000, 1, 1)    # no exception
-        self.theclass(2000, 12, 1)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 0, 1)
-        self.assertRaises(ValueError, self.theclass, 2000, 13, 1)
-        # bad days
-        self.theclass(2000, 2, 29)   # no exception
-        self.theclass(2004, 2, 29)   # no exception
-        self.theclass(2400, 2, 29)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 2, 30)
-        self.assertRaises(ValueError, self.theclass, 2001, 2, 29)
-        self.assertRaises(ValueError, self.theclass, 2100, 2, 29)
-        self.assertRaises(ValueError, self.theclass, 1900, 2, 29)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 0)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 32)
-
-    def test_hash_equality(self):
-        d = self.theclass(2000, 12, 31)
-        # same thing
-        e = self.theclass(2000, 12, 31)
-        self.assertEqual(d, e)
-        self.assertEqual(hash(d), hash(e))
-
-        dic = {d: 1}
-        dic[e] = 2
-        self.assertEqual(len(dic), 1)
-        self.assertEqual(dic[d], 2)
-        self.assertEqual(dic[e], 2)
-
-        d = self.theclass(2001,  1,  1)
-        # same thing
-        e = self.theclass(2001,  1,  1)
-        self.assertEqual(d, e)
-        self.assertEqual(hash(d), hash(e))
-
-        dic = {d: 1}
-        dic[e] = 2
-        self.assertEqual(len(dic), 1)
-        self.assertEqual(dic[d], 2)
-        self.assertEqual(dic[e], 2)
-
-    def test_computations(self):
-        a = self.theclass(2002, 1, 31)
-        b = self.theclass(1956, 1, 31)
-        c = self.theclass(2001,2,1)
-
-        diff = a-b
-        self.assertEqual(diff.days, 46*365 + len(range(1956, 2002, 4)))
-        self.assertEqual(diff.seconds, 0)
-        self.assertEqual(diff.microseconds, 0)
-
-        day = timedelta(1)
-        week = timedelta(7)
-        a = self.theclass(2002, 3, 2)
-        self.assertEqual(a + day, self.theclass(2002, 3, 3))
-        self.assertEqual(day + a, self.theclass(2002, 3, 3))
-        self.assertEqual(a - day, self.theclass(2002, 3, 1))
-        self.assertEqual(-day + a, self.theclass(2002, 3, 1))
-        self.assertEqual(a + week, self.theclass(2002, 3, 9))
-        self.assertEqual(a - week, self.theclass(2002, 2, 23))
-        self.assertEqual(a + 52*week, self.theclass(2003, 3, 1))
-        self.assertEqual(a - 52*week, self.theclass(2001, 3, 3))
-        self.assertEqual((a + week) - a, week)
-        self.assertEqual((a + day) - a, day)
-        self.assertEqual((a - week) - a, -week)
-        self.assertEqual((a - day) - a, -day)
-        self.assertEqual(a - (a + week), -week)
-        self.assertEqual(a - (a + day), -day)
-        self.assertEqual(a - (a - week), week)
-        self.assertEqual(a - (a - day), day)
-        self.assertEqual(c - (c - day), day)
-
-        # Add/sub ints or floats should be illegal
-        for i in 1, 1.0:
-            self.assertRaises(TypeError, lambda: a+i)
-            self.assertRaises(TypeError, lambda: a-i)
-            self.assertRaises(TypeError, lambda: i+a)
-            self.assertRaises(TypeError, lambda: i-a)
-
-        # delta - date is senseless.
-        self.assertRaises(TypeError, lambda: day - a)
-        # mixing date and (delta or date) via * or // is senseless
-        self.assertRaises(TypeError, lambda: day * a)
-        self.assertRaises(TypeError, lambda: a * day)
-        self.assertRaises(TypeError, lambda: day // a)
-        self.assertRaises(TypeError, lambda: a // day)
-        self.assertRaises(TypeError, lambda: a * a)
-        self.assertRaises(TypeError, lambda: a // a)
-        # date + date is senseless
-        self.assertRaises(TypeError, lambda: a + a)
-
-    def test_overflow(self):
-        tiny = self.theclass.resolution
-
-        for delta in [tiny, timedelta(1), timedelta(2)]:
-            dt = self.theclass.min + delta
-            dt -= delta  # no problem
-            self.assertRaises(OverflowError, dt.__sub__, delta)
-            self.assertRaises(OverflowError, dt.__add__, -delta)
-
-            dt = self.theclass.max - delta
-            dt += delta  # no problem
-            self.assertRaises(OverflowError, dt.__add__, delta)
-            self.assertRaises(OverflowError, dt.__sub__, -delta)
-
-    def test_fromtimestamp(self):
-        import time
-
-        # Try an arbitrary fixed value.
-        year, month, day = 1999, 9, 19
-        ts = time.mktime((year, month, day, 0, 0, 0, 0, 0, -1))
-        d = self.theclass.fromtimestamp(ts)
-        self.assertEqual(d.year, year)
-        self.assertEqual(d.month, month)
-        self.assertEqual(d.day, day)
-
-    def test_insane_fromtimestamp(self):
-        # It's possible that some platform maps time_t to double,
-        # and that this test will fail there.  This test should
-        # exempt such platforms (provided they return reasonable
-        # results!).
-        for insane in -1e200, 1e200:
-            self.assertRaises(ValueError, self.theclass.fromtimestamp,
-                              insane)
-
-    def test_today(self):
-        import time
-
-        # We claim that today() is like fromtimestamp(time.time()), so
-        # prove it.
-        for dummy in range(3):
-            today = self.theclass.today()
-            ts = time.time()
-            todayagain = self.theclass.fromtimestamp(ts)
-            if today == todayagain:
-                break
-            # There are several legit reasons that could fail:
-            # 1. It recently became midnight, between the today() and the
-            #    time() calls.
-            # 2. The platform time() has such fine resolution that we'll
-            #    never get the same value twice.
-            # 3. The platform time() has poor resolution, and we just
-            #    happened to call today() right before a resolution quantum
-            #    boundary.
-            # 4. The system clock got fiddled between calls.
-            # In any case, wait a little while and try again.
-            time.sleep(0.1)
-
-        # It worked or it didn't.  If it didn't, assume it's reason #2, and
-        # let the test pass if they're within half a second of each other.
-        self.assertTrue(today == todayagain or
-                        abs(todayagain - today) < timedelta(seconds=0.5))
-
-    def test_weekday(self):
-        for i in range(7):
-            # March 4, 2002 is a Monday
-            self.assertEqual(self.theclass(2002, 3, 4+i).weekday(), i)
-            self.assertEqual(self.theclass(2002, 3, 4+i).isoweekday(), i+1)
-            # January 2, 1956 is a Monday
-            self.assertEqual(self.theclass(1956, 1, 2+i).weekday(), i)
-            self.assertEqual(self.theclass(1956, 1, 2+i).isoweekday(), i+1)
-
-    def test_isocalendar(self):
-        # Check examples from
-        # http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
-        for i in range(7):
-            d = self.theclass(2003, 12, 22+i)
-            self.assertEqual(d.isocalendar(), (2003, 52, i+1))
-            d = self.theclass(2003, 12, 29) + timedelta(i)
-            self.assertEqual(d.isocalendar(), (2004, 1, i+1))
-            d = self.theclass(2004, 1, 5+i)
-            self.assertEqual(d.isocalendar(), (2004, 2, i+1))
-            d = self.theclass(2009, 12, 21+i)
-            self.assertEqual(d.isocalendar(), (2009, 52, i+1))
-            d = self.theclass(2009, 12, 28) + timedelta(i)
-            self.assertEqual(d.isocalendar(), (2009, 53, i+1))
-            d = self.theclass(2010, 1, 4+i)
-            self.assertEqual(d.isocalendar(), (2010, 1, i+1))
-
-    def test_iso_long_years(self):
-        # Calculate long ISO years and compare to table from
-        # http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
-        ISO_LONG_YEARS_TABLE = """
-              4   32   60   88
-              9   37   65   93
-             15   43   71   99
-             20   48   76
-             26   54   82
-
-            105  133  161  189
-            111  139  167  195
-            116  144  172
-            122  150  178
-            128  156  184
-
-            201  229  257  285
-            207  235  263  291
-            212  240  268  296
-            218  246  274
-            224  252  280
-
-            303  331  359  387
-            308  336  364  392
-            314  342  370  398
-            320  348  376
-            325  353  381
-        """
-        iso_long_years = sorted(map(int, ISO_LONG_YEARS_TABLE.split()))
-        L = []
-        for i in range(400):
-            d = self.theclass(2000+i, 12, 31)
-            d1 = self.theclass(1600+i, 12, 31)
-            self.assertEqual(d.isocalendar()[1:], d1.isocalendar()[1:])
-            if d.isocalendar()[1] == 53:
-                L.append(i)
-        self.assertEqual(L, iso_long_years)
-
-    def test_isoformat(self):
-        t = self.theclass(2, 3, 2)
-        self.assertEqual(t.isoformat(), "0002-03-02")
-
-    def test_ctime(self):
-        t = self.theclass(2002, 3, 2)
-        self.assertEqual(t.ctime(), "Sat Mar  2 00:00:00 2002")
-
-    def test_strftime(self):
-        t = self.theclass(2005, 3, 2)
-        self.assertEqual(t.strftime("m:%m d:%d y:%y"), "m:03 d:02 y:05")
-        self.assertEqual(t.strftime(""), "") # SF bug #761337
-        self.assertEqual(t.strftime('x'*1000), 'x'*1000) # SF bug #1556784
-
-        self.assertRaises(TypeError, t.strftime) # needs an arg
-        self.assertRaises(TypeError, t.strftime, "one", "two") # too many args
-        self.assertRaises(TypeError, t.strftime, 42) # arg wrong type
-
-        # test that unicode input is allowed (issue 2782)
-        self.assertEqual(t.strftime("%m"), "03")
-
-        # A naive object replaces %z and %Z w/ empty strings.
-        self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
-
-        #make sure that invalid format specifiers are handled correctly
-        #self.assertRaises(ValueError, t.strftime, "%e")
-        #self.assertRaises(ValueError, t.strftime, "%")
-        #self.assertRaises(ValueError, t.strftime, "%#")
-
-        #oh well, some systems just ignore those invalid ones.
-        #at least, excercise them to make sure that no crashes
-        #are generated
-        for f in ["%e", "%", "%#"]:
-            try:
-                t.strftime(f)
-            except ValueError:
-                pass
-
-        #check that this standard extension works
-        t.strftime("%f")
-
-
-    def test_format(self):
-        dt = self.theclass(2007, 9, 10)
-        self.assertEqual(dt.__format__(''), str(dt))
-
-        # check that a derived class's __str__() gets called
-        class A(self.theclass):
-            def __str__(self):
-                return 'A'
-        a = A(2007, 9, 10)
-        self.assertEqual(a.__format__(''), 'A')
-
-        # check that a derived class's strftime gets called
-        class B(self.theclass):
-            def strftime(self, format_spec):
-                return 'B'
-        b = B(2007, 9, 10)
-        self.assertEqual(b.__format__(''), str(dt))
-
-        for fmt in ["m:%m d:%d y:%y",
-                    "m:%m d:%d y:%y H:%H M:%M S:%S",
-                    "%z %Z",
-                    ]:
-            self.assertEqual(dt.__format__(fmt), dt.strftime(fmt))
-            self.assertEqual(a.__format__(fmt), dt.strftime(fmt))
-            self.assertEqual(b.__format__(fmt), 'B')
-
-    def test_resolution_info(self):
-        # XXX: Should min and max respect subclassing?
-        if issubclass(self.theclass, datetime):
-            expected_class = datetime
-        else:
-            expected_class = date
-        self.assertIsInstance(self.theclass.min, expected_class)
-        self.assertIsInstance(self.theclass.max, expected_class)
-        self.assertIsInstance(self.theclass.resolution, timedelta)
-        self.assertTrue(self.theclass.max > self.theclass.min)
-
-    def test_extreme_timedelta(self):
-        big = self.theclass.max - self.theclass.min
-        # 3652058 days, 23 hours, 59 minutes, 59 seconds, 999999 microseconds
-        n = (big.days*24*3600 + big.seconds)*1000000 + big.microseconds
-        # n == 315537897599999999 ~= 2**58.13
-        justasbig = timedelta(0, 0, n)
-        self.assertEqual(big, justasbig)
-        self.assertEqual(self.theclass.min + big, self.theclass.max)
-        self.assertEqual(self.theclass.max - big, self.theclass.min)
-
-    def test_timetuple(self):
-        for i in range(7):
-            # January 2, 1956 is a Monday (0)
-            d = self.theclass(1956, 1, 2+i)
-            t = d.timetuple()
-            self.assertEqual(t, (1956, 1, 2+i, 0, 0, 0, i, 2+i, -1))
-            # February 1, 1956 is a Wednesday (2)
-            d = self.theclass(1956, 2, 1+i)
-            t = d.timetuple()
-            self.assertEqual(t, (1956, 2, 1+i, 0, 0, 0, (2+i)%7, 32+i, -1))
-            # March 1, 1956 is a Thursday (3), and is the 31+29+1 = 61st day
-            # of the year.
-            d = self.theclass(1956, 3, 1+i)
-            t = d.timetuple()
-            self.assertEqual(t, (1956, 3, 1+i, 0, 0, 0, (3+i)%7, 61+i, -1))
-            self.assertEqual(t.tm_year, 1956)
-            self.assertEqual(t.tm_mon, 3)
-            self.assertEqual(t.tm_mday, 1+i)
-            self.assertEqual(t.tm_hour, 0)
-            self.assertEqual(t.tm_min, 0)
-            self.assertEqual(t.tm_sec, 0)
-            self.assertEqual(t.tm_wday, (3+i)%7)
-            self.assertEqual(t.tm_yday, 61+i)
-            self.assertEqual(t.tm_isdst, -1)
-
-    def test_pickling(self):
-        args = 6, 7, 23
-        orig = self.theclass(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_compare(self):
-        t1 = self.theclass(2, 3, 4)
-        t2 = self.theclass(2, 3, 4)
-        self.assertEqual(t1, t2)
-        self.assertTrue(t1 <= t2)
-        self.assertTrue(t1 >= t2)
-        self.assertTrue(not t1 != t2)
-        self.assertTrue(not t1 < t2)
-        self.assertTrue(not t1 > t2)
-
-        for args in (3, 3, 3), (2, 4, 4), (2, 3, 5):
-            t2 = self.theclass(*args)   # this is larger than t1
-            self.assertTrue(t1 < t2)
-            self.assertTrue(t2 > t1)
-            self.assertTrue(t1 <= t2)
-            self.assertTrue(t2 >= t1)
-            self.assertTrue(t1 != t2)
-            self.assertTrue(t2 != t1)
-            self.assertTrue(not t1 == t2)
-            self.assertTrue(not t2 == t1)
-            self.assertTrue(not t1 > t2)
-            self.assertTrue(not t2 < t1)
-            self.assertTrue(not t1 >= t2)
-            self.assertTrue(not t2 <= t1)
-
-        for badarg in OTHERSTUFF:
-            self.assertEqual(t1 == badarg, False)
-            self.assertEqual(t1 != badarg, True)
-            self.assertEqual(badarg == t1, False)
-            self.assertEqual(badarg != t1, True)
-
-            self.assertRaises(TypeError, lambda: t1 < badarg)
-            self.assertRaises(TypeError, lambda: t1 > badarg)
-            self.assertRaises(TypeError, lambda: t1 >= badarg)
-            self.assertRaises(TypeError, lambda: badarg <= t1)
-            self.assertRaises(TypeError, lambda: badarg < t1)
-            self.assertRaises(TypeError, lambda: badarg > t1)
-            self.assertRaises(TypeError, lambda: badarg >= t1)
-
-    def test_mixed_compare(self):
-        our = self.theclass(2000, 4, 5)
-
-        # Our class can be compared for equality to other classes
-        self.assertEqual(our == 1, False)
-        self.assertEqual(1 == our, False)
-        self.assertEqual(our != 1, True)
-        self.assertEqual(1 != our, True)
-
-        # But the ordering is undefined
-        self.assertRaises(TypeError, lambda: our < 1)
-        self.assertRaises(TypeError, lambda: 1 < our)
-
-        # Repeat those tests with a different class
-
-        class SomeClass:
-            pass
-
-        their = SomeClass()
-        self.assertEqual(our == their, False)
-        self.assertEqual(their == our, False)
-        self.assertEqual(our != their, True)
-        self.assertEqual(their != our, True)
-        self.assertRaises(TypeError, lambda: our < their)
-        self.assertRaises(TypeError, lambda: their < our)
-
-        # However, if the other class explicitly defines ordering
-        # relative to our class, it is allowed to do so
-
-        class LargerThanAnything:
-            def __lt__(self, other):
-                return False
-            def __le__(self, other):
-                return isinstance(other, LargerThanAnything)
-            def __eq__(self, other):
-                return isinstance(other, LargerThanAnything)
-            def __ne__(self, other):
-                return not isinstance(other, LargerThanAnything)
-            def __gt__(self, other):
-                return not isinstance(other, LargerThanAnything)
-            def __ge__(self, other):
-                return True
-
-        their = LargerThanAnything()
-        self.assertEqual(our == their, False)
-        self.assertEqual(their == our, False)
-        self.assertEqual(our != their, True)
-        self.assertEqual(their != our, True)
-        self.assertEqual(our < their, True)
-        self.assertEqual(their < our, False)
-
-    def test_bool(self):
-        # All dates are considered true.
-        self.assertTrue(self.theclass.min)
-        self.assertTrue(self.theclass.max)
-
-    def test_strftime_out_of_range(self):
-        # For nasty technical reasons, we can't handle years before 1900.
-        cls = self.theclass
-        self.assertEqual(cls(1900, 1, 1).strftime("%Y"), "1900")
-        for y in 1, 49, 51, 99, 100, 1000, 1899:
-            self.assertRaises(ValueError, cls(y, 1, 1).strftime, "%Y")
-
-    def test_replace(self):
-        cls = self.theclass
-        args = [1, 2, 3]
-        base = cls(*args)
-        self.assertEqual(base, base.replace())
-
-        i = 0
-        for name, newval in (("year", 2),
-                             ("month", 3),
-                             ("day", 4)):
-            newargs = args[:]
-            newargs[i] = newval
-            expected = cls(*newargs)
-            got = base.replace(**{name: newval})
-            self.assertEqual(expected, got)
-            i += 1
-
-        # Out of bounds.
-        base = cls(2000, 2, 29)
-        self.assertRaises(ValueError, base.replace, year=2001)
-
-    def test_subclass_date(self):
-
-        class C(self.theclass):
-            theAnswer = 42
-
-            def __new__(cls, *args, **kws):
-                temp = kws.copy()
-                extra = temp.pop('extra')
-                result = self.theclass.__new__(cls, *args, **temp)
-                result.extra = extra
-                return result
-
-            def newmeth(self, start):
-                return start + self.year + self.month
-
-        args = 2003, 4, 14
-
-        dt1 = self.theclass(*args)
-        dt2 = C(*args, **{'extra': 7})
-
-        self.assertEqual(dt2.__class__, C)
-        self.assertEqual(dt2.theAnswer, 42)
-        self.assertEqual(dt2.extra, 7)
-        self.assertEqual(dt1.toordinal(), dt2.toordinal())
-        self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month - 7)
-
-    def test_pickling_subclass_date(self):
-
-        args = 6, 7, 23
-        orig = SubclassDate(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_backdoor_resistance(self):
-        # For fast unpickling, the constructor accepts a pickle byte string.
-        # This is a low-overhead backdoor.  A user can (by intent or
-        # mistake) pass a string directly, which (if it's the right length)
-        # will get treated like a pickle, and bypass the normal sanity
-        # checks in the constructor.  This can create insane objects.
-        # The constructor doesn't want to burn the time to validate all
-        # fields, but does check the month field.  This stops, e.g.,
-        # datetime.datetime('1995-03-25') from yielding an insane object.
-        base = b'1995-03-25'
-        if not issubclass(self.theclass, datetime):
-            base = base[:4]
-        for month_byte in b'9', b'\0', b'\r', b'\xff':
-            self.assertRaises(TypeError, self.theclass,
-                                         base[:2] + month_byte + base[3:])
-        # Good bytes, but bad tzinfo:
-        self.assertRaises(TypeError, self.theclass,
-                          bytes([1] * len(base)), 'EST')
-
-        for ord_byte in range(1, 13):
-            # This shouldn't blow up because of the month byte alone.  If
-            # the implementation changes to do more-careful checking, it may
-            # blow up because other fields are insane.
-            self.theclass(base[:2] + bytes([ord_byte]) + base[3:])
-
-#############################################################################
-# datetime tests
-
-class SubclassDatetime(datetime):
-    sub_var = 1
-
-class TestDateTime(TestDate):
-
-    theclass = datetime
-
-    def test_basic_attributes(self):
-        dt = self.theclass(2002, 3, 1, 12, 0)
-        self.assertEqual(dt.year, 2002)
-        self.assertEqual(dt.month, 3)
-        self.assertEqual(dt.day, 1)
-        self.assertEqual(dt.hour, 12)
-        self.assertEqual(dt.minute, 0)
-        self.assertEqual(dt.second, 0)
-        self.assertEqual(dt.microsecond, 0)
-
-    def test_basic_attributes_nonzero(self):
-        # Make sure all attributes are non-zero so bugs in
-        # bit-shifting access show up.
-        dt = self.theclass(2002, 3, 1, 12, 59, 59, 8000)
-        self.assertEqual(dt.year, 2002)
-        self.assertEqual(dt.month, 3)
-        self.assertEqual(dt.day, 1)
-        self.assertEqual(dt.hour, 12)
-        self.assertEqual(dt.minute, 59)
-        self.assertEqual(dt.second, 59)
-        self.assertEqual(dt.microsecond, 8000)
-
-    def test_roundtrip(self):
-        for dt in (self.theclass(1, 2, 3, 4, 5, 6, 7),
-                   self.theclass.now()):
-            # Verify dt -> string -> datetime identity.
-            s = repr(dt)
-            self.assertTrue(s.startswith('datetime.'))
-            s = s[9:]
-            dt2 = eval(s)
-            self.assertEqual(dt, dt2)
-
-            # Verify identity via reconstructing from pieces.
-            dt2 = self.theclass(dt.year, dt.month, dt.day,
-                                dt.hour, dt.minute, dt.second,
-                                dt.microsecond)
-            self.assertEqual(dt, dt2)
-
-    def test_isoformat(self):
-        t = self.theclass(2, 3, 2, 4, 5, 1, 123)
-        self.assertEqual(t.isoformat(),    "0002-03-02T04:05:01.000123")
-        self.assertEqual(t.isoformat('T'), "0002-03-02T04:05:01.000123")
-        self.assertEqual(t.isoformat(' '), "0002-03-02 04:05:01.000123")
-        self.assertEqual(t.isoformat('\x00'), "0002-03-02\x0004:05:01.000123")
-        # str is ISO format with the separator forced to a blank.
-        self.assertEqual(str(t), "0002-03-02 04:05:01.000123")
-
-        t = self.theclass(2, 3, 2)
-        self.assertEqual(t.isoformat(),    "0002-03-02T00:00:00")
-        self.assertEqual(t.isoformat('T'), "0002-03-02T00:00:00")
-        self.assertEqual(t.isoformat(' '), "0002-03-02 00:00:00")
-        # str is ISO format with the separator forced to a blank.
-        self.assertEqual(str(t), "0002-03-02 00:00:00")
-
-    def test_format(self):
-        dt = self.theclass(2007, 9, 10, 4, 5, 1, 123)
-        self.assertEqual(dt.__format__(''), str(dt))
-
-        # check that a derived class's __str__() gets called
-        class A(self.theclass):
-            def __str__(self):
-                return 'A'
-        a = A(2007, 9, 10, 4, 5, 1, 123)
-        self.assertEqual(a.__format__(''), 'A')
-
-        # check that a derived class's strftime gets called
-        class B(self.theclass):
-            def strftime(self, format_spec):
-                return 'B'
-        b = B(2007, 9, 10, 4, 5, 1, 123)
-        self.assertEqual(b.__format__(''), str(dt))
-
-        for fmt in ["m:%m d:%d y:%y",
-                    "m:%m d:%d y:%y H:%H M:%M S:%S",
-                    "%z %Z",
-                    ]:
-            self.assertEqual(dt.__format__(fmt), dt.strftime(fmt))
-            self.assertEqual(a.__format__(fmt), dt.strftime(fmt))
-            self.assertEqual(b.__format__(fmt), 'B')
-
-    def test_more_ctime(self):
-        # Test fields that TestDate doesn't touch.
-        import time
-
-        t = self.theclass(2002, 3, 2, 18, 3, 5, 123)
-        self.assertEqual(t.ctime(), "Sat Mar  2 18:03:05 2002")
-        # Oops!  The next line fails on Win2K under MSVC 6, so it's commented
-        # out.  The difference is that t.ctime() produces " 2" for the day,
-        # but platform ctime() produces "02" for the day.  According to
-        # C99, t.ctime() is correct here.
-        # self.assertEqual(t.ctime(), time.ctime(time.mktime(t.timetuple())))
-
-        # So test a case where that difference doesn't matter.
-        t = self.theclass(2002, 3, 22, 18, 3, 5, 123)
-        self.assertEqual(t.ctime(), time.ctime(time.mktime(t.timetuple())))
-
-    def test_tz_independent_comparing(self):
-        dt1 = self.theclass(2002, 3, 1, 9, 0, 0)
-        dt2 = self.theclass(2002, 3, 1, 10, 0, 0)
-        dt3 = self.theclass(2002, 3, 1, 9, 0, 0)
-        self.assertEqual(dt1, dt3)
-        self.assertTrue(dt2 > dt3)
-
-        # Make sure comparison doesn't forget microseconds, and isn't done
-        # via comparing a float timestamp (an IEEE double doesn't have enough
-        # precision to span microsecond resolution across years 1 thru 9999,
-        # so comparing via timestamp necessarily calls some distinct values
-        # equal).
-        dt1 = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999998)
-        us = timedelta(microseconds=1)
-        dt2 = dt1 + us
-        self.assertEqual(dt2 - dt1, us)
-        self.assertTrue(dt1 < dt2)
-
-    def test_strftime_with_bad_tzname_replace(self):
-        # verify ok if tzinfo.tzname().replace() returns a non-string
-        class MyTzInfo(FixedOffset):
-            def tzname(self, dt):
-                class MyStr(str):
-                    def replace(self, *args):
-                        return None
-                return MyStr('name')
-        t = self.theclass(2005, 3, 2, 0, 0, 0, 0, MyTzInfo(3, 'name'))
-        self.assertRaises(TypeError, t.strftime, '%Z')
-
-    def test_bad_constructor_arguments(self):
-        # bad years
-        self.theclass(MINYEAR, 1, 1)  # no exception
-        self.theclass(MAXYEAR, 1, 1)  # no exception
-        self.assertRaises(ValueError, self.theclass, MINYEAR-1, 1, 1)
-        self.assertRaises(ValueError, self.theclass, MAXYEAR+1, 1, 1)
-        # bad months
-        self.theclass(2000, 1, 1)    # no exception
-        self.theclass(2000, 12, 1)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 0, 1)
-        self.assertRaises(ValueError, self.theclass, 2000, 13, 1)
-        # bad days
-        self.theclass(2000, 2, 29)   # no exception
-        self.theclass(2004, 2, 29)   # no exception
-        self.theclass(2400, 2, 29)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 2, 30)
-        self.assertRaises(ValueError, self.theclass, 2001, 2, 29)
-        self.assertRaises(ValueError, self.theclass, 2100, 2, 29)
-        self.assertRaises(ValueError, self.theclass, 1900, 2, 29)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 0)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 32)
-        # bad hours
-        self.theclass(2000, 1, 31, 0)    # no exception
-        self.theclass(2000, 1, 31, 23)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 31, -1)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 24)
-        # bad minutes
-        self.theclass(2000, 1, 31, 23, 0)    # no exception
-        self.theclass(2000, 1, 31, 23, 59)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, -1)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 60)
-        # bad seconds
-        self.theclass(2000, 1, 31, 23, 59, 0)    # no exception
-        self.theclass(2000, 1, 31, 23, 59, 59)   # no exception
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, -1)
-        self.assertRaises(ValueError, self.theclass, 2000, 1, 31, 23, 59, 60)
-        # bad microseconds
-        self.theclass(2000, 1, 31, 23, 59, 59, 0)    # no exception
-        self.theclass(2000, 1, 31, 23, 59, 59, 999999)   # no exception
-        self.assertRaises(ValueError, self.theclass,
-                          2000, 1, 31, 23, 59, 59, -1)
-        self.assertRaises(ValueError, self.theclass,
-                          2000, 1, 31, 23, 59, 59,
-                          1000000)
-
-    def test_hash_equality(self):
-        d = self.theclass(2000, 12, 31, 23, 30, 17)
-        e = self.theclass(2000, 12, 31, 23, 30, 17)
-        self.assertEqual(d, e)
-        self.assertEqual(hash(d), hash(e))
-
-        dic = {d: 1}
-        dic[e] = 2
-        self.assertEqual(len(dic), 1)
-        self.assertEqual(dic[d], 2)
-        self.assertEqual(dic[e], 2)
-
-        d = self.theclass(2001,  1,  1,  0,  5, 17)
-        e = self.theclass(2001,  1,  1,  0,  5, 17)
-        self.assertEqual(d, e)
-        self.assertEqual(hash(d), hash(e))
-
-        dic = {d: 1}
-        dic[e] = 2
-        self.assertEqual(len(dic), 1)
-        self.assertEqual(dic[d], 2)
-        self.assertEqual(dic[e], 2)
-
-    def test_computations(self):
-        a = self.theclass(2002, 1, 31)
-        b = self.theclass(1956, 1, 31)
-        diff = a-b
-        self.assertEqual(diff.days, 46*365 + len(range(1956, 2002, 4)))
-        self.assertEqual(diff.seconds, 0)
-        self.assertEqual(diff.microseconds, 0)
-        a = self.theclass(2002, 3, 2, 17, 6)
-        millisec = timedelta(0, 0, 1000)
-        hour = timedelta(0, 3600)
-        day = timedelta(1)
-        week = timedelta(7)
-        self.assertEqual(a + hour, self.theclass(2002, 3, 2, 18, 6))
-        self.assertEqual(hour + a, self.theclass(2002, 3, 2, 18, 6))
-        self.assertEqual(a + 10*hour, self.theclass(2002, 3, 3, 3, 6))
-        self.assertEqual(a - hour, self.theclass(2002, 3, 2, 16, 6))
-        self.assertEqual(-hour + a, self.theclass(2002, 3, 2, 16, 6))
-        self.assertEqual(a - hour, a + -hour)
-        self.assertEqual(a - 20*hour, self.theclass(2002, 3, 1, 21, 6))
-        self.assertEqual(a + day, self.theclass(2002, 3, 3, 17, 6))
-        self.assertEqual(a - day, self.theclass(2002, 3, 1, 17, 6))
-        self.assertEqual(a + week, self.theclass(2002, 3, 9, 17, 6))
-        self.assertEqual(a - week, self.theclass(2002, 2, 23, 17, 6))
-        self.assertEqual(a + 52*week, self.theclass(2003, 3, 1, 17, 6))
-        self.assertEqual(a - 52*week, self.theclass(2001, 3, 3, 17, 6))
-        self.assertEqual((a + week) - a, week)
-        self.assertEqual((a + day) - a, day)
-        self.assertEqual((a + hour) - a, hour)
-        self.assertEqual((a + millisec) - a, millisec)
-        self.assertEqual((a - week) - a, -week)
-        self.assertEqual((a - day) - a, -day)
-        self.assertEqual((a - hour) - a, -hour)
-        self.assertEqual((a - millisec) - a, -millisec)
-        self.assertEqual(a - (a + week), -week)
-        self.assertEqual(a - (a + day), -day)
-        self.assertEqual(a - (a + hour), -hour)
-        self.assertEqual(a - (a + millisec), -millisec)
-        self.assertEqual(a - (a - week), week)
-        self.assertEqual(a - (a - day), day)
-        self.assertEqual(a - (a - hour), hour)
-        self.assertEqual(a - (a - millisec), millisec)
-        self.assertEqual(a + (week + day + hour + millisec),
-                         self.theclass(2002, 3, 10, 18, 6, 0, 1000))
-        self.assertEqual(a + (week + day + hour + millisec),
-                         (((a + week) + day) + hour) + millisec)
-        self.assertEqual(a - (week + day + hour + millisec),
-                         self.theclass(2002, 2, 22, 16, 5, 59, 999000))
-        self.assertEqual(a - (week + day + hour + millisec),
-                         (((a - week) - day) - hour) - millisec)
-        # Add/sub ints or floats should be illegal
-        for i in 1, 1.0:
-            self.assertRaises(TypeError, lambda: a+i)
-            self.assertRaises(TypeError, lambda: a-i)
-            self.assertRaises(TypeError, lambda: i+a)
-            self.assertRaises(TypeError, lambda: i-a)
-
-        # delta - datetime is senseless.
-        self.assertRaises(TypeError, lambda: day - a)
-        # mixing datetime and (delta or datetime) via * or // is senseless
-        self.assertRaises(TypeError, lambda: day * a)
-        self.assertRaises(TypeError, lambda: a * day)
-        self.assertRaises(TypeError, lambda: day // a)
-        self.assertRaises(TypeError, lambda: a // day)
-        self.assertRaises(TypeError, lambda: a * a)
-        self.assertRaises(TypeError, lambda: a // a)
-        # datetime + datetime is senseless
-        self.assertRaises(TypeError, lambda: a + a)
-
-    def test_pickling(self):
-        args = 6, 7, 23, 20, 59, 1, 64**2
-        orig = self.theclass(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_more_pickling(self):
-        a = self.theclass(2003, 2, 7, 16, 48, 37, 444116)
-        s = pickle.dumps(a)
-        b = pickle.loads(s)
-        self.assertEqual(b.year, 2003)
-        self.assertEqual(b.month, 2)
-        self.assertEqual(b.day, 7)
-
-    def test_pickling_subclass_datetime(self):
-        args = 6, 7, 23, 20, 59, 1, 64**2
-        orig = SubclassDatetime(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_more_compare(self):
-        # The test_compare() inherited from TestDate covers the error cases.
-        # We just want to test lexicographic ordering on the members datetime
-        # has that date lacks.
-        args = [2000, 11, 29, 20, 58, 16, 999998]
-        t1 = self.theclass(*args)
-        t2 = self.theclass(*args)
-        self.assertEqual(t1, t2)
-        self.assertTrue(t1 <= t2)
-        self.assertTrue(t1 >= t2)
-        self.assertTrue(not t1 != t2)
-        self.assertTrue(not t1 < t2)
-        self.assertTrue(not t1 > t2)
-
-        for i in range(len(args)):
-            newargs = args[:]
-            newargs[i] = args[i] + 1
-            t2 = self.theclass(*newargs)   # this is larger than t1
-            self.assertTrue(t1 < t2)
-            self.assertTrue(t2 > t1)
-            self.assertTrue(t1 <= t2)
-            self.assertTrue(t2 >= t1)
-            self.assertTrue(t1 != t2)
-            self.assertTrue(t2 != t1)
-            self.assertTrue(not t1 == t2)
-            self.assertTrue(not t2 == t1)
-            self.assertTrue(not t1 > t2)
-            self.assertTrue(not t2 < t1)
-            self.assertTrue(not t1 >= t2)
-            self.assertTrue(not t2 <= t1)
-
-
-    # A helper for timestamp constructor tests.
-    def verify_field_equality(self, expected, got):
-        self.assertEqual(expected.tm_year, got.year)
-        self.assertEqual(expected.tm_mon, got.month)
-        self.assertEqual(expected.tm_mday, got.day)
-        self.assertEqual(expected.tm_hour, got.hour)
-        self.assertEqual(expected.tm_min, got.minute)
-        self.assertEqual(expected.tm_sec, got.second)
-
-    def test_fromtimestamp(self):
-        import time
-
-        ts = time.time()
-        expected = time.localtime(ts)
-        got = self.theclass.fromtimestamp(ts)
-        self.verify_field_equality(expected, got)
-
-    def test_utcfromtimestamp(self):
-        import time
-
-        ts = time.time()
-        expected = time.gmtime(ts)
-        got = self.theclass.utcfromtimestamp(ts)
-        self.verify_field_equality(expected, got)
-
-    def test_microsecond_rounding(self):
-        # Test whether fromtimestamp "rounds up" floats that are less
-        # than one microsecond smaller than an integer.
-        self.assertEqual(self.theclass.fromtimestamp(0.9999999),
-                         self.theclass.fromtimestamp(1))
-
-    def test_insane_fromtimestamp(self):
-        # It's possible that some platform maps time_t to double,
-        # and that this test will fail there.  This test should
-        # exempt such platforms (provided they return reasonable
-        # results!).
-        for insane in -1e200, 1e200:
-            self.assertRaises(ValueError, self.theclass.fromtimestamp,
-                              insane)
-
-    def test_insane_utcfromtimestamp(self):
-        # It's possible that some platform maps time_t to double,
-        # and that this test will fail there.  This test should
-        # exempt such platforms (provided they return reasonable
-        # results!).
-        for insane in -1e200, 1e200:
-            self.assertRaises(ValueError, self.theclass.utcfromtimestamp,
-                              insane)
-    @unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
-    def test_negative_float_fromtimestamp(self):
-        # The result is tz-dependent; at least test that this doesn't
-        # fail (like it did before bug 1646728 was fixed).
-        self.theclass.fromtimestamp(-1.05)
-
-    @unittest.skipIf(sys.platform == "win32", "Windows doesn't accept negative timestamps")
-    def test_negative_float_utcfromtimestamp(self):
-        d = self.theclass.utcfromtimestamp(-1.05)
-        self.assertEqual(d, self.theclass(1969, 12, 31, 23, 59, 58, 950000))
-
-    def test_utcnow(self):
-        import time
-
-        # Call it a success if utcnow() and utcfromtimestamp() are within
-        # a second of each other.
-        tolerance = timedelta(seconds=1)
-        for dummy in range(3):
-            from_now = self.theclass.utcnow()
-            from_timestamp = self.theclass.utcfromtimestamp(time.time())
-            if abs(from_timestamp - from_now) <= tolerance:
-                break
-            # Else try again a few times.
-        self.assertTrue(abs(from_timestamp - from_now) <= tolerance)
-
-    def test_strptime(self):
-        import _strptime
-
-        string = '2004-12-01 13:02:47.197'
-        format = '%Y-%m-%d %H:%M:%S.%f'
-        expected = _strptime._strptime_datetime(self.theclass, string, format)
-        got = self.theclass.strptime(string, format)
-        self.assertEqual(expected, got)
-        self.assertIs(type(expected), self.theclass)
-        self.assertIs(type(got), self.theclass)
-
-        strptime = self.theclass.strptime
-        self.assertEqual(strptime("+0002", "%z").utcoffset(), 2 * MINUTE)
-        self.assertEqual(strptime("-0002", "%z").utcoffset(), -2 * MINUTE)
-        # Only local timezone and UTC are supported
-        for tzseconds, tzname in ((0, 'UTC'), (0, 'GMT'),
-                                 (-_time.timezone, _time.tzname[0])):
-            if tzseconds < 0:
-                sign = '-'
-                seconds = -tzseconds
-            else:
-                sign ='+'
-                seconds = tzseconds
-            hours, minutes = divmod(seconds//60, 60)
-            dtstr = "{}{:02d}{:02d} {}".format(sign, hours, minutes, tzname)
-            dt = strptime(dtstr, "%z %Z")
-            self.assertEqual(dt.utcoffset(), timedelta(seconds=tzseconds))
-            self.assertEqual(dt.tzname(), tzname)
-        # Can produce inconsistent datetime
-        dtstr, fmt = "+1234 UTC", "%z %Z"
-        dt = strptime(dtstr, fmt)
-        self.assertEqual(dt.utcoffset(), 12 * HOUR + 34 * MINUTE)
-        self.assertEqual(dt.tzname(), 'UTC')
-        # yet will roundtrip
-        self.assertEqual(dt.strftime(fmt), dtstr)
-
-        # Produce naive datetime if no %z is provided
-        self.assertEqual(strptime("UTC", "%Z").tzinfo, None)
-
-        with self.assertRaises(ValueError): strptime("-2400", "%z")
-        with self.assertRaises(ValueError): strptime("-000", "%z")
-
-    def test_more_timetuple(self):
-        # This tests fields beyond those tested by the TestDate.test_timetuple.
-        t = self.theclass(2004, 12, 31, 6, 22, 33)
-        self.assertEqual(t.timetuple(), (2004, 12, 31, 6, 22, 33, 4, 366, -1))
-        self.assertEqual(t.timetuple(),
-                         (t.year, t.month, t.day,
-                          t.hour, t.minute, t.second,
-                          t.weekday(),
-                          t.toordinal() - date(t.year, 1, 1).toordinal() + 1,
-                          -1))
-        tt = t.timetuple()
-        self.assertEqual(tt.tm_year, t.year)
-        self.assertEqual(tt.tm_mon, t.month)
-        self.assertEqual(tt.tm_mday, t.day)
-        self.assertEqual(tt.tm_hour, t.hour)
-        self.assertEqual(tt.tm_min, t.minute)
-        self.assertEqual(tt.tm_sec, t.second)
-        self.assertEqual(tt.tm_wday, t.weekday())
-        self.assertEqual(tt.tm_yday, t.toordinal() -
-                                     date(t.year, 1, 1).toordinal() + 1)
-        self.assertEqual(tt.tm_isdst, -1)
-
-    def test_more_strftime(self):
-        # This tests fields beyond those tested by the TestDate.test_strftime.
-        t = self.theclass(2004, 12, 31, 6, 22, 33, 47)
-        self.assertEqual(t.strftime("%m %d %y %f %S %M %H %j"),
-                                    "12 31 04 000047 33 22 06 366")
-
-    def test_extract(self):
-        dt = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
-        self.assertEqual(dt.date(), date(2002, 3, 4))
-        self.assertEqual(dt.time(), time(18, 45, 3, 1234))
-
-    def test_combine(self):
-        d = date(2002, 3, 4)
-        t = time(18, 45, 3, 1234)
-        expected = self.theclass(2002, 3, 4, 18, 45, 3, 1234)
-        combine = self.theclass.combine
-        dt = combine(d, t)
-        self.assertEqual(dt, expected)
-
-        dt = combine(time=t, date=d)
-        self.assertEqual(dt, expected)
-
-        self.assertEqual(d, dt.date())
-        self.assertEqual(t, dt.time())
-        self.assertEqual(dt, combine(dt.date(), dt.time()))
-
-        self.assertRaises(TypeError, combine) # need an arg
-        self.assertRaises(TypeError, combine, d) # need two args
-        self.assertRaises(TypeError, combine, t, d) # args reversed
-        self.assertRaises(TypeError, combine, d, t, 1) # too many args
-        self.assertRaises(TypeError, combine, "date", "time") # wrong types
-        self.assertRaises(TypeError, combine, d, "time") # wrong type
-        self.assertRaises(TypeError, combine, "date", t) # wrong type
-
-    def test_replace(self):
-        cls = self.theclass
-        args = [1, 2, 3, 4, 5, 6, 7]
-        base = cls(*args)
-        self.assertEqual(base, base.replace())
-
-        i = 0
-        for name, newval in (("year", 2),
-                             ("month", 3),
-                             ("day", 4),
-                             ("hour", 5),
-                             ("minute", 6),
-                             ("second", 7),
-                             ("microsecond", 8)):
-            newargs = args[:]
-            newargs[i] = newval
-            expected = cls(*newargs)
-            got = base.replace(**{name: newval})
-            self.assertEqual(expected, got)
-            i += 1
-
-        # Out of bounds.
-        base = cls(2000, 2, 29)
-        self.assertRaises(ValueError, base.replace, year=2001)
-
-    def test_astimezone(self):
-        # Pretty boring!  The TZ test is more interesting here.  astimezone()
-        # simply can't be applied to a naive object.
-        dt = self.theclass.now()
-        f = FixedOffset(44, "")
-        self.assertRaises(TypeError, dt.astimezone) # not enough args
-        self.assertRaises(TypeError, dt.astimezone, f, f) # too many args
-        self.assertRaises(TypeError, dt.astimezone, dt) # arg wrong type
-        self.assertRaises(ValueError, dt.astimezone, f) # naive
-        self.assertRaises(ValueError, dt.astimezone, tz=f)  # naive
-
-        class Bogus(tzinfo):
-            def utcoffset(self, dt): return None
-            def dst(self, dt): return timedelta(0)
-        bog = Bogus()
-        self.assertRaises(ValueError, dt.astimezone, bog)   # naive
-        self.assertRaises(ValueError,
-                          dt.replace(tzinfo=bog).astimezone, f)
-
-        class AlsoBogus(tzinfo):
-            def utcoffset(self, dt): return timedelta(0)
-            def dst(self, dt): return None
-        alsobog = AlsoBogus()
-        self.assertRaises(ValueError, dt.astimezone, alsobog) # also naive
-
-    def test_subclass_datetime(self):
-
-        class C(self.theclass):
-            theAnswer = 42
-
-            def __new__(cls, *args, **kws):
-                temp = kws.copy()
-                extra = temp.pop('extra')
-                result = self.theclass.__new__(cls, *args, **temp)
-                result.extra = extra
-                return result
-
-            def newmeth(self, start):
-                return start + self.year + self.month + self.second
-
-        args = 2003, 4, 14, 12, 13, 41
-
-        dt1 = self.theclass(*args)
-        dt2 = C(*args, **{'extra': 7})
-
-        self.assertEqual(dt2.__class__, C)
-        self.assertEqual(dt2.theAnswer, 42)
-        self.assertEqual(dt2.extra, 7)
-        self.assertEqual(dt1.toordinal(), dt2.toordinal())
-        self.assertEqual(dt2.newmeth(-7), dt1.year + dt1.month +
-                                          dt1.second - 7)
-
-class TestSubclassDateTime(TestDateTime):
-    theclass = SubclassDatetime
-    # Override tests not designed for subclass
-    def test_roundtrip(self):
-        pass
-
-class SubclassTime(time):
-    sub_var = 1
-
-class TestTime(HarmlessMixedComparison, unittest.TestCase):
-
-    theclass = time
-
-    def test_basic_attributes(self):
-        t = self.theclass(12, 0)
-        self.assertEqual(t.hour, 12)
-        self.assertEqual(t.minute, 0)
-        self.assertEqual(t.second, 0)
-        self.assertEqual(t.microsecond, 0)
-
-    def test_basic_attributes_nonzero(self):
-        # Make sure all attributes are non-zero so bugs in
-        # bit-shifting access show up.
-        t = self.theclass(12, 59, 59, 8000)
-        self.assertEqual(t.hour, 12)
-        self.assertEqual(t.minute, 59)
-        self.assertEqual(t.second, 59)
-        self.assertEqual(t.microsecond, 8000)
-
-    def test_roundtrip(self):
-        t = self.theclass(1, 2, 3, 4)
-
-        # Verify t -> string -> time identity.
-        s = repr(t)
-        self.assertTrue(s.startswith('datetime.'))
-        s = s[9:]
-        t2 = eval(s)
-        self.assertEqual(t, t2)
-
-        # Verify identity via reconstructing from pieces.
-        t2 = self.theclass(t.hour, t.minute, t.second,
-                           t.microsecond)
-        self.assertEqual(t, t2)
-
-    def test_comparing(self):
-        args = [1, 2, 3, 4]
-        t1 = self.theclass(*args)
-        t2 = self.theclass(*args)
-        self.assertEqual(t1, t2)
-        self.assertTrue(t1 <= t2)
-        self.assertTrue(t1 >= t2)
-        self.assertTrue(not t1 != t2)
-        self.assertTrue(not t1 < t2)
-        self.assertTrue(not t1 > t2)
-
-        for i in range(len(args)):
-            newargs = args[:]
-            newargs[i] = args[i] + 1
-            t2 = self.theclass(*newargs)   # this is larger than t1
-            self.assertTrue(t1 < t2)
-            self.assertTrue(t2 > t1)
-            self.assertTrue(t1 <= t2)
-            self.assertTrue(t2 >= t1)
-            self.assertTrue(t1 != t2)
-            self.assertTrue(t2 != t1)
-            self.assertTrue(not t1 == t2)
-            self.assertTrue(not t2 == t1)
-            self.assertTrue(not t1 > t2)
-            self.assertTrue(not t2 < t1)
-            self.assertTrue(not t1 >= t2)
-            self.assertTrue(not t2 <= t1)
-
-        for badarg in OTHERSTUFF:
-            self.assertEqual(t1 == badarg, False)
-            self.assertEqual(t1 != badarg, True)
-            self.assertEqual(badarg == t1, False)
-            self.assertEqual(badarg != t1, True)
-
-            self.assertRaises(TypeError, lambda: t1 <= badarg)
-            self.assertRaises(TypeError, lambda: t1 < badarg)
-            self.assertRaises(TypeError, lambda: t1 > badarg)
-            self.assertRaises(TypeError, lambda: t1 >= badarg)
-            self.assertRaises(TypeError, lambda: badarg <= t1)
-            self.assertRaises(TypeError, lambda: badarg < t1)
-            self.assertRaises(TypeError, lambda: badarg > t1)
-            self.assertRaises(TypeError, lambda: badarg >= t1)
-
-    def test_bad_constructor_arguments(self):
-        # bad hours
-        self.theclass(0, 0)    # no exception
-        self.theclass(23, 0)   # no exception
-        self.assertRaises(ValueError, self.theclass, -1, 0)
-        self.assertRaises(ValueError, self.theclass, 24, 0)
-        # bad minutes
-        self.theclass(23, 0)    # no exception
-        self.theclass(23, 59)   # no exception
-        self.assertRaises(ValueError, self.theclass, 23, -1)
-        self.assertRaises(ValueError, self.theclass, 23, 60)
-        # bad seconds
-        self.theclass(23, 59, 0)    # no exception
-        self.theclass(23, 59, 59)   # no exception
-        self.assertRaises(ValueError, self.theclass, 23, 59, -1)
-        self.assertRaises(ValueError, self.theclass, 23, 59, 60)
-        # bad microseconds
-        self.theclass(23, 59, 59, 0)        # no exception
-        self.theclass(23, 59, 59, 999999)   # no exception
-        self.assertRaises(ValueError, self.theclass, 23, 59, 59, -1)
-        self.assertRaises(ValueError, self.theclass, 23, 59, 59, 1000000)
-
-    def test_hash_equality(self):
-        d = self.theclass(23, 30, 17)
-        e = self.theclass(23, 30, 17)
-        self.assertEqual(d, e)
-        self.assertEqual(hash(d), hash(e))
-
-        dic = {d: 1}
-        dic[e] = 2
-        self.assertEqual(len(dic), 1)
-        self.assertEqual(dic[d], 2)
-        self.assertEqual(dic[e], 2)
-
-        d = self.theclass(0,  5, 17)
-        e = self.theclass(0,  5, 17)
-        self.assertEqual(d, e)
-        self.assertEqual(hash(d), hash(e))
-
-        dic = {d: 1}
-        dic[e] = 2
-        self.assertEqual(len(dic), 1)
-        self.assertEqual(dic[d], 2)
-        self.assertEqual(dic[e], 2)
-
-    def test_isoformat(self):
-        t = self.theclass(4, 5, 1, 123)
-        self.assertEqual(t.isoformat(), "04:05:01.000123")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass()
-        self.assertEqual(t.isoformat(), "00:00:00")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass(microsecond=1)
-        self.assertEqual(t.isoformat(), "00:00:00.000001")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass(microsecond=10)
-        self.assertEqual(t.isoformat(), "00:00:00.000010")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass(microsecond=100)
-        self.assertEqual(t.isoformat(), "00:00:00.000100")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass(microsecond=1000)
-        self.assertEqual(t.isoformat(), "00:00:00.001000")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass(microsecond=10000)
-        self.assertEqual(t.isoformat(), "00:00:00.010000")
-        self.assertEqual(t.isoformat(), str(t))
-
-        t = self.theclass(microsecond=100000)
-        self.assertEqual(t.isoformat(), "00:00:00.100000")
-        self.assertEqual(t.isoformat(), str(t))
-
-    def test_1653736(self):
-        # verify it doesn't accept extra keyword arguments
-        t = self.theclass(second=1)
-        self.assertRaises(TypeError, t.isoformat, foo=3)
-
-    def test_strftime(self):
-        t = self.theclass(1, 2, 3, 4)
-        self.assertEqual(t.strftime('%H %M %S %f'), "01 02 03 000004")
-        # A naive object replaces %z and %Z with empty strings.
-        self.assertEqual(t.strftime("'%z' '%Z'"), "'' ''")
-
-    def test_format(self):
-        t = self.theclass(1, 2, 3, 4)
-        self.assertEqual(t.__format__(''), str(t))
-
-        # check that a derived class's __str__() gets called
-        class A(self.theclass):
-            def __str__(self):
-                return 'A'
-        a = A(1, 2, 3, 4)
-        self.assertEqual(a.__format__(''), 'A')
-
-        # check that a derived class's strftime gets called
-        class B(self.theclass):
-            def strftime(self, format_spec):
-                return 'B'
-        b = B(1, 2, 3, 4)
-        self.assertEqual(b.__format__(''), str(t))
-
-        for fmt in ['%H %M %S',
-                    ]:
-            self.assertEqual(t.__format__(fmt), t.strftime(fmt))
-            self.assertEqual(a.__format__(fmt), t.strftime(fmt))
-            self.assertEqual(b.__format__(fmt), 'B')
-
-    def test_str(self):
-        self.assertEqual(str(self.theclass(1, 2, 3, 4)), "01:02:03.000004")
-        self.assertEqual(str(self.theclass(10, 2, 3, 4000)), "10:02:03.004000")
-        self.assertEqual(str(self.theclass(0, 2, 3, 400000)), "00:02:03.400000")
-        self.assertEqual(str(self.theclass(12, 2, 3, 0)), "12:02:03")
-        self.assertEqual(str(self.theclass(23, 15, 0, 0)), "23:15:00")
-
-    def test_repr(self):
-        name = 'datetime.' + self.theclass.__name__
-        self.assertEqual(repr(self.theclass(1, 2, 3, 4)),
-                         "%s(1, 2, 3, 4)" % name)
-        self.assertEqual(repr(self.theclass(10, 2, 3, 4000)),
-                         "%s(10, 2, 3, 4000)" % name)
-        self.assertEqual(repr(self.theclass(0, 2, 3, 400000)),
-                         "%s(0, 2, 3, 400000)" % name)
-        self.assertEqual(repr(self.theclass(12, 2, 3, 0)),
-                         "%s(12, 2, 3)" % name)
-        self.assertEqual(repr(self.theclass(23, 15, 0, 0)),
-                         "%s(23, 15)" % name)
-
-    def test_resolution_info(self):
-        self.assertIsInstance(self.theclass.min, self.theclass)
-        self.assertIsInstance(self.theclass.max, self.theclass)
-        self.assertIsInstance(self.theclass.resolution, timedelta)
-        self.assertTrue(self.theclass.max > self.theclass.min)
-
-    def test_pickling(self):
-        args = 20, 59, 16, 64**2
-        orig = self.theclass(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_pickling_subclass_time(self):
-        args = 20, 59, 16, 64**2
-        orig = SubclassTime(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-    def test_bool(self):
-        cls = self.theclass
-        self.assertTrue(cls(1))
-        self.assertTrue(cls(0, 1))
-        self.assertTrue(cls(0, 0, 1))
-        self.assertTrue(cls(0, 0, 0, 1))
-        self.assertTrue(not cls(0))
-        self.assertTrue(not cls())
-
-    def test_replace(self):
-        cls = self.theclass
-        args = [1, 2, 3, 4]
-        base = cls(*args)
-        self.assertEqual(base, base.replace())
-
-        i = 0
-        for name, newval in (("hour", 5),
-                             ("minute", 6),
-                             ("second", 7),
-                             ("microsecond", 8)):
-            newargs = args[:]
-            newargs[i] = newval
-            expected = cls(*newargs)
-            got = base.replace(**{name: newval})
-            self.assertEqual(expected, got)
-            i += 1
-
-        # Out of bounds.
-        base = cls(1)
-        self.assertRaises(ValueError, base.replace, hour=24)
-        self.assertRaises(ValueError, base.replace, minute=-1)
-        self.assertRaises(ValueError, base.replace, second=100)
-        self.assertRaises(ValueError, base.replace, microsecond=1000000)
-
-    def test_subclass_time(self):
-
-        class C(self.theclass):
-            theAnswer = 42
-
-            def __new__(cls, *args, **kws):
-                temp = kws.copy()
-                extra = temp.pop('extra')
-                result = self.theclass.__new__(cls, *args, **temp)
-                result.extra = extra
-                return result
-
-            def newmeth(self, start):
-                return start + self.hour + self.second
-
-        args = 4, 5, 6
-
-        dt1 = self.theclass(*args)
-        dt2 = C(*args, **{'extra': 7})
-
-        self.assertEqual(dt2.__class__, C)
-        self.assertEqual(dt2.theAnswer, 42)
-        self.assertEqual(dt2.extra, 7)
-        self.assertEqual(dt1.isoformat(), dt2.isoformat())
-        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7)
-
-    def test_backdoor_resistance(self):
-        # see TestDate.test_backdoor_resistance().
-        base = '2:59.0'
-        for hour_byte in ' ', '9', chr(24), '\xff':
-            self.assertRaises(TypeError, self.theclass,
-                                         hour_byte + base[1:])
-
-# A mixin for classes with a tzinfo= argument.  Subclasses must define
-# theclass as a class atribute, and theclass(1, 1, 1, tzinfo=whatever)
-# must be legit (which is true for time and datetime).
-class TZInfoBase:
-
-    def test_argument_passing(self):
-        cls = self.theclass
-        # A datetime passes itself on, a time passes None.
-        class introspective(tzinfo):
-            def tzname(self, dt):    return dt and "real" or "none"
-            def utcoffset(self, dt):
-                return timedelta(minutes = dt and 42 or -42)
-            dst = utcoffset
-
-        obj = cls(1, 2, 3, tzinfo=introspective())
-
-        expected = cls is time and "none" or "real"
-        self.assertEqual(obj.tzname(), expected)
-
-        expected = timedelta(minutes=(cls is time and -42 or 42))
-        self.assertEqual(obj.utcoffset(), expected)
-        self.assertEqual(obj.dst(), expected)
-
-    def test_bad_tzinfo_classes(self):
-        cls = self.theclass
-        self.assertRaises(TypeError, cls, 1, 1, 1, tzinfo=12)
-
-        class NiceTry(object):
-            def __init__(self): pass
-            def utcoffset(self, dt): pass
-        self.assertRaises(TypeError, cls, 1, 1, 1, tzinfo=NiceTry)
-
-        class BetterTry(tzinfo):
-            def __init__(self): pass
-            def utcoffset(self, dt): pass
-        b = BetterTry()
-        t = cls(1, 1, 1, tzinfo=b)
-        self.assertTrue(t.tzinfo is b)
-
-    def test_utc_offset_out_of_bounds(self):
-        class Edgy(tzinfo):
-            def __init__(self, offset):
-                self.offset = timedelta(minutes=offset)
-            def utcoffset(self, dt):
-                return self.offset
-
-        cls = self.theclass
-        for offset, legit in ((-1440, False),
-                              (-1439, True),
-                              (1439, True),
-                              (1440, False)):
-            if cls is time:
-                t = cls(1, 2, 3, tzinfo=Edgy(offset))
-            elif cls is datetime:
-                t = cls(6, 6, 6, 1, 2, 3, tzinfo=Edgy(offset))
-            else:
-                assert 0, "impossible"
-            if legit:
-                aofs = abs(offset)
-                h, m = divmod(aofs, 60)
-                tag = "%c%02d:%02d" % (offset < 0 and '-' or '+', h, m)
-                if isinstance(t, datetime):
-                    t = t.timetz()
-                self.assertEqual(str(t), "01:02:03" + tag)
-            else:
-                self.assertRaises(ValueError, str, t)
-
-    def test_tzinfo_classes(self):
-        cls = self.theclass
-        class C1(tzinfo):
-            def utcoffset(self, dt): return None
-            def dst(self, dt): return None
-            def tzname(self, dt): return None
-        for t in (cls(1, 1, 1),
-                  cls(1, 1, 1, tzinfo=None),
-                  cls(1, 1, 1, tzinfo=C1())):
-            self.assertTrue(t.utcoffset() is None)
-            self.assertTrue(t.dst() is None)
-            self.assertTrue(t.tzname() is None)
-
-        class C3(tzinfo):
-            def utcoffset(self, dt): return timedelta(minutes=-1439)
-            def dst(self, dt): return timedelta(minutes=1439)
-            def tzname(self, dt): return "aname"
-        t = cls(1, 1, 1, tzinfo=C3())
-        self.assertEqual(t.utcoffset(), timedelta(minutes=-1439))
-        self.assertEqual(t.dst(), timedelta(minutes=1439))
-        self.assertEqual(t.tzname(), "aname")
-
-        # Wrong types.
-        class C4(tzinfo):
-            def utcoffset(self, dt): return "aname"
-            def dst(self, dt): return 7
-            def tzname(self, dt): return 0
-        t = cls(1, 1, 1, tzinfo=C4())
-        self.assertRaises(TypeError, t.utcoffset)
-        self.assertRaises(TypeError, t.dst)
-        self.assertRaises(TypeError, t.tzname)
-
-        # Offset out of range.
-        class C6(tzinfo):
-            def utcoffset(self, dt): return timedelta(hours=-24)
-            def dst(self, dt): return timedelta(hours=24)
-        t = cls(1, 1, 1, tzinfo=C6())
-        self.assertRaises(ValueError, t.utcoffset)
-        self.assertRaises(ValueError, t.dst)
-
-        # Not a whole number of minutes.
-        class C7(tzinfo):
-            def utcoffset(self, dt): return timedelta(seconds=61)
-            def dst(self, dt): return timedelta(microseconds=-81)
-        t = cls(1, 1, 1, tzinfo=C7())
-        self.assertRaises(ValueError, t.utcoffset)
-        self.assertRaises(ValueError, t.dst)
-
-    def test_aware_compare(self):
-        cls = self.theclass
-
-        # Ensure that utcoffset() gets ignored if the comparands have
-        # the same tzinfo member.
-        class OperandDependentOffset(tzinfo):
-            def utcoffset(self, t):
-                if t.minute < 10:
-                    # d0 and d1 equal after adjustment
-                    return timedelta(minutes=t.minute)
-                else:
-                    # d2 off in the weeds
-                    return timedelta(minutes=59)
-
-        base = cls(8, 9, 10, tzinfo=OperandDependentOffset())
-        d0 = base.replace(minute=3)
-        d1 = base.replace(minute=9)
-        d2 = base.replace(minute=11)
-        for x in d0, d1, d2:
-            for y in d0, d1, d2:
-                for op in lt, le, gt, ge, eq, ne:
-                    got = op(x, y)
-                    expected = op(x.minute, y.minute)
-                    self.assertEqual(got, expected)
-
-        # However, if they're different members, uctoffset is not ignored.
-        # Note that a time can't actually have an operand-depedent offset,
-        # though (and time.utcoffset() passes None to tzinfo.utcoffset()),
-        # so skip this test for time.
-        if cls is not time:
-            d0 = base.replace(minute=3, tzinfo=OperandDependentOffset())
-            d1 = base.replace(minute=9, tzinfo=OperandDependentOffset())
-            d2 = base.replace(minute=11, tzinfo=OperandDependentOffset())
-            for x in d0, d1, d2:
-                for y in d0, d1, d2:
-                    got = (x > y) - (x < y)
-                    if (x is d0 or x is d1) and (y is d0 or y is d1):
-                        expected = 0
-                    elif x is y is d2:
-                        expected = 0
-                    elif x is d2:
-                        expected = -1
-                    else:
-                        assert y is d2
-                        expected = 1
-                    self.assertEqual(got, expected)
-
-
-# Testing time objects with a non-None tzinfo.
-class TestTimeTZ(TestTime, TZInfoBase, unittest.TestCase):
-    theclass = time
-
-    def test_empty(self):
-        t = self.theclass()
-        self.assertEqual(t.hour, 0)
-        self.assertEqual(t.minute, 0)
-        self.assertEqual(t.second, 0)
-        self.assertEqual(t.microsecond, 0)
-        self.assertTrue(t.tzinfo is None)
-
-    def test_zones(self):
-        est = FixedOffset(-300, "EST", 1)
-        utc = FixedOffset(0, "UTC", -2)
-        met = FixedOffset(60, "MET", 3)
-        t1 = time( 7, 47, tzinfo=est)
-        t2 = time(12, 47, tzinfo=utc)
-        t3 = time(13, 47, tzinfo=met)
-        t4 = time(microsecond=40)
-        t5 = time(microsecond=40, tzinfo=utc)
-
-        self.assertEqual(t1.tzinfo, est)
-        self.assertEqual(t2.tzinfo, utc)
-        self.assertEqual(t3.tzinfo, met)
-        self.assertTrue(t4.tzinfo is None)
-        self.assertEqual(t5.tzinfo, utc)
-
-        self.assertEqual(t1.utcoffset(), timedelta(minutes=-300))
-        self.assertEqual(t2.utcoffset(), timedelta(minutes=0))
-        self.assertEqual(t3.utcoffset(), timedelta(minutes=60))
-        self.assertTrue(t4.utcoffset() is None)
-        self.assertRaises(TypeError, t1.utcoffset, "no args")
-
-        self.assertEqual(t1.tzname(), "EST")
-        self.assertEqual(t2.tzname(), "UTC")
-        self.assertEqual(t3.tzname(), "MET")
-        self.assertTrue(t4.tzname() is None)
-        self.assertRaises(TypeError, t1.tzname, "no args")
-
-        self.assertEqual(t1.dst(), timedelta(minutes=1))
-        self.assertEqual(t2.dst(), timedelta(minutes=-2))
-        self.assertEqual(t3.dst(), timedelta(minutes=3))
-        self.assertTrue(t4.dst() is None)
-        self.assertRaises(TypeError, t1.dst, "no args")
-
-        self.assertEqual(hash(t1), hash(t2))
-        self.assertEqual(hash(t1), hash(t3))
-        self.assertEqual(hash(t2), hash(t3))
-
-        self.assertEqual(t1, t2)
-        self.assertEqual(t1, t3)
-        self.assertEqual(t2, t3)
-        self.assertRaises(TypeError, lambda: t4 == t5) # mixed tz-aware & naive
-        self.assertRaises(TypeError, lambda: t4 < t5) # mixed tz-aware & naive
-        self.assertRaises(TypeError, lambda: t5 < t4) # mixed tz-aware & naive
-
-        self.assertEqual(str(t1), "07:47:00-05:00")
-        self.assertEqual(str(t2), "12:47:00+00:00")
-        self.assertEqual(str(t3), "13:47:00+01:00")
-        self.assertEqual(str(t4), "00:00:00.000040")
-        self.assertEqual(str(t5), "00:00:00.000040+00:00")
-
-        self.assertEqual(t1.isoformat(), "07:47:00-05:00")
-        self.assertEqual(t2.isoformat(), "12:47:00+00:00")
-        self.assertEqual(t3.isoformat(), "13:47:00+01:00")
-        self.assertEqual(t4.isoformat(), "00:00:00.000040")
-        self.assertEqual(t5.isoformat(), "00:00:00.000040+00:00")
-
-        d = 'datetime.time'
-        self.assertEqual(repr(t1), d + "(7, 47, tzinfo=est)")
-        self.assertEqual(repr(t2), d + "(12, 47, tzinfo=utc)")
-        self.assertEqual(repr(t3), d + "(13, 47, tzinfo=met)")
-        self.assertEqual(repr(t4), d + "(0, 0, 0, 40)")
-        self.assertEqual(repr(t5), d + "(0, 0, 0, 40, tzinfo=utc)")
-
-        self.assertEqual(t1.strftime("%H:%M:%S %%Z=%Z %%z=%z"),
-                                     "07:47:00 %Z=EST %z=-0500")
-        self.assertEqual(t2.strftime("%H:%M:%S %Z %z"), "12:47:00 UTC +0000")
-        self.assertEqual(t3.strftime("%H:%M:%S %Z %z"), "13:47:00 MET +0100")
-
-        yuck = FixedOffset(-1439, "%z %Z %%z%%Z")
-        t1 = time(23, 59, tzinfo=yuck)
-        self.assertEqual(t1.strftime("%H:%M %%Z='%Z' %%z='%z'"),
-                                     "23:59 %Z='%z %Z %%z%%Z' %z='-2359'")
-
-        # Check that an invalid tzname result raises an exception.
-        class Badtzname(tzinfo):
-            def tzname(self, dt): return 42
-        t = time(2, 3, 4, tzinfo=Badtzname())
-        self.assertEqual(t.strftime("%H:%M:%S"), "02:03:04")
-        self.assertRaises(TypeError, t.strftime, "%Z")
-
-    def test_hash_edge_cases(self):
-        # Offsets that overflow a basic time.
-        t1 = self.theclass(0, 1, 2, 3, tzinfo=FixedOffset(1439, ""))
-        t2 = self.theclass(0, 0, 2, 3, tzinfo=FixedOffset(1438, ""))
-        self.assertEqual(hash(t1), hash(t2))
-
-        t1 = self.theclass(23, 58, 6, 100, tzinfo=FixedOffset(-1000, ""))
-        t2 = self.theclass(23, 48, 6, 100, tzinfo=FixedOffset(-1010, ""))
-        self.assertEqual(hash(t1), hash(t2))
-
-    def test_pickling(self):
-        # Try one without a tzinfo.
-        args = 20, 59, 16, 64**2
-        orig = self.theclass(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-        # Try one with a tzinfo.
-        tinfo = PicklableFixedOffset(-300, 'cookie')
-        orig = self.theclass(5, 6, 7, tzinfo=tinfo)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-            self.assertIsInstance(derived.tzinfo, PicklableFixedOffset)
-            self.assertEqual(derived.utcoffset(), timedelta(minutes=-300))
-            self.assertEqual(derived.tzname(), 'cookie')
-
-    def test_more_bool(self):
-        # Test cases with non-None tzinfo.
-        cls = self.theclass
-
-        t = cls(0, tzinfo=FixedOffset(-300, ""))
-        self.assertTrue(t)
-
-        t = cls(5, tzinfo=FixedOffset(-300, ""))
-        self.assertTrue(t)
-
-        t = cls(5, tzinfo=FixedOffset(300, ""))
-        self.assertTrue(not t)
-
-        t = cls(23, 59, tzinfo=FixedOffset(23*60 + 59, ""))
-        self.assertTrue(not t)
-
-        # Mostly ensuring this doesn't overflow internally.
-        t = cls(0, tzinfo=FixedOffset(23*60 + 59, ""))
-        self.assertTrue(t)
-
-        # But this should yield a value error -- the utcoffset is bogus.
-        t = cls(0, tzinfo=FixedOffset(24*60, ""))
-        self.assertRaises(ValueError, lambda: bool(t))
-
-        # Likewise.
-        t = cls(0, tzinfo=FixedOffset(-24*60, ""))
-        self.assertRaises(ValueError, lambda: bool(t))
-
-    def test_replace(self):
-        cls = self.theclass
-        z100 = FixedOffset(100, "+100")
-        zm200 = FixedOffset(timedelta(minutes=-200), "-200")
-        args = [1, 2, 3, 4, z100]
-        base = cls(*args)
-        self.assertEqual(base, base.replace())
-
-        i = 0
-        for name, newval in (("hour", 5),
-                             ("minute", 6),
-                             ("second", 7),
-                             ("microsecond", 8),
-                             ("tzinfo", zm200)):
-            newargs = args[:]
-            newargs[i] = newval
-            expected = cls(*newargs)
-            got = base.replace(**{name: newval})
-            self.assertEqual(expected, got)
-            i += 1
-
-        # Ensure we can get rid of a tzinfo.
-        self.assertEqual(base.tzname(), "+100")
-        base2 = base.replace(tzinfo=None)
-        self.assertTrue(base2.tzinfo is None)
-        self.assertTrue(base2.tzname() is None)
-
-        # Ensure we can add one.
-        base3 = base2.replace(tzinfo=z100)
-        self.assertEqual(base, base3)
-        self.assertTrue(base.tzinfo is base3.tzinfo)
-
-        # Out of bounds.
-        base = cls(1)
-        self.assertRaises(ValueError, base.replace, hour=24)
-        self.assertRaises(ValueError, base.replace, minute=-1)
-        self.assertRaises(ValueError, base.replace, second=100)
-        self.assertRaises(ValueError, base.replace, microsecond=1000000)
-
-    def test_mixed_compare(self):
-        t1 = time(1, 2, 3)
-        t2 = time(1, 2, 3)
-        self.assertEqual(t1, t2)
-        t2 = t2.replace(tzinfo=None)
-        self.assertEqual(t1, t2)
-        t2 = t2.replace(tzinfo=FixedOffset(None, ""))
-        self.assertEqual(t1, t2)
-        t2 = t2.replace(tzinfo=FixedOffset(0, ""))
-        self.assertRaises(TypeError, lambda: t1 == t2)
-
-        # In time w/ identical tzinfo objects, utcoffset is ignored.
-        class Varies(tzinfo):
-            def __init__(self):
-                self.offset = timedelta(minutes=22)
-            def utcoffset(self, t):
-                self.offset += timedelta(minutes=1)
-                return self.offset
-
-        v = Varies()
-        t1 = t2.replace(tzinfo=v)
-        t2 = t2.replace(tzinfo=v)
-        self.assertEqual(t1.utcoffset(), timedelta(minutes=23))
-        self.assertEqual(t2.utcoffset(), timedelta(minutes=24))
-        self.assertEqual(t1, t2)
-
-        # But if they're not identical, it isn't ignored.
-        t2 = t2.replace(tzinfo=Varies())
-        self.assertTrue(t1 < t2)  # t1's offset counter still going up
-
-    def test_subclass_timetz(self):
-
-        class C(self.theclass):
-            theAnswer = 42
-
-            def __new__(cls, *args, **kws):
-                temp = kws.copy()
-                extra = temp.pop('extra')
-                result = self.theclass.__new__(cls, *args, **temp)
-                result.extra = extra
-                return result
-
-            def newmeth(self, start):
-                return start + self.hour + self.second
-
-        args = 4, 5, 6, 500, FixedOffset(-300, "EST", 1)
-
-        dt1 = self.theclass(*args)
-        dt2 = C(*args, **{'extra': 7})
-
-        self.assertEqual(dt2.__class__, C)
-        self.assertEqual(dt2.theAnswer, 42)
-        self.assertEqual(dt2.extra, 7)
-        self.assertEqual(dt1.utcoffset(), dt2.utcoffset())
-        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.second - 7)
-
-
-# Testing datetime objects with a non-None tzinfo.
-
-class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
-    theclass = datetime
-
-    def test_trivial(self):
-        dt = self.theclass(1, 2, 3, 4, 5, 6, 7)
-        self.assertEqual(dt.year, 1)
-        self.assertEqual(dt.month, 2)
-        self.assertEqual(dt.day, 3)
-        self.assertEqual(dt.hour, 4)
-        self.assertEqual(dt.minute, 5)
-        self.assertEqual(dt.second, 6)
-        self.assertEqual(dt.microsecond, 7)
-        self.assertEqual(dt.tzinfo, None)
-
-    def test_even_more_compare(self):
-        # The test_compare() and test_more_compare() inherited from TestDate
-        # and TestDateTime covered non-tzinfo cases.
-
-        # Smallest possible after UTC adjustment.
-        t1 = self.theclass(1, 1, 1, tzinfo=FixedOffset(1439, ""))
-        # Largest possible after UTC adjustment.
-        t2 = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999999,
-                           tzinfo=FixedOffset(-1439, ""))
-
-        # Make sure those compare correctly, and w/o overflow.
-        self.assertTrue(t1 < t2)
-        self.assertTrue(t1 != t2)
-        self.assertTrue(t2 > t1)
-
-        self.assertEqual(t1, t1)
-        self.assertEqual(t2, t2)
-
-        # Equal afer adjustment.
-        t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""))
-        t2 = self.theclass(2, 1, 1, 3, 13, tzinfo=FixedOffset(3*60+13+2, ""))
-        self.assertEqual(t1, t2)
-
-        # Change t1 not to subtract a minute, and t1 should be larger.
-        t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(0, ""))
-        self.assertTrue(t1 > t2)
-
-        # Change t1 to subtract 2 minutes, and t1 should be smaller.
-        t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(2, ""))
-        self.assertTrue(t1 < t2)
-
-        # Back to the original t1, but make seconds resolve it.
-        t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""),
-                           second=1)
-        self.assertTrue(t1 > t2)
-
-        # Likewise, but make microseconds resolve it.
-        t1 = self.theclass(1, 12, 31, 23, 59, tzinfo=FixedOffset(1, ""),
-                           microsecond=1)
-        self.assertTrue(t1 > t2)
-
-        # Make t2 naive and it should fail.
-        t2 = self.theclass.min
-        self.assertRaises(TypeError, lambda: t1 == t2)
-        self.assertEqual(t2, t2)
-
-        # It's also naive if it has tzinfo but tzinfo.utcoffset() is None.
-        class Naive(tzinfo):
-            def utcoffset(self, dt): return None
-        t2 = self.theclass(5, 6, 7, tzinfo=Naive())
-        self.assertRaises(TypeError, lambda: t1 == t2)
-        self.assertEqual(t2, t2)
-
-        # OTOH, it's OK to compare two of these mixing the two ways of being
-        # naive.
-        t1 = self.theclass(5, 6, 7)
-        self.assertEqual(t1, t2)
-
-        # Try a bogus uctoffset.
-        class Bogus(tzinfo):
-            def utcoffset(self, dt):
-                return timedelta(minutes=1440) # out of bounds
-        t1 = self.theclass(2, 2, 2, tzinfo=Bogus())
-        t2 = self.theclass(2, 2, 2, tzinfo=FixedOffset(0, ""))
-        self.assertRaises(ValueError, lambda: t1 == t2)
-
-    def test_pickling(self):
-        # Try one without a tzinfo.
-        args = 6, 7, 23, 20, 59, 1, 64**2
-        orig = self.theclass(*args)
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-
-        # Try one with a tzinfo.
-        tinfo = PicklableFixedOffset(-300, 'cookie')
-        orig = self.theclass(*args, **{'tzinfo': tinfo})
-        derived = self.theclass(1, 1, 1, tzinfo=FixedOffset(0, "", 0))
-        for pickler, unpickler, proto in pickle_choices:
-            green = pickler.dumps(orig, proto)
-            derived = unpickler.loads(green)
-            self.assertEqual(orig, derived)
-            self.assertIsInstance(derived.tzinfo, PicklableFixedOffset)
-            self.assertEqual(derived.utcoffset(), timedelta(minutes=-300))
-            self.assertEqual(derived.tzname(), 'cookie')
-
-    def test_extreme_hashes(self):
-        # If an attempt is made to hash these via subtracting the offset
-        # then hashing a datetime object, OverflowError results.  The
-        # Python implementation used to blow up here.
-        t = self.theclass(1, 1, 1, tzinfo=FixedOffset(1439, ""))
-        hash(t)
-        t = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999999,
-                          tzinfo=FixedOffset(-1439, ""))
-        hash(t)
-
-        # OTOH, an OOB offset should blow up.
-        t = self.theclass(5, 5, 5, tzinfo=FixedOffset(-1440, ""))
-        self.assertRaises(ValueError, hash, t)
-
-    def test_zones(self):
-        est = FixedOffset(-300, "EST")
-        utc = FixedOffset(0, "UTC")
-        met = FixedOffset(60, "MET")
-        t1 = datetime(2002, 3, 19,  7, 47, tzinfo=est)
-        t2 = datetime(2002, 3, 19, 12, 47, tzinfo=utc)
-        t3 = datetime(2002, 3, 19, 13, 47, tzinfo=met)
-        self.assertEqual(t1.tzinfo, est)
-        self.assertEqual(t2.tzinfo, utc)
-        self.assertEqual(t3.tzinfo, met)
-        self.assertEqual(t1.utcoffset(), timedelta(minutes=-300))
-        self.assertEqual(t2.utcoffset(), timedelta(minutes=0))
-        self.assertEqual(t3.utcoffset(), timedelta(minutes=60))
-        self.assertEqual(t1.tzname(), "EST")
-        self.assertEqual(t2.tzname(), "UTC")
-        self.assertEqual(t3.tzname(), "MET")
-        self.assertEqual(hash(t1), hash(t2))
-        self.assertEqual(hash(t1), hash(t3))
-        self.assertEqual(hash(t2), hash(t3))
-        self.assertEqual(t1, t2)
-        self.assertEqual(t1, t3)
-        self.assertEqual(t2, t3)
-        self.assertEqual(str(t1), "2002-03-19 07:47:00-05:00")
-        self.assertEqual(str(t2), "2002-03-19 12:47:00+00:00")
-        self.assertEqual(str(t3), "2002-03-19 13:47:00+01:00")
-        d = 'datetime.datetime(2002, 3, 19, '
-        self.assertEqual(repr(t1), d + "7, 47, tzinfo=est)")
-        self.assertEqual(repr(t2), d + "12, 47, tzinfo=utc)")
-        self.assertEqual(repr(t3), d + "13, 47, tzinfo=met)")
-
-    def test_combine(self):
-        met = FixedOffset(60, "MET")
-        d = date(2002, 3, 4)
-        tz = time(18, 45, 3, 1234, tzinfo=met)
-        dt = datetime.combine(d, tz)
-        self.assertEqual(dt, datetime(2002, 3, 4, 18, 45, 3, 1234,
-                                        tzinfo=met))
-
-    def test_extract(self):
-        met = FixedOffset(60, "MET")
-        dt = self.theclass(2002, 3, 4, 18, 45, 3, 1234, tzinfo=met)
-        self.assertEqual(dt.date(), date(2002, 3, 4))
-        self.assertEqual(dt.time(), time(18, 45, 3, 1234))
-        self.assertEqual(dt.timetz(), time(18, 45, 3, 1234, tzinfo=met))
-
-    def test_tz_aware_arithmetic(self):
-        import random
-
-        now = self.theclass.now()
-        tz55 = FixedOffset(-330, "west 5:30")
-        timeaware = now.time().replace(tzinfo=tz55)
-        nowaware = self.theclass.combine(now.date(), timeaware)
-        self.assertTrue(nowaware.tzinfo is tz55)
-        self.assertEqual(nowaware.timetz(), timeaware)
-
-        # Can't mix aware and non-aware.
-        self.assertRaises(TypeError, lambda: now - nowaware)
-        self.assertRaises(TypeError, lambda: nowaware - now)
-
-        # And adding datetime's doesn't make sense, aware or not.
-        self.assertRaises(TypeError, lambda: now + nowaware)
-        self.assertRaises(TypeError, lambda: nowaware + now)
-        self.assertRaises(TypeError, lambda: nowaware + nowaware)
-
-        # Subtracting should yield 0.
-        self.assertEqual(now - now, timedelta(0))
-        self.assertEqual(nowaware - nowaware, timedelta(0))
-
-        # Adding a delta should preserve tzinfo.
-        delta = timedelta(weeks=1, minutes=12, microseconds=5678)
-        nowawareplus = nowaware + delta
-        self.assertTrue(nowaware.tzinfo is tz55)
-        nowawareplus2 = delta + nowaware
-        self.assertTrue(nowawareplus2.tzinfo is tz55)
-        self.assertEqual(nowawareplus, nowawareplus2)
-
-        # that - delta should be what we started with, and that - what we
-        # started with should be delta.
-        diff = nowawareplus - delta
-        self.assertTrue(diff.tzinfo is tz55)
-        self.assertEqual(nowaware, diff)
-        self.assertRaises(TypeError, lambda: delta - nowawareplus)
-        self.assertEqual(nowawareplus - nowaware, delta)
-
-        # Make up a random timezone.
-        tzr = FixedOffset(random.randrange(-1439, 1440), "randomtimezone")
-        # Attach it to nowawareplus.
-        nowawareplus = nowawareplus.replace(tzinfo=tzr)
-        self.assertTrue(nowawareplus.tzinfo is tzr)
-        # Make sure the difference takes the timezone adjustments into account.
-        got = nowaware - nowawareplus
-        # Expected:  (nowaware base - nowaware offset) -
-        #            (nowawareplus base - nowawareplus offset) =
-        #            (nowaware base - nowawareplus base) +
-        #            (nowawareplus offset - nowaware offset) =
-        #            -delta + nowawareplus offset - nowaware offset
-        expected = nowawareplus.utcoffset() - nowaware.utcoffset() - delta
-        self.assertEqual(got, expected)
-
-        # Try max possible difference.
-        min = self.theclass(1, 1, 1, tzinfo=FixedOffset(1439, "min"))
-        max = self.theclass(MAXYEAR, 12, 31, 23, 59, 59, 999999,
-                            tzinfo=FixedOffset(-1439, "max"))
-        maxdiff = max - min
-        self.assertEqual(maxdiff, self.theclass.max - self.theclass.min +
-                                  timedelta(minutes=2*1439))
-        # Different tzinfo, but the same offset
-        tza = timezone(HOUR, 'A')
-        tzb = timezone(HOUR, 'B')
-        delta = min.replace(tzinfo=tza) - max.replace(tzinfo=tzb)
-        self.assertEqual(delta, self.theclass.min - self.theclass.max)
-
-    def test_tzinfo_now(self):
-        meth = self.theclass.now
-        # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up).
-        base = meth()
-        # Try with and without naming the keyword.
-        off42 = FixedOffset(42, "42")
-        another = meth(off42)
-        again = meth(tz=off42)
-        self.assertTrue(another.tzinfo is again.tzinfo)
-        self.assertEqual(another.utcoffset(), timedelta(minutes=42))
-        # Bad argument with and w/o naming the keyword.
-        self.assertRaises(TypeError, meth, 16)
-        self.assertRaises(TypeError, meth, tzinfo=16)
-        # Bad keyword name.
-        self.assertRaises(TypeError, meth, tinfo=off42)
-        # Too many args.
-        self.assertRaises(TypeError, meth, off42, off42)
-
-        # We don't know which time zone we're in, and don't have a tzinfo
-        # class to represent it, so seeing whether a tz argument actually
-        # does a conversion is tricky.
-        utc = FixedOffset(0, "utc", 0)
-        for weirdtz in [FixedOffset(timedelta(hours=15, minutes=58), "weirdtz", 0),
-                        timezone(timedelta(hours=15, minutes=58), "weirdtz"),]:
-            for dummy in range(3):
-                now = datetime.now(weirdtz)
-                self.assertTrue(now.tzinfo is weirdtz)
-                utcnow = datetime.utcnow().replace(tzinfo=utc)
-                now2 = utcnow.astimezone(weirdtz)
-                if abs(now - now2) < timedelta(seconds=30):
-                    break
-                # Else the code is broken, or more than 30 seconds passed between
-                # calls; assuming the latter, just try again.
-            else:
-                # Three strikes and we're out.
-                self.fail("utcnow(), now(tz), or astimezone() may be broken")
-
-    def test_tzinfo_fromtimestamp(self):
-        import time
-        meth = self.theclass.fromtimestamp
-        ts = time.time()
-        # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up).
-        base = meth(ts)
-        # Try with and without naming the keyword.
-        off42 = FixedOffset(42, "42")
-        another = meth(ts, off42)
-        again = meth(ts, tz=off42)
-        self.assertTrue(another.tzinfo is again.tzinfo)
-        self.assertEqual(another.utcoffset(), timedelta(minutes=42))
-        # Bad argument with and w/o naming the keyword.
-        self.assertRaises(TypeError, meth, ts, 16)
-        self.assertRaises(TypeError, meth, ts, tzinfo=16)
-        # Bad keyword name.
-        self.assertRaises(TypeError, meth, ts, tinfo=off42)
-        # Too many args.
-        self.assertRaises(TypeError, meth, ts, off42, off42)
-        # Too few args.
-        self.assertRaises(TypeError, meth)
-
-        # Try to make sure tz= actually does some conversion.
-        timestamp = 1000000000
-        utcdatetime = datetime.utcfromtimestamp(timestamp)
-        # In POSIX (epoch 1970), that's 2001-09-09 01:46:40 UTC, give or take.
-        # But on some flavor of Mac, it's nowhere near that.  So we can't have
-        # any idea here what time that actually is, we can only test that
-        # relative changes match.
-        utcoffset = timedelta(hours=-15, minutes=39) # arbitrary, but not zero
-        tz = FixedOffset(utcoffset, "tz", 0)
-        expected = utcdatetime + utcoffset
-        got = datetime.fromtimestamp(timestamp, tz)
-        self.assertEqual(expected, got.replace(tzinfo=None))
-
-    def test_tzinfo_utcnow(self):
-        meth = self.theclass.utcnow
-        # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up).
-        base = meth()
-        # Try with and without naming the keyword; for whatever reason,
-        # utcnow() doesn't accept a tzinfo argument.
-        off42 = FixedOffset(42, "42")
-        self.assertRaises(TypeError, meth, off42)
-        self.assertRaises(TypeError, meth, tzinfo=off42)
-
-    def test_tzinfo_utcfromtimestamp(self):
-        import time
-        meth = self.theclass.utcfromtimestamp
-        ts = time.time()
-        # Ensure it doesn't require tzinfo (i.e., that this doesn't blow up).
-        base = meth(ts)
-        # Try with and without naming the keyword; for whatever reason,
-        # utcfromtimestamp() doesn't accept a tzinfo argument.
-        off42 = FixedOffset(42, "42")
-        self.assertRaises(TypeError, meth, ts, off42)
-        self.assertRaises(TypeError, meth, ts, tzinfo=off42)
-
-    def test_tzinfo_timetuple(self):
-        # TestDateTime tested most of this.  datetime adds a twist to the
-        # DST flag.
-        class DST(tzinfo):
-            def __init__(self, dstvalue):
-                if isinstance(dstvalue, int):
-                    dstvalue = timedelta(minutes=dstvalue)
-                self.dstvalue = dstvalue
-            def dst(self, dt):
-                return self.dstvalue
-
-        cls = self.theclass
-        for dstvalue, flag in (-33, 1), (33, 1), (0, 0), (None, -1):
-            d = cls(1, 1, 1, 10, 20, 30, 40, tzinfo=DST(dstvalue))
-            t = d.timetuple()
-            self.assertEqual(1, t.tm_year)
-            self.assertEqual(1, t.tm_mon)
-            self.assertEqual(1, t.tm_mday)
-            self.assertEqual(10, t.tm_hour)
-            self.assertEqual(20, t.tm_min)
-            self.assertEqual(30, t.tm_sec)
-            self.assertEqual(0, t.tm_wday)
-            self.assertEqual(1, t.tm_yday)
-            self.assertEqual(flag, t.tm_isdst)
-
-        # dst() returns wrong type.
-        self.assertRaises(TypeError, cls(1, 1, 1, tzinfo=DST("x")).timetuple)
-
-        # dst() at the edge.
-        self.assertEqual(cls(1,1,1, tzinfo=DST(1439)).timetuple().tm_isdst, 1)
-        self.assertEqual(cls(1,1,1, tzinfo=DST(-1439)).timetuple().tm_isdst, 1)
-
-        # dst() out of range.
-        self.assertRaises(ValueError, cls(1,1,1, tzinfo=DST(1440)).timetuple)
-        self.assertRaises(ValueError, cls(1,1,1, tzinfo=DST(-1440)).timetuple)
-
-    def test_utctimetuple(self):
-        class DST(tzinfo):
-            def __init__(self, dstvalue=0):
-                if isinstance(dstvalue, int):
-                    dstvalue = timedelta(minutes=dstvalue)
-                self.dstvalue = dstvalue
-            def dst(self, dt):
-                return self.dstvalue
-
-        cls = self.theclass
-        # This can't work:  DST didn't implement utcoffset.
-        self.assertRaises(NotImplementedError,
-                          cls(1, 1, 1, tzinfo=DST(0)).utcoffset)
-
-        class UOFS(DST):
-            def __init__(self, uofs, dofs=None):
-                DST.__init__(self, dofs)
-                self.uofs = timedelta(minutes=uofs)
-            def utcoffset(self, dt):
-                return self.uofs
-
-        for dstvalue in -33, 33, 0, None:
-            d = cls(1, 2, 3, 10, 20, 30, 40, tzinfo=UOFS(-53, dstvalue))
-            t = d.utctimetuple()
-            self.assertEqual(d.year, t.tm_year)
-            self.assertEqual(d.month, t.tm_mon)
-            self.assertEqual(d.day, t.tm_mday)
-            self.assertEqual(11, t.tm_hour) # 20mm + 53mm = 1hn + 13mm
-            self.assertEqual(13, t.tm_min)
-            self.assertEqual(d.second, t.tm_sec)
-            self.assertEqual(d.weekday(), t.tm_wday)
-            self.assertEqual(d.toordinal() - date(1, 1, 1).toordinal() + 1,
-                             t.tm_yday)
-            # Ensure tm_isdst is 0 regardless of what dst() says: DST
-            # is never in effect for a UTC time.
-            self.assertEqual(0, t.tm_isdst)
-
-        # For naive datetime, utctimetuple == timetuple except for isdst
-        d = cls(1, 2, 3, 10, 20, 30, 40)
-        t = d.utctimetuple()
-        self.assertEqual(t[:-1], d.timetuple()[:-1])
-        self.assertEqual(0, t.tm_isdst)
-        # Same if utcoffset is None
-        class NOFS(DST):
-            def utcoffset(self, dt):
-                return None
-        d = cls(1, 2, 3, 10, 20, 30, 40, tzinfo=NOFS())
-        t = d.utctimetuple()
-        self.assertEqual(t[:-1], d.timetuple()[:-1])
-        self.assertEqual(0, t.tm_isdst)
-        # Check that bad tzinfo is detected
-        class BOFS(DST):
-            def utcoffset(self, dt):
-                return "EST"
-        d = cls(1, 2, 3, 10, 20, 30, 40, tzinfo=BOFS())
-        self.assertRaises(TypeError, d.utctimetuple)
-
-        # Check that utctimetuple() is the same as
-        # astimezone(utc).timetuple()
-        d = cls(2010, 11, 13, 14, 15, 16, 171819)
-        for tz in [timezone.min, timezone.utc, timezone.max]:
-            dtz = d.replace(tzinfo=tz)
-            self.assertEqual(dtz.utctimetuple()[:-1],
-                             dtz.astimezone(timezone.utc).timetuple()[:-1])
-        # At the edges, UTC adjustment can produce years out-of-range
-        # for a datetime object.  Ensure that an OverflowError is
-        # raised.
-        tiny = cls(MINYEAR, 1, 1, 0, 0, 37, tzinfo=UOFS(1439))
-        # That goes back 1 minute less than a full day.
-        self.assertRaises(OverflowError, tiny.utctimetuple)
-
-        huge = cls(MAXYEAR, 12, 31, 23, 59, 37, 999999, tzinfo=UOFS(-1439))
-        # That goes forward 1 minute less than a full day.
-        self.assertRaises(OverflowError, huge.utctimetuple)
-        # More overflow cases
-        tiny = cls.min.replace(tzinfo=timezone(MINUTE))
-        self.assertRaises(OverflowError, tiny.utctimetuple)
-        huge = cls.max.replace(tzinfo=timezone(-MINUTE))
-        self.assertRaises(OverflowError, huge.utctimetuple)
-
-    def test_tzinfo_isoformat(self):
-        zero = FixedOffset(0, "+00:00")
-        plus = FixedOffset(220, "+03:40")
-        minus = FixedOffset(-231, "-03:51")
-        unknown = FixedOffset(None, "")
-
-        cls = self.theclass
-        datestr = '0001-02-03'
-        for ofs in None, zero, plus, minus, unknown:
-            for us in 0, 987001:
-                d = cls(1, 2, 3, 4, 5, 59, us, tzinfo=ofs)
-                timestr = '04:05:59' + (us and '.987001' or '')
-                ofsstr = ofs is not None and d.tzname() or ''
-                tailstr = timestr + ofsstr
-                iso = d.isoformat()
-                self.assertEqual(iso, datestr + 'T' + tailstr)
-                self.assertEqual(iso, d.isoformat('T'))
-                self.assertEqual(d.isoformat('k'), datestr + 'k' + tailstr)
-                self.assertEqual(d.isoformat('\u1234'), datestr + '\u1234' + tailstr)
-                self.assertEqual(str(d), datestr + ' ' + tailstr)
-
-    def test_replace(self):
-        cls = self.theclass
-        z100 = FixedOffset(100, "+100")
-        zm200 = FixedOffset(timedelta(minutes=-200), "-200")
-        args = [1, 2, 3, 4, 5, 6, 7, z100]
-        base = cls(*args)
-        self.assertEqual(base, base.replace())
-
-        i = 0
-        for name, newval in (("year", 2),
-                             ("month", 3),
-                             ("day", 4),
-                             ("hour", 5),
-                             ("minute", 6),
-                             ("second", 7),
-                             ("microsecond", 8),
-                             ("tzinfo", zm200)):
-            newargs = args[:]
-            newargs[i] = newval
-            expected = cls(*newargs)
-            got = base.replace(**{name: newval})
-            self.assertEqual(expected, got)
-            i += 1
-
-        # Ensure we can get rid of a tzinfo.
-        self.assertEqual(base.tzname(), "+100")
-        base2 = base.replace(tzinfo=None)
-        self.assertTrue(base2.tzinfo is None)
-        self.assertTrue(base2.tzname() is None)
-
-        # Ensure we can add one.
-        base3 = base2.replace(tzinfo=z100)
-        self.assertEqual(base, base3)
-        self.assertTrue(base.tzinfo is base3.tzinfo)
-
-        # Out of bounds.
-        base = cls(2000, 2, 29)
-        self.assertRaises(ValueError, base.replace, year=2001)
-
-    def test_more_astimezone(self):
-        # The inherited test_astimezone covered some trivial and error cases.
-        fnone = FixedOffset(None, "None")
-        f44m = FixedOffset(44, "44")
-        fm5h = FixedOffset(-timedelta(hours=5), "m300")
-
-        dt = self.theclass.now(tz=f44m)
-        self.assertTrue(dt.tzinfo is f44m)
-        # Replacing with degenerate tzinfo raises an exception.
-        self.assertRaises(ValueError, dt.astimezone, fnone)
-        # Ditto with None tz.
-        self.assertRaises(TypeError, dt.astimezone, None)
-        # Replacing with same tzinfo makes no change.
-        x = dt.astimezone(dt.tzinfo)
-        self.assertTrue(x.tzinfo is f44m)
-        self.assertEqual(x.date(), dt.date())
-        self.assertEqual(x.time(), dt.time())
-
-        # Replacing with different tzinfo does adjust.
-        got = dt.astimezone(fm5h)
-        self.assertTrue(got.tzinfo is fm5h)
-        self.assertEqual(got.utcoffset(), timedelta(hours=-5))
-        expected = dt - dt.utcoffset()  # in effect, convert to UTC
-        expected += fm5h.utcoffset(dt)  # and from there to local time
-        expected = expected.replace(tzinfo=fm5h) # and attach new tzinfo
-        self.assertEqual(got.date(), expected.date())
-        self.assertEqual(got.time(), expected.time())
-        self.assertEqual(got.timetz(), expected.timetz())
-        self.assertTrue(got.tzinfo is expected.tzinfo)
-        self.assertEqual(got, expected)
-
-    def test_aware_subtract(self):
-        cls = self.theclass
-
-        # Ensure that utcoffset() is ignored when the operands have the
-        # same tzinfo member.
-        class OperandDependentOffset(tzinfo):
-            def utcoffset(self, t):
-                if t.minute < 10:
-                    # d0 and d1 equal after adjustment
-                    return timedelta(minutes=t.minute)
-                else:
-                    # d2 off in the weeds
-                    return timedelta(minutes=59)
-
-        base = cls(8, 9, 10, 11, 12, 13, 14, tzinfo=OperandDependentOffset())
-        d0 = base.replace(minute=3)
-        d1 = base.replace(minute=9)
-        d2 = base.replace(minute=11)
-        for x in d0, d1, d2:
-            for y in d0, d1, d2:
-                got = x - y
-                expected = timedelta(minutes=x.minute - y.minute)
-                self.assertEqual(got, expected)
-
-        # OTOH, if the tzinfo members are distinct, utcoffsets aren't
-        # ignored.
-        base = cls(8, 9, 10, 11, 12, 13, 14)
-        d0 = base.replace(minute=3, tzinfo=OperandDependentOffset())
-        d1 = base.replace(minute=9, tzinfo=OperandDependentOffset())
-        d2 = base.replace(minute=11, tzinfo=OperandDependentOffset())
-        for x in d0, d1, d2:
-            for y in d0, d1, d2:
-                got = x - y
-                if (x is d0 or x is d1) and (y is d0 or y is d1):
-                    expected = timedelta(0)
-                elif x is y is d2:
-                    expected = timedelta(0)
-                elif x is d2:
-                    expected = timedelta(minutes=(11-59)-0)
-                else:
-                    assert y is d2
-                    expected = timedelta(minutes=0-(11-59))
-                self.assertEqual(got, expected)
-
-    def test_mixed_compare(self):
-        t1 = datetime(1, 2, 3, 4, 5, 6, 7)
-        t2 = datetime(1, 2, 3, 4, 5, 6, 7)
-        self.assertEqual(t1, t2)
-        t2 = t2.replace(tzinfo=None)
-        self.assertEqual(t1, t2)
-        t2 = t2.replace(tzinfo=FixedOffset(None, ""))
-        self.assertEqual(t1, t2)
-        t2 = t2.replace(tzinfo=FixedOffset(0, ""))
-        self.assertRaises(TypeError, lambda: t1 == t2)
-
-        # In datetime w/ identical tzinfo objects, utcoffset is ignored.
-        class Varies(tzinfo):
-            def __init__(self):
-                self.offset = timedelta(minutes=22)
-            def utcoffset(self, t):
-                self.offset += timedelta(minutes=1)
-                return self.offset
-
-        v = Varies()
-        t1 = t2.replace(tzinfo=v)
-        t2 = t2.replace(tzinfo=v)
-        self.assertEqual(t1.utcoffset(), timedelta(minutes=23))
-        self.assertEqual(t2.utcoffset(), timedelta(minutes=24))
-        self.assertEqual(t1, t2)
-
-        # But if they're not identical, it isn't ignored.
-        t2 = t2.replace(tzinfo=Varies())
-        self.assertTrue(t1 < t2)  # t1's offset counter still going up
-
-    def test_subclass_datetimetz(self):
-
-        class C(self.theclass):
-            theAnswer = 42
-
-            def __new__(cls, *args, **kws):
-                temp = kws.copy()
-                extra = temp.pop('extra')
-                result = self.theclass.__new__(cls, *args, **temp)
-                result.extra = extra
-                return result
-
-            def newmeth(self, start):
-                return start + self.hour + self.year
-
-        args = 2002, 12, 31, 4, 5, 6, 500, FixedOffset(-300, "EST", 1)
-
-        dt1 = self.theclass(*args)
-        dt2 = C(*args, **{'extra': 7})
-
-        self.assertEqual(dt2.__class__, C)
-        self.assertEqual(dt2.theAnswer, 42)
-        self.assertEqual(dt2.extra, 7)
-        self.assertEqual(dt1.utcoffset(), dt2.utcoffset())
-        self.assertEqual(dt2.newmeth(-7), dt1.hour + dt1.year - 7)
-
-# Pain to set up DST-aware tzinfo classes.
-
-def first_sunday_on_or_after(dt):
-    days_to_go = 6 - dt.weekday()
-    if days_to_go:
-        dt += timedelta(days_to_go)
-    return dt
-
-ZERO = timedelta(0)
-MINUTE = timedelta(minutes=1)
-HOUR = timedelta(hours=1)
-DAY = timedelta(days=1)
-# In the US, DST starts at 2am (standard time) on the first Sunday in April.
-DSTSTART = datetime(1, 4, 1, 2)
-# and ends at 2am (DST time; 1am standard time) on the last Sunday of Oct,
-# which is the first Sunday on or after Oct 25.  Because we view 1:MM as
-# being standard time on that day, there is no spelling in local time of
-# the last hour of DST (that's 1:MM DST, but 1:MM is taken as standard time).
-DSTEND = datetime(1, 10, 25, 1)
-
-class USTimeZone(tzinfo):
-
-    def __init__(self, hours, reprname, stdname, dstname):
-        self.stdoffset = timedelta(hours=hours)
-        self.reprname = reprname
-        self.stdname = stdname
-        self.dstname = dstname
-
-    def __repr__(self):
-        return self.reprname
-
-    def tzname(self, dt):
-        if self.dst(dt):
-            return self.dstname
-        else:
-            return self.stdname
-
-    def utcoffset(self, dt):
-        return self.stdoffset + self.dst(dt)
-
-    def dst(self, dt):
-        if dt is None or dt.tzinfo is None:
-            # An exception instead may be sensible here, in one or more of
-            # the cases.
-            return ZERO
-        assert dt.tzinfo is self
-
-        # Find first Sunday in April.
-        start = first_sunday_on_or_after(DSTSTART.replace(year=dt.year))
-        assert start.weekday() == 6 and start.month == 4 and start.day <= 7
-
-        # Find last Sunday in October.
-        end = first_sunday_on_or_after(DSTEND.replace(year=dt.year))
-        assert end.weekday() == 6 and end.month == 10 and end.day >= 25
-
-        # Can't compare naive to aware objects, so strip the timezone from
-        # dt first.
-        if start <= dt.replace(tzinfo=None) < end:
-            return HOUR
-        else:
-            return ZERO
-
-Eastern  = USTimeZone(-5, "Eastern",  "EST", "EDT")
-Central  = USTimeZone(-6, "Central",  "CST", "CDT")
-Mountain = USTimeZone(-7, "Mountain", "MST", "MDT")
-Pacific  = USTimeZone(-8, "Pacific",  "PST", "PDT")
-utc_real = FixedOffset(0, "UTC", 0)
-# For better test coverage, we want another flavor of UTC that's west of
-# the Eastern and Pacific timezones.
-utc_fake = FixedOffset(-12*60, "UTCfake", 0)
-
-class TestTimezoneConversions(unittest.TestCase):
-    # The DST switch times for 2002, in std time.
-    dston = datetime(2002, 4, 7, 2)
-    dstoff = datetime(2002, 10, 27, 1)
-
-    theclass = datetime
-
-    # Check a time that's inside DST.
-    def checkinside(self, dt, tz, utc, dston, dstoff):
-        self.assertEqual(dt.dst(), HOUR)
-
-        # Conversion to our own timezone is always an identity.
-        self.assertEqual(dt.astimezone(tz), dt)
-
-        asutc = dt.astimezone(utc)
-        there_and_back = asutc.astimezone(tz)
-
-        # Conversion to UTC and back isn't always an identity here,
-        # because there are redundant spellings (in local time) of
-        # UTC time when DST begins:  the clock jumps from 1:59:59
-        # to 3:00:00, and a local time of 2:MM:SS doesn't really
-        # make sense then.  The classes above treat 2:MM:SS as
-        # daylight time then (it's "after 2am"), really an alias
-        # for 1:MM:SS standard time.  The latter form is what
-        # conversion back from UTC produces.
-        if dt.date() == dston.date() and dt.hour == 2:
-            # We're in the redundant hour, and coming back from
-            # UTC gives the 1:MM:SS standard-time spelling.
-            self.assertEqual(there_and_back + HOUR, dt)
-            # Although during was considered to be in daylight
-            # time, there_and_back is not.
-            self.assertEqual(there_and_back.dst(), ZERO)
-            # They're the same times in UTC.
-            self.assertEqual(there_and_back.astimezone(utc),
-                             dt.astimezone(utc))
-        else:
-            # We're not in the redundant hour.
-            self.assertEqual(dt, there_and_back)
-
-        # Because we have a redundant spelling when DST begins, there is
-        # (unforunately) an hour when DST ends that can't be spelled at all in
-        # local time.  When DST ends, the clock jumps from 1:59 back to 1:00
-        # again.  The hour 1:MM DST has no spelling then:  1:MM is taken to be
-        # standard time.  1:MM DST == 0:MM EST, but 0:MM is taken to be
-        # daylight time.  The hour 1:MM daylight == 0:MM standard can't be
-        # expressed in local time.  Nevertheless, we want conversion back
-        # from UTC to mimic the local clock's "repeat an hour" behavior.
-        nexthour_utc = asutc + HOUR
-        nexthour_tz = nexthour_utc.astimezone(tz)
-        if dt.date() == dstoff.date() and dt.hour == 0:
-            # We're in the hour before the last DST hour.  The last DST hour
-            # is ineffable.  We want the conversion back to repeat 1:MM.
-            self.assertEqual(nexthour_tz, dt.replace(hour=1))
-            nexthour_utc += HOUR
-            nexthour_tz = nexthour_utc.astimezone(tz)
-            self.assertEqual(nexthour_tz, dt.replace(hour=1))
-        else:
-            self.assertEqual(nexthour_tz - dt, HOUR)
-
-    # Check a time that's outside DST.
-    def checkoutside(self, dt, tz, utc):
-        self.assertEqual(dt.dst(), ZERO)
-
-        # Conversion to our own timezone is always an identity.
-        self.assertEqual(dt.astimezone(tz), dt)
-
-        # Converting to UTC and back is an identity too.
-        asutc = dt.astimezone(utc)
-        there_and_back = asutc.astimezone(tz)
-        self.assertEqual(dt, there_and_back)
-
-    def convert_between_tz_and_utc(self, tz, utc):
-        dston = self.dston.replace(tzinfo=tz)
-        # Because 1:MM on the day DST ends is taken as being standard time,
-        # there is no spelling in tz for the last hour of daylight time.
-        # For purposes of the test, the last hour of DST is 0:MM, which is
-        # taken as being daylight time (and 1:MM is taken as being standard
-        # time).
-        dstoff = self.dstoff.replace(tzinfo=tz)
-        for delta in (timedelta(weeks=13),
-                      DAY,
-                      HOUR,
-                      timedelta(minutes=1),
-                      timedelta(microseconds=1)):
-
-            self.checkinside(dston, tz, utc, dston, dstoff)
-            for during in dston + delta, dstoff - delta:
-                self.checkinside(during, tz, utc, dston, dstoff)
-
-            self.checkoutside(dstoff, tz, utc)
-            for outside in dston - delta, dstoff + delta:
-                self.checkoutside(outside, tz, utc)
-
-    def test_easy(self):
-        # Despite the name of this test, the endcases are excruciating.
-        self.convert_between_tz_and_utc(Eastern, utc_real)
-        self.convert_between_tz_and_utc(Pacific, utc_real)
-        self.convert_between_tz_and_utc(Eastern, utc_fake)
-        self.convert_between_tz_and_utc(Pacific, utc_fake)
-        # The next is really dancing near the edge.  It works because
-        # Pacific and Eastern are far enough apart that their "problem
-        # hours" don't overlap.
-        self.convert_between_tz_and_utc(Eastern, Pacific)
-        self.convert_between_tz_and_utc(Pacific, Eastern)
-        # OTOH, these fail!  Don't enable them.  The difficulty is that
-        # the edge case tests assume that every hour is representable in
-        # the "utc" class.  This is always true for a fixed-offset tzinfo
-        # class (lke utc_real and utc_fake), but not for Eastern or Central.
-        # For these adjacent DST-aware time zones, the range of time offsets
-        # tested ends up creating hours in the one that aren't representable
-        # in the other.  For the same reason, we would see failures in the
-        # Eastern vs Pacific tests too if we added 3*HOUR to the list of
-        # offset deltas in convert_between_tz_and_utc().
-        #
-        # self.convert_between_tz_and_utc(Eastern, Central)  # can't work
-        # self.convert_between_tz_and_utc(Central, Eastern)  # can't work
-
-    def test_tricky(self):
-        # 22:00 on day before daylight starts.
-        fourback = self.dston - timedelta(hours=4)
-        ninewest = FixedOffset(-9*60, "-0900", 0)
-        fourback = fourback.replace(tzinfo=ninewest)
-        # 22:00-0900 is 7:00 UTC == 2:00 EST == 3:00 DST.  Since it's "after
-        # 2", we should get the 3 spelling.
-        # If we plug 22:00 the day before into Eastern, it "looks like std
-        # time", so its offset is returned as -5, and -5 - -9 = 4.  Adding 4
-        # to 22:00 lands on 2:00, which makes no sense in local time (the
-        # local clock jumps from 1 to 3).  The point here is to make sure we
-        # get the 3 spelling.
-        expected = self.dston.replace(hour=3)
-        got = fourback.astimezone(Eastern).replace(tzinfo=None)
-        self.assertEqual(expected, got)
-
-        # Similar, but map to 6:00 UTC == 1:00 EST == 2:00 DST.  In that
-        # case we want the 1:00 spelling.
-        sixutc = self.dston.replace(hour=6, tzinfo=utc_real)
-        # Now 6:00 "looks like daylight", so the offset wrt Eastern is -4,
-        # and adding -4-0 == -4 gives the 2:00 spelling.  We want the 1:00 EST
-        # spelling.
-        expected = self.dston.replace(hour=1)
-        got = sixutc.astimezone(Eastern).replace(tzinfo=None)
-        self.assertEqual(expected, got)
-
-        # Now on the day DST ends, we want "repeat an hour" behavior.
-        #  UTC  4:MM  5:MM  6:MM  7:MM  checking these
-        #  EST 23:MM  0:MM  1:MM  2:MM
-        #  EDT  0:MM  1:MM  2:MM  3:MM
-        # wall  0:MM  1:MM  1:MM  2:MM  against these
-        for utc in utc_real, utc_fake:
-            for tz in Eastern, Pacific:
-                first_std_hour = self.dstoff - timedelta(hours=2) # 23:MM
-                # Convert that to UTC.
-                first_std_hour -= tz.utcoffset(None)
-                # Adjust for possibly fake UTC.
-                asutc = first_std_hour + utc.utcoffset(None)
-                # First UTC hour to convert; this is 4:00 when utc=utc_real &
-                # tz=Eastern.
-                asutcbase = asutc.replace(tzinfo=utc)
-                for tzhour in (0, 1, 1, 2):
-                    expectedbase = self.dstoff.replace(hour=tzhour)
-                    for minute in 0, 30, 59:
-                        expected = expectedbase.replace(minute=minute)
-                        asutc = asutcbase.replace(minute=minute)
-                        astz = asutc.astimezone(tz)
-                        self.assertEqual(astz.replace(tzinfo=None), expected)
-                    asutcbase += HOUR
-
-
-    def test_bogus_dst(self):
-        class ok(tzinfo):
-            def utcoffset(self, dt): return HOUR
-            def dst(self, dt): return HOUR
-
-        now = self.theclass.now().replace(tzinfo=utc_real)
-        # Doesn't blow up.
-        now.astimezone(ok())
-
-        # Does blow up.
-        class notok(ok):
-            def dst(self, dt): return None
-        self.assertRaises(ValueError, now.astimezone, notok())
-
-        # Sometimes blow up. In the following, tzinfo.dst()
-        # implementation may return None or not None depending on
-        # whether DST is assumed to be in effect.  In this situation,
-        # a ValueError should be raised by astimezone().
-        class tricky_notok(ok):
-            def dst(self, dt):
-                if dt.year == 2000:
-                    return None
-                else:
-                    return 10*HOUR
-        dt = self.theclass(2001, 1, 1).replace(tzinfo=utc_real)
-        self.assertRaises(ValueError, dt.astimezone, tricky_notok())
-
-    def test_fromutc(self):
-        self.assertRaises(TypeError, Eastern.fromutc)   # not enough args
-        now = datetime.utcnow().replace(tzinfo=utc_real)
-        self.assertRaises(ValueError, Eastern.fromutc, now) # wrong tzinfo
-        now = now.replace(tzinfo=Eastern)   # insert correct tzinfo
-        enow = Eastern.fromutc(now)         # doesn't blow up
-        self.assertEqual(enow.tzinfo, Eastern) # has right tzinfo member
-        self.assertRaises(TypeError, Eastern.fromutc, now, now) # too many args
-        self.assertRaises(TypeError, Eastern.fromutc, date.today()) # wrong type
-
-        # Always converts UTC to standard time.
-        class FauxUSTimeZone(USTimeZone):
-            def fromutc(self, dt):
-                return dt + self.stdoffset
-        FEastern  = FauxUSTimeZone(-5, "FEastern",  "FEST", "FEDT")
-
-        #  UTC  4:MM  5:MM  6:MM  7:MM  8:MM  9:MM
-        #  EST 23:MM  0:MM  1:MM  2:MM  3:MM  4:MM
-        #  EDT  0:MM  1:MM  2:MM  3:MM  4:MM  5:MM
-
-        # Check around DST start.
-        start = self.dston.replace(hour=4, tzinfo=Eastern)
-        fstart = start.replace(tzinfo=FEastern)
-        for wall in 23, 0, 1, 3, 4, 5:
-            expected = start.replace(hour=wall)
-            if wall == 23:
-                expected -= timedelta(days=1)
-            got = Eastern.fromutc(start)
-            self.assertEqual(expected, got)
-
-            expected = fstart + FEastern.stdoffset
-            got = FEastern.fromutc(fstart)
-            self.assertEqual(expected, got)
-
-            # Ensure astimezone() calls fromutc() too.
-            got = fstart.replace(tzinfo=utc_real).astimezone(FEastern)
-            self.assertEqual(expected, got)
-
-            start += HOUR
-            fstart += HOUR
-
-        # Check around DST end.
-        start = self.dstoff.replace(hour=4, tzinfo=Eastern)
-        fstart = start.replace(tzinfo=FEastern)
-        for wall in 0, 1, 1, 2, 3, 4:
-            expected = start.replace(hour=wall)
-            got = Eastern.fromutc(start)
-            self.assertEqual(expected, got)
-
-            expected = fstart + FEastern.stdoffset
-            got = FEastern.fromutc(fstart)
-            self.assertEqual(expected, got)
-
-            # Ensure astimezone() calls fromutc() too.
-            got = fstart.replace(tzinfo=utc_real).astimezone(FEastern)
-            self.assertEqual(expected, got)
-
-            start += HOUR
-            fstart += HOUR
-
-
-#############################################################################
-# oddballs
-
-class Oddballs(unittest.TestCase):
-
-    def test_bug_1028306(self):
-        # Trying to compare a date to a datetime should act like a mixed-
-        # type comparison, despite that datetime is a subclass of date.
-        as_date = date.today()
-        as_datetime = datetime.combine(as_date, time())
-        self.assertTrue(as_date != as_datetime)
-        self.assertTrue(as_datetime != as_date)
-        self.assertTrue(not as_date == as_datetime)
-        self.assertTrue(not as_datetime == as_date)
-        self.assertRaises(TypeError, lambda: as_date < as_datetime)
-        self.assertRaises(TypeError, lambda: as_datetime < as_date)
-        self.assertRaises(TypeError, lambda: as_date <= as_datetime)
-        self.assertRaises(TypeError, lambda: as_datetime <= as_date)
-        self.assertRaises(TypeError, lambda: as_date > as_datetime)
-        self.assertRaises(TypeError, lambda: as_datetime > as_date)
-        self.assertRaises(TypeError, lambda: as_date >= as_datetime)
-        self.assertRaises(TypeError, lambda: as_datetime >= as_date)
-
-        # Neverthelss, comparison should work with the base-class (date)
-        # projection if use of a date method is forced.
-        self.assertEqual(as_date.__eq__(as_datetime), True)
-        different_day = (as_date.day + 1) % 20 + 1
-        as_different = as_datetime.replace(day= different_day)
-        self.assertEqual(as_date.__eq__(as_different), False)
-
-        # And date should compare with other subclasses of date.  If a
-        # subclass wants to stop this, it's up to the subclass to do so.
-        date_sc = SubclassDate(as_date.year, as_date.month, as_date.day)
-        self.assertEqual(as_date, date_sc)
-        self.assertEqual(date_sc, as_date)
-
-        # Ditto for datetimes.
-        datetime_sc = SubclassDatetime(as_datetime.year, as_datetime.month,
-                                       as_date.day, 0, 0, 0)
-        self.assertEqual(as_datetime, datetime_sc)
-        self.assertEqual(datetime_sc, as_datetime)
+import sys
+from test.support import import_fresh_module, run_unittest
+TESTS = 'test.datetimetester'
+# XXX: import_fresh_module() is supposed to leave sys.module cache untouched,
+# XXX: but it does not, so we have to save and restore it ourselves.
+save_sys_modules = sys.modules.copy()
+try:
+    pure_tests = import_fresh_module(TESTS, fresh=['datetime', '_strptime'],
+                                     blocked=['_datetime'])
+    fast_tests = import_fresh_module(TESTS, fresh=['datetime',
+                                                   '_datetime', '_strptime'])
+finally:
+    sys.modules.clear()
+    sys.modules.update(save_sys_modules)
+test_modules = [pure_tests, fast_tests]
+test_suffixes = ["_Pure", "_Fast"]
+
+for module, suffix in zip(test_modules, test_suffixes):
+    for name, cls in module.__dict__.items():
+        if isinstance(cls, type) and issubclass(cls, unittest.TestCase):
+            name += suffix
+            cls.__name__ = name
+            globals()[name] = cls
+            def setUp(self, module=module, setup=cls.setUp):
+                self._save_sys_modules = sys.modules.copy()
+                sys.modules[TESTS] = module
+                sys.modules['datetime'] = module.datetime_module
+                sys.modules['_strptime'] = module._strptime
+                setup(self)
+            def tearDown(self, teardown=cls.tearDown):
+                teardown(self)
+                sys.modules.clear()
+                sys.modules.update(self._save_sys_modules)
+            cls.setUp = setUp
+            cls.tearDown = tearDown
 
 def test_main():
-    support.run_unittest(__name__)
+    run_unittest(__name__)
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/import_unicode/Lib/test/test_fnmatch.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_fnmatch.py	(original)
+++ python/branches/import_unicode/Lib/test/test_fnmatch.py	Fri Jul 30 01:19:37 2010
@@ -3,10 +3,15 @@
 from test import support
 import unittest
 
-from fnmatch import fnmatch, fnmatchcase
+from fnmatch import (fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb, purge,
+                        translate, filter)
 
 
 class FnmatchTestCase(unittest.TestCase):
+
+    def tearDown(self):
+        purge()
+
     def check_match(self, filename, pattern, should_match=1, fn=fnmatch):
         if should_match:
             self.assertTrue(fn(filename, pattern),
@@ -60,9 +65,45 @@
         self.check_match(b'test\xff', b'te*\xff')
         self.check_match(b'foo\nbar', b'foo*')
 
+    def test_cache_clearing(self):
+        # check that caches do not grow too large
+        # http://bugs.python.org/issue7846
+
+        # string pattern cache
+        for i in range(_MAXCACHE + 1):
+            fnmatch('foo', '?' * i)
+
+        self.assertLessEqual(len(_cache), _MAXCACHE)
+
+        # bytes pattern cache
+        for i in range(_MAXCACHE + 1):
+            fnmatch(b'foo', b'?' * i)
+        self.assertLessEqual(len(_cacheb), _MAXCACHE)
+
+
+class TranslateTestCase(unittest.TestCase):
+
+    def test_translate(self):
+        self.assertEqual(translate('*'), '.*\Z(?ms)')
+        self.assertEqual(translate('?'), '.\Z(?ms)')
+        self.assertEqual(translate('a?b*'), 'a.b.*\Z(?ms)')
+        self.assertEqual(translate('[abc]'), '[abc]\Z(?ms)')
+        self.assertEqual(translate('[]]'), '[]]\Z(?ms)')
+        self.assertEqual(translate('[!x]'), '[^x]\Z(?ms)')
+        self.assertEqual(translate('[^x]'), '[\\^x]\Z(?ms)')
+        self.assertEqual(translate('[x'), '\\[x\Z(?ms)')
+
+
+class FilterTestCase(unittest.TestCase):
+
+    def test_filter(self):
+        self.assertEqual(filter(['a', 'b'], 'a'), ['a'])
+
 
 def test_main():
-    support.run_unittest(FnmatchTestCase)
+    support.run_unittest(FnmatchTestCase,
+                         TranslateTestCase,
+                         FilterTestCase)
 
 
 if __name__ == "__main__":

Modified: python/branches/import_unicode/Lib/test/test_getopt.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_getopt.py	(original)
+++ python/branches/import_unicode/Lib/test/test_getopt.py	Fri Jul 30 01:19:37 2010
@@ -173,6 +173,12 @@
         m = types.ModuleType("libreftest", s)
         run_doctest(m, verbose)
 
+    def test_issue4629(self):
+        longopts, shortopts = getopt.getopt(['--help='], '', ['help='])
+        self.assertEquals(longopts, [('--help', '')])
+        longopts, shortopts = getopt.getopt(['--help=x'], '', ['help='])
+        self.assertEquals(longopts, [('--help', 'x')])
+        self.assertRaises(getopt.GetoptError, getopt.getopt, ['--help='], '', ['help'])
 
 def test_main():
     run_unittest(GetoptTests)

Modified: python/branches/import_unicode/Lib/test/test_http_cookiejar.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_http_cookiejar.py	(original)
+++ python/branches/import_unicode/Lib/test/test_http_cookiejar.py	Fri Jul 30 01:19:37 2010
@@ -1,18 +1,21 @@
 """Tests for http/cookiejar.py."""
 
-import re, os, time, urllib.request
-from unittest import TestCase
+import os
+import re
+import test.support
+import time
+import unittest
+import urllib.request
+
+from http.cookiejar import (time2isoz, http2time, time2netscape,
+     parse_ns_headers, join_header_words, split_header_words, Cookie,
+     CookieJar, DefaultCookiePolicy, LWPCookieJar, MozillaCookieJar,
+     LoadError, lwp_cookie_str, DEFAULT_HTTP_PORT, escape_path,
+     reach, is_HDN, domain_match, user_domain_match, request_path,
+     request_port, request_host)
 
-from test import support
 
-from http.cookiejar import time2isoz, http2time, time2netscape, \
-     parse_ns_headers, join_header_words, split_header_words, Cookie, \
-     CookieJar, DefaultCookiePolicy, LWPCookieJar, MozillaCookieJar, \
-     LoadError, lwp_cookie_str, DEFAULT_HTTP_PORT, escape_path, \
-     reach, is_HDN, domain_match, user_domain_match, request_path, \
-     request_port, request_host
-
-class DateTimeTests(TestCase):
+class DateTimeTests(unittest.TestCase):
 
     def test_time2isoz(self):
         base = 1019227000
@@ -96,7 +99,7 @@
                          )
 
 
-class HeaderTests(TestCase):
+class HeaderTests(unittest.TestCase):
 
     def test_parse_ns_headers(self):
         # quotes should be stripped
@@ -228,10 +231,10 @@
     return cookie_hdr
 
 
-class FileCookieJarTests(TestCase):
+class FileCookieJarTests(unittest.TestCase):
     def test_lwp_valueless_cookie(self):
         # cookies with no value should be saved and loaded consistently
-        filename = support.TESTFN
+        filename = test.support.TESTFN
         c = LWPCookieJar()
         interact_netscape(c, "http://www.acme.com/", 'boo')
         self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
@@ -246,7 +249,7 @@
 
     def test_bad_magic(self):
         # IOErrors (eg. file doesn't exist) are allowed to propagate
-        filename = support.TESTFN
+        filename = test.support.TESTFN
         for cookiejar_class in LWPCookieJar, MozillaCookieJar:
             c = cookiejar_class()
             try:
@@ -269,7 +272,7 @@
             try: os.unlink(filename)
             except OSError: pass
 
-class CookieTests(TestCase):
+class CookieTests(unittest.TestCase):
     # XXX
     # Get rid of string comparisons where not actually testing str / repr.
     # .clear() etc.
@@ -349,7 +352,7 @@
     def test_missing_value(self):
         # missing = sign in Cookie: header is regarded by Mozilla as a missing
         # name, and by http.cookiejar as a missing value
-        filename = support.TESTFN
+        filename = test.support.TESTFN
         c = MozillaCookieJar(filename)
         interact_netscape(c, "http://www.acme.com/", 'eggs')
         interact_netscape(c, "http://www.acme.com/", '"spam"; path=/foo/')
@@ -534,6 +537,16 @@
         interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"')
         self.assertIn("/blah/rhubarb", c._cookies["www.acme.com"])
 
+    def test_default_path_with_query(self):
+        cj = CookieJar()
+        uri = "http://example.com/?spam/eggs"
+        value = 'eggs="bar"'
+        interact_netscape(cj, uri, value)
+        # Default path does not include query, so is "/", not "/?spam".
+        self.assertIn("/", cj._cookies["example.com"])
+        # Cookie is sent back to the same URI.
+        self.assertEquals(interact_netscape(cj, uri), value)
+
     def test_escape_path(self):
         cases = [
             # quoted safe
@@ -562,16 +575,15 @@
     def test_request_path(self):
         # with parameters
         req = urllib.request.Request(
-            "http://www.example.com/rheum/rhaponicum;"
+            "http://www.example.com/rheum/rhaponticum;"
             "foo=bar;sing=song?apples=pears&spam=eggs#ni")
-        self.assertEquals(request_path(req), "/rheum/rhaponicum;"
-                     "foo=bar;sing=song?apples=pears&spam=eggs#ni")
+        self.assertEquals(request_path(req),
+                          "/rheum/rhaponticum;foo=bar;sing=song")
         # without parameters
         req = urllib.request.Request(
-            "http://www.example.com/rheum/rhaponicum?"
+            "http://www.example.com/rheum/rhaponticum?"
             "apples=pears&spam=eggs#ni")
-        self.assertEquals(request_path(req), "/rheum/rhaponicum?"
-                     "apples=pears&spam=eggs#ni")
+        self.assertEquals(request_path(req), "/rheum/rhaponticum")
         # missing final slash
         req = urllib.request.Request("http://www.example.com")
         self.assertEquals(request_path(req), "/")
@@ -1045,7 +1057,7 @@
         self.assertTrue(cookie.expires is None)
 
 
-class LWPCookieTests(TestCase):
+class LWPCookieTests(unittest.TestCase):
     # Tests taken from libwww-perl, with a few modifications and additions.
 
     def test_netscape_example_1(self):
@@ -1435,7 +1447,7 @@
         self.assertEquals(len(c), 6)
 
         # save and restore
-        filename = support.TESTFN
+        filename = test.support.TESTFN
 
         try:
             c.save(filename, ignore_discard=True)
@@ -1475,7 +1487,7 @@
         # Save / load Mozilla/Netscape cookie file format.
         year_plus_one = time.localtime()[0] + 1
 
-        filename = support.TESTFN
+        filename = test.support.TESTFN
 
         c = MozillaCookieJar(filename,
                              policy=DefaultCookiePolicy(rfc2965=True))
@@ -1637,7 +1649,7 @@
 
 
 def test_main(verbose=None):
-    support.run_unittest(
+    test.support.run_unittest(
         DateTimeTests,
         HeaderTests,
         CookieTests,

Modified: python/branches/import_unicode/Lib/test/test_import.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_import.py	(original)
+++ python/branches/import_unicode/Lib/test/test_import.py	Fri Jul 30 01:19:37 2010
@@ -1,6 +1,8 @@
 import builtins
 import errno
 import imp
+from importlib.test.import_ import test_relative_imports
+from importlib.test.import_ import util as importlib_util
 import marshal
 import os
 import py_compile
@@ -640,10 +642,21 @@
                          os.path.join(os.curdir, foo_pyc))
 
 
+class RelativeImportFromImportlibTests(test_relative_imports.RelativeImports):
+
+    def setUp(self):
+        self._importlib_util_flag = importlib_util.using___import__
+        importlib_util.using___import__ = True
+
+    def tearDown(self):
+        importlib_util.using___import__ = self._importlib_util_flag
+
+
 def test_main(verbose=None):
     run_unittest(ImportTests, PycacheTests,
                  PycRewritingTests, PathsTests, RelativeImportTests,
-                 OverridingImportBuiltinTests)
+                 OverridingImportBuiltinTests,
+                 RelativeImportFromImportlibTests)
 
 
 if __name__ == '__main__':

Modified: python/branches/import_unicode/Lib/test/test_math.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_math.py	(original)
+++ python/branches/import_unicode/Lib/test/test_math.py	Fri Jul 30 01:19:37 2010
@@ -915,6 +915,15 @@
         self.assertRaises(TypeError, math.trunc, 1, 2)
         self.assertRaises(TypeError, math.trunc, TestNoTrunc())
 
+    def testIsfinite(self):
+        self.assertTrue(math.isfinite(0.0))
+        self.assertTrue(math.isfinite(-0.0))
+        self.assertTrue(math.isfinite(1.0))
+        self.assertTrue(math.isfinite(-1.0))
+        self.assertFalse(math.isfinite(float("nan")))
+        self.assertFalse(math.isfinite(float("inf")))
+        self.assertFalse(math.isfinite(float("-inf")))
+
     def testIsnan(self):
         self.assertTrue(math.isnan(float("nan")))
         self.assertTrue(math.isnan(float("inf")* 0.))

Modified: python/branches/import_unicode/Lib/test/test_minidom.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_minidom.py	(original)
+++ python/branches/import_unicode/Lib/test/test_minidom.py	Fri Jul 30 01:19:37 2010
@@ -951,6 +951,14 @@
         doc.unlink()
 
 
+    def testBug0777884(self):
+        doc = parseString("<o>text</o>")
+        text = doc.documentElement.childNodes[0]
+        self.assertEquals(text.nodeType, Node.TEXT_NODE)
+        # Should run quietly, doing nothing.
+        text.normalize()
+        doc.unlink()
+
     def testBug1433694(self):
         doc = parseString("<o><i/>t</o>")
         node = doc.documentElement

Modified: python/branches/import_unicode/Lib/test/test_os.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_os.py	(original)
+++ python/branches/import_unicode/Lib/test/test_os.py	Fri Jul 30 01:19:37 2010
@@ -423,7 +423,9 @@
         """Check that the repr() of os.environ looks like environ({...})."""
         env = os.environ
         self.assertTrue(isinstance(env.data, dict))
-        self.assertEqual(repr(env), 'environ({!r})'.format(env.data))
+        self.assertEqual(repr(env), 'environ({{{}}})'.format(', '.join(
+            '{!r}: {!r}'.format(key, value)
+            for key, value in env.items())))
 
     def test_get_exec_path(self):
         defpath_list = os.defpath.split(os.pathsep)
@@ -1034,7 +1036,8 @@
 
 
 def skipUnlessWindows6(test):
-    if hasattr(sys, 'getwindowsversion') and sys.getwindowsversion().major >= 6:
+    if (hasattr(sys, 'getwindowsversion')
+        and sys.getwindowsversion().major >= 6):
         return test
     return unittest.skip("Requires Windows Vista or later")(test)
 

Modified: python/branches/import_unicode/Lib/test/test_osx_env.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_osx_env.py	(original)
+++ python/branches/import_unicode/Lib/test/test_osx_env.py	Fri Jul 30 01:19:37 2010
@@ -8,7 +8,7 @@
 import unittest
 
 class OSXEnvironmentVariableTestCase(unittest.TestCase):
-    def _check_sys(self, ev, cond, sv, val = '/some/path/to/python'):
+    def _check_sys(self, ev, cond, sv, val = sys.executable + 'dummy'):
         with EnvironmentVarGuard() as evg:
             subpc = [str(sys.executable), '-c',
                 'import sys; sys.exit(2 if "%s" %s %s else 3)' % (val, cond, sv)]

Modified: python/branches/import_unicode/Lib/test/test_platform.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_platform.py	(original)
+++ python/branches/import_unicode/Lib/test/test_platform.py	Fri Jul 30 01:19:37 2010
@@ -15,8 +15,8 @@
         # On Windows, the EXE needs to know where pythonXY.dll is at so we have
         # to add the directory to the path.
         if sys.platform == "win32":
-            os.environ["Path"] = "{};{}".format(os.path.dirname(sys.executable),
-                                                os.environ["Path"])
+            os.environ["Path"] = "{};{}".format(
+                os.path.dirname(sys.executable), os.environ["Path"])
 
         def get(python):
             cmd = [python, '-c',
@@ -194,6 +194,25 @@
             else:
                 self.assertEquals(res[2], 'PowerPC')
 
+
+    @unittest.skipUnless(sys.platform == 'darwin', "OSX only test")
+    def test_mac_ver_with_fork(self):
+        # Issue7895: platform.mac_ver() crashes when using fork without exec
+        #
+        # This test checks that the fix for that issue works.
+        #
+        pid = os.fork()
+        if pid == 0:
+            # child
+            info = platform.mac_ver()
+            os._exit(0)
+
+        else:
+            # parent
+            cpid, sts = os.waitpid(pid, 0)
+            self.assertEquals(cpid, pid)
+            self.assertEquals(sts, 0)
+
     def test_dist(self):
         res = platform.dist()
 

Modified: python/branches/import_unicode/Lib/test/test_posix.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_posix.py	(original)
+++ python/branches/import_unicode/Lib/test/test_posix.py	Fri Jul 30 01:19:37 2010
@@ -6,6 +6,7 @@
 posix = support.import_module('posix')
 
 import errno
+import sys
 import time
 import os
 import pwd
@@ -252,9 +253,14 @@
             posix.chdir(os.curdir)
             self.assertRaises(OSError, posix.chdir, support.TESTFN)
 
-    def test_lsdir(self):
-        if hasattr(posix, 'lsdir'):
-            self.assertIn(support.TESTFN, posix.lsdir(os.curdir))
+    def test_listdir(self):
+        if hasattr(posix, 'listdir'):
+            self.assertTrue(support.TESTFN in posix.listdir(os.curdir))
+
+    def test_listdir_default(self):
+        # When listdir is called without argument, it's the same as listdir(os.curdir)
+        if hasattr(posix, 'listdir'):
+            self.assertTrue(support.TESTFN in posix.listdir())
 
     def test_access(self):
         if hasattr(posix, 'access'):
@@ -344,9 +350,63 @@
                 os.chdir(curdir)
                 support.rmtree(base_path)
 
+    def test_getgroups(self):
+        with os.popen('id -G') as idg:
+            groups = idg.read().strip()
+
+        if not groups:
+            raise unittest.SkipTest("need working 'id -G'")
+
+        # The order of groups isn't important, hence the calls
+        # to sorted.
+        self.assertEqual(
+                list(sorted([int(x) for x in groups.split()])),
+                list(sorted(posix.getgroups())))
+
+class PosixGroupsTester(unittest.TestCase):
+
+    def setUp(self):
+        if posix.getuid() != 0:
+            raise unittest.SkipTest("not enough privileges")
+        if not hasattr(posix, 'getgroups'):
+            raise unittest.SkipTest("need posix.getgroups")
+        if sys.platform == 'darwin':
+            raise unittest.SkipTest("getgroups(2) is broken on OSX")
+        self.saved_groups = posix.getgroups()
+
+    def tearDown(self):
+        if hasattr(posix, 'setgroups'):
+            posix.setgroups(self.saved_groups)
+        elif hasattr(posix, 'initgroups'):
+            name = pwd.getpwuid(posix.getuid()).pw_name
+            posix.initgroups(name, self.saved_groups[0])
+
+    @unittest.skipUnless(hasattr(posix, 'initgroups'),
+                         "test needs posix.initgroups()")
+    def test_initgroups(self):
+        # find missing group
+
+        groups = sorted(self.saved_groups)
+        for g1,g2 in zip(groups[:-1], groups[1:]):
+            g = g1 + 1
+            if g < g2:
+                break
+        else:
+            g = g2 + 1
+        name = pwd.getpwuid(posix.getuid()).pw_name
+        posix.initgroups(name, g)
+        self.assertIn(g, posix.getgroups())
+
+    @unittest.skipUnless(hasattr(posix, 'setgroups'),
+                         "test needs posix.setgroups()")
+    def test_setgroups(self):
+        for groups in [[0], range(16)]:
+            posix.setgroups(groups)
+            self.assertListEqual(groups, posix.getgroups())
+
 
 def test_main():
-    support.run_unittest(PosixTester)
+    support.run_unittest(PosixTester, PosixGroupsTester)
 
 if __name__ == '__main__':
     test_main()

Modified: python/branches/import_unicode/Lib/test/test_posixpath.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_posixpath.py	(original)
+++ python/branches/import_unicode/Lib/test/test_posixpath.py	Fri Jul 30 01:19:37 2010
@@ -208,6 +208,7 @@
     def test_samestat_on_links(self):
         test_fn1 = support.TESTFN + "1"
         test_fn2 = support.TESTFN + "2"
+        self._create_file(test_fn1)
         test_fns = (test_fn1, test_fn2)
         os.symlink(*test_fns)
         stats = map(os.stat, test_fns)

Modified: python/branches/import_unicode/Lib/test/test_pow.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_pow.py	(original)
+++ python/branches/import_unicode/Lib/test/test_pow.py	Fri Jul 30 01:19:37 2010
@@ -18,14 +18,14 @@
                 self.assertEquals(pow(2, i), pow2)
                 if i != 30 : pow2 = pow2*2
 
-            for othertype in int, int:
+            for othertype in (int,):
                 for i in list(range(-10, 0)) + list(range(1, 10)):
                     ii = type(i)
                     for j in range(1, 11):
                         jj = -othertype(j)
                         pow(ii, jj)
 
-        for othertype in int, int, float:
+        for othertype in int, float:
             for i in range(1, 100):
                 zero = type(0)
                 exp = -othertype(i/10.0)

Deleted: python/branches/import_unicode/Lib/test/test_profilehooks.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_profilehooks.py	Fri Jul 30 01:19:37 2010
+++ (empty file)
@@ -1,385 +0,0 @@
-import pprint
-import sys
-import unittest
-
-from test import support
-
-class TestGetProfile(unittest.TestCase):
-    def setUp(self):
-        sys.setprofile(None)
-
-    def tearDown(self):
-        sys.setprofile(None)
-
-    def test_empty(self):
-        assert sys.getprofile() is None
-
-    def test_setget(self):
-        def fn(*args):
-            pass
-
-        sys.setprofile(fn)
-        assert sys.getprofile() == fn
-
-class HookWatcher:
-    def __init__(self):
-        self.frames = []
-        self.events = []
-
-    def callback(self, frame, event, arg):
-        if (event == "call"
-            or event == "return"
-            or event == "exception"):
-            self.add_event(event, frame)
-
-    def add_event(self, event, frame=None):
-        """Add an event to the log."""
-        if frame is None:
-            frame = sys._getframe(1)
-
-        try:
-            frameno = self.frames.index(frame)
-        except ValueError:
-            frameno = len(self.frames)
-            self.frames.append(frame)
-
-        self.events.append((frameno, event, ident(frame)))
-
-    def get_events(self):
-        """Remove calls to add_event()."""
-        disallowed = [ident(self.add_event.__func__), ident(ident)]
-        self.frames = None
-
-        return [item for item in self.events if item[2] not in disallowed]
-
-
-class ProfileSimulator(HookWatcher):
-    def __init__(self, testcase):
-        self.testcase = testcase
-        self.stack = []
-        HookWatcher.__init__(self)
-
-    def callback(self, frame, event, arg):
-        # Callback registered with sys.setprofile()/sys.settrace()
-        self.dispatch[event](self, frame)
-
-    def trace_call(self, frame):
-        self.add_event('call', frame)
-        self.stack.append(frame)
-
-    def trace_return(self, frame):
-        self.add_event('return', frame)
-        self.stack.pop()
-
-    def trace_exception(self, frame):
-        self.testcase.fail(
-            "the profiler should never receive exception events")
-
-    def trace_pass(self, frame):
-        pass
-
-    dispatch = {
-        'call': trace_call,
-        'exception': trace_exception,
-        'return': trace_return,
-        'c_call': trace_pass,
-        'c_return': trace_pass,
-        'c_exception': trace_pass,
-        }
-
-
-class TestCaseBase(unittest.TestCase):
-    def check_events(self, callable, expected):
-        events = capture_events(callable, self.new_watcher())
-        if events != expected:
-            self.fail("Expected events:\n%s\nReceived events:\n%s"
-                      % (pprint.pformat(expected), pprint.pformat(events)))
-
-
-class ProfileHookTestCase(TestCaseBase):
-    def new_watcher(self):
-        return HookWatcher()
-
-    def test_simple(self):
-        def f(p):
-            pass
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_exception(self):
-        def f(p):
-            1/0
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_caught_exception(self):
-        def f(p):
-            try: 1/0
-            except: pass
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_caught_nested_exception(self):
-        def f(p):
-            try: 1/0
-            except: pass
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_nested_exception(self):
-        def f(p):
-            1/0
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              # This isn't what I expected:
-                              # (0, 'exception', protect_ident),
-                              # I expected this again:
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_exception_in_except_clause(self):
-        def f(p):
-            1/0
-        def g(p):
-            try:
-                f(p)
-            except:
-                try: f(p)
-                except: pass
-        f_ident = ident(f)
-        g_ident = ident(g)
-        self.check_events(g, [(1, 'call', g_ident),
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              (3, 'call', f_ident),
-                              (3, 'return', f_ident),
-                              (1, 'return', g_ident),
-                              ])
-
-    def test_exception_propogation(self):
-        def f(p):
-            1/0
-        def g(p):
-            try: f(p)
-            finally: p.add_event("falling through")
-        f_ident = ident(f)
-        g_ident = ident(g)
-        self.check_events(g, [(1, 'call', g_ident),
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              (1, 'falling through', g_ident),
-                              (1, 'return', g_ident),
-                              ])
-
-    def test_raise_twice(self):
-        def f(p):
-            try: 1/0
-            except: 1/0
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_raise_reraise(self):
-        def f(p):
-            try: 1/0
-            except: raise
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_raise(self):
-        def f(p):
-            raise Exception()
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_distant_exception(self):
-        def f():
-            1/0
-        def g():
-            f()
-        def h():
-            g()
-        def i():
-            h()
-        def j(p):
-            i()
-        f_ident = ident(f)
-        g_ident = ident(g)
-        h_ident = ident(h)
-        i_ident = ident(i)
-        j_ident = ident(j)
-        self.check_events(j, [(1, 'call', j_ident),
-                              (2, 'call', i_ident),
-                              (3, 'call', h_ident),
-                              (4, 'call', g_ident),
-                              (5, 'call', f_ident),
-                              (5, 'return', f_ident),
-                              (4, 'return', g_ident),
-                              (3, 'return', h_ident),
-                              (2, 'return', i_ident),
-                              (1, 'return', j_ident),
-                              ])
-
-    def test_generator(self):
-        def f():
-            for i in range(2):
-                yield i
-        def g(p):
-            for i in f():
-                pass
-        f_ident = ident(f)
-        g_ident = ident(g)
-        self.check_events(g, [(1, 'call', g_ident),
-                              # call the iterator twice to generate values
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              # once more; returns end-of-iteration with
-                              # actually raising an exception
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              (1, 'return', g_ident),
-                              ])
-
-    def test_stop_iteration(self):
-        def f():
-            for i in range(2):
-                yield i
-            raise StopIteration
-        def g(p):
-            for i in f():
-                pass
-        f_ident = ident(f)
-        g_ident = ident(g)
-        self.check_events(g, [(1, 'call', g_ident),
-                              # call the iterator twice to generate values
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              # once more to hit the raise:
-                              (2, 'call', f_ident),
-                              (2, 'return', f_ident),
-                              (1, 'return', g_ident),
-                              ])
-
-
-class ProfileSimulatorTestCase(TestCaseBase):
-    def new_watcher(self):
-        return ProfileSimulator(self)
-
-    def test_simple(self):
-        def f(p):
-            pass
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_basic_exception(self):
-        def f(p):
-            1/0
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_caught_exception(self):
-        def f(p):
-            try: 1/0
-            except: pass
-        f_ident = ident(f)
-        self.check_events(f, [(1, 'call', f_ident),
-                              (1, 'return', f_ident),
-                              ])
-
-    def test_distant_exception(self):
-        def f():
-            1/0
-        def g():
-            f()
-        def h():
-            g()
-        def i():
-            h()
-        def j(p):
-            i()
-        f_ident = ident(f)
-        g_ident = ident(g)
-        h_ident = ident(h)
-        i_ident = ident(i)
-        j_ident = ident(j)
-        self.check_events(j, [(1, 'call', j_ident),
-                              (2, 'call', i_ident),
-                              (3, 'call', h_ident),
-                              (4, 'call', g_ident),
-                              (5, 'call', f_ident),
-                              (5, 'return', f_ident),
-                              (4, 'return', g_ident),
-                              (3, 'return', h_ident),
-                              (2, 'return', i_ident),
-                              (1, 'return', j_ident),
-                              ])
-
-
-def ident(function):
-    if hasattr(function, "f_code"):
-        code = function.f_code
-    else:
-        code = function.__code__
-    return code.co_firstlineno, code.co_name
-
-
-def protect(f, p):
-    try: f(p)
-    except: pass
-
-protect_ident = ident(protect)
-
-
-def capture_events(callable, p=None):
-    try:
-        sys.setprofile()
-    except TypeError:
-        pass
-    else:
-        raise support.TestFailed(
-            'sys.setprofile() did not raise TypeError')
-
-    if p is None:
-        p = HookWatcher()
-    sys.setprofile(p.callback)
-    protect(callable, p)
-    sys.setprofile(None)
-    return p.get_events()[1:-1]
-
-
-def show_events(callable):
-    import pprint
-    pprint.pprint(capture_events(callable))
-
-
-def test_main():
-    support.run_unittest(
-        TestGetProfile,
-        ProfileHookTestCase,
-        ProfileSimulatorTestCase
-    )
-
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/import_unicode/Lib/test/test_queue.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_queue.py	(original)
+++ python/branches/import_unicode/Lib/test/test_queue.py	Fri Jul 30 01:19:37 2010
@@ -90,6 +90,8 @@
     def simple_queue_test(self, q):
         if q.qsize():
             raise RuntimeError("Call this function with an empty queue")
+        self.assertTrue(q.empty())
+        self.assertFalse(q.full())
         # I guess we better check things actually queue correctly a little :)
         q.put(111)
         q.put(333)
@@ -108,6 +110,8 @@
         full = 3 * 2 * QUEUE_SIZE
         q.put(last)
         self.assertTrue(qfull(q), "Queue should be full")
+        self.assertFalse(q.empty())
+        self.assertTrue(q.full())
         try:
             q.put(full, block=0)
             self.fail("Didn't appear to block with a full queue")
@@ -193,6 +197,25 @@
         self.simple_queue_test(q)
         self.simple_queue_test(q)
 
+    def test_negative_timeout_raises_exception(self):
+        q = self.type2test(QUEUE_SIZE)
+        with self.assertRaises(ValueError):
+            q.put(1, timeout=-1)
+        with self.assertRaises(ValueError):
+            q.get(1, timeout=-1)
+
+    def test_nowait(self):
+        q = self.type2test(QUEUE_SIZE)
+        for i in range(QUEUE_SIZE):
+            q.put_nowait(1)
+        with self.assertRaises(queue.Full):
+            q.put_nowait(1)
+
+        for i in range(QUEUE_SIZE):
+            q.get_nowait()
+        with self.assertRaises(queue.Empty):
+            q.get_nowait()
+
 
 class QueueTest(BaseQueueTest):
     type2test = queue.Queue

Modified: python/branches/import_unicode/Lib/test/test_re.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_re.py	(original)
+++ python/branches/import_unicode/Lib/test/test_re.py	Fri Jul 30 01:19:37 2010
@@ -874,8 +874,71 @@
                 if result is None:
                     print('=== Fails on unicode-sensitive match', t)
 
+
+class ReCacheTests(unittest.TestCase):
+    """These tests are specific to the re._shrink_cache implementation."""
+
+    def setUp(self):
+        self._orig_maxcache = re._MAXCACHE
+
+    def tearDown(self):
+        re._MAXCACHE = self._orig_maxcache
+
+    def test_compile_cache_overflow(self):
+        # NOTE: If a profiler or debugger is tracing code and compiling
+        # regular expressions while tracing through this test... expect
+        # the test to fail.  This test is not concurrency safe.
+
+        # Explicitly fill the caches.
+        re._MAXCACHE = 20
+        max_cache = re._MAXCACHE
+        unique_chars = tuple(chr(char_num) for char_num in
+                             range(b'a'[0], b'a'[0]+max_cache))
+        re._cache.clear()
+        for char in unique_chars:
+            re._compile(char, 0)
+        self.assertEqual(max_cache, len(re._cache))
+        re._cache_repl.clear()
+        for char in unique_chars:
+            re._compile_repl(char*2, char)
+        self.assertEqual(max_cache, len(re._cache_repl))
+
+        # Overflow both caches and make sure they have extra room left
+        # afterwards as well as having more than a single entry.
+        re._compile('A', 0)
+        self.assertLess(len(re._cache), max_cache)
+        self.assertGreater(len(re._cache), 1)
+        re._compile_repl('A', 'A')
+        self.assertLess(len(re._cache_repl), max_cache)
+        self.assertGreater(len(re._cache_repl), 1)
+
+    def test_shrink_cache_at_limit(self):
+        cache = dict(zip(range(6), range(6)))
+        re._shrink_cache(cache, 6, divisor=3)
+        self.assertEqual(4, len(cache))
+
+    def test_shrink_cache_empty(self):
+        cache = {}
+        re._shrink_cache(cache, 6, divisor=3)
+        # Cache was empty, make sure we didn't raise an exception.
+        self.assertEqual(0, len(cache))
+
+    def test_shrink_cache_overflowing(self):
+        cache = dict(zip(range(6), range(6)))
+        re._shrink_cache(cache, 4, divisor=2)
+        # Cache was larger than the maximum, be sure we shrunk to smaller.
+        self.assertEqual(2, len(cache))
+
+    def test_shrink_cache_underflow(self):
+        cache = dict(zip(range(6), range(6)))
+        # No shrinking to do.
+        re._shrink_cache(cache, 9, divisor=3)
+        self.assertEqual(6, len(cache))
+
+
 def test_main():
     run_unittest(ReTests)
+    run_unittest(ReCacheTests)
     run_re_tests()
 
 if __name__ == "__main__":

Modified: python/branches/import_unicode/Lib/test/test_robotparser.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_robotparser.py	(original)
+++ python/branches/import_unicode/Lib/test/test_robotparser.py	Fri Jul 30 01:19:37 2010
@@ -205,6 +205,31 @@
 RobotTest(13, doc, good, bad, agent="googlebot")
 
 
+# 14. For issue #6325 (query string support)
+doc = """
+User-agent: *
+Disallow: /some/path?name=value
+"""
+
+good = ['/some/path']
+bad = ['/some/path?name=value']
+
+RobotTest(14, doc, good, bad)
+
+# 15. For issue #4108 (obey first * entry)
+doc = """
+User-agent: *
+Disallow: /some/path
+
+User-agent: *
+Disallow: /another/path
+"""
+
+good = ['/another/path']
+bad = ['/some/path']
+
+RobotTest(15, doc, good, bad)
+
 
 class NetworkTestCase(unittest.TestCase):
 

Modified: python/branches/import_unicode/Lib/test/test_struct.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_struct.py	(original)
+++ python/branches/import_unicode/Lib/test/test_struct.py	Fri Jul 30 01:19:37 2010
@@ -47,8 +47,8 @@
 
         self.assertRaises(struct.error, struct.pack, 'iii', 3)
         self.assertRaises(struct.error, struct.pack, 'i', 3, 3, 3)
-        self.assertRaises(struct.error, struct.pack, 'i', 'foo')
-        self.assertRaises(struct.error, struct.pack, 'P', 'foo')
+        self.assertRaises((TypeError, struct.error), struct.pack, 'i', 'foo')
+        self.assertRaises((TypeError, struct.error), struct.pack, 'P', 'foo')
         self.assertRaises(struct.error, struct.unpack, 'd', b'flap')
         s = struct.pack('ii', 1, 2)
         self.assertRaises(struct.error, struct.unpack, 'iii', s)
@@ -213,6 +213,7 @@
                     expected = '%x' % expected
                     if len(expected) & 1:
                         expected = "0" + expected
+                    expected = expected.encode('ascii')
                     expected = unhexlify(expected)
                     expected = (b"\x00" * (self.bytesize - len(expected)) +
                                 expected)
@@ -234,7 +235,8 @@
                                                                  b'\x01' + got)
                 else:
                     # x is out of range -- verify pack realizes that.
-                    self.assertRaises(struct.error, pack, format, x)
+                    self.assertRaises((OverflowError, ValueError, struct.error),
+                                      pack, format, x)
 
             def run(self):
                 from random import randrange
@@ -445,7 +447,8 @@
 
         # Test bogus offset (issue 3694)
         sb = small_buf
-        self.assertRaises(TypeError, struct.pack_into, b'', sb, None)
+        self.assertRaises((TypeError, struct.error), struct.pack_into, b'', sb,
+                          None)
 
     def test_pack_into_fn(self):
         test_string = b'Reykjavik rocks, eow!'
@@ -510,8 +513,13 @@
                 self.assertFalse(prefix, msg='encoded bool is not one byte: %r'
                                              %packed)
 
-            self.assertRaises(IOError, struct.pack, prefix + '?',
-                              ExplodingBool())
+            try:
+                struct.pack(prefix + '?', ExplodingBool())
+            except IOError:
+                pass
+            else:
+                self.fail("Expected IOError: struct.pack(%r, "
+                          "ExplodingBool())" % (prefix + '?'))
 
         for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
             self.assertTrue(struct.unpack('>?', c)[0])

Modified: python/branches/import_unicode/Lib/test/test_structseq.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_structseq.py	(original)
+++ python/branches/import_unicode/Lib/test/test_structseq.py	Fri Jul 30 01:19:37 2010
@@ -8,7 +8,7 @@
 
     def test_tuple(self):
         t = time.gmtime()
-        assert isinstance(t, tuple)
+        self.assertIsInstance(t, tuple)
         astuple = tuple(t)
         self.assertEqual(len(t), len(astuple))
         self.assertEqual(t, astuple)
@@ -38,7 +38,7 @@
         # os.stat() gives a complicated struct sequence.
         st = os.stat(__file__)
         rep = repr(st)
-        self.assertTrue(rep.startswith("posix.stat_result"))
+        self.assertTrue(rep.startswith(os.name + ".stat_result"))
         self.assertIn("st_mode=", rep)
         self.assertIn("st_ino=", rep)
         self.assertIn("st_dev=", rep)

Modified: python/branches/import_unicode/Lib/test/test_subprocess.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_subprocess.py	(original)
+++ python/branches/import_unicode/Lib/test/test_subprocess.py	Fri Jul 30 01:19:37 2010
@@ -559,6 +559,21 @@
         except (ImportError, ValueError, resource.error):
             pass
 
+        if sys.platform == 'darwin':
+            # Check if the 'Crash Reporter' on OSX was configured
+            # in 'Developer' mode and warn that it will get triggered
+            # when it is.
+            #
+            # This assumes that this context manager is used in tests
+            # that might trigger the next manager.
+            value = subprocess.Popen(['/usr/bin/defaults', 'read',
+                    'com.apple.CrashReporter', 'DialogType'],
+                    stdout=subprocess.PIPE).communicate()[0]
+            if value.strip() == b'developer':
+                print("this tests triggers the Crash Reporter, "
+                      "that is intentional", end='')
+                sys.stdout.flush()
+
     def __exit__(self, *args):
         """Return core file behavior to default."""
         if self.old_limit is None:
@@ -750,6 +765,25 @@
         os.remove(fname)
         self.assertEqual(rc, 47)
 
+    def test_specific_shell(self):
+        # Issue #9265: Incorrect name passed as arg[0].
+        shells = []
+        for prefix in ['/bin', '/usr/bin/', '/usr/local/bin']:
+            for name in ['bash', 'ksh']:
+                sh = os.path.join(prefix, name)
+                if os.path.isfile(sh):
+                    shells.append(sh)
+        if not shells: # Will probably work for any shell but csh.
+            self.skipTest("bash or ksh required for this test")
+        sh = '/bin/sh'
+        if os.path.isfile(sh) and not os.path.islink(sh):
+            # Test will fail if /bin/sh is a symlink to csh.
+            shells.append(sh)
+        for sh in shells:
+            p = subprocess.Popen("echo $0", executable=sh, shell=True,
+                                 stdout=subprocess.PIPE)
+            self.assertEqual(p.stdout.read().strip(), bytes(sh, 'ascii'))
+
     def _kill_process(self, method, *args):
         # Do not inherit file handles from the parent.
         # It should fix failures on some platforms.

Modified: python/branches/import_unicode/Lib/test/test_sys.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_sys.py	(original)
+++ python/branches/import_unicode/Lib/test/test_sys.py	Fri Jul 30 01:19:37 2010
@@ -86,7 +86,6 @@
     # Python/pythonrun.c::PyErr_PrintEx() is tricky.
 
     def test_exit(self):
-        import subprocess
 
         self.assertRaises(TypeError, sys.exit, 42, 42)
 
@@ -179,8 +178,8 @@
         # can't check more than the type, as the user might have changed it
         self.assertIsInstance(sys.getdefaultencoding(), str)
 
-    # testing sys.settrace() is done in test_trace.py
-    # testing sys.setprofile() is done in test_profile.py
+    # testing sys.settrace() is done in test_sys_settrace.py
+    # testing sys.setprofile() is done in test_sys_setprofile.py
 
     def test_setcheckinterval(self):
         with warnings.catch_warnings():
@@ -530,7 +529,6 @@
         sys._clear_type_cache()
 
     def test_ioencoding(self):
-        import subprocess
         env = dict(os.environ)
 
         # Test character: cent sign, encoded as 0x4A (ASCII J) in CP424,
@@ -552,7 +550,7 @@
         # Issue #7774: Ensure that sys.executable is an empty string if argv[0]
         # has been set to an non existent program name and Python is unable to
         # retrieve the real program name
-        import subprocess
+
         # For a normal installation, it should work without 'cwd'
         # argument. For test runs in the build directory, see #7774.
         python_dir = os.path.dirname(os.path.realpath(sys.executable))

Modified: python/branches/import_unicode/Lib/test/test_sysconfig.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_sysconfig.py	(original)
+++ python/branches/import_unicode/Lib/test/test_sysconfig.py	Fri Jul 30 01:19:37 2010
@@ -244,8 +244,8 @@
         # On Windows, the EXE needs to know where pythonXY.dll is at so we have
         # to add the directory to the path.
         if sys.platform == "win32":
-            os.environ["Path"] = "{};{}".format(os.path.dirname(sys.executable),
-                                                os.environ["Path"])
+            os.environ["Path"] = "{};{}".format(
+                os.path.dirname(sys.executable), os.environ["Path"])
 
         # Issue 7880
         def get(python):
@@ -277,6 +277,13 @@
             _main()
         self.assertTrue(len(output.getvalue().split('\n')) > 0)
 
+    @unittest.skipIf(sys.platform == "win32", "Does not apply to Windows")
+    def test_ldshared_value(self):
+        ldflags = sysconfig.get_config_var('LDFLAGS')
+        ldshared = sysconfig.get_config_var('LDSHARED')
+
+        self.assertIn(ldflags, ldshared)
+
 
 def test_main():
     run_unittest(TestSysConfig)

Modified: python/branches/import_unicode/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_tarfile.py	(original)
+++ python/branches/import_unicode/Lib/test/test_tarfile.py	Fri Jul 30 01:19:37 2010
@@ -291,7 +291,8 @@
         self.assertTrue(self.tar.getmembers()[-1].name == "misc/eof",
                 "could not find all members")
 
-    @unittest.skipUnless(hasattr(os, "link"), "Missing hardlink implementation")
+    @unittest.skipUnless(hasattr(os, "link"),
+                         "Missing hardlink implementation")
     @support.skip_unless_symlink
     def test_extract_hardlink(self):
         # Test hardlink extraction (e.g. bug #857297).
@@ -1423,11 +1424,13 @@
     def test_hardlink_extraction2(self):
         self._test_link_extraction("./ustar/linktest2/lnktype")
 
-    @unittest.skipIf(hasattr(os, "symlink"), "Skip emulation if symlink exists")
+    @unittest.skipIf(hasattr(os, "symlink"),
+                     "Skip emulation if symlink exists")
     def test_symlink_extraction1(self):
         self._test_link_extraction("ustar/symtype")
 
-    @unittest.skipIf(hasattr(os, "symlink"), "Skip emulation if symlink exists")
+    @unittest.skipIf(hasattr(os, "symlink"),
+                     "Skip emulation if symlink exists")
     def test_symlink_extraction2(self):
         self._test_link_extraction("./ustar/linktest2/symtype")
 

Modified: python/branches/import_unicode/Lib/test/test_threaded_import.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_threaded_import.py	(original)
+++ python/branches/import_unicode/Lib/test/test_threaded_import.py	Fri Jul 30 01:19:37 2010
@@ -5,72 +5,77 @@
 # complains several times about module random having no attribute
 # randrange, and then Python hangs.
 
+import imp
+import sys
 import unittest
-from test.support import verbose, TestFailed, import_module
+from test.support import verbose, TestFailed, import_module, run_unittest
 thread = import_module('_thread')
 
-critical_section = thread.allocate_lock()
-done = thread.allocate_lock()
+def task(N, done, done_tasks, errors):
+    try:
+        import random
+        # This will fail if random is not completely initialized
+        x = random.randrange(1, 3)
+    except Exception as e:
+        errors.append(e.with_traceback(None))
+    finally:
+        done_tasks.append(thread.get_ident())
+        finished = len(done_tasks) == N
+        if finished:
+            done.release()
+
+
+class ThreadedImportTests(unittest.TestCase):
+
+    def setUp(self):
+        self.old_random = sys.modules.pop('random', None)
+
+    def tearDown(self):
+        # If the `random` module was already initialized, we restore the
+        # old module at the end so that pickling tests don't fail.
+        # See http://bugs.python.org/issue3657#msg110461
+        if self.old_random is not None:
+            sys.modules['random'] = self.old_random
+
+    def test_parallel_module_init(self):
+        if imp.lock_held():
+            # This triggers on, e.g., from test import autotest.
+            raise unittest.SkipTest("can't run when import lock is held")
 
-def task():
-    global N, critical_section, done
-    import random
-    x = random.randrange(1, 3)
-    critical_section.acquire()
-    N -= 1
-    # Must release critical_section before releasing done, else the main
-    # thread can exit and set critical_section to None as part of global
-    # teardown; then critical_section.release() raises AttributeError.
-    finished = N == 0
-    critical_section.release()
-    if finished:
+        done = thread.allocate_lock()
+        done.acquire()
+        for N in (20, 50) * 3:
+            if verbose:
+                print("Trying", N, "threads ...", end=' ')
+            # Make sure that random gets reimported freshly
+            try:
+                del sys.modules['random']
+            except KeyError:
+                pass
+            errors = []
+            done_tasks = []
+            for i in range(N):
+                thread.start_new_thread(task, (N, done, done_tasks, errors,))
+            done.acquire()
+            self.assertFalse(errors)
+            if verbose:
+                print("OK.")
         done.release()
 
-def test_import_hangers():
-    import sys
-    if verbose:
-        print("testing import hangers ...", end=' ')
-
-    import test.threaded_import_hangers
-    try:
-        if test.threaded_import_hangers.errors:
-            raise TestFailed(test.threaded_import_hangers.errors)
-        elif verbose:
-            print("OK.")
-    finally:
+    def test_import_hangers(self):
         # In case this test is run again, make sure the helper module
         # gets loaded from scratch again.
-        del sys.modules['test.threaded_import_hangers']
+        try:
+            del sys.modules['test.threaded_import_hangers']
+        except KeyError:
+            pass
+        import test.threaded_import_hangers
+        self.assertFalse(test.threaded_import_hangers.errors)
 
-# Tricky:  When regrtest imports this module, the thread running regrtest
-# grabs the import lock and won't let go of it until this module returns.
-# All other threads attempting an import hang for the duration.  Since
-# this test spawns threads that do little *but* import, we can't do that
-# successfully until after this module finishes importing and regrtest
-# regains control.  To make this work, a special case was added to
-# regrtest to invoke a module's "test_main" function (if any) after
-# importing it.
-
-def test_main():        # magic name!  see above
-    global N, done
-
-    import imp
-    if imp.lock_held():
-        # This triggers on, e.g., from test import autotest.
-        raise unittest.SkipTest("can't run when import lock is held")
-
-    done.acquire()
-    for N in (20, 50) * 3:
-        if verbose:
-            print("Trying", N, "threads ...", end=' ')
-        for i in range(N):
-            thread.start_new_thread(task, ())
-        done.acquire()
-        if verbose:
-            print("OK.")
-    done.release()
 
-    test_import_hangers()
+def test_main():
+    run_unittest(ThreadedImportTests)
+
 
 if __name__ == "__main__":
     test_main()

Modified: python/branches/import_unicode/Lib/test/test_threading.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_threading.py	(original)
+++ python/branches/import_unicode/Lib/test/test_threading.py	Fri Jul 30 01:19:37 2010
@@ -97,7 +97,8 @@
             self.assertTrue(not t.is_alive())
             self.assertNotEqual(t.ident, 0)
             self.assertFalse(t.ident is None)
-            self.assertTrue(re.match('<TestThread\(.*, \w+ -?\d+\)>', repr(t)))
+            self.assertTrue(re.match('<TestThread\(.*, stopped -?\d+\)>',
+                                     repr(t)))
         if verbose:
             print('all tasks done')
         self.assertEqual(numrunning.get(), 0)
@@ -413,6 +414,12 @@
         e.isSet()
         threading.activeCount()
 
+    def test_repr_daemon(self):
+        t = threading.Thread()
+        self.assertFalse('daemon' in repr(t))
+        t.daemon = True
+        self.assertTrue('daemon' in repr(t))
+
 
 class ThreadJoinOnShutdown(BaseTestCase):
 

Deleted: python/branches/import_unicode/Lib/test/test_trace.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_trace.py	Fri Jul 30 01:19:37 2010
+++ (empty file)
@@ -1,790 +0,0 @@
-# Testing the line trace facility.
-
-from test import support
-import unittest
-import sys
-import difflib
-import gc
-
-# A very basic example.  If this fails, we're in deep trouble.
-def basic():
-    return 1
-
-basic.events = [(0, 'call'),
-                (1, 'line'),
-                (1, 'return')]
-
-# Many of the tests below are tricky because they involve pass statements.
-# If there is implicit control flow around a pass statement (in an except
-# clause or else caluse) under what conditions do you set a line number
-# following that clause?
-
-
-# The entire "while 0:" statement is optimized away.  No code
-# exists for it, so the line numbers skip directly from "del x"
-# to "x = 1".
-def arigo_example():
-    x = 1
-    del x
-    while 0:
-        pass
-    x = 1
-
-arigo_example.events = [(0, 'call'),
-                        (1, 'line'),
-                        (2, 'line'),
-                        (5, 'line'),
-                        (5, 'return')]
-
-# check that lines consisting of just one instruction get traced:
-def one_instr_line():
-    x = 1
-    del x
-    x = 1
-
-one_instr_line.events = [(0, 'call'),
-                         (1, 'line'),
-                         (2, 'line'),
-                         (3, 'line'),
-                         (3, 'return')]
-
-def no_pop_tops():      # 0
-    x = 1               # 1
-    for a in range(2):  # 2
-        if a:           # 3
-            x = 1       # 4
-        else:           # 5
-            x = 1       # 6
-
-no_pop_tops.events = [(0, 'call'),
-                      (1, 'line'),
-                      (2, 'line'),
-                      (3, 'line'),
-                      (6, 'line'),
-                      (2, 'line'),
-                      (3, 'line'),
-                      (4, 'line'),
-                      (2, 'line'),
-                      (2, 'return')]
-
-def no_pop_blocks():
-    y = 1
-    while not y:
-        bla
-    x = 1
-
-no_pop_blocks.events = [(0, 'call'),
-                        (1, 'line'),
-                        (2, 'line'),
-                        (4, 'line'),
-                        (4, 'return')]
-
-def called(): # line -3
-    x = 1
-
-def call():   # line 0
-    called()
-
-call.events = [(0, 'call'),
-               (1, 'line'),
-               (-3, 'call'),
-               (-2, 'line'),
-               (-2, 'return'),
-               (1, 'return')]
-
-def raises():
-    raise Exception
-
-def test_raise():
-    try:
-        raises()
-    except Exception as exc:
-        x = 1
-
-test_raise.events = [(0, 'call'),
-                     (1, 'line'),
-                     (2, 'line'),
-                     (-3, 'call'),
-                     (-2, 'line'),
-                     (-2, 'exception'),
-                     (-2, 'return'),
-                     (2, 'exception'),
-                     (3, 'line'),
-                     (4, 'line'),
-                     (4, 'return')]
-
-def _settrace_and_return(tracefunc):
-    sys.settrace(tracefunc)
-    sys._getframe().f_back.f_trace = tracefunc
-def settrace_and_return(tracefunc):
-    _settrace_and_return(tracefunc)
-
-settrace_and_return.events = [(1, 'return')]
-
-def _settrace_and_raise(tracefunc):
-    sys.settrace(tracefunc)
-    sys._getframe().f_back.f_trace = tracefunc
-    raise RuntimeError
-def settrace_and_raise(tracefunc):
-    try:
-        _settrace_and_raise(tracefunc)
-    except RuntimeError as exc:
-        pass
-
-settrace_and_raise.events = [(2, 'exception'),
-                             (3, 'line'),
-                             (4, 'line'),
-                             (4, 'return')]
-
-# implicit return example
-# This test is interesting because of the else: pass
-# part of the code.  The code generate for the true
-# part of the if contains a jump past the else branch.
-# The compiler then generates an implicit "return None"
-# Internally, the compiler visits the pass statement
-# and stores its line number for use on the next instruction.
-# The next instruction is the implicit return None.
-def ireturn_example():
-    a = 5
-    b = 5
-    if a == b:
-        b = a+1
-    else:
-        pass
-
-ireturn_example.events = [(0, 'call'),
-                          (1, 'line'),
-                          (2, 'line'),
-                          (3, 'line'),
-                          (4, 'line'),
-                          (6, 'line'),
-                          (6, 'return')]
-
-# Tight loop with while(1) example (SF #765624)
-def tightloop_example():
-    items = range(0, 3)
-    try:
-        i = 0
-        while 1:
-            b = items[i]; i+=1
-    except IndexError:
-        pass
-
-tightloop_example.events = [(0, 'call'),
-                            (1, 'line'),
-                            (2, 'line'),
-                            (3, 'line'),
-                            (4, 'line'),
-                            (5, 'line'),
-                            (5, 'line'),
-                            (5, 'line'),
-                            (5, 'line'),
-                            (5, 'exception'),
-                            (6, 'line'),
-                            (7, 'line'),
-                            (7, 'return')]
-
-def tighterloop_example():
-    items = range(1, 4)
-    try:
-        i = 0
-        while 1: i = items[i]
-    except IndexError:
-        pass
-
-tighterloop_example.events = [(0, 'call'),
-                            (1, 'line'),
-                            (2, 'line'),
-                            (3, 'line'),
-                            (4, 'line'),
-                            (4, 'line'),
-                            (4, 'line'),
-                            (4, 'line'),
-                            (4, 'exception'),
-                            (5, 'line'),
-                            (6, 'line'),
-                            (6, 'return')]
-
-def generator_function():
-    try:
-        yield True
-        "continued"
-    finally:
-        "finally"
-def generator_example():
-    # any() will leave the generator before its end
-    x = any(generator_function())
-
-    # the following lines were not traced
-    for x in range(10):
-        y = x
-
-generator_example.events = ([(0, 'call'),
-                             (2, 'line'),
-                             (-6, 'call'),
-                             (-5, 'line'),
-                             (-4, 'line'),
-                             (-4, 'return'),
-                             (-4, 'call'),
-                             (-4, 'exception'),
-                             (-1, 'line'),
-                             (-1, 'return')] +
-                            [(5, 'line'), (6, 'line')] * 10 +
-                            [(5, 'line'), (5, 'return')])
-
-
-class Tracer:
-    def __init__(self):
-        self.events = []
-    def trace(self, frame, event, arg):
-        self.events.append((frame.f_lineno, event))
-        return self.trace
-    def traceWithGenexp(self, frame, event, arg):
-        (o for o in [1])
-        self.events.append((frame.f_lineno, event))
-        return self.trace
-
-class TraceTestCase(unittest.TestCase):
-
-    # Disable gc collection when tracing, otherwise the
-    # deallocators may be traced as well.
-    def setUp(self):
-        self.using_gc = gc.isenabled()
-        gc.disable()
-
-    def tearDown(self):
-        if self.using_gc:
-            gc.enable()
-
-    def compare_events(self, line_offset, events, expected_events):
-        events = [(l - line_offset, e) for (l, e) in events]
-        if events != expected_events:
-            self.fail(
-                "events did not match expectation:\n" +
-                "\n".join(difflib.ndiff([str(x) for x in expected_events],
-                                        [str(x) for x in events])))
-
-    def run_and_compare(self, func, events):
-        tracer = Tracer()
-        sys.settrace(tracer.trace)
-        func()
-        sys.settrace(None)
-        self.compare_events(func.__code__.co_firstlineno,
-                            tracer.events, events)
-
-    def run_test(self, func):
-        self.run_and_compare(func, func.events)
-
-    def run_test2(self, func):
-        tracer = Tracer()
-        func(tracer.trace)
-        sys.settrace(None)
-        self.compare_events(func.__code__.co_firstlineno,
-                            tracer.events, func.events)
-
-    def set_and_retrieve_none(self):
-        sys.settrace(None)
-        assert sys.gettrace() is None
-
-    def set_and_retrieve_func(self):
-        def fn(*args):
-            pass
-
-        sys.settrace(fn)
-        try:
-            assert sys.gettrace() is fn
-        finally:
-            sys.settrace(None)
-
-    def test_01_basic(self):
-        self.run_test(basic)
-    def test_02_arigo(self):
-        self.run_test(arigo_example)
-    def test_03_one_instr(self):
-        self.run_test(one_instr_line)
-    def test_04_no_pop_blocks(self):
-        self.run_test(no_pop_blocks)
-    def test_05_no_pop_tops(self):
-        self.run_test(no_pop_tops)
-    def test_06_call(self):
-        self.run_test(call)
-    def test_07_raise(self):
-        self.run_test(test_raise)
-
-    def test_08_settrace_and_return(self):
-        self.run_test2(settrace_and_return)
-    def test_09_settrace_and_raise(self):
-        self.run_test2(settrace_and_raise)
-    def test_10_ireturn(self):
-        self.run_test(ireturn_example)
-    def test_11_tightloop(self):
-        self.run_test(tightloop_example)
-    def test_12_tighterloop(self):
-        self.run_test(tighterloop_example)
-
-    def test_13_genexp(self):
-        self.run_test(generator_example)
-        # issue1265: if the trace function contains a generator,
-        # and if the traced function contains another generator
-        # that is not completely exhausted, the trace stopped.
-        # Worse: the 'finally' clause was not invoked.
-        tracer = Tracer()
-        sys.settrace(tracer.traceWithGenexp)
-        generator_example()
-        sys.settrace(None)
-        self.compare_events(generator_example.__code__.co_firstlineno,
-                            tracer.events, generator_example.events)
-
-    def test_14_onliner_if(self):
-        def onliners():
-            if True: False
-            else: True
-            return 0
-        self.run_and_compare(
-            onliners,
-            [(0, 'call'),
-             (1, 'line'),
-             (3, 'line'),
-             (3, 'return')])
-
-    def test_15_loops(self):
-        # issue1750076: "while" expression is skipped by debugger
-        def for_example():
-            for x in range(2):
-                pass
-        self.run_and_compare(
-            for_example,
-            [(0, 'call'),
-             (1, 'line'),
-             (2, 'line'),
-             (1, 'line'),
-             (2, 'line'),
-             (1, 'line'),
-             (1, 'return')])
-
-        def while_example():
-            # While expression should be traced on every loop
-            x = 2
-            while x > 0:
-                x -= 1
-        self.run_and_compare(
-            while_example,
-            [(0, 'call'),
-             (2, 'line'),
-             (3, 'line'),
-             (4, 'line'),
-             (3, 'line'),
-             (4, 'line'),
-             (3, 'line'),
-             (3, 'return')])
-
-    def test_16_blank_lines(self):
-        namespace = {}
-        exec("def f():\n" + "\n" * 256 + "    pass", namespace)
-        self.run_and_compare(
-            namespace["f"],
-            [(0, 'call'),
-             (257, 'line'),
-             (257, 'return')])
-
-
-class RaisingTraceFuncTestCase(unittest.TestCase):
-    def trace(self, frame, event, arg):
-        """A trace function that raises an exception in response to a
-        specific trace event."""
-        if event == self.raiseOnEvent:
-            raise ValueError # just something that isn't RuntimeError
-        else:
-            return self.trace
-
-    def f(self):
-        """The function to trace; raises an exception if that's the case
-        we're testing, so that the 'exception' trace event fires."""
-        if self.raiseOnEvent == 'exception':
-            x = 0
-            y = 1/x
-        else:
-            return 1
-
-    def run_test_for_event(self, event):
-        """Tests that an exception raised in response to the given event is
-        handled OK."""
-        self.raiseOnEvent = event
-        try:
-            for i in range(sys.getrecursionlimit() + 1):
-                sys.settrace(self.trace)
-                try:
-                    self.f()
-                except ValueError:
-                    pass
-                else:
-                    self.fail("exception not thrown!")
-        except RuntimeError:
-            self.fail("recursion counter not reset")
-
-    # Test the handling of exceptions raised by each kind of trace event.
-    def test_call(self):
-        self.run_test_for_event('call')
-    def test_line(self):
-        self.run_test_for_event('line')
-    def test_return(self):
-        self.run_test_for_event('return')
-    def test_exception(self):
-        self.run_test_for_event('exception')
-
-    def test_trash_stack(self):
-        def f():
-            for i in range(5):
-                print(i)  # line tracing will raise an exception at this line
-
-        def g(frame, why, extra):
-            if (why == 'line' and
-                frame.f_lineno == f.__code__.co_firstlineno + 2):
-                raise RuntimeError("i am crashing")
-            return g
-
-        sys.settrace(g)
-        try:
-            f()
-        except RuntimeError:
-            # the test is really that this doesn't segfault:
-            import gc
-            gc.collect()
-        else:
-            self.fail("exception not propagated")
-
-
-# 'Jump' tests: assigning to frame.f_lineno within a trace function
-# moves the execution position - it's how debuggers implement a Jump
-# command (aka. "Set next statement").
-
-class JumpTracer:
-    """Defines a trace function that jumps from one place to another,
-    with the source and destination lines of the jump being defined by
-    the 'jump' property of the function under test."""
-
-    def __init__(self, function):
-        self.function = function
-        self.jumpFrom = function.jump[0]
-        self.jumpTo = function.jump[1]
-        self.done = False
-
-    def trace(self, frame, event, arg):
-        if not self.done and frame.f_code == self.function.__code__:
-            firstLine = frame.f_code.co_firstlineno
-            if event == 'line' and frame.f_lineno == firstLine + self.jumpFrom:
-                # Cope with non-integer self.jumpTo (because of
-                # no_jump_to_non_integers below).
-                try:
-                    frame.f_lineno = firstLine + self.jumpTo
-                except TypeError:
-                    frame.f_lineno = self.jumpTo
-                self.done = True
-        return self.trace
-
-# The first set of 'jump' tests are for things that are allowed:
-
-def jump_simple_forwards(output):
-    output.append(1)
-    output.append(2)
-    output.append(3)
-
-jump_simple_forwards.jump = (1, 3)
-jump_simple_forwards.output = [3]
-
-def jump_simple_backwards(output):
-    output.append(1)
-    output.append(2)
-
-jump_simple_backwards.jump = (2, 1)
-jump_simple_backwards.output = [1, 1, 2]
-
-def jump_out_of_block_forwards(output):
-    for i in 1, 2:
-        output.append(2)
-        for j in [3]:  # Also tests jumping over a block
-            output.append(4)
-    output.append(5)
-
-jump_out_of_block_forwards.jump = (3, 5)
-jump_out_of_block_forwards.output = [2, 5]
-
-def jump_out_of_block_backwards(output):
-    output.append(1)
-    for i in [1]:
-        output.append(3)
-        for j in [2]:  # Also tests jumping over a block
-            output.append(5)
-        output.append(6)
-    output.append(7)
-
-jump_out_of_block_backwards.jump = (6, 1)
-jump_out_of_block_backwards.output = [1, 3, 5, 1, 3, 5, 6, 7]
-
-def jump_to_codeless_line(output):
-    output.append(1)
-    # Jumping to this line should skip to the next one.
-    output.append(3)
-
-jump_to_codeless_line.jump = (1, 2)
-jump_to_codeless_line.output = [3]
-
-def jump_to_same_line(output):
-    output.append(1)
-    output.append(2)
-    output.append(3)
-
-jump_to_same_line.jump = (2, 2)
-jump_to_same_line.output = [1, 2, 3]
-
-# Tests jumping within a finally block, and over one.
-def jump_in_nested_finally(output):
-    try:
-        output.append(2)
-    finally:
-        output.append(4)
-        try:
-            output.append(6)
-        finally:
-            output.append(8)
-        output.append(9)
-
-jump_in_nested_finally.jump = (4, 9)
-jump_in_nested_finally.output = [2, 9]
-
-# The second set of 'jump' tests are for things that are not allowed:
-
-def no_jump_too_far_forwards(output):
-    try:
-        output.append(2)
-        output.append(3)
-    except ValueError as e:
-        output.append('after' in str(e))
-
-no_jump_too_far_forwards.jump = (3, 6)
-no_jump_too_far_forwards.output = [2, True]
-
-def no_jump_too_far_backwards(output):
-    try:
-        output.append(2)
-        output.append(3)
-    except ValueError as e:
-        output.append('before' in str(e))
-
-no_jump_too_far_backwards.jump = (3, -1)
-no_jump_too_far_backwards.output = [2, True]
-
-# Test each kind of 'except' line.
-def no_jump_to_except_1(output):
-    try:
-        output.append(2)
-    except:
-        e = sys.exc_info()[1]
-        output.append('except' in str(e))
-
-no_jump_to_except_1.jump = (2, 3)
-no_jump_to_except_1.output = [True]
-
-def no_jump_to_except_2(output):
-    try:
-        output.append(2)
-    except ValueError:
-        e = sys.exc_info()[1]
-        output.append('except' in str(e))
-
-no_jump_to_except_2.jump = (2, 3)
-no_jump_to_except_2.output = [True]
-
-def no_jump_to_except_3(output):
-    try:
-        output.append(2)
-    except ValueError as e:
-        output.append('except' in str(e))
-
-no_jump_to_except_3.jump = (2, 3)
-no_jump_to_except_3.output = [True]
-
-def no_jump_to_except_4(output):
-    try:
-        output.append(2)
-    except (ValueError, RuntimeError) as e:
-        output.append('except' in str(e))
-
-no_jump_to_except_4.jump = (2, 3)
-no_jump_to_except_4.output = [True]
-
-def no_jump_forwards_into_block(output):
-    try:
-        output.append(2)
-        for i in 1, 2:
-            output.append(4)
-    except ValueError as e:
-        output.append('into' in str(e))
-
-no_jump_forwards_into_block.jump = (2, 4)
-no_jump_forwards_into_block.output = [True]
-
-def no_jump_backwards_into_block(output):
-    try:
-        for i in 1, 2:
-            output.append(3)
-        output.append(4)
-    except ValueError as e:
-        output.append('into' in str(e))
-
-no_jump_backwards_into_block.jump = (4, 3)
-no_jump_backwards_into_block.output = [3, 3, True]
-
-def no_jump_into_finally_block(output):
-    try:
-        try:
-            output.append(3)
-            x = 1
-        finally:
-            output.append(6)
-    except ValueError as e:
-        output.append('finally' in str(e))
-
-no_jump_into_finally_block.jump = (4, 6)
-no_jump_into_finally_block.output = [3, 6, True]  # The 'finally' still runs
-
-def no_jump_out_of_finally_block(output):
-    try:
-        try:
-            output.append(3)
-        finally:
-            output.append(5)
-            output.append(6)
-    except ValueError as e:
-        output.append('finally' in str(e))
-
-no_jump_out_of_finally_block.jump = (5, 1)
-no_jump_out_of_finally_block.output = [3, True]
-
-# This verifies the line-numbers-must-be-integers rule.
-def no_jump_to_non_integers(output):
-    try:
-        output.append(2)
-    except ValueError as e:
-        output.append('integer' in str(e))
-
-no_jump_to_non_integers.jump = (2, "Spam")
-no_jump_to_non_integers.output = [True]
-
-# This verifies that you can't set f_lineno via _getframe or similar
-# trickery.
-def no_jump_without_trace_function():
-    try:
-        previous_frame = sys._getframe().f_back
-        previous_frame.f_lineno = previous_frame.f_lineno
-    except ValueError as e:
-        # This is the exception we wanted; make sure the error message
-        # talks about trace functions.
-        if 'trace' not in str(e):
-            raise
-    else:
-        # Something's wrong - the expected exception wasn't raised.
-        raise RuntimeError("Trace-function-less jump failed to fail")
-
-
-class JumpTestCase(unittest.TestCase):
-    def compare_jump_output(self, expected, received):
-        if received != expected:
-            self.fail( "Outputs don't match:\n" +
-                       "Expected: " + repr(expected) + "\n" +
-                       "Received: " + repr(received))
-
-    def run_test(self, func):
-        tracer = JumpTracer(func)
-        sys.settrace(tracer.trace)
-        output = []
-        func(output)
-        sys.settrace(None)
-        self.compare_jump_output(func.output, output)
-
-    def test_01_jump_simple_forwards(self):
-        self.run_test(jump_simple_forwards)
-    def test_02_jump_simple_backwards(self):
-        self.run_test(jump_simple_backwards)
-    def test_03_jump_out_of_block_forwards(self):
-        self.run_test(jump_out_of_block_forwards)
-    def test_04_jump_out_of_block_backwards(self):
-        self.run_test(jump_out_of_block_backwards)
-    def test_05_jump_to_codeless_line(self):
-        self.run_test(jump_to_codeless_line)
-    def test_06_jump_to_same_line(self):
-        self.run_test(jump_to_same_line)
-    def test_07_jump_in_nested_finally(self):
-        self.run_test(jump_in_nested_finally)
-    def test_08_no_jump_too_far_forwards(self):
-        self.run_test(no_jump_too_far_forwards)
-    def test_09_no_jump_too_far_backwards(self):
-        self.run_test(no_jump_too_far_backwards)
-    def test_10_no_jump_to_except_1(self):
-        self.run_test(no_jump_to_except_1)
-    def test_11_no_jump_to_except_2(self):
-        self.run_test(no_jump_to_except_2)
-    def test_12_no_jump_to_except_3(self):
-        self.run_test(no_jump_to_except_3)
-    def test_13_no_jump_to_except_4(self):
-        self.run_test(no_jump_to_except_4)
-    def test_14_no_jump_forwards_into_block(self):
-        self.run_test(no_jump_forwards_into_block)
-    def test_15_no_jump_backwards_into_block(self):
-        self.run_test(no_jump_backwards_into_block)
-    def test_16_no_jump_into_finally_block(self):
-        self.run_test(no_jump_into_finally_block)
-    def test_17_no_jump_out_of_finally_block(self):
-        self.run_test(no_jump_out_of_finally_block)
-    def test_18_no_jump_to_non_integers(self):
-        self.run_test(no_jump_to_non_integers)
-    def test_19_no_jump_without_trace_function(self):
-        no_jump_without_trace_function()
-
-    def test_20_large_function(self):
-        d = {}
-        exec("""def f(output):        # line 0
-            x = 0                     # line 1
-            y = 1                     # line 2
-            '''                       # line 3
-            %s                        # lines 4-1004
-            '''                       # line 1005
-            x += 1                    # line 1006
-            output.append(x)          # line 1007
-            return""" % ('\n' * 1000,), d)
-        f = d['f']
-
-        f.jump = (2, 1007)
-        f.output = [0]
-        self.run_test(f)
-
-    def test_jump_to_firstlineno(self):
-        # This tests that PDB can jump back to the first line in a
-        # file.  See issue #1689458.  It can only be triggered in a
-        # function call if the function is defined on a single line.
-        code = compile("""
-# Comments don't count.
-output.append(2)  # firstlineno is here.
-output.append(3)
-output.append(4)
-""", "<fake module>", "exec")
-        class fake_function:
-            __code__ = code
-            jump = (2, 0)
-        tracer = JumpTracer(fake_function)
-        sys.settrace(tracer.trace)
-        namespace = {"output": []}
-        exec(code, namespace)
-        sys.settrace(None)
-        self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"])
-
-
-def test_main():
-    support.run_unittest(
-        TraceTestCase,
-        RaisingTraceFuncTestCase,
-        JumpTestCase
-    )
-
-if __name__ == "__main__":
-    test_main()

Modified: python/branches/import_unicode/Lib/test/test_unicode.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_unicode.py	(original)
+++ python/branches/import_unicode/Lib/test/test_unicode.py	Fri Jul 30 01:19:37 2010
@@ -757,6 +757,7 @@
         self.assertRaises(OverflowError, "%c".__mod__, (0x110000,))
         self.assertEqual('%c' % '\U00021483', '\U00021483')
         self.assertRaises(TypeError, "%c".__mod__, "aa")
+        self.assertRaises(ValueError, "%.1\u1032f".__mod__, (1.0/3))
 
         # formatting jobs delegated from the string implementation:
         self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...')

Modified: python/branches/import_unicode/Lib/test/test_unpack.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_unpack.py	(original)
+++ python/branches/import_unicode/Lib/test/test_unpack.py	Fri Jul 30 01:19:37 2010
@@ -62,14 +62,14 @@
     >>> a, b = t
     Traceback (most recent call last):
       ...
-    ValueError: too many values to unpack
+    ValueError: too many values to unpack (expected 2)
 
 Unpacking tuple of wrong size
 
     >>> a, b = l
     Traceback (most recent call last):
       ...
-    ValueError: too many values to unpack
+    ValueError: too many values to unpack (expected 2)
 
 Unpacking sequence too short
 
@@ -83,7 +83,7 @@
     >>> a, b = Seq()
     Traceback (most recent call last):
       ...
-    ValueError: too many values to unpack
+    ValueError: too many values to unpack (expected 2)
 
 Unpacking a sequence where the test for too long raises a different kind of
 error

Modified: python/branches/import_unicode/Lib/test/test_urllib.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_urllib.py	(original)
+++ python/branches/import_unicode/Lib/test/test_urllib.py	Fri Jul 30 01:19:37 2010
@@ -558,6 +558,7 @@
         self.assertEqual(result.count('%'), 1,
                          "using unquote(): not all characters escaped: "
                          "%s" % result)
+        self.assertRaises(TypeError, urllib.parse.unquote, None)
 
     def test_unquoting_badpercent(self):
         # Test unquoting on bad percent-escapes
@@ -593,6 +594,8 @@
         self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
                          % (expect, result))
 
+        self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, None)
+
     def test_unquoting_mixed_case(self):
         # Test unquoting on mixed-case hex digits in the percent-escapes
         given = '%Ab%eA'

Modified: python/branches/import_unicode/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_urllib2.py	(original)
+++ python/branches/import_unicode/Lib/test/test_urllib2.py	Fri Jul 30 01:19:37 2010
@@ -735,6 +735,8 @@
             ("file://ftp.example.com///foo.txt", False),
 # XXXX bug: fails with OSError, should be URLError
             ("file://ftp.example.com/foo.txt", False),
+            ("file://somehost//foo/something.txt", True),
+            ("file://localhost//foo/something.txt", False),
             ]:
             req = Request(url)
             try:
@@ -745,6 +747,7 @@
             else:
                 self.assertTrue(o.req is req)
                 self.assertEqual(req.type, "ftp")
+            self.assertEqual(req.type is "ftp", ftp)
 
     def test_http(self):
 

Modified: python/branches/import_unicode/Lib/test/test_urlparse.py
==============================================================================
--- python/branches/import_unicode/Lib/test/test_urlparse.py	(original)
+++ python/branches/import_unicode/Lib/test/test_urlparse.py	Fri Jul 30 01:19:37 2010
@@ -7,6 +7,7 @@
 RFC1808_BASE = "http://a/b/c/d;p?q#f"
 RFC2396_BASE = "http://a/b/c/d;p?q"
 RFC3986_BASE = 'http://a/b/c/d;p?q'
+SIMPLE_BASE  = 'http://a/b/c/d'
 
 # A list of test cases.  Each test case is a a two-tuple that contains
 # a string with the query and a dictionary with the expected result.
@@ -295,6 +296,37 @@
         #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
         self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') #relaxed parser
 
+    def test_urljoins(self):
+        self.checkJoin(SIMPLE_BASE, 'g:h','g:h')
+        self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
+        self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
+        self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g')
+        self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g')
+        self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/')
+        self.checkJoin(SIMPLE_BASE, '/g','http://a/g')
+        self.checkJoin(SIMPLE_BASE, '//g','http://g')
+        self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y')
+        self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y')
+        self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
+        self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/')
+        self.checkJoin(SIMPLE_BASE, './','http://a/b/c/')
+        self.checkJoin(SIMPLE_BASE, '..','http://a/b/')
+        self.checkJoin(SIMPLE_BASE, '../','http://a/b/')
+        self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g')
+        self.checkJoin(SIMPLE_BASE, '../..','http://a/')
+        self.checkJoin(SIMPLE_BASE, '../../g','http://a/g')
+        self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g')
+        self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g')
+        self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/')
+        self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g')
+        self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h')
+        self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h')
+        self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
+        self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
+        self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y')
+        self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y')
+        self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x')
+
     def test_RFC2732(self):
         for url, hostname, port in [
             ('http://Test.python.org:5432/foo/', 'test.python.org', 5432),

Modified: python/branches/import_unicode/Lib/threading.py
==============================================================================
--- python/branches/import_unicode/Lib/threading.py	(original)
+++ python/branches/import_unicode/Lib/threading.py	Fri Jul 30 01:19:37 2010
@@ -871,91 +871,3 @@
         _active.clear()
         _active.update(new_active)
         assert len(_active) == 1
-
-
-# Self-test code
-
-def _test():
-
-    class BoundedQueue(_Verbose):
-
-        def __init__(self, limit):
-            _Verbose.__init__(self)
-            self.mon = RLock()
-            self.rc = Condition(self.mon)
-            self.wc = Condition(self.mon)
-            self.limit = limit
-            self.queue = deque()
-
-        def put(self, item):
-            self.mon.acquire()
-            while len(self.queue) >= self.limit:
-                self._note("put(%s): queue full", item)
-                self.wc.wait()
-            self.queue.append(item)
-            self._note("put(%s): appended, length now %d",
-                       item, len(self.queue))
-            self.rc.notify()
-            self.mon.release()
-
-        def get(self):
-            self.mon.acquire()
-            while not self.queue:
-                self._note("get(): queue empty")
-                self.rc.wait()
-            item = self.queue.popleft()
-            self._note("get(): got %s, %d left", item, len(self.queue))
-            self.wc.notify()
-            self.mon.release()
-            return item
-
-    class ProducerThread(Thread):
-
-        def __init__(self, queue, quota):
-            Thread.__init__(self, name="Producer")
-            self.queue = queue
-            self.quota = quota
-
-        def run(self):
-            from random import random
-            counter = 0
-            while counter < self.quota:
-                counter = counter + 1
-                self.queue.put("%s.%d" % (self.name, counter))
-                _sleep(random() * 0.00001)
-
-
-    class ConsumerThread(Thread):
-
-        def __init__(self, queue, count):
-            Thread.__init__(self, name="Consumer")
-            self.queue = queue
-            self.count = count
-
-        def run(self):
-            while self.count > 0:
-                item = self.queue.get()
-                print(item)
-                self.count = self.count - 1
-
-    NP = 3
-    QL = 4
-    NI = 5
-
-    Q = BoundedQueue(QL)
-    P = []
-    for i in range(NP):
-        t = ProducerThread(Q, NI)
-        t.name = "Producer-%d" % (i+1)
-        P.append(t)
-    C = ConsumerThread(Q, NI*NP)
-    for t in P:
-        t.start()
-        _sleep(0.000001)
-    C.start()
-    for t in P:
-        t.join()
-    C.join()
-
-if __name__ == '__main__':
-    _test()

Modified: python/branches/import_unicode/Lib/trace.py
==============================================================================
--- python/branches/import_unicode/Lib/trace.py	(original)
+++ python/branches/import_unicode/Lib/trace.py	Fri Jul 30 01:19:37 2010
@@ -257,7 +257,8 @@
         if self.calledfuncs:
             print()
             print("functions called:")
-            for filename, modulename, funcname in sorted(calls.keys()):
+            calls = self.calledfuncs.keys()
+            for filename, modulename, funcname in sorted(calls):
                 print(("filename: %s, modulename: %s, funcname: %s"
                        % (filename, modulename, funcname)))
 
@@ -796,12 +797,9 @@
                   ignoredirs=ignore_dirs, infile=counts_file,
                   outfile=counts_file, timing=timing)
         try:
-            fp = open(progname)
-            try:
-                script = fp.read()
-            finally:
-                fp.close()
-            t.run('exec(%r)' % (script,))
+            with open(progname) as fp:
+                code = compile(fp.read(), progname, 'exec')
+            t.run(code)
         except IOError as err:
             _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err))
         except SystemExit:

Modified: python/branches/import_unicode/Lib/unittest/case.py
==============================================================================
--- python/branches/import_unicode/Lib/unittest/case.py	(original)
+++ python/branches/import_unicode/Lib/unittest/case.py	Fri Jul 30 01:19:37 2010
@@ -940,9 +940,14 @@
                 'Second argument is not a string'))
 
         if first != second:
-            standardMsg = '%s != %s' % (safe_repr(first, True), safe_repr(second, True))
-            diff = '\n' + ''.join(difflib.ndiff(first.splitlines(True),
-                                                       second.splitlines(True)))
+            firstlines = first.splitlines(True)
+            secondlines = second.splitlines(True)
+            if len(firstlines) == 1 and first.strip('\r\n') == first:
+                firstlines = [first + '\n']
+                secondlines = [second + '\n']
+            standardMsg = '%s != %s' % (safe_repr(first, True),
+                                        safe_repr(second, True))
+            diff = '\n' + ''.join(difflib.ndiff(firstlines, secondlines))
             standardMsg = self._truncateMessage(standardMsg, diff)
             self.fail(self._formatMessage(msg, standardMsg))
 

Modified: python/branches/import_unicode/Lib/unittest/test/test_case.py
==============================================================================
--- python/branches/import_unicode/Lib/unittest/test/test_case.py	(original)
+++ python/branches/import_unicode/Lib/unittest/test/test_case.py	Fri Jul 30 01:19:37 2010
@@ -841,6 +841,21 @@
             # so can't use assertEqual either. Just use assertTrue.
             self.assertTrue(sample_text_error == error)
 
+    def testAsertEqualSingleLine(self):
+        sample_text = "laden swallows fly slowly"
+        revised_sample_text = "unladen swallows fly quickly"
+        sample_text_error = """\
+- laden swallows fly slowly
+?                    ^^^^
++ unladen swallows fly quickly
+? ++                   ^^^^^
+"""
+        try:
+            self.assertEqual(sample_text, revised_sample_text)
+        except self.failureException as e:
+            error = str(e).split('\n', 1)[1]
+            self.assertTrue(sample_text_error == error)
+
     def testAssertIsNone(self):
         self.assertIsNone(None)
         self.assertRaises(self.failureException, self.assertIsNone, False)

Modified: python/branches/import_unicode/Lib/urllib/parse.py
==============================================================================
--- python/branches/import_unicode/Lib/urllib/parse.py	(original)
+++ python/branches/import_unicode/Lib/urllib/parse.py	Fri Jul 30 01:19:37 2010
@@ -314,6 +314,8 @@
     # Note: strings are encoded as UTF-8. This is only an issue if it contains
     # unescaped non-ASCII characters, which URIs should not.
     if not string:
+        if string is None:
+            raise TypeError('None object is invalid for unquote_to_bytes()')
         return b''
     if isinstance(string, str):
         string = string.encode('utf-8')
@@ -339,6 +341,8 @@
     unquote('abc%20def') -> 'abc def'.
     """
     if not string:
+        if string is None:
+            raise TypeError('None object is invalid for unquote() function.')
         return string
     res = string.split('%')
     if len(res) == 1:
@@ -799,67 +803,3 @@
     match = _valueprog.match(attr)
     if match: return match.group(1, 2)
     return attr, None
-
-test_input = """
-      http://a/b/c/d
-
-      g:h        = <URL:g:h>
-      http:g     = <URL:http://a/b/c/g>
-      http:      = <URL:http://a/b/c/d>
-      g          = <URL:http://a/b/c/g>
-      ./g        = <URL:http://a/b/c/g>
-      g/         = <URL:http://a/b/c/g/>
-      /g         = <URL:http://a/g>
-      //g        = <URL:http://g>
-      ?y         = <URL:http://a/b/c/d?y>
-      g?y        = <URL:http://a/b/c/g?y>
-      g?y/./x    = <URL:http://a/b/c/g?y/./x>
-      .          = <URL:http://a/b/c/>
-      ./         = <URL:http://a/b/c/>
-      ..         = <URL:http://a/b/>
-      ../        = <URL:http://a/b/>
-      ../g       = <URL:http://a/b/g>
-      ../..      = <URL:http://a/>
-      ../../g    = <URL:http://a/g>
-      ../../../g = <URL:http://a/../g>
-      ./../g     = <URL:http://a/b/g>
-      ./g/.      = <URL:http://a/b/c/g/>
-      /./g       = <URL:http://a/./g>
-      g/./h      = <URL:http://a/b/c/g/h>
-      g/../h     = <URL:http://a/b/c/h>
-      http:g     = <URL:http://a/b/c/g>
-      http:      = <URL:http://a/b/c/d>
-      http:?y         = <URL:http://a/b/c/d?y>
-      http:g?y        = <URL:http://a/b/c/g?y>
-      http:g?y/./x    = <URL:http://a/b/c/g?y/./x>
-"""
-
-def test():
-    base = ''
-    if sys.argv[1:]:
-        fn = sys.argv[1]
-        if fn == '-':
-            fp = sys.stdin
-        else:
-            fp = open(fn)
-    else:
-        from io import StringIO
-        fp = StringIO(test_input)
-    for line in fp:
-        words = line.split()
-        if not words:
-            continue
-        url = words[0]
-        parts = urlparse(url)
-        print('%-10s : %s' % (url, parts))
-        abs = urljoin(base, url)
-        if not base:
-            base = abs
-        wrapped = '<URL:%s>' % abs
-        print('%-10s = %s' % (url, wrapped))
-        if len(words) == 3 and words[1] == '=':
-            if wrapped != words[2]:
-                print('EXPECTED', words[2], '!!!!!!!!!!')
-
-if __name__ == '__main__':
-    test()

Modified: python/branches/import_unicode/Lib/urllib/request.py
==============================================================================
--- python/branches/import_unicode/Lib/urllib/request.py	(original)
+++ python/branches/import_unicode/Lib/urllib/request.py	Fri Jul 30 01:19:37 2010
@@ -1188,7 +1188,8 @@
     # Use local file or FTP depending on form of URL
     def file_open(self, req):
         url = req.selector
-        if url[:2] == '//' and url[2:3] != '/':
+        if url[:2] == '//' and url[2:3] != '/' and (req.host and
+                req.host != 'localhost'):
             req.type = 'ftp'
             return self.parent.open(req)
         else:
@@ -2278,6 +2279,7 @@
                         proxies['http'] = proxyServer
                     else:
                         proxies['http'] = 'http://%s' % proxyServer
+                        proxies['https'] = 'https://%s' % proxyServer
                         proxies['ftp'] = 'ftp://%s' % proxyServer
             internetSettings.Close()
         except (WindowsError, ValueError, TypeError):

Modified: python/branches/import_unicode/Lib/urllib/robotparser.py
==============================================================================
--- python/branches/import_unicode/Lib/urllib/robotparser.py	(original)
+++ python/branches/import_unicode/Lib/urllib/robotparser.py	Fri Jul 30 01:19:37 2010
@@ -66,7 +66,9 @@
     def _add_entry(self, entry):
         if "*" in entry.useragents:
             # the default entry is considered last
-            self.default_entry = entry
+            if self.default_entry is None:
+                # the first default entry wins
+                self.default_entry = entry
         else:
             self.entries.append(entry)
 
@@ -118,7 +120,7 @@
                         entry.rulelines.append(RuleLine(line[1], True))
                         state = 2
         if state == 2:
-            self.entries.append(entry)
+            self._add_entry(entry)
 
 
     def can_fetch(self, useragent, url):
@@ -129,8 +131,10 @@
             return True
         # search for given user agent matches
         # the first match counts
-        url = urllib.parse.quote(
-            urllib.parse.urlparse(urllib.parse.unquote(url))[2])
+        parsed_url = urllib.parse.urlparse(urllib.parse.unquote(url))
+        url = urllib.parse.urlunparse(('','',parsed_url.path,
+            parsed_url.params,parsed_url.query, parsed_url.fragment))
+        url = urllib.parse.quote(url)
         if not url:
             url = "/"
         for entry in self.entries:

Modified: python/branches/import_unicode/Lib/xml/dom/expatbuilder.py
==============================================================================
--- python/branches/import_unicode/Lib/xml/dom/expatbuilder.py	(original)
+++ python/branches/import_unicode/Lib/xml/dom/expatbuilder.py	Fri Jul 30 01:19:37 2010
@@ -242,7 +242,7 @@
         doctype = self.document.implementation.createDocumentType(
             doctypeName, publicId, systemId)
         doctype.ownerDocument = self.document
-        self.document.childNodes.append(doctype)
+        _append_child(self.document, doctype)
         self.document.doctype = doctype
         if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT:
             self.document.doctype = None

Modified: python/branches/import_unicode/Lib/xml/dom/minidom.py
==============================================================================
--- python/branches/import_unicode/Lib/xml/dom/minidom.py	(original)
+++ python/branches/import_unicode/Lib/xml/dom/minidom.py	Fri Jul 30 01:19:37 2010
@@ -920,6 +920,10 @@
         raise xml.dom.NotFoundErr(
             self.nodeName + " nodes do not have children")
 
+    def normalize(self):
+        # For childless nodes, normalize() has nothing to do.
+        pass
+
     def replaceChild(self, newChild, oldChild):
         raise xml.dom.HierarchyRequestErr(
             self.nodeName + " nodes do not have children")

Modified: python/branches/import_unicode/Lib/xmlrpc/client.py
==============================================================================
--- python/branches/import_unicode/Lib/xmlrpc/client.py	(original)
+++ python/branches/import_unicode/Lib/xmlrpc/client.py	Fri Jul 30 01:19:37 2010
@@ -1135,7 +1135,7 @@
             try:
                 return self.single_request(host, handler, request_body, verbose)
             except socket.error as e:
-                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED):
+                if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
                     raise
             except http.client.BadStatusLine: #close after we sent request
                 if i:

Modified: python/branches/import_unicode/Makefile.pre.in
==============================================================================
--- python/branches/import_unicode/Makefile.pre.in	(original)
+++ python/branches/import_unicode/Makefile.pre.in	Fri Jul 30 01:19:37 2010
@@ -59,12 +59,18 @@
 # Compiler options
 OPT=		@OPT@
 BASECFLAGS=	@BASECFLAGS@
-CFLAGS=		$(BASECFLAGS) @CFLAGS@ $(OPT) $(EXTRA_CFLAGS)
+CONFIGURE_CFLAGS=	@CFLAGS@
+CONFIGURE_CPPFLAGS=	@CPPFLAGS@
+CONFIGURE_LDFLAGS=	@LDFLAGS@
+# Avoid assigning CFLAGS, LDFLAGS, etc. so users can use them on the
+# command line to append to these values without stomping the pre-set
+# values.
+PY_CFLAGS=	$(BASECFLAGS) $(OPT) $(CONFIGURE_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS)
 # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to
 # be able to build extension modules using the directories specified in the
 # environment variables
-CPPFLAGS=	-I. -IInclude -I$(srcdir)/Include @CPPFLAGS@
-LDFLAGS=	@LDFLAGS@
+PY_CPPFLAGS=	-I. -IInclude -I$(srcdir)/Include $(CONFIGURE_CPPFLAGS) $(CPPFLAGS)
+PY_LDFLAGS=	$(CONFIGURE_LDFLAGS) $(LDFLAGS)
 LDLAST=		@LDLAST@
 SGI_ABI=	@SGI_ABI@
 CCSHARED=	@CCSHARED@
@@ -73,7 +79,7 @@
 # Extra C flags added for building the interpreter object files.
 CFLAGSFORSHARED=@CFLAGSFORSHARED@
 # C flags used for building the interpreter object files
-PY_CFLAGS=	$(CFLAGS) $(CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
+PY_CORE_CFLAGS=	$(PY_CFLAGS) $(PY_CPPFLAGS) $(CFLAGSFORSHARED) -DPy_BUILD_CORE
 
 
 # Machine-dependent subdirectories
@@ -411,7 +417,7 @@
 
 # Build the interpreter
 $(BUILDPYTHON):	Modules/python.o $(LIBRARY) $(LDLIBRARY)
-		$(LINKCC) $(LDFLAGS) $(LINKFORSHARED) -o $@ \
+		$(LINKCC) $(PY_LDFLAGS) $(LINKFORSHARED) -o $@ \
 			Modules/python.o \
 			$(BLDLIBRARY) $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST)
 
@@ -422,8 +428,8 @@
 # Build the shared modules
 sharedmods: $(BUILDPYTHON)
 	@case $$MAKEFLAGS in \
-	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
-	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
+	*s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(PY_LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \
+	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(PY_LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
 	esac
 
 # Build static library
@@ -440,18 +446,18 @@
 
 libpython$(VERSION).so: $(LIBRARY_OBJS)
 	if test $(INSTSONAME) != $(LDLIBRARY); then \
-		$(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+		$(LDSHARED) $(PY_LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
 		$(LN) -f $(INSTSONAME) $@; \
 	else \
-		$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+		$(LDSHARED) $(PY_LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
 	fi
 
 libpython$(VERSION).dylib: $(LIBRARY_OBJS)
-	 $(CC) -dynamiclib -Wl,-single_module $(LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
+	 $(CC) -dynamiclib -Wl,-single_module $(PY_LDFLAGS) -undefined dynamic_lookup -Wl,-install_name,$(prefix)/lib/libpython$(VERSION).dylib -Wl,-compatibility_version,$(VERSION) -Wl,-current_version,$(VERSION) -o $@ $(LIBRARY_OBJS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
 		 
 
 libpython$(VERSION).sl: $(LIBRARY_OBJS)
-	$(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
+	$(LDSHARED) $(PY_LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST)
 
 # Copy up the gdb python hooks into a position where they can be automatically
 # loaded by gdb during Lib/test/test_gdb.py
@@ -497,7 +503,7 @@
 # for a shared core library; otherwise, this rule is a noop.
 $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS)
 	if test -n "$(DLLLIBRARY)"; then \
-		$(LDSHARED) $(LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
+		$(LDSHARED) $(PY_LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \
 			$(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \
 	else true; \
 	fi
@@ -541,10 +547,10 @@
 		$(SIGNAL_OBJS) \
 		$(MODOBJS) \
 		$(srcdir)/Modules/getbuildinfo.c
-	$(CC) -c $(PY_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c
+	$(CC) -c $(PY_CORE_CFLAGS) -DSVNVERSION="\"`LC_ALL=C $(SVNVERSION)`\"" -o $@ $(srcdir)/Modules/getbuildinfo.c
 
 Modules/getpath.o: $(srcdir)/Modules/getpath.c Makefile
-	$(CC) -c $(PY_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
+	$(CC) -c $(PY_CORE_CFLAGS) -DPYTHONPATH='"$(PYTHONPATH)"' \
 		-DPREFIX='"$(prefix)"' \
 		-DEXEC_PREFIX='"$(exec_prefix)"' \
 		-DVERSION='"$(VERSION)"' \
@@ -552,7 +558,7 @@
 		-o $@ $(srcdir)/Modules/getpath.c
 
 Modules/python.o: $(srcdir)/Modules/python.c
-	$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
+	$(MAINCC) -c $(PY_CORE_CFLAGS) -o $@ $(srcdir)/Modules/python.c
 
 $(IO_OBJS): $(IO_H)
 
@@ -561,7 +567,7 @@
 		-$(PGEN) $(GRAMMAR_INPUT) $(GRAMMAR_H) $(GRAMMAR_C)
 
 $(PGEN):	$(PGENOBJS)
-		$(CC) $(OPT) $(LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
+		$(CC) $(OPT) $(PY_LDFLAGS) $(PGENOBJS) $(LIBS) -o $(PGEN)
 
 Parser/grammar.o:	$(srcdir)/Parser/grammar.c \
 				$(srcdir)/Include/token.h \
@@ -581,10 +587,10 @@
 Python/compile.o Python/symtable.o Python/ast.o: $(GRAMMAR_H) $(AST_H)
 
 Python/getplatform.o: $(srcdir)/Python/getplatform.c
-		$(CC) -c $(PY_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
+		$(CC) -c $(PY_CORE_CFLAGS) -DPLATFORM='"$(MACHDEP)"' -o $@ $(srcdir)/Python/getplatform.c
 
 Python/importdl.o: $(srcdir)/Python/importdl.c
-		$(CC) -c $(PY_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
+		$(CC) -c $(PY_CORE_CFLAGS) -I$(DLINCLDIR) -o $@ $(srcdir)/Python/importdl.c
 
 Objects/unicodectype.o:	$(srcdir)/Objects/unicodectype.c \
 				$(srcdir)/Objects/unicodetype_db.h
@@ -1039,7 +1045,7 @@
 
 # Install the dynamically loadable modules
 # This goes into $(exec_prefix)
-sharedinstall:
+sharedinstall: sharedmods
 	$(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
 	   	--prefix=$(prefix) \
 		--install-scripts=$(BINDIR) \
@@ -1130,7 +1136,7 @@
 
 # Some make's put the object file in the current directory
 .c.o:
-	$(CC) -c $(PY_CFLAGS) -o $@ $<
+	$(CC) -c $(PY_CORE_CFLAGS) -o $@ $<
 
 # Run reindent on the library
 reindent:

Modified: python/branches/import_unicode/Misc/ACKS
==============================================================================
--- python/branches/import_unicode/Misc/ACKS	(original)
+++ python/branches/import_unicode/Misc/ACKS	Fri Jul 30 01:19:37 2010
@@ -63,6 +63,7 @@
 Ben Bell
 Thomas Bellman
 Alexander Belopolsky
+Eli Bendersky
 Andrew Bennetts
 Andy Bensky
 Michel Van den Bergh
@@ -97,6 +98,7 @@
 Georg Brandl
 Christopher Brannon
 Terrence Brannon
+Brian Brazil
 Dave Brennan
 Tom Bridgman
 Richard Brodie
@@ -128,6 +130,7 @@
 Per Cederqvist
 Octavian Cerna
 Pascal Chambon
+John Chandler
 Hye-Shik Chang
 Jeffrey Chang
 Mitch Chapman
@@ -145,6 +148,7 @@
 Vadim Chugunov
 David Cinege
 Mike Clarkson
+Andrew Clegg
 Brad Clements
 Steve Clift
 Nick Coghlan
@@ -154,11 +158,11 @@
 Jeffery Collins
 Robert Collins
 Paul Colomiets
-Jason R. Coombs
 Geremy Condra
 Juan José Conti
 Matt Conway
 David M. Cooke
+Jason R. Coombs
 Greg Copeland
 Aldo Cortesi
 David Costanzo
@@ -444,6 +448,7 @@
 Vladimir Kushnir
 Cameron Laird
 Torsten Landschoff
+Łukasz Langa
 Tino Lange
 Andrew Langmead
 Detlef Lannert
@@ -453,6 +458,7 @@
 Simon Law
 Chris Lawrence
 Brian Leair
+James Lee
 John J. Lee
 Inyeol Lee
 Thomas Lee
@@ -473,6 +479,7 @@
 Ross Light
 Shawn Ligocki
 Martin Ligr
+Grant Limberg
 Christopher Lindblad
 Bjorn Lindqvist
 Per Lindqvist

Modified: python/branches/import_unicode/Misc/NEWS
==============================================================================
--- python/branches/import_unicode/Misc/NEWS	(original)
+++ python/branches/import_unicode/Misc/NEWS	Fri Jul 30 01:19:37 2010
@@ -12,6 +12,11 @@
 Core and Builtins
 -----------------
 
+- Issue #8991: convertbuffer() rejects discontigious buffers.
+
+- Issue #7616: Fix copying of overlapping memoryview slices with the Intel
+  compiler.
+
 - Issue #8413: structsequence now subclasses tuple.
 
 - Issue #8271: during the decoding of an invalid UTF-8 byte sequence, only the
@@ -470,6 +475,87 @@
 Library
 -------
 
+- Issue #4108: In urllib.robotparser, if there are multiple 'User-agent: *'
+  entries, consider the first one.
+
+- Issue #6630: Allow customizing regex flags when subclassing the
+  string.Template class.
+
+- Issue #9411: Allow specifying an encoding for config files in the
+  configparser module.
+
+- Issue #1682942: Improvements to configparser: support alternate
+  delimiters, alternate comment prefixes and empty lines in values.
+
+- Issue #9354: Provide getsockopt() in asyncore's file_wrapper.
+
+- Issue #8966: ctypes: Remove implicit bytes-unicode conversion.
+
+- Issue #9378: python -m pickle <pickle file> will now load and
+  display the first object in the pickle file.
+
+- Issue #4770: Restrict binascii module to accept only bytes (as specified).
+  And fix the email package to encode to ASCII instead of
+  ``raw-unicode-escape`` before ASCII-to-binary decoding.
+
+- Issue #9384: python -m tkinter will now display a simple demo applet.
+
+- The default size of the re module's compiled regular expression cache has
+  been increased from 100 to 500 and the cache replacement policy has changed
+  from simply clearing the entire cache on overflow to randomly forgetting 20%
+  of the existing cached compiled regular expressions.  This is a performance
+  win for applications that use a lot of regular expressions and limits the
+  impact of the performance hit anytime the cache is exceeded.
+
+- Issue #7113: Speed up loading in configparser. Patch by Łukasz Langa.
+
+- Issue #9032: XML-RPC client retries the request on EPIPE error. The EPIPE
+  error occurs when the server closes the socket and the client sends a big
+  XML-RPC request.
+
+- Issue #4629: getopt raises an error if an argument ends with = whereas getopt
+  doesn't except a value (eg. --help= is rejected if getopt uses ['help='] long
+  options).
+
+- Issue #7989: Added pure python implementation of the `datetime`
+  module.  The C module is renamed to `_datetime` and if available,
+  overrides all classes defined in datetime with fast C impementation.
+  Python implementation is based on the original python prototype for
+  the datetime module by Tim Peters with minor modifications by the
+  PyPy project.  The test suite now tests `datetime` module with and
+  without `_datetime` acceleration using the same test cases.
+
+- Issue #7895: platform.mac_ver() no longer crashes after calling os.fork()
+
+- Issue #9323: Fixed a bug in trace.py that resulted in loosing the
+  name of the script being traced.  Patch by Eli Bendersky.
+
+- Issue #9282: Fixed --listfuncs option of trace.py.  Thanks Eli
+  Bendersky for the patch.
+
+- Issue #3704: http.cookiejar was not properly handling URLs with a / in the
+  parameters.
+
+- Issue #9268: ``pickletools.dis()`` now has an optional *annotate*
+  argument which controls printing of opcode descriptions in ``dis()``
+  output.
+
+- Issue #1555570: email no longer inserts extra blank lines when a \r\n
+  combo crosses an 8192 byte boundary.
+
+- Issue #9243: Fix sndhdr module and add unit tests, contributed by James Lee.
+
+- ``ast.literal_eval()`` now allows byte literals.
+
+- Issue #9137: Fix issue in MutableMapping.update, which incorrectly
+  treated keyword arguments called 'self' or 'other' specially.
+
+- ``ast.literal_eval()`` now allows set literals.
+
+- Issue #9164: Ensure that sysconfig handles duplicate -arch flags in CFLAGS.
+
+- Issue #7646: The fnmatch pattern cache no longer grows without bound.
+
 - Issue #9136: Fix 'dictionary changed size during iteration'
   RuntimeError produced when profiling the decimal module.  This was
   due to a dangerous iteration over 'locals()' in Context.__init__.
@@ -1406,6 +1492,28 @@
 Extension Modules
 -----------------
 
+- Issue #9422: Fix memory leak when re-initializing a struct.Struct object.
+
+- Issue #7900: The getgroups(2) system call on MacOSX behaves rather oddly
+  compared to other unix systems. In particular, os.getgroups() does
+  not reflect any changes made using os.setgroups() but basicly always
+  returns the same information as the id command.
+
+  os.getgroups() can now return more than 16 groups on MacOSX.
+
+- Issue #6095: Make directory argument to os.listdir optional.
+
+- Issue #9277: Fix bug in struct.pack for bools in standard mode
+  (e.g., struct.pack('>?')):  if conversion to bool raised an exception
+  then that exception wasn't properly propagated on machines where
+  char is unsigned.
+
+- Issue #5180: Fixed a bug that prevented loading 2.x pickles in 3.x
+  python when they contain instances of old-style classes.
+
+- Issue #9165: Add new functions math.isfinite and cmath.isfinite, to
+  accompany existing isinf and isnan functions.
+
 - Issue #1578269: Implement os.symlink for Windows 6.0+. Patch by
   Jason R. Coombs
 
@@ -1528,6 +1636,14 @@
 Build
 -----
 
+- Issue #9280: Make sharedinstall depend on sharedmods.
+
+- Issue #9189: Make a user-specified CFLAGS, CPPFLAGS, or LDFLAGS
+  setting override the configure and makefile defaults, without
+  deleting options the user didn't intend to override.  Developers
+  should no longer need to specify OPT or EXTRA_CFLAGS, although those
+  variables are still present for backward-compatibility.
+
 - Issue #8854: Fix finding Visual Studio 2008 on Windows x64.
 
 - Issue #1759169, #8864: Drop _XOPEN_SOURCE on Solaris, define it for
@@ -1604,6 +1720,9 @@
 Documentation
 ------------
 
+- Issue 9255: Document that the 'test' package is meant for internal Python use
+  only.
+
 - A small wsgi server was added as Tools/scripts/serve.py, and is used to
   implement a local documentation server via 'make serve' in the doc directory.
 
@@ -1625,6 +1744,9 @@
 Tests
 -----
 
+- Issue #9251: test_threaded_import didn't fail when run through regrtest
+  if the import lock was disabled.
+
 - Issue #8605: Skip test_gdb if Python is compiled with optimizations.
 
 - Issue #7449: Skip test_socketserver if threading support is disabled
@@ -1755,7 +1877,7 @@
 Tools/Demos
 -----------
 
-- Issue #5464: Implement plural forms in msgfmt.py.
+- Issue #5464, #8974: Implement plural forms in msgfmt.py.
 
 - iobench (a file I/O benchmark) and ccbench (a concurrency benchmark) were
   added to the `Tools/` directory.  They were previously living in the

Modified: python/branches/import_unicode/Misc/developers.txt
==============================================================================
--- python/branches/import_unicode/Misc/developers.txt	(original)
+++ python/branches/import_unicode/Misc/developers.txt	Fri Jul 30 01:19:37 2010
@@ -20,6 +20,13 @@
 Permissions History
 -------------------
 
+- Brian Quinlan was given commit access on Jul 26 2010 by GFB,
+  for work related to PEP 3148.
+
+- Reid Kleckner was given commit access on Jul 11 2010 by GFB,
+  for work on the py3k-jit branch, at suggestion of the Unladen
+  Swallow team.
+
 - Alexander Belopolsky was given commit access on May 25 2010
   by MvL at suggestion of Mark Dickinson.
 

Modified: python/branches/import_unicode/Misc/maintainers.rst
==============================================================================
--- python/branches/import_unicode/Misc/maintainers.rst	(original)
+++ python/branches/import_unicode/Misc/maintainers.rst	Fri Jul 30 01:19:37 2010
@@ -89,7 +89,7 @@
 doctest             tim_one (inactive)
 dummy_threading     brett.cannon
 email               barry, r.david.murray
-encodings           lemburg, loewis
+encodings           lemburg
 errno
 exceptions
 fcntl
@@ -104,7 +104,7 @@
 gc                  pitrou
 getopt
 getpass
-gettext             loewis
+gettext
 glob
 grp
 gzip
@@ -125,7 +125,7 @@
 keyword
 lib2to3             benjamin.peterson
 linecache
-locale              loewis, lemburg
+locale              lemburg
 logging             vsajip
 macpath
 mailbox             andrew.kuchling
@@ -135,7 +135,7 @@
 mimetypes
 mmap
 modulefinder        theller, jvr
-msilib              loewis
+msilib
 msvcrt
 multiprocessing     jnoller
 netrc
@@ -144,7 +144,7 @@
 numbers
 operator
 optparse            aronacher
-os                  loewis
+os
 ossaudiodev
 parser
 pdb
@@ -212,12 +212,12 @@
 tkinter             gpolo
 token               georg.brandl
 tokenize
-trace
+trace               alexander.belopolsky
 traceback           georg.brandl
 tty
 turtle              gregorlingl
 types
-unicodedata         loewis, lemburg, ezio.melotti
+unicodedata         lemburg, ezio.melotti
 unittest            michael.foord
 urllib              orsenthil
 uu
@@ -226,13 +226,13 @@
 wave
 weakref             fdrake
 webbrowser          georg.brandl
-winreg
+winreg              brian.curtin
 winsound            effbot (inactive)
 wsgiref             pje
 xdrlib
-xml                 loewis
+xml
 xml.etree           effbot (inactive)
-xmlrpc              loewis
+xmlrpc
 zipfile
 zipimport
 zlib
@@ -277,13 +277,13 @@
 i18n                lemburg
 import machinery    brett.cannon, ncoghlan
 io                  pitrou, benjamin.peterson
-locale              lemburg, loewis
+locale              lemburg
 mathematics         mark.dickinson, eric.smith, lemburg
 memory management   tim_one, lemburg
 networking          giampaolo.rodola
 packaging           tarek, lemburg
 py3 transition      benjamin.peterson
-release management  tarek, lemburg, benjamin.peterson, barry, loewis,
+release management  tarek, lemburg, benjamin.peterson, barry,
                     gvanrossum, anthonybaxter
 str.format          eric.smith
 time and dates      lemburg

Modified: python/branches/import_unicode/Misc/python-wing.wpr
==============================================================================
--- python/branches/import_unicode/Misc/python-wing.wpr	(original)
+++ python/branches/import_unicode/Misc/python-wing.wpr	Fri Jul 30 01:19:37 2010
@@ -5,7 +5,7 @@
 ##################################################################
 [project attributes]
 proj.directory-list = [{'dirloc': loc('..'),
-                        'excludes': (),
+                        'excludes': [u'Lib/__pycache__'],
                         'filter': '*',
                         'include_hidden': False,
                         'recursive': True,

Modified: python/branches/import_unicode/Modules/Setup.dist
==============================================================================
--- python/branches/import_unicode/Modules/Setup.dist	(original)
+++ python/branches/import_unicode/Modules/Setup.dist	Fri Jul 30 01:19:37 2010
@@ -170,7 +170,7 @@
 #atexit atexitmodule.c      # Register functions to be run at interpreter-shutdown
 #_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c	# elementtree accelerator
 #_pickle _pickle.c	# pickle accelerator
-#datetime datetimemodule.c	# date/time type
+#_datetime _datetimemodule.c	# datetime accelerator
 #_bisect _bisectmodule.c	# Bisection algorithms
 #_heapq _heapqmodule.c	# Heap queue algorithm
 

Modified: python/branches/import_unicode/Modules/_ctypes/_ctypes.c
==============================================================================
--- python/branches/import_unicode/Modules/_ctypes/_ctypes.c	(original)
+++ python/branches/import_unicode/Modules/_ctypes/_ctypes.c	Fri Jul 30 01:19:37 2010
@@ -132,8 +132,6 @@
 /* a callable object used for unpickling */
 static PyObject *_unpickle;
 
-char *_ctypes_conversion_encoding = NULL;
-char *_ctypes_conversion_errors = NULL;
 
 
 /****************************************************************/
@@ -1090,13 +1088,7 @@
         return -1;
     }
 
-    if (PyUnicode_Check(value)) {
-        value = PyUnicode_AsEncodedString(value,
-                                          _ctypes_conversion_encoding,
-                                          _ctypes_conversion_errors);
-        if (!value)
-            return -1;
-    } else if (!PyBytes_Check(value)) {
+    if (!PyBytes_Check(value)) {
         PyErr_Format(PyExc_TypeError,
                      "str/bytes expected instead of %s instance",
                      Py_TYPE(value)->tp_name);
@@ -1150,13 +1142,7 @@
                         "can't delete attribute");
         return -1;
     }
-    if (PyBytes_Check(value)) {
-        value = PyUnicode_FromEncodedObject(value,
-                                            _ctypes_conversion_encoding,
-                                            _ctypes_conversion_errors);
-        if (!value)
-            return -1;
-    } else if (!PyUnicode_Check(value)) {
+    if (!PyUnicode_Check(value)) {
         PyErr_Format(PyExc_TypeError,
                         "unicode string expected instead of %s instance",
                         Py_TYPE(value)->tp_name);
@@ -1510,7 +1496,7 @@
         Py_INCREF(Py_None);
         return Py_None;
     }
-    if (PyBytes_Check(value) || PyUnicode_Check(value)) {
+    if (PyBytes_Check(value)) {
         PyCArgObject *parg;
         struct fielddesc *fd = _ctypes_get_fielddesc("z");
 

Modified: python/branches/import_unicode/Modules/_ctypes/callproc.c
==============================================================================
--- python/branches/import_unicode/Modules/_ctypes/callproc.c	(original)
+++ python/branches/import_unicode/Modules/_ctypes/callproc.c	Fri Jul 30 01:19:37 2010
@@ -1641,37 +1641,6 @@
     return arg;
 }
 
-#ifdef CTYPES_UNICODE
-
-static char set_conversion_mode_doc[] =
-"set_conversion_mode(encoding, errors) -> (previous-encoding, previous-errors)\n\
-\n\
-Set the encoding and error handling ctypes uses when converting\n\
-between unicode and strings.  Returns the previous values.\n";
-
-static PyObject *
-set_conversion_mode(PyObject *self, PyObject *args)
-{
-    char *coding, *mode;
-    PyObject *result;
-
-    if (!PyArg_ParseTuple(args, "zs:set_conversion_mode", &coding, &mode))
-        return NULL;
-    result = Py_BuildValue("(zz)", _ctypes_conversion_encoding, _ctypes_conversion_errors);
-    if (coding) {
-        PyMem_Free(_ctypes_conversion_encoding);
-        _ctypes_conversion_encoding = PyMem_Malloc(strlen(coding) + 1);
-        strcpy(_ctypes_conversion_encoding, coding);
-    } else {
-        _ctypes_conversion_encoding = NULL;
-    }
-    PyMem_Free(_ctypes_conversion_errors);
-    _ctypes_conversion_errors = PyMem_Malloc(strlen(mode) + 1);
-    strcpy(_ctypes_conversion_errors, mode);
-    return result;
-}
-#endif
-
 static PyObject *
 resize(PyObject *self, PyObject *args)
 {
@@ -1852,9 +1821,6 @@
     {"_unpickle", unpickle, METH_VARARGS },
     {"buffer_info", buffer_info, METH_O, "Return buffer interface information"},
     {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"},
-#ifdef CTYPES_UNICODE
-    {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc},
-#endif
 #ifdef MS_WIN32
     {"get_last_error", get_last_error, METH_NOARGS},
     {"set_last_error", set_last_error, METH_VARARGS},

Modified: python/branches/import_unicode/Modules/_ctypes/cfield.c
==============================================================================
--- python/branches/import_unicode/Modules/_ctypes/cfield.c	(original)
+++ python/branches/import_unicode/Modules/_ctypes/cfield.c	Fri Jul 30 01:19:37 2010
@@ -1168,20 +1168,6 @@
 static PyObject *
 c_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
-    if (PyUnicode_Check(value)) {
-        value = PyUnicode_AsEncodedString(value,
-                                          _ctypes_conversion_encoding,
-                                          _ctypes_conversion_errors);
-        if (value == NULL)
-            return NULL;
-        if (PyBytes_GET_SIZE(value) != 1) {
-            Py_DECREF(value);
-            goto error;
-        }
-        *(char *)ptr = PyBytes_AS_STRING(value)[0];
-        Py_DECREF(value);
-        _RET(value);
-    }
     if (PyBytes_Check(value) && PyBytes_GET_SIZE(value) == 1) {
         *(char *)ptr = PyBytes_AS_STRING(value)[0];
         _RET(value);
@@ -1217,13 +1203,7 @@
 u_set(void *ptr, PyObject *value, Py_ssize_t size)
 {
     Py_ssize_t len;
-    if (PyBytes_Check(value)) {
-        value = PyUnicode_FromEncodedObject(value,
-                                            _ctypes_conversion_encoding,
-                                            _ctypes_conversion_errors);
-        if (!value)
-            return NULL;
-    } else if (!PyUnicode_Check(value)) {
+    if (!PyUnicode_Check(value)) {
         PyErr_Format(PyExc_TypeError,
                         "unicode string expected instead of %s instance",
                         value->ob_type->tp_name);
@@ -1292,13 +1272,7 @@
     /* It's easier to calculate in characters than in bytes */
     length /= sizeof(wchar_t);
 
-    if (PyBytes_Check(value)) {
-        value = PyUnicode_FromEncodedObject(value,
-                                            _ctypes_conversion_encoding,
-                                            _ctypes_conversion_errors);
-        if (!value)
-            return NULL;
-    } else if (!PyUnicode_Check(value)) {
+    if (!PyUnicode_Check(value)) {
         PyErr_Format(PyExc_TypeError,
                         "unicode string expected instead of %s instance",
                         value->ob_type->tp_name);
@@ -1342,14 +1316,7 @@
     char *data;
     Py_ssize_t size;
 
-    if (PyUnicode_Check(value)) {
-        value = PyUnicode_AsEncodedString(value,
-                                                                          _ctypes_conversion_encoding,
-                                                                          _ctypes_conversion_errors);
-        if (value == NULL)
-            return NULL;
-        assert(PyBytes_Check(value));
-    } else if(PyBytes_Check(value)) {
+    if(PyBytes_Check(value)) {
         Py_INCREF(value);
     } else {
         PyErr_Format(PyExc_TypeError,
@@ -1393,14 +1360,6 @@
         *(char **)ptr = PyBytes_AsString(value);
         Py_INCREF(value);
         return value;
-    } else if (PyUnicode_Check(value)) {
-        PyObject *str = PyUnicode_AsEncodedString(value,
-                                                  _ctypes_conversion_encoding,
-                                                  _ctypes_conversion_errors);
-        if (str == NULL)
-            return NULL;
-        *(char **)ptr = PyBytes_AS_STRING(str);
-        return str;
     } else if (PyLong_Check(value)) {
 #if SIZEOF_VOID_P == SIZEOF_LONG_LONG
         *(char **)ptr = (char *)PyLong_AsUnsignedLongLongMask(value);
@@ -1454,13 +1413,7 @@
         Py_INCREF(Py_None);
         return Py_None;
     }
-    if (PyBytes_Check(value)) {
-        value = PyUnicode_FromEncodedObject(value,
-                                            _ctypes_conversion_encoding,
-                                            _ctypes_conversion_errors);
-        if (!value)
-            return NULL;
-    } else if (!PyUnicode_Check(value)) {
+    if (!PyUnicode_Check(value)) {
         PyErr_Format(PyExc_TypeError,
                      "unicode string or integer address expected instead of %s instance",
                      value->ob_type->tp_name);
@@ -1540,12 +1493,6 @@
     /* convert value into a PyUnicodeObject or NULL */
     if (Py_None == value) {
         value = NULL;
-    } else if (PyBytes_Check(value)) {
-        value = PyUnicode_FromEncodedObject(value,
-                                            _ctypes_conversion_encoding,
-                                            _ctypes_conversion_errors);
-        if (!value)
-            return NULL;
     } else if (PyUnicode_Check(value)) {
         Py_INCREF(value); /* for the descref below */
     } else {

Modified: python/branches/import_unicode/Modules/_io/_iomodule.c
==============================================================================
--- python/branches/import_unicode/Modules/_io/_iomodule.c	(original)
+++ python/branches/import_unicode/Modules/_io/_iomodule.c	Fri Jul 30 01:19:37 2010
@@ -176,7 +176,7 @@
  * The main open() function
  */
 PyDoc_STRVAR(open_doc,
-"open(file, mode='r', buffering=None, encoding=None,\n"
+"open(file, mode='r', buffering=-1, encoding=None,\n"
 "     errors=None, newline=None, closefd=True) -> file object\n"
 "\n"
 "Open file and return a stream.  Raise IOError upon failure.\n"

Modified: python/branches/import_unicode/Modules/_json.c
==============================================================================
--- python/branches/import_unicode/Modules/_json.c	(original)
+++ python/branches/import_unicode/Modules/_json.c	Fri Jul 30 01:19:37 2010
@@ -1454,7 +1454,7 @@
         }
         else {
             /* TODO: include repr of key */
-            PyErr_SetString(PyExc_ValueError, "keys must be a string");
+            PyErr_SetString(PyExc_TypeError, "keys must be a string");
             goto bail;
         }
 

Modified: python/branches/import_unicode/Modules/_pickle.c
==============================================================================
--- python/branches/import_unicode/Modules/_pickle.c	(original)
+++ python/branches/import_unicode/Modules/_pickle.c	Fri Jul 30 01:19:37 2010
@@ -3466,29 +3466,19 @@
 static PyObject *
 instantiate(PyObject *cls, PyObject *args)
 {
-    PyObject *r = NULL;
-
-    /* XXX: The pickle.py module does not create instances this way when the
-       args tuple is empty. See Unpickler._instantiate(). */
-    if ((r = PyObject_CallObject(cls, args)))
-        return r;
-
-    /* XXX: Is this still nescessary? */
-    {
-        PyObject *tp, *v, *tb, *tmp_value;
-
-        PyErr_Fetch(&tp, &v, &tb);
-        tmp_value = v;
-        /* NULL occurs when there was a KeyboardInterrupt */
-        if (tmp_value == NULL)
-            tmp_value = Py_None;
-        if ((r = PyTuple_Pack(3, tmp_value, cls, args))) {
-            Py_XDECREF(v);
-            v = r;
-        }
-        PyErr_Restore(tp, v, tb);
+    PyObject *result = NULL;
+    /* Caller must assure args are a tuple.  Normally, args come from
+       Pdata_poptuple which packs objects from the top of the stack
+       into a newly created tuple. */
+    assert(PyTuple_Check(args));
+    if (Py_SIZE(args) > 0 || !PyType_Check(cls) ||
+        PyObject_HasAttrString(cls, "__getinitargs__")) {
+        result = PyObject_CallObject(cls, args);
+    }
+    else {
+        result = PyObject_CallMethod(cls, "__new__", "O", cls);
     }
-    return NULL;
+    return result;
 }
 
 static int
@@ -3547,7 +3537,7 @@
         if (len < 2)
             return bad_readline();
         class_name = PyUnicode_DecodeASCII(s, len - 1, "strict");
-        if (class_name == NULL) {
+        if (class_name != NULL) {
             cls = find_class(self, module_name, class_name);
             Py_DECREF(class_name);
         }
@@ -4276,7 +4266,7 @@
         return -1;
     PDATA_POP(self->stack, callable);
     if (callable) {
-        obj = instantiate(callable, argtup);
+        obj = PyObject_CallObject(callable, argtup);
         Py_DECREF(callable);
     }
     Py_DECREF(argtup);

Modified: python/branches/import_unicode/Modules/_struct.c
==============================================================================
--- python/branches/import_unicode/Modules/_struct.c	(original)
+++ python/branches/import_unicode/Modules/_struct.c	Fri Jul 30 01:19:37 2010
@@ -867,11 +867,11 @@
 static int
 bp_bool(char *p, PyObject *v, const formatdef *f)
 {
-    char y;
+    int y;
     y = PyObject_IsTrue(v);
     if (y < 0)
         return -1;
-    memcpy(p, (char *)&y, sizeof y);
+    *p = (char)y;
     return 0;
 }
 
@@ -1247,6 +1247,9 @@
         PyErr_NoMemory();
         return -1;
     }
+    /* Free any s_codes value left over from a previous initialization. */
+    if (self->s_codes != NULL)
+        PyMem_FREE(self->s_codes);
     self->s_codes = codes;
 
     s = fmt;

Modified: python/branches/import_unicode/Modules/binascii.c
==============================================================================
--- python/branches/import_unicode/Modules/binascii.c	(original)
+++ python/branches/import_unicode/Modules/binascii.c	Fri Jul 30 01:19:37 2010
@@ -546,7 +546,7 @@
     Py_ssize_t len;
     int done = 0;
 
-    if ( !PyArg_ParseTuple(args, "s*:a2b_hqx", &pascii) )
+    if ( !PyArg_ParseTuple(args, "y*:a2b_hqx", &pascii) )
         return NULL;
     ascii_data = pascii.buf;
     len = pascii.len;
@@ -750,7 +750,7 @@
     PyObject *rv;
     Py_ssize_t in_len, out_len, out_len_left;
 
-    if ( !PyArg_ParseTuple(args, "s*:rledecode_hqx", &pin) )
+    if ( !PyArg_ParseTuple(args, "y*:rledecode_hqx", &pin) )
         return NULL;
     in_data = pin.buf;
     in_len = pin.len;
@@ -1121,7 +1121,7 @@
     char* retbuf;
     Py_ssize_t i, j;
 
-    if (!PyArg_ParseTuple(args, "s*:a2b_hex", &parg))
+    if (!PyArg_ParseTuple(args, "y*:a2b_hex", &parg))
         return NULL;
     argbuf = parg.buf;
     arglen = parg.len;
@@ -1199,7 +1199,7 @@
     static char *kwlist[] = {"data", "header", NULL};
     int header = 0;
 
-    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|i", kwlist, &pdata,
+    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i", kwlist, &pdata,
           &header))
         return NULL;
     data = pdata.buf;

Modified: python/branches/import_unicode/Modules/cmathmodule.c
==============================================================================
--- python/branches/import_unicode/Modules/cmathmodule.c	(original)
+++ python/branches/import_unicode/Modules/cmathmodule.c	Fri Jul 30 01:19:37 2010
@@ -1024,6 +1024,19 @@
 Convert from polar coordinates to rectangular coordinates.");
 
 static PyObject *
+cmath_isfinite(PyObject *self, PyObject *args)
+{
+    Py_complex z;
+    if (!PyArg_ParseTuple(args, "D:isfinite", &z))
+        return NULL;
+    return PyBool_FromLong(Py_IS_FINITE(z.real) && Py_IS_FINITE(z.imag));
+}
+
+PyDoc_STRVAR(cmath_isfinite_doc,
+"isfinite(z) -> bool\n\
+Return True if both the real and imaginary parts of z are finite, else False.");
+
+static PyObject *
 cmath_isnan(PyObject *self, PyObject *args)
 {
     Py_complex z;
@@ -1065,6 +1078,7 @@
     {"cos",    cmath_cos,   METH_VARARGS, c_cos_doc},
     {"cosh",   cmath_cosh,  METH_VARARGS, c_cosh_doc},
     {"exp",    cmath_exp,   METH_VARARGS, c_exp_doc},
+    {"isfinite", cmath_isfinite, METH_VARARGS, cmath_isfinite_doc},
     {"isinf",  cmath_isinf, METH_VARARGS, cmath_isinf_doc},
     {"isnan",  cmath_isnan, METH_VARARGS, cmath_isnan_doc},
     {"log",    cmath_log,   METH_VARARGS, cmath_log_doc},

Deleted: python/branches/import_unicode/Modules/datetimemodule.c
==============================================================================
--- python/branches/import_unicode/Modules/datetimemodule.c	Fri Jul 30 01:19:37 2010
+++ (empty file)
@@ -1,5488 +0,0 @@
-/*  C implementation for the date/time type documented at
- *  http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage
- */
-
-#include "Python.h"
-#include "modsupport.h"
-#include "structmember.h"
-
-#include <time.h>
-
-#include "timefuncs.h"
-
-/* Differentiate between building the core module and building extension
- * modules.
- */
-#ifndef Py_BUILD_CORE
-#define Py_BUILD_CORE
-#endif
-#include "datetime.h"
-#undef Py_BUILD_CORE
-
-/* We require that C int be at least 32 bits, and use int virtually
- * everywhere.  In just a few cases we use a temp long, where a Python
- * API returns a C long.  In such cases, we have to ensure that the
- * final result fits in a C int (this can be an issue on 64-bit boxes).
- */
-#if SIZEOF_INT < 4
-#       error "datetime.c requires that C int have at least 32 bits"
-#endif
-
-#define MINYEAR 1
-#define MAXYEAR 9999
-#define MAXORDINAL 3652059 /* date(9999,12,31).toordinal() */
-
-/* Nine decimal digits is easy to communicate, and leaves enough room
- * so that two delta days can be added w/o fear of overflowing a signed
- * 32-bit int, and with plenty of room left over to absorb any possible
- * carries from adding seconds.
- */
-#define MAX_DELTA_DAYS 999999999
-
-/* Rename the long macros in datetime.h to more reasonable short names. */
-#define GET_YEAR                PyDateTime_GET_YEAR
-#define GET_MONTH               PyDateTime_GET_MONTH
-#define GET_DAY                 PyDateTime_GET_DAY
-#define DATE_GET_HOUR           PyDateTime_DATE_GET_HOUR
-#define DATE_GET_MINUTE         PyDateTime_DATE_GET_MINUTE
-#define DATE_GET_SECOND         PyDateTime_DATE_GET_SECOND
-#define DATE_GET_MICROSECOND    PyDateTime_DATE_GET_MICROSECOND
-
-/* Date accessors for date and datetime. */
-#define SET_YEAR(o, v)          (((o)->data[0] = ((v) & 0xff00) >> 8), \
-                 ((o)->data[1] = ((v) & 0x00ff)))
-#define SET_MONTH(o, v)         (PyDateTime_GET_MONTH(o) = (v))
-#define SET_DAY(o, v)           (PyDateTime_GET_DAY(o) = (v))
-
-/* Date/Time accessors for datetime. */
-#define DATE_SET_HOUR(o, v)     (PyDateTime_DATE_GET_HOUR(o) = (v))
-#define DATE_SET_MINUTE(o, v)   (PyDateTime_DATE_GET_MINUTE(o) = (v))
-#define DATE_SET_SECOND(o, v)   (PyDateTime_DATE_GET_SECOND(o) = (v))
-#define DATE_SET_MICROSECOND(o, v)      \
-    (((o)->data[7] = ((v) & 0xff0000) >> 16), \
-     ((o)->data[8] = ((v) & 0x00ff00) >> 8), \
-     ((o)->data[9] = ((v) & 0x0000ff)))
-
-/* Time accessors for time. */
-#define TIME_GET_HOUR           PyDateTime_TIME_GET_HOUR
-#define TIME_GET_MINUTE         PyDateTime_TIME_GET_MINUTE
-#define TIME_GET_SECOND         PyDateTime_TIME_GET_SECOND
-#define TIME_GET_MICROSECOND    PyDateTime_TIME_GET_MICROSECOND
-#define TIME_SET_HOUR(o, v)     (PyDateTime_TIME_GET_HOUR(o) = (v))
-#define TIME_SET_MINUTE(o, v)   (PyDateTime_TIME_GET_MINUTE(o) = (v))
-#define TIME_SET_SECOND(o, v)   (PyDateTime_TIME_GET_SECOND(o) = (v))
-#define TIME_SET_MICROSECOND(o, v)      \
-    (((o)->data[3] = ((v) & 0xff0000) >> 16), \
-     ((o)->data[4] = ((v) & 0x00ff00) >> 8), \
-     ((o)->data[5] = ((v) & 0x0000ff)))
-
-/* Delta accessors for timedelta. */
-#define GET_TD_DAYS(o)          (((PyDateTime_Delta *)(o))->days)
-#define GET_TD_SECONDS(o)       (((PyDateTime_Delta *)(o))->seconds)
-#define GET_TD_MICROSECONDS(o)  (((PyDateTime_Delta *)(o))->microseconds)
-
-#define SET_TD_DAYS(o, v)       ((o)->days = (v))
-#define SET_TD_SECONDS(o, v)    ((o)->seconds = (v))
-#define SET_TD_MICROSECONDS(o, v) ((o)->microseconds = (v))
-
-/* p is a pointer to a time or a datetime object; HASTZINFO(p) returns
- * p->hastzinfo.
- */
-#define HASTZINFO(p) (((_PyDateTime_BaseTZInfo *)(p))->hastzinfo)
-#define GET_TIME_TZINFO(p) (HASTZINFO(p) ? \
-                            ((PyDateTime_Time *)(p))->tzinfo : Py_None)
-#define GET_DT_TZINFO(p) (HASTZINFO(p) ? \
-                          ((PyDateTime_DateTime *)(p))->tzinfo : Py_None)
-/* M is a char or int claiming to be a valid month.  The macro is equivalent
- * to the two-sided Python test
- *      1 <= M <= 12
- */
-#define MONTH_IS_SANE(M) ((unsigned int)(M) - 1 < 12)
-
-/* Forward declarations. */
-static PyTypeObject PyDateTime_DateType;
-static PyTypeObject PyDateTime_DateTimeType;
-static PyTypeObject PyDateTime_DeltaType;
-static PyTypeObject PyDateTime_TimeType;
-static PyTypeObject PyDateTime_TZInfoType;
-static PyTypeObject PyDateTime_TimeZoneType;
-
-/* ---------------------------------------------------------------------------
- * Math utilities.
- */
-
-/* k = i+j overflows iff k differs in sign from both inputs,
- * iff k^i has sign bit set and k^j has sign bit set,
- * iff (k^i)&(k^j) has sign bit set.
- */
-#define SIGNED_ADD_OVERFLOWED(RESULT, I, J) \
-    ((((RESULT) ^ (I)) & ((RESULT) ^ (J))) < 0)
-
-/* Compute Python divmod(x, y), returning the quotient and storing the
- * remainder into *r.  The quotient is the floor of x/y, and that's
- * the real point of this.  C will probably truncate instead (C99
- * requires truncation; C89 left it implementation-defined).
- * Simplification:  we *require* that y > 0 here.  That's appropriate
- * for all the uses made of it.  This simplifies the code and makes
- * the overflow case impossible (divmod(LONG_MIN, -1) is the only
- * overflow case).
- */
-static int
-divmod(int x, int y, int *r)
-{
-    int quo;
-
-    assert(y > 0);
-    quo = x / y;
-    *r = x - quo * y;
-    if (*r < 0) {
-        --quo;
-        *r += y;
-    }
-    assert(0 <= *r && *r < y);
-    return quo;
-}
-
-/* Round a double to the nearest long.  |x| must be small enough to fit
- * in a C long; this is not checked.
- */
-static long
-round_to_long(double x)
-{
-    if (x >= 0.0)
-        x = floor(x + 0.5);
-    else
-        x = ceil(x - 0.5);
-    return (long)x;
-}
-
-/* Nearest integer to m / n for integers m and n. Half-integer results
- * are rounded to even.
- */
-static PyObject *
-divide_nearest(PyObject *m, PyObject *n)
-{
-    PyObject *result;
-    PyObject *temp;
-
-    temp = _PyLong_DivmodNear(m, n);
-    if (temp == NULL)
-        return NULL;
-    result = PyTuple_GET_ITEM(temp, 0);
-    Py_INCREF(result);
-    Py_DECREF(temp);
-
-    return result;
-}
-
-/* ---------------------------------------------------------------------------
- * General calendrical helper functions
- */
-
-/* For each month ordinal in 1..12, the number of days in that month,
- * and the number of days before that month in the same year.  These
- * are correct for non-leap years only.
- */
-static int _days_in_month[] = {
-    0, /* unused; this vector uses 1-based indexing */
-    31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-};
-
-static int _days_before_month[] = {
-    0, /* unused; this vector uses 1-based indexing */
-    0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
-};
-
-/* year -> 1 if leap year, else 0. */
-static int
-is_leap(int year)
-{
-    /* Cast year to unsigned.  The result is the same either way, but
-     * C can generate faster code for unsigned mod than for signed
-     * mod (especially for % 4 -- a good compiler should just grab
-     * the last 2 bits when the LHS is unsigned).
-     */
-    const unsigned int ayear = (unsigned int)year;
-    return ayear % 4 == 0 && (ayear % 100 != 0 || ayear % 400 == 0);
-}
-
-/* year, month -> number of days in that month in that year */
-static int
-days_in_month(int year, int month)
-{
-    assert(month >= 1);
-    assert(month <= 12);
-    if (month == 2 && is_leap(year))
-        return 29;
-    else
-        return _days_in_month[month];
-}
-
-/* year, month -> number of days in year preceeding first day of month */
-static int
-days_before_month(int year, int month)
-{
-    int days;
-
-    assert(month >= 1);
-    assert(month <= 12);
-    days = _days_before_month[month];
-    if (month > 2 && is_leap(year))
-        ++days;
-    return days;
-}
-
-/* year -> number of days before January 1st of year.  Remember that we
- * start with year 1, so days_before_year(1) == 0.
- */
-static int
-days_before_year(int year)
-{
-    int y = year - 1;
-    /* This is incorrect if year <= 0; we really want the floor
-     * here.  But so long as MINYEAR is 1, the smallest year this
-     * can see is 0 (this can happen in some normalization endcases),
-     * so we'll just special-case that.
-     */
-    assert (year >= 0);
-    if (y >= 0)
-        return y*365 + y/4 - y/100 + y/400;
-    else {
-        assert(y == -1);
-        return -366;
-    }
-}
-
-/* Number of days in 4, 100, and 400 year cycles.  That these have
- * the correct values is asserted in the module init function.
- */
-#define DI4Y    1461    /* days_before_year(5); days in 4 years */
-#define DI100Y  36524   /* days_before_year(101); days in 100 years */
-#define DI400Y  146097  /* days_before_year(401); days in 400 years  */
-
-/* ordinal -> year, month, day, considering 01-Jan-0001 as day 1. */
-static void
-ord_to_ymd(int ordinal, int *year, int *month, int *day)
-{
-    int n, n1, n4, n100, n400, leapyear, preceding;
-
-    /* ordinal is a 1-based index, starting at 1-Jan-1.  The pattern of
-     * leap years repeats exactly every 400 years.  The basic strategy is
-     * to find the closest 400-year boundary at or before ordinal, then
-     * work with the offset from that boundary to ordinal.  Life is much
-     * clearer if we subtract 1 from ordinal first -- then the values
-     * of ordinal at 400-year boundaries are exactly those divisible
-     * by DI400Y:
-     *
-     *    D  M   Y            n              n-1
-     *    -- --- ----        ----------     ----------------
-     *    31 Dec -400        -DI400Y       -DI400Y -1
-     *     1 Jan -399         -DI400Y +1   -DI400Y      400-year boundary
-     *    ...
-     *    30 Dec  000        -1             -2
-     *    31 Dec  000         0             -1
-     *     1 Jan  001         1              0          400-year boundary
-     *     2 Jan  001         2              1
-     *     3 Jan  001         3              2
-     *    ...
-     *    31 Dec  400         DI400Y        DI400Y -1
-     *     1 Jan  401         DI400Y +1     DI400Y      400-year boundary
-     */
-    assert(ordinal >= 1);
-    --ordinal;
-    n400 = ordinal / DI400Y;
-    n = ordinal % DI400Y;
-    *year = n400 * 400 + 1;
-
-    /* Now n is the (non-negative) offset, in days, from January 1 of
-     * year, to the desired date.  Now compute how many 100-year cycles
-     * precede n.
-     * Note that it's possible for n100 to equal 4!  In that case 4 full
-     * 100-year cycles precede the desired day, which implies the
-     * desired day is December 31 at the end of a 400-year cycle.
-     */
-    n100 = n / DI100Y;
-    n = n % DI100Y;
-
-    /* Now compute how many 4-year cycles precede it. */
-    n4 = n / DI4Y;
-    n = n % DI4Y;
-
-    /* And now how many single years.  Again n1 can be 4, and again
-     * meaning that the desired day is December 31 at the end of the
-     * 4-year cycle.
-     */
-    n1 = n / 365;
-    n = n % 365;
-
-    *year += n100 * 100 + n4 * 4 + n1;
-    if (n1 == 4 || n100 == 4) {
-        assert(n == 0);
-        *year -= 1;
-        *month = 12;
-        *day = 31;
-        return;
-    }
-
-    /* Now the year is correct, and n is the offset from January 1.  We
-     * find the month via an estimate that's either exact or one too
-     * large.
-     */
-    leapyear = n1 == 3 && (n4 != 24 || n100 == 3);
-    assert(leapyear == is_leap(*year));
-    *month = (n + 50) >> 5;
-    preceding = (_days_before_month[*month] + (*month > 2 && leapyear));
-    if (preceding > n) {
-        /* estimate is too large */
-        *month -= 1;
-        preceding -= days_in_month(*year, *month);
-    }
-    n -= preceding;
-    assert(0 <= n);
-    assert(n < days_in_month(*year, *month));
-
-    *day = n + 1;
-}
-
-/* year, month, day -> ordinal, considering 01-Jan-0001 as day 1. */
-static int
-ymd_to_ord(int year, int month, int day)
-{
-    return days_before_year(year) + days_before_month(year, month) + day;
-}
-
-/* Day of week, where Monday==0, ..., Sunday==6.  1/1/1 was a Monday. */
-static int
-weekday(int year, int month, int day)
-{
-    return (ymd_to_ord(year, month, day) + 6) % 7;
-}
-
-/* Ordinal of the Monday starting week 1 of the ISO year.  Week 1 is the
- * first calendar week containing a Thursday.
- */
-static int
-iso_week1_monday(int year)
-{
-    int first_day = ymd_to_ord(year, 1, 1);     /* ord of 1/1 */
-    /* 0 if 1/1 is a Monday, 1 if a Tue, etc. */
-    int first_weekday = (first_day + 6) % 7;
-    /* ordinal of closest Monday at or before 1/1 */
-    int week1_monday  = first_day - first_weekday;
-
-    if (first_weekday > 3)      /* if 1/1 was Fri, Sat, Sun */
-        week1_monday += 7;
-    return week1_monday;
-}
-
-/* ---------------------------------------------------------------------------
- * Range checkers.
- */
-
-/* Check that -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS.  If so, return 0.
- * If not, raise OverflowError and return -1.
- */
-static int
-check_delta_day_range(int days)
-{
-    if (-MAX_DELTA_DAYS <= days && days <= MAX_DELTA_DAYS)
-        return 0;
-    PyErr_Format(PyExc_OverflowError,
-                 "days=%d; must have magnitude <= %d",
-                 days, MAX_DELTA_DAYS);
-    return -1;
-}
-
-/* Check that date arguments are in range.  Return 0 if they are.  If they
- * aren't, raise ValueError and return -1.
- */
-static int
-check_date_args(int year, int month, int day)
-{
-
-    if (year < MINYEAR || year > MAXYEAR) {
-        PyErr_SetString(PyExc_ValueError,
-                        "year is out of range");
-        return -1;
-    }
-    if (month < 1 || month > 12) {
-        PyErr_SetString(PyExc_ValueError,
-                        "month must be in 1..12");
-        return -1;
-    }
-    if (day < 1 || day > days_in_month(year, month)) {
-        PyErr_SetString(PyExc_ValueError,
-                        "day is out of range for month");
-        return -1;
-    }
-    return 0;
-}
-
-/* Check that time arguments are in range.  Return 0 if they are.  If they
- * aren't, raise ValueError and return -1.
- */
-static int
-check_time_args(int h, int m, int s, int us)
-{
-    if (h < 0 || h > 23) {
-        PyErr_SetString(PyExc_ValueError,
-                        "hour must be in 0..23");
-        return -1;
-    }
-    if (m < 0 || m > 59) {
-        PyErr_SetString(PyExc_ValueError,
-                        "minute must be in 0..59");
-        return -1;
-    }
-    if (s < 0 || s > 59) {
-        PyErr_SetString(PyExc_ValueError,
-                        "second must be in 0..59");
-        return -1;
-    }
-    if (us < 0 || us > 999999) {
-        PyErr_SetString(PyExc_ValueError,
-                        "microsecond must be in 0..999999");
-        return -1;
-    }
-    return 0;
-}
-
-/* ---------------------------------------------------------------------------
- * Normalization utilities.
- */
-
-/* One step of a mixed-radix conversion.  A "hi" unit is equivalent to
- * factor "lo" units.  factor must be > 0.  If *lo is less than 0, or
- * at least factor, enough of *lo is converted into "hi" units so that
- * 0 <= *lo < factor.  The input values must be such that int overflow
- * is impossible.
- */
-static void
-normalize_pair(int *hi, int *lo, int factor)
-{
-    assert(factor > 0);
-    assert(lo != hi);
-    if (*lo < 0 || *lo >= factor) {
-        const int num_hi = divmod(*lo, factor, lo);
-        const int new_hi = *hi + num_hi;
-        assert(! SIGNED_ADD_OVERFLOWED(new_hi, *hi, num_hi));
-        *hi = new_hi;
-    }
-    assert(0 <= *lo && *lo < factor);
-}
-
-/* Fiddle days (d), seconds (s), and microseconds (us) so that
- *      0 <= *s < 24*3600
- *      0 <= *us < 1000000
- * The input values must be such that the internals don't overflow.
- * The way this routine is used, we don't get close.
- */
-static void
-normalize_d_s_us(int *d, int *s, int *us)
-{
-    if (*us < 0 || *us >= 1000000) {
-        normalize_pair(s, us, 1000000);
-        /* |s| can't be bigger than about
-         * |original s| + |original us|/1000000 now.
-         */
-
-    }
-    if (*s < 0 || *s >= 24*3600) {
-        normalize_pair(d, s, 24*3600);
-        /* |d| can't be bigger than about
-         * |original d| +
-         * (|original s| + |original us|/1000000) / (24*3600) now.
-         */
-    }
-    assert(0 <= *s && *s < 24*3600);
-    assert(0 <= *us && *us < 1000000);
-}
-
-/* Fiddle years (y), months (m), and days (d) so that
- *      1 <= *m <= 12
- *      1 <= *d <= days_in_month(*y, *m)
- * The input values must be such that the internals don't overflow.
- * The way this routine is used, we don't get close.
- */
-static int
-normalize_y_m_d(int *y, int *m, int *d)
-{
-    int dim;            /* # of days in month */
-
-    /* This gets muddy:  the proper range for day can't be determined
-     * without knowing the correct month and year, but if day is, e.g.,
-     * plus or minus a million, the current month and year values make
-     * no sense (and may also be out of bounds themselves).
-     * Saying 12 months == 1 year should be non-controversial.
-     */
-    if (*m < 1 || *m > 12) {
-        --*m;
-        normalize_pair(y, m, 12);
-        ++*m;
-        /* |y| can't be bigger than about
-         * |original y| + |original m|/12 now.
-         */
-    }
-    assert(1 <= *m && *m <= 12);
-
-    /* Now only day can be out of bounds (year may also be out of bounds
-     * for a datetime object, but we don't care about that here).
-     * If day is out of bounds, what to do is arguable, but at least the
-     * method here is principled and explainable.
-     */
-    dim = days_in_month(*y, *m);
-    if (*d < 1 || *d > dim) {
-        /* Move day-1 days from the first of the month.  First try to
-         * get off cheap if we're only one day out of range
-         * (adjustments for timezone alone can't be worse than that).
-         */
-        if (*d == 0) {
-            --*m;
-            if (*m > 0)
-                *d = days_in_month(*y, *m);
-            else {
-                --*y;
-                *m = 12;
-                *d = 31;
-            }
-        }
-        else if (*d == dim + 1) {
-            /* move forward a day */
-            ++*m;
-            *d = 1;
-            if (*m > 12) {
-                *m = 1;
-                ++*y;
-            }
-        }
-        else {
-            int ordinal = ymd_to_ord(*y, *m, 1) +
-                                      *d - 1;
-            if (ordinal < 1 || ordinal > MAXORDINAL) {
-                goto error;
-            } else {
-                ord_to_ymd(ordinal, y, m, d);
-                return 0;
-            }
-        }
-    }
-    assert(*m > 0);
-    assert(*d > 0);
-    if (MINYEAR <= *y && *y <= MAXYEAR)
-        return 0;
- error:
-    PyErr_SetString(PyExc_OverflowError,
-            "date value out of range");
-    return -1;
-
-}
-
-/* Fiddle out-of-bounds months and days so that the result makes some kind
- * of sense.  The parameters are both inputs and outputs.  Returns < 0 on
- * failure, where failure means the adjusted year is out of bounds.
- */
-static int
-normalize_date(int *year, int *month, int *day)
-{
-    return normalize_y_m_d(year, month, day);
-}
-
-/* Force all the datetime fields into range.  The parameters are both
- * inputs and outputs.  Returns < 0 on error.
- */
-static int
-normalize_datetime(int *year, int *month, int *day,
-                   int *hour, int *minute, int *second,
-                   int *microsecond)
-{
-    normalize_pair(second, microsecond, 1000000);
-    normalize_pair(minute, second, 60);
-    normalize_pair(hour, minute, 60);
-    normalize_pair(day, hour, 24);
-    return normalize_date(year, month, day);
-}
-
-/* ---------------------------------------------------------------------------
- * Basic object allocation:  tp_alloc implementations.  These allocate
- * Python objects of the right size and type, and do the Python object-
- * initialization bit.  If there's not enough memory, they return NULL after
- * setting MemoryError.  All data members remain uninitialized trash.
- *
- * We abuse the tp_alloc "nitems" argument to communicate whether a tzinfo
- * member is needed.  This is ugly, imprecise, and possibly insecure.
- * tp_basicsize for the time and datetime types is set to the size of the
- * struct that has room for the tzinfo member, so subclasses in Python will
- * allocate enough space for a tzinfo member whether or not one is actually
- * needed.  That's the "ugly and imprecise" parts.  The "possibly insecure"
- * part is that PyType_GenericAlloc() (which subclasses in Python end up
- * using) just happens today to effectively ignore the nitems argument
- * when tp_itemsize is 0, which it is for these type objects.  If that
- * changes, perhaps the callers of tp_alloc slots in this file should
- * be changed to force a 0 nitems argument unless the type being allocated
- * is a base type implemented in this file (so that tp_alloc is time_alloc
- * or datetime_alloc below, which know about the nitems abuse).
- */
-
-static PyObject *
-time_alloc(PyTypeObject *type, Py_ssize_t aware)
-{
-    PyObject *self;
-
-    self = (PyObject *)
-        PyObject_MALLOC(aware ?
-                        sizeof(PyDateTime_Time) :
-                sizeof(_PyDateTime_BaseTime));
-    if (self == NULL)
-        return (PyObject *)PyErr_NoMemory();
-    PyObject_INIT(self, type);
-    return self;
-}
-
-static PyObject *
-datetime_alloc(PyTypeObject *type, Py_ssize_t aware)
-{
-    PyObject *self;
-
-    self = (PyObject *)
-        PyObject_MALLOC(aware ?
-                        sizeof(PyDateTime_DateTime) :
-                sizeof(_PyDateTime_BaseDateTime));
-    if (self == NULL)
-        return (PyObject *)PyErr_NoMemory();
-    PyObject_INIT(self, type);
-    return self;
-}
-
-/* ---------------------------------------------------------------------------
- * Helpers for setting object fields.  These work on pointers to the
- * appropriate base class.
- */
-
-/* For date and datetime. */
-static void
-set_date_fields(PyDateTime_Date *self, int y, int m, int d)
-{
-    self->hashcode = -1;
-    SET_YEAR(self, y);
-    SET_MONTH(self, m);
-    SET_DAY(self, d);
-}
-
-/* ---------------------------------------------------------------------------
- * Create various objects, mostly without range checking.
- */
-
-/* Create a date instance with no range checking. */
-static PyObject *
-new_date_ex(int year, int month, int day, PyTypeObject *type)
-{
-    PyDateTime_Date *self;
-
-    self = (PyDateTime_Date *) (type->tp_alloc(type, 0));
-    if (self != NULL)
-        set_date_fields(self, year, month, day);
-    return (PyObject *) self;
-}
-
-#define new_date(year, month, day) \
-    new_date_ex(year, month, day, &PyDateTime_DateType)
-
-/* Create a datetime instance with no range checking. */
-static PyObject *
-new_datetime_ex(int year, int month, int day, int hour, int minute,
-             int second, int usecond, PyObject *tzinfo, PyTypeObject *type)
-{
-    PyDateTime_DateTime *self;
-    char aware = tzinfo != Py_None;
-
-    self = (PyDateTime_DateTime *) (type->tp_alloc(type, aware));
-    if (self != NULL) {
-        self->hastzinfo = aware;
-        set_date_fields((PyDateTime_Date *)self, year, month, day);
-        DATE_SET_HOUR(self, hour);
-        DATE_SET_MINUTE(self, minute);
-        DATE_SET_SECOND(self, second);
-        DATE_SET_MICROSECOND(self, usecond);
-        if (aware) {
-            Py_INCREF(tzinfo);
-            self->tzinfo = tzinfo;
-        }
-    }
-    return (PyObject *)self;
-}
-
-#define new_datetime(y, m, d, hh, mm, ss, us, tzinfo)           \
-    new_datetime_ex(y, m, d, hh, mm, ss, us, tzinfo,            \
-                    &PyDateTime_DateTimeType)
-
-/* Create a time instance with no range checking. */
-static PyObject *
-new_time_ex(int hour, int minute, int second, int usecond,
-            PyObject *tzinfo, PyTypeObject *type)
-{
-    PyDateTime_Time *self;
-    char aware = tzinfo != Py_None;
-
-    self = (PyDateTime_Time *) (type->tp_alloc(type, aware));
-    if (self != NULL) {
-        self->hastzinfo = aware;
-        self->hashcode = -1;
-        TIME_SET_HOUR(self, hour);
-        TIME_SET_MINUTE(self, minute);
-        TIME_SET_SECOND(self, second);
-        TIME_SET_MICROSECOND(self, usecond);
-        if (aware) {
-            Py_INCREF(tzinfo);
-            self->tzinfo = tzinfo;
-        }
-    }
-    return (PyObject *)self;
-}
-
-#define new_time(hh, mm, ss, us, tzinfo)                \
-    new_time_ex(hh, mm, ss, us, tzinfo, &PyDateTime_TimeType)
-
-/* Create a timedelta instance.  Normalize the members iff normalize is
- * true.  Passing false is a speed optimization, if you know for sure
- * that seconds and microseconds are already in their proper ranges.  In any
- * case, raises OverflowError and returns NULL if the normalized days is out
- * of range).
- */
-static PyObject *
-new_delta_ex(int days, int seconds, int microseconds, int normalize,
-             PyTypeObject *type)
-{
-    PyDateTime_Delta *self;
-
-    if (normalize)
-        normalize_d_s_us(&days, &seconds, &microseconds);
-    assert(0 <= seconds && seconds < 24*3600);
-    assert(0 <= microseconds && microseconds < 1000000);
-
-    if (check_delta_day_range(days) < 0)
-        return NULL;
-
-    self = (PyDateTime_Delta *) (type->tp_alloc(type, 0));
-    if (self != NULL) {
-        self->hashcode = -1;
-        SET_TD_DAYS(self, days);
-        SET_TD_SECONDS(self, seconds);
-        SET_TD_MICROSECONDS(self, microseconds);
-    }
-    return (PyObject *) self;
-}
-
-#define new_delta(d, s, us, normalize)  \
-    new_delta_ex(d, s, us, normalize, &PyDateTime_DeltaType)
-
-
-typedef struct
-{
-    PyObject_HEAD
-    PyObject *offset;
-    PyObject *name;
-} PyDateTime_TimeZone;
-
-PyObject *PyDateTime_TimeZone_UTC;
-
-/* Create new timezone instance checking offset range.  This
-   function does not check the name argument.  Caller must assure
-   that offset is a timedelta instance and name is either NULL
-   or a unicode object. */
-static PyObject *
-new_timezone(PyObject *offset, PyObject *name)
-{
-    PyDateTime_TimeZone *self;
-    PyTypeObject *type = &PyDateTime_TimeZoneType;
-
-    assert(offset != NULL);
-    assert(PyDelta_Check(offset));
-    assert(name == NULL || PyUnicode_Check(name));
-
-    if (GET_TD_MICROSECONDS(offset) != 0 || GET_TD_SECONDS(offset) % 60 != 0) {
-        PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
-                     " representing a whole number of minutes");
-        return NULL;
-    }
-    if ((GET_TD_DAYS(offset) == -1 && GET_TD_SECONDS(offset) == 0) ||
-        GET_TD_DAYS(offset) < -1 || GET_TD_DAYS(offset) >= 1) {
-        PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
-                     " strictly between -timedelta(hours=24) and"
-                     " timedelta(hours=24).");
-        return NULL;
-    }
-
-    self = (PyDateTime_TimeZone *)(type->tp_alloc(type, 0));
-    if (self == NULL) {
-        return NULL;
-    }
-    Py_INCREF(offset);
-    self->offset = offset;
-    Py_XINCREF(name);
-    self->name = name;
-    return (PyObject *)self;
-}
-
-/* ---------------------------------------------------------------------------
- * tzinfo helpers.
- */
-
-/* Ensure that p is None or of a tzinfo subclass.  Return 0 if OK; if not
- * raise TypeError and return -1.
- */
-static int
-check_tzinfo_subclass(PyObject *p)
-{
-    if (p == Py_None || PyTZInfo_Check(p))
-        return 0;
-    PyErr_Format(PyExc_TypeError,
-                 "tzinfo argument must be None or of a tzinfo subclass, "
-                 "not type '%s'",
-                 Py_TYPE(p)->tp_name);
-    return -1;
-}
-
-/* If self has a tzinfo member, return a BORROWED reference to it.  Else
- * return NULL, which is NOT AN ERROR.  There are no error returns here,
- * and the caller must not decref the result.
- */
-static PyObject *
-get_tzinfo_member(PyObject *self)
-{
-    PyObject *tzinfo = NULL;
-
-    if (PyDateTime_Check(self) && HASTZINFO(self))
-        tzinfo = ((PyDateTime_DateTime *)self)->tzinfo;
-    else if (PyTime_Check(self) && HASTZINFO(self))
-        tzinfo = ((PyDateTime_Time *)self)->tzinfo;
-
-    return tzinfo;
-}
-
-/* Call getattr(tzinfo, name)(tzinfoarg), and check the result.  tzinfo must
- * be an instance of the tzinfo class.  If the method returns None, this
- * returns None.  If the method doesn't return None or timedelta, TypeError is
- * raised and this returns NULL.  If it returns a timedelta and the value is
- * out of range or isn't a whole number of minutes, ValueError is raised and
- * this returns NULL.  Else result is returned.
- */
-static PyObject *
-call_tzinfo_method(PyObject *tzinfo, char *name, PyObject *tzinfoarg)
-{
-    PyObject *offset;
-
-    assert(tzinfo != NULL);
-    assert(PyTZInfo_Check(tzinfo) || tzinfo == Py_None);
-    assert(tzinfoarg != NULL);
-
-    if (tzinfo == Py_None)
-        Py_RETURN_NONE;
-    offset = PyObject_CallMethod(tzinfo, name, "O", tzinfoarg);
-    if (offset == Py_None || offset == NULL)
-        return offset;
-    if (PyDelta_Check(offset)) {
-        if (GET_TD_MICROSECONDS(offset) != 0 || GET_TD_SECONDS(offset) % 60 != 0) {
-            Py_DECREF(offset);
-            PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
-                         " representing a whole number of minutes");
-            return NULL;
-        }
-        if ((GET_TD_DAYS(offset) == -1 && GET_TD_SECONDS(offset) == 0) ||
-            GET_TD_DAYS(offset) < -1 || GET_TD_DAYS(offset) >= 1) {
-            Py_DECREF(offset);
-            PyErr_Format(PyExc_ValueError, "offset must be a timedelta"
-                         " strictly between -timedelta(hours=24) and"
-                         " timedelta(hours=24).");
-            return NULL;
-        }
-    }
-    else {
-        Py_DECREF(offset);
-        PyErr_Format(PyExc_TypeError,
-                     "tzinfo.%s() must return None or "
-                     "timedelta, not '%.200s'",
-                     name, Py_TYPE(offset)->tp_name);
-        return NULL;
-    }
-
-    return offset;
-}
-
-/* Call tzinfo.utcoffset(tzinfoarg), and extract an integer from the
- * result.  tzinfo must be an instance of the tzinfo class.  If utcoffset()
- * returns None, call_utcoffset returns 0 and sets *none to 1.  If uctoffset()
- * doesn't return None or timedelta, TypeError is raised and this returns -1.
- * If utcoffset() returns an invalid timedelta (out of range, or not a whole
- * # of minutes), ValueError is raised and this returns -1.  Else *none is
- * set to 0 and the offset is returned (as int # of minutes east of UTC).
- */
-static PyObject *
-call_utcoffset(PyObject *tzinfo, PyObject *tzinfoarg)
-{
-    return call_tzinfo_method(tzinfo, "utcoffset", tzinfoarg);
-}
-
-/* Call tzinfo.dst(tzinfoarg), and extract an integer from the
- * result.  tzinfo must be an instance of the tzinfo class.  If dst()
- * returns None, call_dst returns 0 and sets *none to 1.  If dst()
- & doesn't return None or timedelta, TypeError is raised and this
- * returns -1.  If dst() returns an invalid timedelta for a UTC offset,
- * ValueError is raised and this returns -1.  Else *none is set to 0 and
- * the offset is returned (as an int # of minutes east of UTC).
- */
-static PyObject *
-call_dst(PyObject *tzinfo, PyObject *tzinfoarg)
-{
-    return call_tzinfo_method(tzinfo, "dst", tzinfoarg);
-}
-
-/* Call tzinfo.tzname(tzinfoarg), and return the result.  tzinfo must be
- * an instance of the tzinfo class or None.  If tzinfo isn't None, and
- * tzname() doesn't return None or a string, TypeError is raised and this
- * returns NULL.  If the result is a string, we ensure it is a Unicode
- * string.
- */
-static PyObject *
-call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
-{
-    PyObject *result;
-
-    assert(tzinfo != NULL);
-    assert(check_tzinfo_subclass(tzinfo) >= 0);
-    assert(tzinfoarg != NULL);
-
-    if (tzinfo == Py_None)
-        Py_RETURN_NONE;
-
-    result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg);
-
-    if (result == NULL || result == Py_None)
-        return result;
-
-    if (!PyUnicode_Check(result)) {
-        PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
-                     "return None or a string, not '%s'",
-                     Py_TYPE(result)->tp_name);
-        Py_DECREF(result);
-        result = NULL;
-    }
-
-    return result;
-}
-
-/* repr is like "someclass(arg1, arg2)".  If tzinfo isn't None,
- * stuff
- *     ", tzinfo=" + repr(tzinfo)
- * before the closing ")".
- */
-static PyObject *
-append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo)
-{
-    PyObject *temp;
-
-    assert(PyUnicode_Check(repr));
-    assert(tzinfo);
-    if (tzinfo == Py_None)
-        return repr;
-    /* Get rid of the trailing ')'. */
-    assert(PyUnicode_AS_UNICODE(repr)[PyUnicode_GET_SIZE(repr)-1] == ')');
-    temp = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(repr),
-                                      PyUnicode_GET_SIZE(repr) - 1);
-    Py_DECREF(repr);
-    if (temp == NULL)
-        return NULL;
-    repr = PyUnicode_FromFormat("%U, tzinfo=%R)", temp, tzinfo);
-    Py_DECREF(temp);
-    return repr;
-}
-
-/* ---------------------------------------------------------------------------
- * String format helpers.
- */
-
-static PyObject *
-format_ctime(PyDateTime_Date *date, int hours, int minutes, int seconds)
-{
-    static const char *DayNames[] = {
-        "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"
-    };
-    static const char *MonthNames[] = {
-        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-    };
-
-    int wday = weekday(GET_YEAR(date), GET_MONTH(date), GET_DAY(date));
-
-    return PyUnicode_FromFormat("%s %s %2d %02d:%02d:%02d %04d",
-                                DayNames[wday], MonthNames[GET_MONTH(date)-1],
-                                GET_DAY(date), hours, minutes, seconds,
-                                GET_YEAR(date));
-}
-
-static PyObject *delta_negative(PyDateTime_Delta *self);
-
-/* Add an hours & minutes UTC offset string to buf.  buf has no more than
- * buflen bytes remaining.  The UTC offset is gotten by calling
- * tzinfo.uctoffset(tzinfoarg).  If that returns None, \0 is stored into
- * *buf, and that's all.  Else the returned value is checked for sanity (an
- * integer in range), and if that's OK it's converted to an hours & minutes
- * string of the form
- *   sign HH sep MM
- * Returns 0 if everything is OK.  If the return value from utcoffset() is
- * bogus, an appropriate exception is set and -1 is returned.
- */
-static int
-format_utcoffset(char *buf, size_t buflen, const char *sep,
-                PyObject *tzinfo, PyObject *tzinfoarg)
-{
-    PyObject *offset;
-    int hours, minutes, seconds;
-    char sign;
-
-    assert(buflen >= 1);
-
-    offset = call_utcoffset(tzinfo, tzinfoarg);
-    if (offset == NULL)
-        return -1;
-    if (offset == Py_None) {
-        Py_DECREF(offset);
-        *buf = '\0';
-        return 0;
-    }
-    /* Offset is normalized, so it is negative if days < 0 */
-    if (GET_TD_DAYS(offset) < 0) {
-        PyObject *temp = offset;
-        sign = '-';
-        offset = delta_negative((PyDateTime_Delta *)offset);
-        Py_DECREF(temp);
-        if (offset == NULL)
-            return -1;
-    }
-    else {
-        sign = '+';
-    }
-    /* Offset is not negative here. */
-    seconds = GET_TD_SECONDS(offset);
-    Py_DECREF(offset);
-    minutes = divmod(seconds, 60, &seconds);
-    hours = divmod(minutes, 60, &minutes);
-    assert(seconds == 0);
-    /* XXX ignore sub-minute data, curently not allowed. */
-    PyOS_snprintf(buf, buflen, "%c%02d%s%02d", sign, hours, sep, minutes);
-
-    return 0;
-}
-
-static PyObject *
-make_Zreplacement(PyObject *object, PyObject *tzinfoarg)
-{
-    PyObject *temp;
-    PyObject *tzinfo = get_tzinfo_member(object);
-    PyObject *Zreplacement = PyUnicode_FromStringAndSize(NULL, 0);
-    if (Zreplacement == NULL)
-        return NULL;
-    if (tzinfo == Py_None || tzinfo == NULL)
-        return Zreplacement;
-
-    assert(tzinfoarg != NULL);
-    temp = call_tzname(tzinfo, tzinfoarg);
-    if (temp == NULL)
-        goto Error;
-    if (temp == Py_None) {
-        Py_DECREF(temp);
-        return Zreplacement;
-    }
-
-    assert(PyUnicode_Check(temp));
-    /* Since the tzname is getting stuffed into the
-     * format, we have to double any % signs so that
-     * strftime doesn't treat them as format codes.
-     */
-    Py_DECREF(Zreplacement);
-    Zreplacement = PyObject_CallMethod(temp, "replace", "ss", "%", "%%");
-    Py_DECREF(temp);
-    if (Zreplacement == NULL)
-        return NULL;
-    if (!PyUnicode_Check(Zreplacement)) {
-        PyErr_SetString(PyExc_TypeError,
-                        "tzname.replace() did not return a string");
-        goto Error;
-    }
-    return Zreplacement;
-
-  Error:
-    Py_DECREF(Zreplacement);
-    return NULL;
-}
-
-static PyObject *
-make_freplacement(PyObject *object)
-{
-    char freplacement[64];
-    if (PyTime_Check(object))
-        sprintf(freplacement, "%06d", TIME_GET_MICROSECOND(object));
-    else if (PyDateTime_Check(object))
-        sprintf(freplacement, "%06d", DATE_GET_MICROSECOND(object));
-    else
-        sprintf(freplacement, "%06d", 0);
-
-    return PyBytes_FromStringAndSize(freplacement, strlen(freplacement));
-}
-
-/* I sure don't want to reproduce the strftime code from the time module,
- * so this imports the module and calls it.  All the hair is due to
- * giving special meanings to the %z, %Z and %f format codes via a
- * preprocessing step on the format string.
- * tzinfoarg is the argument to pass to the object's tzinfo method, if
- * needed.
- */
-static PyObject *
-wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
-              PyObject *tzinfoarg)
-{
-    PyObject *result = NULL;            /* guilty until proved innocent */
-
-    PyObject *zreplacement = NULL;      /* py string, replacement for %z */
-    PyObject *Zreplacement = NULL;      /* py string, replacement for %Z */
-    PyObject *freplacement = NULL;      /* py string, replacement for %f */
-
-    const char *pin;            /* pointer to next char in input format */
-    Py_ssize_t flen;            /* length of input format */
-    char ch;                    /* next char in input format */
-
-    PyObject *newfmt = NULL;            /* py string, the output format */
-    char *pnew;         /* pointer to available byte in output format */
-    size_t totalnew;            /* number bytes total in output format buffer,
-                               exclusive of trailing \0 */
-    size_t usednew;     /* number bytes used so far in output format buffer */
-
-    const char *ptoappend;      /* ptr to string to append to output buffer */
-    Py_ssize_t ntoappend;       /* # of bytes to append to output buffer */
-
-    assert(object && format && timetuple);
-    assert(PyUnicode_Check(format));
-    /* Convert the input format to a C string and size */
-    pin = _PyUnicode_AsStringAndSize(format, &flen);
-    if (!pin)
-        return NULL;
-
-    /* Give up if the year is before 1900.
-     * Python strftime() plays games with the year, and different
-     * games depending on whether envar PYTHON2K is set.  This makes
-     * years before 1900 a nightmare, even if the platform strftime
-     * supports them (and not all do).
-     * We could get a lot farther here by avoiding Python's strftime
-     * wrapper and calling the C strftime() directly, but that isn't
-     * an option in the Python implementation of this module.
-     */
-    {
-        long year;
-        PyObject *pyyear = PySequence_GetItem(timetuple, 0);
-        if (pyyear == NULL) return NULL;
-        assert(PyLong_Check(pyyear));
-        year = PyLong_AsLong(pyyear);
-        Py_DECREF(pyyear);
-        if (year < 1900) {
-            PyErr_Format(PyExc_ValueError, "year=%ld is before "
-                         "1900; the datetime strftime() "
-                         "methods require year >= 1900",
-                         year);
-            return NULL;
-        }
-    }
-
-    /* Scan the input format, looking for %z/%Z/%f escapes, building
-     * a new format.  Since computing the replacements for those codes
-     * is expensive, don't unless they're actually used.
-     */
-    if (flen > INT_MAX - 1) {
-        PyErr_NoMemory();
-        goto Done;
-    }
-
-    totalnew = flen + 1;        /* realistic if no %z/%Z */
-    newfmt = PyBytes_FromStringAndSize(NULL, totalnew);
-    if (newfmt == NULL) goto Done;
-    pnew = PyBytes_AsString(newfmt);
-    usednew = 0;
-
-    while ((ch = *pin++) != '\0') {
-        if (ch != '%') {
-            ptoappend = pin - 1;
-            ntoappend = 1;
-        }
-        else if ((ch = *pin++) == '\0') {
-            /* There's a lone trailing %; doesn't make sense. */
-            PyErr_SetString(PyExc_ValueError, "strftime format "
-                            "ends with raw %");
-            goto Done;
-        }
-        /* A % has been seen and ch is the character after it. */
-        else if (ch == 'z') {
-            if (zreplacement == NULL) {
-                /* format utcoffset */
-                char buf[100];
-                PyObject *tzinfo = get_tzinfo_member(object);
-                zreplacement = PyBytes_FromStringAndSize("", 0);
-                if (zreplacement == NULL) goto Done;
-                if (tzinfo != Py_None && tzinfo != NULL) {
-                    assert(tzinfoarg != NULL);
-                    if (format_utcoffset(buf,
-                                         sizeof(buf),
-                                         "",
-                                         tzinfo,
-                                         tzinfoarg) < 0)
-                        goto Done;
-                    Py_DECREF(zreplacement);
-                    zreplacement =
-                      PyBytes_FromStringAndSize(buf,
-                                               strlen(buf));
-                    if (zreplacement == NULL)
-                        goto Done;
-                }
-            }
-            assert(zreplacement != NULL);
-            ptoappend = PyBytes_AS_STRING(zreplacement);
-            ntoappend = PyBytes_GET_SIZE(zreplacement);
-        }
-        else if (ch == 'Z') {
-            /* format tzname */
-            if (Zreplacement == NULL) {
-                Zreplacement = make_Zreplacement(object,
-                                                 tzinfoarg);
-                if (Zreplacement == NULL)
-                    goto Done;
-            }
-            assert(Zreplacement != NULL);
-            assert(PyUnicode_Check(Zreplacement));
-            ptoappend = _PyUnicode_AsStringAndSize(Zreplacement,
-                                                  &ntoappend);
-            ntoappend = Py_SIZE(Zreplacement);
-        }
-        else if (ch == 'f') {
-            /* format microseconds */
-            if (freplacement == NULL) {
-                freplacement = make_freplacement(object);
-                if (freplacement == NULL)
-                    goto Done;
-            }
-            assert(freplacement != NULL);
-            assert(PyBytes_Check(freplacement));
-            ptoappend = PyBytes_AS_STRING(freplacement);
-            ntoappend = PyBytes_GET_SIZE(freplacement);
-        }
-        else {
-            /* percent followed by neither z nor Z */
-            ptoappend = pin - 2;
-            ntoappend = 2;
-        }
-
-        /* Append the ntoappend chars starting at ptoappend to
-         * the new format.
-         */
-        if (ntoappend == 0)
-            continue;
-        assert(ptoappend != NULL);
-        assert(ntoappend > 0);
-        while (usednew + ntoappend > totalnew) {
-            size_t bigger = totalnew << 1;
-            if ((bigger >> 1) != totalnew) { /* overflow */
-                PyErr_NoMemory();
-                goto Done;
-            }
-            if (_PyBytes_Resize(&newfmt, bigger) < 0)
-                goto Done;
-            totalnew = bigger;
-            pnew = PyBytes_AsString(newfmt) + usednew;
-        }
-        memcpy(pnew, ptoappend, ntoappend);
-        pnew += ntoappend;
-        usednew += ntoappend;
-        assert(usednew <= totalnew);
-    }  /* end while() */
-
-    if (_PyBytes_Resize(&newfmt, usednew) < 0)
-        goto Done;
-    {
-        PyObject *format;
-        PyObject *time = PyImport_ImportModuleNoBlock("time");
-        if (time == NULL)
-            goto Done;
-        format = PyUnicode_FromString(PyBytes_AS_STRING(newfmt));
-        if (format != NULL) {
-            result = PyObject_CallMethod(time, "strftime", "OO",
-                                         format, timetuple, NULL);
-            Py_DECREF(format);
-        }
-        Py_DECREF(time);
-    }
- Done:
-    Py_XDECREF(freplacement);
-    Py_XDECREF(zreplacement);
-    Py_XDECREF(Zreplacement);
-    Py_XDECREF(newfmt);
-    return result;
-}
-
-/* ---------------------------------------------------------------------------
- * Wrap functions from the time module.  These aren't directly available
- * from C.  Perhaps they should be.
- */
-
-/* Call time.time() and return its result (a Python float). */
-static PyObject *
-time_time(void)
-{
-    PyObject *result = NULL;
-    PyObject *time = PyImport_ImportModuleNoBlock("time");
-
-    if (time != NULL) {
-        result = PyObject_CallMethod(time, "time", "()");
-        Py_DECREF(time);
-    }
-    return result;
-}
-
-/* Build a time.struct_time.  The weekday and day number are automatically
- * computed from the y,m,d args.
- */
-static PyObject *
-build_struct_time(int y, int m, int d, int hh, int mm, int ss, int dstflag)
-{
-    PyObject *time;
-    PyObject *result = NULL;
-
-    time = PyImport_ImportModuleNoBlock("time");
-    if (time != NULL) {
-        result = PyObject_CallMethod(time, "struct_time",
-                                     "((iiiiiiiii))",
-                                     y, m, d,
-                                     hh, mm, ss,
-                                     weekday(y, m, d),
-                                     days_before_month(y, m) + d,
-                                     dstflag);
-        Py_DECREF(time);
-    }
-    return result;
-}
-
-/* ---------------------------------------------------------------------------
- * Miscellaneous helpers.
- */
-
-/* For various reasons, we need to use tp_richcompare instead of tp_reserved.
- * The comparisons here all most naturally compute a cmp()-like result.
- * This little helper turns that into a bool result for rich comparisons.
- */
-static PyObject *
-diff_to_bool(int diff, int op)
-{
-    PyObject *result;
-    int istrue;
-
-    switch (op) {
-        case Py_EQ: istrue = diff == 0; break;
-        case Py_NE: istrue = diff != 0; break;
-        case Py_LE: istrue = diff <= 0; break;
-        case Py_GE: istrue = diff >= 0; break;
-        case Py_LT: istrue = diff < 0; break;
-        case Py_GT: istrue = diff > 0; break;
-        default:
-            assert(! "op unknown");
-            istrue = 0; /* To shut up compiler */
-    }
-    result = istrue ? Py_True : Py_False;
-    Py_INCREF(result);
-    return result;
-}
-
-/* Raises a "can't compare" TypeError and returns NULL. */
-static PyObject *
-cmperror(PyObject *a, PyObject *b)
-{
-    PyErr_Format(PyExc_TypeError,
-                 "can't compare %s to %s",
-                 Py_TYPE(a)->tp_name, Py_TYPE(b)->tp_name);
-    return NULL;
-}
-
-/* ---------------------------------------------------------------------------
- * Cached Python objects; these are set by the module init function.
- */
-
-/* Conversion factors. */
-static PyObject *us_per_us = NULL;      /* 1 */
-static PyObject *us_per_ms = NULL;      /* 1000 */
-static PyObject *us_per_second = NULL;  /* 1000000 */
-static PyObject *us_per_minute = NULL;  /* 1e6 * 60 as Python int */
-static PyObject *us_per_hour = NULL;    /* 1e6 * 3600 as Python long */
-static PyObject *us_per_day = NULL;     /* 1e6 * 3600 * 24 as Python long */
-static PyObject *us_per_week = NULL;    /* 1e6*3600*24*7 as Python long */
-static PyObject *seconds_per_day = NULL; /* 3600*24 as Python int */
-
-/* ---------------------------------------------------------------------------
- * Class implementations.
- */
-
-/*
- * PyDateTime_Delta implementation.
- */
-
-/* Convert a timedelta to a number of us,
- *      (24*3600*self.days + self.seconds)*1000000 + self.microseconds
- * as a Python int or long.
- * Doing mixed-radix arithmetic by hand instead is excruciating in C,
- * due to ubiquitous overflow possibilities.
- */
-static PyObject *
-delta_to_microseconds(PyDateTime_Delta *self)
-{
-    PyObject *x1 = NULL;
-    PyObject *x2 = NULL;
-    PyObject *x3 = NULL;
-    PyObject *result = NULL;
-
-    x1 = PyLong_FromLong(GET_TD_DAYS(self));
-    if (x1 == NULL)
-        goto Done;
-    x2 = PyNumber_Multiply(x1, seconds_per_day);        /* days in seconds */
-    if (x2 == NULL)
-        goto Done;
-    Py_DECREF(x1);
-    x1 = NULL;
-
-    /* x2 has days in seconds */
-    x1 = PyLong_FromLong(GET_TD_SECONDS(self));         /* seconds */
-    if (x1 == NULL)
-        goto Done;
-    x3 = PyNumber_Add(x1, x2);          /* days and seconds in seconds */
-    if (x3 == NULL)
-        goto Done;
-    Py_DECREF(x1);
-    Py_DECREF(x2);
-    x1 = x2 = NULL;
-
-    /* x3 has days+seconds in seconds */
-    x1 = PyNumber_Multiply(x3, us_per_second);          /* us */
-    if (x1 == NULL)
-        goto Done;
-    Py_DECREF(x3);
-    x3 = NULL;
-
-    /* x1 has days+seconds in us */
-    x2 = PyLong_FromLong(GET_TD_MICROSECONDS(self));
-    if (x2 == NULL)
-        goto Done;
-    result = PyNumber_Add(x1, x2);
-
-Done:
-    Py_XDECREF(x1);
-    Py_XDECREF(x2);
-    Py_XDECREF(x3);
-    return result;
-}
-
-/* Convert a number of us (as a Python int or long) to a timedelta.
- */
-static PyObject *
-microseconds_to_delta_ex(PyObject *pyus, PyTypeObject *type)
-{
-    int us;
-    int s;
-    int d;
-    long temp;
-
-    PyObject *tuple = NULL;
-    PyObject *num = NULL;
-    PyObject *result = NULL;
-
-    tuple = PyNumber_Divmod(pyus, us_per_second);
-    if (tuple == NULL)
-        goto Done;
-
-    num = PyTuple_GetItem(tuple, 1);            /* us */
-    if (num == NULL)
-        goto Done;
-    temp = PyLong_AsLong(num);
-    num = NULL;
-    if (temp == -1 && PyErr_Occurred())
-        goto Done;
-    assert(0 <= temp && temp < 1000000);
-    us = (int)temp;
-    if (us < 0) {
-        /* The divisor was positive, so this must be an error. */
-        assert(PyErr_Occurred());
-        goto Done;
-    }
-
-    num = PyTuple_GetItem(tuple, 0);            /* leftover seconds */
-    if (num == NULL)
-        goto Done;
-    Py_INCREF(num);
-    Py_DECREF(tuple);
-
-    tuple = PyNumber_Divmod(num, seconds_per_day);
-    if (tuple == NULL)
-        goto Done;
-    Py_DECREF(num);
-
-    num = PyTuple_GetItem(tuple, 1);            /* seconds */
-    if (num == NULL)
-        goto Done;
-    temp = PyLong_AsLong(num);
-    num = NULL;
-    if (temp == -1 && PyErr_Occurred())
-        goto Done;
-    assert(0 <= temp && temp < 24*3600);
-    s = (int)temp;
-
-    if (s < 0) {
-        /* The divisor was positive, so this must be an error. */
-        assert(PyErr_Occurred());
-        goto Done;
-    }
-
-    num = PyTuple_GetItem(tuple, 0);            /* leftover days */
-    if (num == NULL)
-        goto Done;
-    Py_INCREF(num);
-    temp = PyLong_AsLong(num);
-    if (temp == -1 && PyErr_Occurred())
-        goto Done;
-    d = (int)temp;
-    if ((long)d != temp) {
-        PyErr_SetString(PyExc_OverflowError, "normalized days too "
-                        "large to fit in a C int");
-        goto Done;
-    }
-    result = new_delta_ex(d, s, us, 0, type);
-
-Done:
-    Py_XDECREF(tuple);
-    Py_XDECREF(num);
-    return result;
-}
-
-#define microseconds_to_delta(pymicros) \
-    microseconds_to_delta_ex(pymicros, &PyDateTime_DeltaType)
-
-static PyObject *
-multiply_int_timedelta(PyObject *intobj, PyDateTime_Delta *delta)
-{
-    PyObject *pyus_in;
-    PyObject *pyus_out;
-    PyObject *result;
-
-    pyus_in = delta_to_microseconds(delta);
-    if (pyus_in == NULL)
-        return NULL;
-
-    pyus_out = PyNumber_Multiply(pyus_in, intobj);
-    Py_DECREF(pyus_in);
-    if (pyus_out == NULL)
-        return NULL;
-
-    result = microseconds_to_delta(pyus_out);
-    Py_DECREF(pyus_out);
-    return result;
-}
-
-static PyObject *
-multiply_float_timedelta(PyObject *floatobj, PyDateTime_Delta *delta)
-{
-    PyObject *result = NULL;
-    PyObject *pyus_in = NULL, *temp, *pyus_out;
-    PyObject *ratio = NULL;
-
-    pyus_in = delta_to_microseconds(delta);
-    if (pyus_in == NULL)
-        return NULL;
-    ratio = PyObject_CallMethod(floatobj, "as_integer_ratio", NULL);
-    if (ratio == NULL)
-        goto error;
-    temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 0));
-    Py_DECREF(pyus_in);
-    pyus_in = NULL;
-    if (temp == NULL)
-        goto error;
-    pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, 1));
-    Py_DECREF(temp);
-    if (pyus_out == NULL)
-        goto error;
-    result = microseconds_to_delta(pyus_out);
-    Py_DECREF(pyus_out);
- error:
-    Py_XDECREF(pyus_in);
-    Py_XDECREF(ratio);
-
-    return result;
-}
-
-static PyObject *
-divide_timedelta_int(PyDateTime_Delta *delta, PyObject *intobj)
-{
-    PyObject *pyus_in;
-    PyObject *pyus_out;
-    PyObject *result;
-
-    pyus_in = delta_to_microseconds(delta);
-    if (pyus_in == NULL)
-        return NULL;
-
-    pyus_out = PyNumber_FloorDivide(pyus_in, intobj);
-    Py_DECREF(pyus_in);
-    if (pyus_out == NULL)
-        return NULL;
-
-    result = microseconds_to_delta(pyus_out);
-    Py_DECREF(pyus_out);
-    return result;
-}
-
-static PyObject *
-divide_timedelta_timedelta(PyDateTime_Delta *left, PyDateTime_Delta *right)
-{
-    PyObject *pyus_left;
-    PyObject *pyus_right;
-    PyObject *result;
-
-    pyus_left = delta_to_microseconds(left);
-    if (pyus_left == NULL)
-        return NULL;
-
-    pyus_right = delta_to_microseconds(right);
-    if (pyus_right == NULL)     {
-        Py_DECREF(pyus_left);
-        return NULL;
-    }
-
-    result = PyNumber_FloorDivide(pyus_left, pyus_right);
-    Py_DECREF(pyus_left);
-    Py_DECREF(pyus_right);
-    return result;
-}
-
-static PyObject *
-truedivide_timedelta_timedelta(PyDateTime_Delta *left, PyDateTime_Delta *right)
-{
-    PyObject *pyus_left;
-    PyObject *pyus_right;
-    PyObject *result;
-
-    pyus_left = delta_to_microseconds(left);
-    if (pyus_left == NULL)
-        return NULL;
-
-    pyus_right = delta_to_microseconds(right);
-    if (pyus_right == NULL)     {
-        Py_DECREF(pyus_left);
-        return NULL;
-    }
-
-    result = PyNumber_TrueDivide(pyus_left, pyus_right);
-    Py_DECREF(pyus_left);
-    Py_DECREF(pyus_right);
-    return result;
-}
-
-static PyObject *
-truedivide_timedelta_float(PyDateTime_Delta *delta, PyObject *f)
-{
-    PyObject *result = NULL;
-    PyObject *pyus_in = NULL, *temp, *pyus_out;
-    PyObject *ratio = NULL;
-
-    pyus_in = delta_to_microseconds(delta);
-    if (pyus_in == NULL)
-        return NULL;
-    ratio = PyObject_CallMethod(f, "as_integer_ratio", NULL);
-    if (ratio == NULL)
-        goto error;
-    temp = PyNumber_Multiply(pyus_in, PyTuple_GET_ITEM(ratio, 1));
-    Py_DECREF(pyus_in);
-    pyus_in = NULL;
-    if (temp == NULL)
-        goto error;
-    pyus_out = divide_nearest(temp, PyTuple_GET_ITEM(ratio, 0));
-    Py_DECREF(temp);
-    if (pyus_out == NULL)
-        goto error;
-    result = microseconds_to_delta(pyus_out);
-    Py_DECREF(pyus_out);
- error:
-    Py_XDECREF(pyus_in);
-    Py_XDECREF(ratio);
-
-    return result;
-}
-
-static PyObject *
-truedivide_timedelta_int(PyDateTime_Delta *delta, PyObject *i)
-{
-    PyObject *result;
-    PyObject *pyus_in, *pyus_out;
-    pyus_in = delta_to_microseconds(delta);
-    if (pyus_in == NULL)
-        return NULL;
-    pyus_out = divide_nearest(pyus_in, i);
-    Py_DECREF(pyus_in);
-    if (pyus_out == NULL)
-        return NULL;
-    result = microseconds_to_delta(pyus_out);
-    Py_DECREF(pyus_out);
-
-    return result;
-}
-
-static PyObject *
-delta_add(PyObject *left, PyObject *right)
-{
-    PyObject *result = Py_NotImplemented;
-
-    if (PyDelta_Check(left) && PyDelta_Check(right)) {
-        /* delta + delta */
-        /* The C-level additions can't overflow because of the
-         * invariant bounds.
-         */
-        int days = GET_TD_DAYS(left) + GET_TD_DAYS(right);
-        int seconds = GET_TD_SECONDS(left) + GET_TD_SECONDS(right);
-        int microseconds = GET_TD_MICROSECONDS(left) +
-                           GET_TD_MICROSECONDS(right);
-        result = new_delta(days, seconds, microseconds, 1);
-    }
-
-    if (result == Py_NotImplemented)
-        Py_INCREF(result);
-    return result;
-}
-
-static PyObject *
-delta_negative(PyDateTime_Delta *self)
-{
-    return new_delta(-GET_TD_DAYS(self),
-                     -GET_TD_SECONDS(self),
-                     -GET_TD_MICROSECONDS(self),
-                     1);
-}
-
-static PyObject *
-delta_positive(PyDateTime_Delta *self)
-{
-    /* Could optimize this (by returning self) if this isn't a
-     * subclass -- but who uses unary + ?  Approximately nobody.
-     */
-    return new_delta(GET_TD_DAYS(self),
-                     GET_TD_SECONDS(self),
-                     GET_TD_MICROSECONDS(self),
-                     0);
-}
-
-static PyObject *
-delta_abs(PyDateTime_Delta *self)
-{
-    PyObject *result;
-
-    assert(GET_TD_MICROSECONDS(self) >= 0);
-    assert(GET_TD_SECONDS(self) >= 0);
-
-    if (GET_TD_DAYS(self) < 0)
-        result = delta_negative(self);
-    else
-        result = delta_positive(self);
-
-    return result;
-}
-
-static PyObject *
-delta_subtract(PyObject *left, PyObject *right)
-{
-    PyObject *result = Py_NotImplemented;
-
-    if (PyDelta_Check(left) && PyDelta_Check(right)) {
-        /* delta - delta */
-        PyObject *minus_right = PyNumber_Negative(right);
-        if (minus_right) {
-            result = delta_add(left, minus_right);
-            Py_DECREF(minus_right);
-        }
-        else
-            result = NULL;
-    }
-
-    if (result == Py_NotImplemented)
-        Py_INCREF(result);
-    return result;
-}
-
-static int
-delta_cmp(PyObject *self, PyObject *other)
-{
-    int diff = GET_TD_DAYS(self) - GET_TD_DAYS(other);
-    if (diff == 0) {
-        diff = GET_TD_SECONDS(self) - GET_TD_SECONDS(other);
-        if (diff == 0)
-            diff = GET_TD_MICROSECONDS(self) -
-                GET_TD_MICROSECONDS(other);
-    }
-    return diff;
-}
-
-static PyObject *
-delta_richcompare(PyObject *self, PyObject *other, int op)
-{
-    if (PyDelta_Check(other)) {
-        int diff = delta_cmp(self, other);
-        return diff_to_bool(diff, op);
-    }
-    else {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-}
-
-static PyObject *delta_getstate(PyDateTime_Delta *self);
-
-static long
-delta_hash(PyDateTime_Delta *self)
-{
-    if (self->hashcode == -1) {
-        PyObject *temp = delta_getstate(self);
-        if (temp != NULL) {
-            self->hashcode = PyObject_Hash(temp);
-            Py_DECREF(temp);
-        }
-    }
-    return self->hashcode;
-}
-
-static PyObject *
-delta_multiply(PyObject *left, PyObject *right)
-{
-    PyObject *result = Py_NotImplemented;
-
-    if (PyDelta_Check(left)) {
-        /* delta * ??? */
-        if (PyLong_Check(right))
-            result = multiply_int_timedelta(right,
-                            (PyDateTime_Delta *) left);
-        else if (PyFloat_Check(right))
-            result = multiply_float_timedelta(right,
-                            (PyDateTime_Delta *) left);
-    }
-    else if (PyLong_Check(left))
-        result = multiply_int_timedelta(left,
-                        (PyDateTime_Delta *) right);
-    else if (PyFloat_Check(left))
-        result = multiply_float_timedelta(left,
-                        (PyDateTime_Delta *) right);
-
-    if (result == Py_NotImplemented)
-        Py_INCREF(result);
-    return result;
-}
-
-static PyObject *
-delta_divide(PyObject *left, PyObject *right)
-{
-    PyObject *result = Py_NotImplemented;
-
-    if (PyDelta_Check(left)) {
-        /* delta * ??? */
-        if (PyLong_Check(right))
-            result = divide_timedelta_int(
-                            (PyDateTime_Delta *)left,
-                            right);
-        else if (PyDelta_Check(right))
-            result = divide_timedelta_timedelta(
-                            (PyDateTime_Delta *)left,
-                            (PyDateTime_Delta *)right);
-    }
-
-    if (result == Py_NotImplemented)
-        Py_INCREF(result);
-    return result;
-}
-
-static PyObject *
-delta_truedivide(PyObject *left, PyObject *right)
-{
-    PyObject *result = Py_NotImplemented;
-
-    if (PyDelta_Check(left)) {
-        if (PyDelta_Check(right))
-            result = truedivide_timedelta_timedelta(
-                            (PyDateTime_Delta *)left,
-                            (PyDateTime_Delta *)right);
-        else if (PyFloat_Check(right))
-            result = truedivide_timedelta_float(
-                            (PyDateTime_Delta *)left, right);
-        else if (PyLong_Check(right))
-            result = truedivide_timedelta_int(
-                            (PyDateTime_Delta *)left, right);
-    }
-
-    if (result == Py_NotImplemented)
-        Py_INCREF(result);
-    return result;
-}
-
-static PyObject *
-delta_remainder(PyObject *left, PyObject *right)
-{
-    PyObject *pyus_left;
-    PyObject *pyus_right;
-    PyObject *pyus_remainder;
-    PyObject *remainder;
-
-    if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-
-    pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
-    if (pyus_left == NULL)
-        return NULL;
-
-    pyus_right = delta_to_microseconds((PyDateTime_Delta *)right);
-    if (pyus_right == NULL) {
-        Py_DECREF(pyus_left);
-        return NULL;
-    }
-
-    pyus_remainder = PyNumber_Remainder(pyus_left, pyus_right);
-    Py_DECREF(pyus_left);
-    Py_DECREF(pyus_right);
-    if (pyus_remainder == NULL)
-        return NULL;
-
-    remainder = microseconds_to_delta(pyus_remainder);
-    Py_DECREF(pyus_remainder);
-    if (remainder == NULL)
-        return NULL;
-
-    return remainder;
-}
-
-static PyObject *
-delta_divmod(PyObject *left, PyObject *right)
-{
-    PyObject *pyus_left;
-    PyObject *pyus_right;
-    PyObject *divmod;
-    PyObject *delta;
-    PyObject *result;
-
-    if (!PyDelta_Check(left) || !PyDelta_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-
-    pyus_left = delta_to_microseconds((PyDateTime_Delta *)left);
-    if (pyus_left == NULL)
-        return NULL;
-
-    pyus_right = delta_to_microseconds((PyDateTime_Delta *)right);
-    if (pyus_right == NULL) {
-        Py_DECREF(pyus_left);
-        return NULL;
-    }
-
-    divmod = PyNumber_Divmod(pyus_left, pyus_right);
-    Py_DECREF(pyus_left);
-    Py_DECREF(pyus_right);
-    if (divmod == NULL)
-        return NULL;
-
-    assert(PyTuple_Size(divmod) == 2);
-    delta = microseconds_to_delta(PyTuple_GET_ITEM(divmod, 1));
-    if (delta == NULL) {
-        Py_DECREF(divmod);
-        return NULL;
-    }
-    result = PyTuple_Pack(2, PyTuple_GET_ITEM(divmod, 0), delta);
-    Py_DECREF(delta);
-    Py_DECREF(divmod);
-    return result;
-}
-
-/* Fold in the value of the tag ("seconds", "weeks", etc) component of a
- * timedelta constructor.  sofar is the # of microseconds accounted for
- * so far, and there are factor microseconds per current unit, the number
- * of which is given by num.  num * factor is added to sofar in a
- * numerically careful way, and that's the result.  Any fractional
- * microseconds left over (this can happen if num is a float type) are
- * added into *leftover.
- * Note that there are many ways this can give an error (NULL) return.
- */
-static PyObject *
-accum(const char* tag, PyObject *sofar, PyObject *num, PyObject *factor,
-      double *leftover)
-{
-    PyObject *prod;
-    PyObject *sum;
-
-    assert(num != NULL);
-
-    if (PyLong_Check(num)) {
-        prod = PyNumber_Multiply(num, factor);
-        if (prod == NULL)
-            return NULL;
-        sum = PyNumber_Add(sofar, prod);
-        Py_DECREF(prod);
-        return sum;
-    }
-
-    if (PyFloat_Check(num)) {
-        double dnum;
-        double fracpart;
-        double intpart;
-        PyObject *x;
-        PyObject *y;
-
-        /* The Plan:  decompose num into an integer part and a
-         * fractional part, num = intpart + fracpart.
-         * Then num * factor ==
-         *      intpart * factor + fracpart * factor
-         * and the LHS can be computed exactly in long arithmetic.
-         * The RHS is again broken into an int part and frac part.
-         * and the frac part is added into *leftover.
-         */
-        dnum = PyFloat_AsDouble(num);
-        if (dnum == -1.0 && PyErr_Occurred())
-            return NULL;
-        fracpart = modf(dnum, &intpart);
-        x = PyLong_FromDouble(intpart);
-        if (x == NULL)
-            return NULL;
-
-        prod = PyNumber_Multiply(x, factor);
-        Py_DECREF(x);
-        if (prod == NULL)
-            return NULL;
-
-        sum = PyNumber_Add(sofar, prod);
-        Py_DECREF(prod);
-        if (sum == NULL)
-            return NULL;
-
-        if (fracpart == 0.0)
-            return sum;
-        /* So far we've lost no information.  Dealing with the
-         * fractional part requires float arithmetic, and may
-         * lose a little info.
-         */
-        assert(PyLong_Check(factor));
-        dnum = PyLong_AsDouble(factor);
-
-        dnum *= fracpart;
-        fracpart = modf(dnum, &intpart);
-        x = PyLong_FromDouble(intpart);
-        if (x == NULL) {
-            Py_DECREF(sum);
-            return NULL;
-        }
-
-        y = PyNumber_Add(sum, x);
-        Py_DECREF(sum);
-        Py_DECREF(x);
-        *leftover += fracpart;
-        return y;
-    }
-
-    PyErr_Format(PyExc_TypeError,
-                 "unsupported type for timedelta %s component: %s",
-                 tag, Py_TYPE(num)->tp_name);
-    return NULL;
-}
-
-static PyObject *
-delta_new(PyTypeObject *type, PyObject *args, PyObject *kw)
-{
-    PyObject *self = NULL;
-
-    /* Argument objects. */
-    PyObject *day = NULL;
-    PyObject *second = NULL;
-    PyObject *us = NULL;
-    PyObject *ms = NULL;
-    PyObject *minute = NULL;
-    PyObject *hour = NULL;
-    PyObject *week = NULL;
-
-    PyObject *x = NULL;         /* running sum of microseconds */
-    PyObject *y = NULL;         /* temp sum of microseconds */
-    double leftover_us = 0.0;
-
-    static char *keywords[] = {
-        "days", "seconds", "microseconds", "milliseconds",
-        "minutes", "hours", "weeks", NULL
-    };
-
-    if (PyArg_ParseTupleAndKeywords(args, kw, "|OOOOOOO:__new__",
-                                    keywords,
-                                    &day, &second, &us,
-                                    &ms, &minute, &hour, &week) == 0)
-        goto Done;
-
-    x = PyLong_FromLong(0);
-    if (x == NULL)
-        goto Done;
-
-#define CLEANUP         \
-    Py_DECREF(x);       \
-    x = y;              \
-    if (x == NULL)      \
-        goto Done
-
-    if (us) {
-        y = accum("microseconds", x, us, us_per_us, &leftover_us);
-        CLEANUP;
-    }
-    if (ms) {
-        y = accum("milliseconds", x, ms, us_per_ms, &leftover_us);
-        CLEANUP;
-    }
-    if (second) {
-        y = accum("seconds", x, second, us_per_second, &leftover_us);
-        CLEANUP;
-    }
-    if (minute) {
-        y = accum("minutes", x, minute, us_per_minute, &leftover_us);
-        CLEANUP;
-    }
-    if (hour) {
-        y = accum("hours", x, hour, us_per_hour, &leftover_us);
-        CLEANUP;
-    }
-    if (day) {
-        y = accum("days", x, day, us_per_day, &leftover_us);
-        CLEANUP;
-    }
-    if (week) {
-        y = accum("weeks", x, week, us_per_week, &leftover_us);
-        CLEANUP;
-    }
-    if (leftover_us) {
-        /* Round to nearest whole # of us, and add into x. */
-        PyObject *temp = PyLong_FromLong(round_to_long(leftover_us));
-        if (temp == NULL) {
-            Py_DECREF(x);
-            goto Done;
-        }
-        y = PyNumber_Add(x, temp);
-        Py_DECREF(temp);
-        CLEANUP;
-    }
-
-    self = microseconds_to_delta_ex(x, type);
-    Py_DECREF(x);
-Done:
-    return self;
-
-#undef CLEANUP
-}
-
-static int
-delta_bool(PyDateTime_Delta *self)
-{
-    return (GET_TD_DAYS(self) != 0
-        || GET_TD_SECONDS(self) != 0
-        || GET_TD_MICROSECONDS(self) != 0);
-}
-
-static PyObject *
-delta_repr(PyDateTime_Delta *self)
-{
-    if (GET_TD_MICROSECONDS(self) != 0)
-        return PyUnicode_FromFormat("%s(%d, %d, %d)",
-                                    Py_TYPE(self)->tp_name,
-                                    GET_TD_DAYS(self),
-                                    GET_TD_SECONDS(self),
-                                    GET_TD_MICROSECONDS(self));
-    if (GET_TD_SECONDS(self) != 0)
-        return PyUnicode_FromFormat("%s(%d, %d)",
-                                    Py_TYPE(self)->tp_name,
-                                    GET_TD_DAYS(self),
-                                    GET_TD_SECONDS(self));
-
-    return PyUnicode_FromFormat("%s(%d)",
-                                Py_TYPE(self)->tp_name,
-                                GET_TD_DAYS(self));
-}
-
-static PyObject *
-delta_str(PyDateTime_Delta *self)
-{
-    int us = GET_TD_MICROSECONDS(self);
-    int seconds = GET_TD_SECONDS(self);
-    int minutes = divmod(seconds, 60, &seconds);
-    int hours = divmod(minutes, 60, &minutes);
-    int days = GET_TD_DAYS(self);
-
-    if (days) {
-        if (us)
-            return PyUnicode_FromFormat("%d day%s, %d:%02d:%02d.%06d",
-                                        days, (days == 1 || days == -1) ? "" : "s",
-                                        hours, minutes, seconds, us);
-        else
-            return PyUnicode_FromFormat("%d day%s, %d:%02d:%02d",
-                                        days, (days == 1 || days == -1) ? "" : "s",
-                                        hours, minutes, seconds);
-    } else {
-        if (us)
-            return PyUnicode_FromFormat("%d:%02d:%02d.%06d",
-                                        hours, minutes, seconds, us);
-        else
-            return PyUnicode_FromFormat("%d:%02d:%02d",
-                                        hours, minutes, seconds);
-    }
-
-}
-
-/* Pickle support, a simple use of __reduce__. */
-
-/* __getstate__ isn't exposed */
-static PyObject *
-delta_getstate(PyDateTime_Delta *self)
-{
-    return Py_BuildValue("iii", GET_TD_DAYS(self),
-                                GET_TD_SECONDS(self),
-                                GET_TD_MICROSECONDS(self));
-}
-
-static PyObject *
-delta_total_seconds(PyObject *self)
-{
-    PyObject *total_seconds;
-    PyObject *total_microseconds;
-    PyObject *one_million;
-
-    total_microseconds = delta_to_microseconds((PyDateTime_Delta *)self);
-    if (total_microseconds == NULL)
-        return NULL;
-
-    one_million = PyLong_FromLong(1000000L);
-    if (one_million == NULL) {
-        Py_DECREF(total_microseconds);
-        return NULL;
-    }
-
-    total_seconds = PyNumber_TrueDivide(total_microseconds, one_million);
-
-    Py_DECREF(total_microseconds);
-    Py_DECREF(one_million);
-    return total_seconds;
-}
-
-static PyObject *
-delta_reduce(PyDateTime_Delta* self)
-{
-    return Py_BuildValue("ON", Py_TYPE(self), delta_getstate(self));
-}
-
-#define OFFSET(field)  offsetof(PyDateTime_Delta, field)
-
-static PyMemberDef delta_members[] = {
-
-    {"days",         T_INT, OFFSET(days),         READONLY,
-     PyDoc_STR("Number of days.")},
-
-    {"seconds",      T_INT, OFFSET(seconds),      READONLY,
-     PyDoc_STR("Number of seconds (>= 0 and less than 1 day).")},
-
-    {"microseconds", T_INT, OFFSET(microseconds), READONLY,
-     PyDoc_STR("Number of microseconds (>= 0 and less than 1 second).")},
-    {NULL}
-};
-
-static PyMethodDef delta_methods[] = {
-    {"total_seconds", (PyCFunction)delta_total_seconds, METH_NOARGS,
-     PyDoc_STR("Total seconds in the duration.")},
-
-    {"__reduce__", (PyCFunction)delta_reduce, METH_NOARGS,
-     PyDoc_STR("__reduce__() -> (cls, state)")},
-
-    {NULL,      NULL},
-};
-
-static char delta_doc[] =
-PyDoc_STR("Difference between two datetime values.");
-
-static PyNumberMethods delta_as_number = {
-    delta_add,                                  /* nb_add */
-    delta_subtract,                             /* nb_subtract */
-    delta_multiply,                             /* nb_multiply */
-    delta_remainder,                            /* nb_remainder */
-    delta_divmod,                               /* nb_divmod */
-    0,                                          /* nb_power */
-    (unaryfunc)delta_negative,                  /* nb_negative */
-    (unaryfunc)delta_positive,                  /* nb_positive */
-    (unaryfunc)delta_abs,                       /* nb_absolute */
-    (inquiry)delta_bool,                        /* nb_bool */
-    0,                                          /*nb_invert*/
-    0,                                          /*nb_lshift*/
-    0,                                          /*nb_rshift*/
-    0,                                          /*nb_and*/
-    0,                                          /*nb_xor*/
-    0,                                          /*nb_or*/
-    0,                                          /*nb_int*/
-    0,                                          /*nb_reserved*/
-    0,                                          /*nb_float*/
-    0,                                          /*nb_inplace_add*/
-    0,                                          /*nb_inplace_subtract*/
-    0,                                          /*nb_inplace_multiply*/
-    0,                                          /*nb_inplace_remainder*/
-    0,                                          /*nb_inplace_power*/
-    0,                                          /*nb_inplace_lshift*/
-    0,                                          /*nb_inplace_rshift*/
-    0,                                          /*nb_inplace_and*/
-    0,                                          /*nb_inplace_xor*/
-    0,                                          /*nb_inplace_or*/
-    delta_divide,                               /* nb_floor_divide */
-    delta_truedivide,                           /* nb_true_divide */
-    0,                                          /* nb_inplace_floor_divide */
-    0,                                          /* nb_inplace_true_divide */
-};
-
-static PyTypeObject PyDateTime_DeltaType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "datetime.timedelta",                               /* tp_name */
-    sizeof(PyDateTime_Delta),                           /* tp_basicsize */
-    0,                                                  /* tp_itemsize */
-    0,                                                  /* tp_dealloc */
-    0,                                                  /* tp_print */
-    0,                                                  /* tp_getattr */
-    0,                                                  /* tp_setattr */
-    0,                                                  /* tp_reserved */
-    (reprfunc)delta_repr,                               /* tp_repr */
-    &delta_as_number,                                   /* tp_as_number */
-    0,                                                  /* tp_as_sequence */
-    0,                                                  /* tp_as_mapping */
-    (hashfunc)delta_hash,                               /* tp_hash */
-    0,                                                  /* tp_call */
-    (reprfunc)delta_str,                                /* tp_str */
-    PyObject_GenericGetAttr,                            /* tp_getattro */
-    0,                                                  /* tp_setattro */
-    0,                                                  /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,           /* tp_flags */
-    delta_doc,                                          /* tp_doc */
-    0,                                                  /* tp_traverse */
-    0,                                                  /* tp_clear */
-    delta_richcompare,                                  /* tp_richcompare */
-    0,                                                  /* tp_weaklistoffset */
-    0,                                                  /* tp_iter */
-    0,                                                  /* tp_iternext */
-    delta_methods,                                      /* tp_methods */
-    delta_members,                                      /* tp_members */
-    0,                                                  /* tp_getset */
-    0,                                                  /* tp_base */
-    0,                                                  /* tp_dict */
-    0,                                                  /* tp_descr_get */
-    0,                                                  /* tp_descr_set */
-    0,                                                  /* tp_dictoffset */
-    0,                                                  /* tp_init */
-    0,                                                  /* tp_alloc */
-    delta_new,                                          /* tp_new */
-    0,                                                  /* tp_free */
-};
-
-/*
- * PyDateTime_Date implementation.
- */
-
-/* Accessor properties. */
-
-static PyObject *
-date_year(PyDateTime_Date *self, void *unused)
-{
-    return PyLong_FromLong(GET_YEAR(self));
-}
-
-static PyObject *
-date_month(PyDateTime_Date *self, void *unused)
-{
-    return PyLong_FromLong(GET_MONTH(self));
-}
-
-static PyObject *
-date_day(PyDateTime_Date *self, void *unused)
-{
-    return PyLong_FromLong(GET_DAY(self));
-}
-
-static PyGetSetDef date_getset[] = {
-    {"year",        (getter)date_year},
-    {"month",       (getter)date_month},
-    {"day",         (getter)date_day},
-    {NULL}
-};
-
-/* Constructors. */
-
-static char *date_kws[] = {"year", "month", "day", NULL};
-
-static PyObject *
-date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
-{
-    PyObject *self = NULL;
-    PyObject *state;
-    int year;
-    int month;
-    int day;
-
-    /* Check for invocation from pickle with __getstate__ state */
-    if (PyTuple_GET_SIZE(args) == 1 &&
-        PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
-        PyBytes_GET_SIZE(state) == _PyDateTime_DATE_DATASIZE &&
-        MONTH_IS_SANE(PyBytes_AS_STRING(state)[2]))
-    {
-        PyDateTime_Date *me;
-
-        me = (PyDateTime_Date *) (type->tp_alloc(type, 0));
-        if (me != NULL) {
-            char *pdata = PyBytes_AS_STRING(state);
-            memcpy(me->data, pdata, _PyDateTime_DATE_DATASIZE);
-            me->hashcode = -1;
-        }
-        return (PyObject *)me;
-    }
-
-    if (PyArg_ParseTupleAndKeywords(args, kw, "iii", date_kws,
-                                    &year, &month, &day)) {
-        if (check_date_args(year, month, day) < 0)
-            return NULL;
-        self = new_date_ex(year, month, day, type);
-    }
-    return self;
-}
-
-/* Return new date from localtime(t). */
-static PyObject *
-date_local_from_time_t(PyObject *cls, double ts)
-{
-    struct tm *tm;
-    time_t t;
-    PyObject *result = NULL;
-
-    t = _PyTime_DoubleToTimet(ts);
-    if (t == (time_t)-1 && PyErr_Occurred())
-        return NULL;
-    tm = localtime(&t);
-    if (tm)
-        result = PyObject_CallFunction(cls, "iii",
-                                       tm->tm_year + 1900,
-                                       tm->tm_mon + 1,
-                                       tm->tm_mday);
-    else
-        PyErr_SetString(PyExc_ValueError,
-                        "timestamp out of range for "
-                        "platform localtime() function");
-    return result;
-}
-
-/* Return new date from current time.
- * We say this is equivalent to fromtimestamp(time.time()), and the
- * only way to be sure of that is to *call* time.time().  That's not
- * generally the same as calling C's time.
- */
-static PyObject *
-date_today(PyObject *cls, PyObject *dummy)
-{
-    PyObject *time;
-    PyObject *result;
-
-    time = time_time();
-    if (time == NULL)
-        return NULL;
-
-    /* Note well:  today() is a class method, so this may not call
-     * date.fromtimestamp.  For example, it may call
-     * datetime.fromtimestamp.  That's why we need all the accuracy
-     * time.time() delivers; if someone were gonzo about optimization,
-     * date.today() could get away with plain C time().
-     */
-    result = PyObject_CallMethod(cls, "fromtimestamp", "O", time);
-    Py_DECREF(time);
-    return result;
-}
-
-/* Return new date from given timestamp (Python timestamp -- a double). */
-static PyObject *
-date_fromtimestamp(PyObject *cls, PyObject *args)
-{
-    double timestamp;
-    PyObject *result = NULL;
-
-    if (PyArg_ParseTuple(args, "d:fromtimestamp", &timestamp))
-        result = date_local_from_time_t(cls, timestamp);
-    return result;
-}
-
-/* Return new date from proleptic Gregorian ordinal.  Raises ValueError if
- * the ordinal is out of range.
- */
-static PyObject *
-date_fromordinal(PyObject *cls, PyObject *args)
-{
-    PyObject *result = NULL;
-    int ordinal;
-
-    if (PyArg_ParseTuple(args, "i:fromordinal", &ordinal)) {
-        int year;
-        int month;
-        int day;
-
-        if (ordinal < 1)
-            PyErr_SetString(PyExc_ValueError, "ordinal must be "
-                                              ">= 1");
-        else {
-            ord_to_ymd(ordinal, &year, &month, &day);
-            result = PyObject_CallFunction(cls, "iii",
-                                           year, month, day);
-        }
-    }
-    return result;
-}
-
-/*
- * Date arithmetic.
- */
-
-/* date + timedelta -> date.  If arg negate is true, subtract the timedelta
- * instead.
- */
-static PyObject *
-add_date_timedelta(PyDateTime_Date *date, PyDateTime_Delta *delta, int negate)
-{
-    PyObject *result = NULL;
-    int year = GET_YEAR(date);
-    int month = GET_MONTH(date);
-    int deltadays = GET_TD_DAYS(delta);
-    /* C-level overflow is impossible because |deltadays| < 1e9. */
-    int day = GET_DAY(date) + (negate ? -deltadays : deltadays);
-
-    if (normalize_date(&year, &month, &day) >= 0)
-        result = new_date(year, month, day);
-    return result;
-}
-
-static PyObject *
-date_add(PyObject *left, PyObject *right)
-{
-    if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-    if (PyDate_Check(left)) {
-        /* date + ??? */
-        if (PyDelta_Check(right))
-            /* date + delta */
-            return add_date_timedelta((PyDateTime_Date *) left,
-                                      (PyDateTime_Delta *) right,
-                                      0);
-    }
-    else {
-        /* ??? + date
-         * 'right' must be one of us, or we wouldn't have been called
-         */
-        if (PyDelta_Check(left))
-            /* delta + date */
-            return add_date_timedelta((PyDateTime_Date *) right,
-                                      (PyDateTime_Delta *) left,
-                                      0);
-    }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
-}
-
-static PyObject *
-date_subtract(PyObject *left, PyObject *right)
-{
-    if (PyDateTime_Check(left) || PyDateTime_Check(right)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-    if (PyDate_Check(left)) {
-        if (PyDate_Check(right)) {
-            /* date - date */
-            int left_ord = ymd_to_ord(GET_YEAR(left),
-                                      GET_MONTH(left),
-                                      GET_DAY(left));
-            int right_ord = ymd_to_ord(GET_YEAR(right),
-                                       GET_MONTH(right),
-                                       GET_DAY(right));
-            return new_delta(left_ord - right_ord, 0, 0, 0);
-        }
-        if (PyDelta_Check(right)) {
-            /* date - delta */
-            return add_date_timedelta((PyDateTime_Date *) left,
-                                      (PyDateTime_Delta *) right,
-                                      1);
-        }
-    }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
-}
-
-
-/* Various ways to turn a date into a string. */
-
-static PyObject *
-date_repr(PyDateTime_Date *self)
-{
-    return PyUnicode_FromFormat("%s(%d, %d, %d)",
-                                Py_TYPE(self)->tp_name,
-                                GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
-}
-
-static PyObject *
-date_isoformat(PyDateTime_Date *self)
-{
-    return PyUnicode_FromFormat("%04d-%02d-%02d",
-                                GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
-}
-
-/* str() calls the appropriate isoformat() method. */
-static PyObject *
-date_str(PyDateTime_Date *self)
-{
-    return PyObject_CallMethod((PyObject *)self, "isoformat", "()");
-}
-
-
-static PyObject *
-date_ctime(PyDateTime_Date *self)
-{
-    return format_ctime(self, 0, 0, 0);
-}
-
-static PyObject *
-date_strftime(PyDateTime_Date *self, PyObject *args, PyObject *kw)
-{
-    /* This method can be inherited, and needs to call the
-     * timetuple() method appropriate to self's class.
-     */
-    PyObject *result;
-    PyObject *tuple;
-    PyObject *format;
-    static char *keywords[] = {"format", NULL};
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
-                                      &format))
-        return NULL;
-
-    tuple = PyObject_CallMethod((PyObject *)self, "timetuple", "()");
-    if (tuple == NULL)
-        return NULL;
-    result = wrap_strftime((PyObject *)self, format, tuple,
-                           (PyObject *)self);
-    Py_DECREF(tuple);
-    return result;
-}
-
-static PyObject *
-date_format(PyDateTime_Date *self, PyObject *args)
-{
-    PyObject *format;
-
-    if (!PyArg_ParseTuple(args, "U:__format__", &format))
-        return NULL;
-
-    /* if the format is zero length, return str(self) */
-    if (PyUnicode_GetSize(format) == 0)
-        return PyObject_Str((PyObject *)self);
-
-    return PyObject_CallMethod((PyObject *)self, "strftime", "O", format);
-}
-
-/* ISO methods. */
-
-static PyObject *
-date_isoweekday(PyDateTime_Date *self)
-{
-    int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
-
-    return PyLong_FromLong(dow + 1);
-}
-
-static PyObject *
-date_isocalendar(PyDateTime_Date *self)
-{
-    int  year         = GET_YEAR(self);
-    int  week1_monday = iso_week1_monday(year);
-    int today         = ymd_to_ord(year, GET_MONTH(self), GET_DAY(self));
-    int  week;
-    int  day;
-
-    week = divmod(today - week1_monday, 7, &day);
-    if (week < 0) {
-        --year;
-        week1_monday = iso_week1_monday(year);
-        week = divmod(today - week1_monday, 7, &day);
-    }
-    else if (week >= 52 && today >= iso_week1_monday(year + 1)) {
-        ++year;
-        week = 0;
-    }
-    return Py_BuildValue("iii", year, week + 1, day + 1);
-}
-
-/* Miscellaneous methods. */
-
-static PyObject *
-date_richcompare(PyObject *self, PyObject *other, int op)
-{
-    if (PyDate_Check(other)) {
-        int diff = memcmp(((PyDateTime_Date *)self)->data,
-                          ((PyDateTime_Date *)other)->data,
-                          _PyDateTime_DATE_DATASIZE);
-        return diff_to_bool(diff, op);
-    }
-    else {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-}
-
-static PyObject *
-date_timetuple(PyDateTime_Date *self)
-{
-    return build_struct_time(GET_YEAR(self),
-                             GET_MONTH(self),
-                             GET_DAY(self),
-                             0, 0, 0, -1);
-}
-
-static PyObject *
-date_replace(PyDateTime_Date *self, PyObject *args, PyObject *kw)
-{
-    PyObject *clone;
-    PyObject *tuple;
-    int year = GET_YEAR(self);
-    int month = GET_MONTH(self);
-    int day = GET_DAY(self);
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "|iii:replace", date_kws,
-                                      &year, &month, &day))
-        return NULL;
-    tuple = Py_BuildValue("iii", year, month, day);
-    if (tuple == NULL)
-        return NULL;
-    clone = date_new(Py_TYPE(self), tuple, NULL);
-    Py_DECREF(tuple);
-    return clone;
-}
-
-/*
-    Borrowed from stringobject.c, originally it was string_hash()
-*/
-static long
-generic_hash(unsigned char *data, int len)
-{
-    register unsigned char *p;
-    register long x;
-
-    p = (unsigned char *) data;
-    x = *p << 7;
-    while (--len >= 0)
-        x = (1000003*x) ^ *p++;
-    x ^= len;
-    if (x == -1)
-        x = -2;
-
-    return x;
-}
-
-
-static PyObject *date_getstate(PyDateTime_Date *self);
-
-static long
-date_hash(PyDateTime_Date *self)
-{
-    if (self->hashcode == -1)
-        self->hashcode = generic_hash(
-            (unsigned char *)self->data, _PyDateTime_DATE_DATASIZE);
-
-    return self->hashcode;
-}
-
-static PyObject *
-date_toordinal(PyDateTime_Date *self)
-{
-    return PyLong_FromLong(ymd_to_ord(GET_YEAR(self), GET_MONTH(self),
-                                     GET_DAY(self)));
-}
-
-static PyObject *
-date_weekday(PyDateTime_Date *self)
-{
-    int dow = weekday(GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
-
-    return PyLong_FromLong(dow);
-}
-
-/* Pickle support, a simple use of __reduce__. */
-
-/* __getstate__ isn't exposed */
-static PyObject *
-date_getstate(PyDateTime_Date *self)
-{
-    PyObject* field;
-    field = PyBytes_FromStringAndSize((char*)self->data,
-                                       _PyDateTime_DATE_DATASIZE);
-    return Py_BuildValue("(N)", field);
-}
-
-static PyObject *
-date_reduce(PyDateTime_Date *self, PyObject *arg)
-{
-    return Py_BuildValue("(ON)", Py_TYPE(self), date_getstate(self));
-}
-
-static PyMethodDef date_methods[] = {
-
-    /* Class methods: */
-
-    {"fromtimestamp", (PyCFunction)date_fromtimestamp, METH_VARARGS |
-                                                       METH_CLASS,
-     PyDoc_STR("timestamp -> local date from a POSIX timestamp (like "
-               "time.time()).")},
-
-    {"fromordinal", (PyCFunction)date_fromordinal,      METH_VARARGS |
-                                                    METH_CLASS,
-     PyDoc_STR("int -> date corresponding to a proleptic Gregorian "
-               "ordinal.")},
-
-    {"today",         (PyCFunction)date_today,   METH_NOARGS | METH_CLASS,
-     PyDoc_STR("Current date or datetime:  same as "
-               "self.__class__.fromtimestamp(time.time()).")},
-
-    /* Instance methods: */
-
-    {"ctime",       (PyCFunction)date_ctime,        METH_NOARGS,
-     PyDoc_STR("Return ctime() style string.")},
-
-    {"strftime",        (PyCFunction)date_strftime,     METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("format -> strftime() style string.")},
-
-    {"__format__",      (PyCFunction)date_format,       METH_VARARGS,
-     PyDoc_STR("Formats self with strftime.")},
-
-    {"timetuple",   (PyCFunction)date_timetuple,    METH_NOARGS,
-     PyDoc_STR("Return time tuple, compatible with time.localtime().")},
-
-    {"isocalendar", (PyCFunction)date_isocalendar,  METH_NOARGS,
-     PyDoc_STR("Return a 3-tuple containing ISO year, week number, and "
-               "weekday.")},
-
-    {"isoformat",   (PyCFunction)date_isoformat,        METH_NOARGS,
-     PyDoc_STR("Return string in ISO 8601 format, YYYY-MM-DD.")},
-
-    {"isoweekday",  (PyCFunction)date_isoweekday,   METH_NOARGS,
-     PyDoc_STR("Return the day of the week represented by the date.\n"
-               "Monday == 1 ... Sunday == 7")},
-
-    {"toordinal",   (PyCFunction)date_toordinal,    METH_NOARGS,
-     PyDoc_STR("Return proleptic Gregorian ordinal.  January 1 of year "
-               "1 is day 1.")},
-
-    {"weekday",     (PyCFunction)date_weekday,      METH_NOARGS,
-     PyDoc_STR("Return the day of the week represented by the date.\n"
-               "Monday == 0 ... Sunday == 6")},
-
-    {"replace",     (PyCFunction)date_replace,      METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("Return date with new specified fields.")},
-
-    {"__reduce__", (PyCFunction)date_reduce,        METH_NOARGS,
-     PyDoc_STR("__reduce__() -> (cls, state)")},
-
-    {NULL,      NULL}
-};
-
-static char date_doc[] =
-PyDoc_STR("date(year, month, day) --> date object");
-
-static PyNumberMethods date_as_number = {
-    date_add,                                           /* nb_add */
-    date_subtract,                                      /* nb_subtract */
-    0,                                                  /* nb_multiply */
-    0,                                                  /* nb_remainder */
-    0,                                                  /* nb_divmod */
-    0,                                                  /* nb_power */
-    0,                                                  /* nb_negative */
-    0,                                                  /* nb_positive */
-    0,                                                  /* nb_absolute */
-    0,                                                  /* nb_bool */
-};
-
-static PyTypeObject PyDateTime_DateType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "datetime.date",                                    /* tp_name */
-    sizeof(PyDateTime_Date),                            /* tp_basicsize */
-    0,                                                  /* tp_itemsize */
-    0,                                                  /* tp_dealloc */
-    0,                                                  /* tp_print */
-    0,                                                  /* tp_getattr */
-    0,                                                  /* tp_setattr */
-    0,                                                  /* tp_reserved */
-    (reprfunc)date_repr,                                /* tp_repr */
-    &date_as_number,                                    /* tp_as_number */
-    0,                                                  /* tp_as_sequence */
-    0,                                                  /* tp_as_mapping */
-    (hashfunc)date_hash,                                /* tp_hash */
-    0,                                                  /* tp_call */
-    (reprfunc)date_str,                                 /* tp_str */
-    PyObject_GenericGetAttr,                            /* tp_getattro */
-    0,                                                  /* tp_setattro */
-    0,                                                  /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,           /* tp_flags */
-    date_doc,                                           /* tp_doc */
-    0,                                                  /* tp_traverse */
-    0,                                                  /* tp_clear */
-    date_richcompare,                                   /* tp_richcompare */
-    0,                                                  /* tp_weaklistoffset */
-    0,                                                  /* tp_iter */
-    0,                                                  /* tp_iternext */
-    date_methods,                                       /* tp_methods */
-    0,                                                  /* tp_members */
-    date_getset,                                        /* tp_getset */
-    0,                                                  /* tp_base */
-    0,                                                  /* tp_dict */
-    0,                                                  /* tp_descr_get */
-    0,                                                  /* tp_descr_set */
-    0,                                                  /* tp_dictoffset */
-    0,                                                  /* tp_init */
-    0,                                                  /* tp_alloc */
-    date_new,                                           /* tp_new */
-    0,                                                  /* tp_free */
-};
-
-/*
- * PyDateTime_TZInfo implementation.
- */
-
-/* This is a pure abstract base class, so doesn't do anything beyond
- * raising NotImplemented exceptions.  Real tzinfo classes need
- * to derive from this.  This is mostly for clarity, and for efficiency in
- * datetime and time constructors (their tzinfo arguments need to
- * be subclasses of this tzinfo class, which is easy and quick to check).
- *
- * Note:  For reasons having to do with pickling of subclasses, we have
- * to allow tzinfo objects to be instantiated.  This wasn't an issue
- * in the Python implementation (__init__() could raise NotImplementedError
- * there without ill effect), but doing so in the C implementation hit a
- * brick wall.
- */
-
-static PyObject *
-tzinfo_nogo(const char* methodname)
-{
-    PyErr_Format(PyExc_NotImplementedError,
-                 "a tzinfo subclass must implement %s()",
-                 methodname);
-    return NULL;
-}
-
-/* Methods.  A subclass must implement these. */
-
-static PyObject *
-tzinfo_tzname(PyDateTime_TZInfo *self, PyObject *dt)
-{
-    return tzinfo_nogo("tzname");
-}
-
-static PyObject *
-tzinfo_utcoffset(PyDateTime_TZInfo *self, PyObject *dt)
-{
-    return tzinfo_nogo("utcoffset");
-}
-
-static PyObject *
-tzinfo_dst(PyDateTime_TZInfo *self, PyObject *dt)
-{
-    return tzinfo_nogo("dst");
-}
-
-
-static PyObject *add_datetime_timedelta(PyDateTime_DateTime *date,
-                                        PyDateTime_Delta *delta,
-                                        int factor);
-static PyObject *datetime_utcoffset(PyObject *self, PyObject *);
-static PyObject *datetime_dst(PyObject *self, PyObject *);
-
-static PyObject *
-tzinfo_fromutc(PyDateTime_TZInfo *self, PyObject *dt)
-{
-    PyObject *result = NULL;
-    PyObject *off = NULL, *dst = NULL;
-    PyDateTime_Delta *delta = NULL;
-
-    if (!PyDateTime_Check(dt)) {
-        PyErr_SetString(PyExc_TypeError,
-                        "fromutc: argument must be a datetime");
-        return NULL;
-    }
-    if (GET_DT_TZINFO(dt) != (PyObject *)self) {
-        PyErr_SetString(PyExc_ValueError, "fromutc: dt.tzinfo "
-                        "is not self");
-        return NULL;
-    }
-
-    off = datetime_utcoffset(dt, NULL);
-    if (off == NULL)
-        return NULL;
-    if (off == Py_None) {
-        PyErr_SetString(PyExc_ValueError, "fromutc: non-None "
-                        "utcoffset() result required");
-        goto Fail;
-    }
-
-    dst = datetime_dst(dt, NULL);
-    if (dst == NULL)
-        goto Fail;
-    if (dst == Py_None) {
-        PyErr_SetString(PyExc_ValueError, "fromutc: non-None "
-                        "dst() result required");
-        goto Fail;
-    }
-
-    delta = (PyDateTime_Delta *)delta_subtract(off, dst);
-    if (delta == NULL)
-        goto Fail;
-    result = add_datetime_timedelta((PyDateTime_DateTime *)dt, delta, 1);
-    if (result == NULL)
-        goto Fail;
-
-    Py_DECREF(dst);
-    dst = call_dst(GET_DT_TZINFO(dt), result);
-    if (dst == NULL)
-        goto Fail;
-    if (dst == Py_None)
-        goto Inconsistent;
-    if (delta_bool(delta) != 0) {
-        PyObject *temp = result;
-        result = add_datetime_timedelta((PyDateTime_DateTime *)result,
-                                        (PyDateTime_Delta *)dst, 1);
-        Py_DECREF(temp);
-        if (result == NULL)
-            goto Fail;
-    }
-    Py_DECREF(delta);
-    Py_DECREF(dst);
-    Py_DECREF(off);
-    return result;
-
-Inconsistent:
-    PyErr_SetString(PyExc_ValueError, "fromutc: tz.dst() gave"
-                    "inconsistent results; cannot convert");
-
-    /* fall thru to failure */
-Fail:
-    Py_XDECREF(off);
-    Py_XDECREF(dst);
-    Py_XDECREF(delta);
-    Py_XDECREF(result);
-    return NULL;
-}
-
-/*
- * Pickle support.  This is solely so that tzinfo subclasses can use
- * pickling -- tzinfo itself is supposed to be uninstantiable.
- */
-
-static PyObject *
-tzinfo_reduce(PyObject *self)
-{
-    PyObject *args, *state, *tmp;
-    PyObject *getinitargs, *getstate;
-
-    tmp = PyTuple_New(0);
-    if (tmp == NULL)
-        return NULL;
-
-    getinitargs = PyObject_GetAttrString(self, "__getinitargs__");
-    if (getinitargs != NULL) {
-        args = PyObject_CallObject(getinitargs, tmp);
-        Py_DECREF(getinitargs);
-        if (args == NULL) {
-            Py_DECREF(tmp);
-            return NULL;
-        }
-    }
-    else {
-        PyErr_Clear();
-        args = tmp;
-        Py_INCREF(args);
-    }
-
-    getstate = PyObject_GetAttrString(self, "__getstate__");
-    if (getstate != NULL) {
-        state = PyObject_CallObject(getstate, tmp);
-        Py_DECREF(getstate);
-        if (state == NULL) {
-            Py_DECREF(args);
-            Py_DECREF(tmp);
-            return NULL;
-        }
-    }
-    else {
-        PyObject **dictptr;
-        PyErr_Clear();
-        state = Py_None;
-        dictptr = _PyObject_GetDictPtr(self);
-        if (dictptr && *dictptr && PyDict_Size(*dictptr))
-            state = *dictptr;
-        Py_INCREF(state);
-    }
-
-    Py_DECREF(tmp);
-
-    if (state == Py_None) {
-        Py_DECREF(state);
-        return Py_BuildValue("(ON)", Py_TYPE(self), args);
-    }
-    else
-        return Py_BuildValue("(ONN)", Py_TYPE(self), args, state);
-}
-
-static PyMethodDef tzinfo_methods[] = {
-
-    {"tzname",          (PyCFunction)tzinfo_tzname,             METH_O,
-     PyDoc_STR("datetime -> string name of time zone.")},
-
-    {"utcoffset",       (PyCFunction)tzinfo_utcoffset,          METH_O,
-     PyDoc_STR("datetime -> timedelta showing offset from UTC, negative "
-           "values indicating West of UTC")},
-
-    {"dst",             (PyCFunction)tzinfo_dst,                METH_O,
-     PyDoc_STR("datetime -> DST offset in minutes east of UTC.")},
-
-    {"fromutc",         (PyCFunction)tzinfo_fromutc,            METH_O,
-     PyDoc_STR("datetime in UTC -> datetime in local time.")},
-
-    {"__reduce__",  (PyCFunction)tzinfo_reduce,             METH_NOARGS,
-     PyDoc_STR("-> (cls, state)")},
-
-    {NULL, NULL}
-};
-
-static char tzinfo_doc[] =
-PyDoc_STR("Abstract base class for time zone info objects.");
-
-static PyTypeObject PyDateTime_TZInfoType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "datetime.tzinfo",                          /* tp_name */
-    sizeof(PyDateTime_TZInfo),                  /* tp_basicsize */
-    0,                                          /* tp_itemsize */
-    0,                                          /* tp_dealloc */
-    0,                                          /* tp_print */
-    0,                                          /* tp_getattr */
-    0,                                          /* tp_setattr */
-    0,                                          /* tp_reserved */
-    0,                                          /* tp_repr */
-    0,                                          /* tp_as_number */
-    0,                                          /* tp_as_sequence */
-    0,                                          /* tp_as_mapping */
-    0,                                          /* tp_hash */
-    0,                                          /* tp_call */
-    0,                                          /* tp_str */
-    PyObject_GenericGetAttr,                    /* tp_getattro */
-    0,                                          /* tp_setattro */
-    0,                                          /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,   /* tp_flags */
-    tzinfo_doc,                                 /* tp_doc */
-    0,                                          /* tp_traverse */
-    0,                                          /* tp_clear */
-    0,                                          /* tp_richcompare */
-    0,                                          /* tp_weaklistoffset */
-    0,                                          /* tp_iter */
-    0,                                          /* tp_iternext */
-    tzinfo_methods,                             /* tp_methods */
-    0,                                          /* tp_members */
-    0,                                          /* tp_getset */
-    0,                                          /* tp_base */
-    0,                                          /* tp_dict */
-    0,                                          /* tp_descr_get */
-    0,                                          /* tp_descr_set */
-    0,                                          /* tp_dictoffset */
-    0,                                          /* tp_init */
-    0,                                          /* tp_alloc */
-    PyType_GenericNew,                          /* tp_new */
-    0,                                          /* tp_free */
-};
-
-static char *timezone_kws[] = {"offset", "name", NULL};
-
-static PyObject *
-timezone_new(PyTypeObject *type, PyObject *args, PyObject *kw)
-{
-    PyObject *offset;
-    PyObject *name = NULL;
-    if (PyArg_ParseTupleAndKeywords(args, kw, "O!|O!:timezone", timezone_kws,
-                                    &PyDateTime_DeltaType, &offset,
-                                    &PyUnicode_Type, &name))
-        return new_timezone(offset, name);
-
-    return NULL;
-}
-
-static void
-timezone_dealloc(PyDateTime_TimeZone *self)
-{
-    Py_CLEAR(self->offset);
-    Py_CLEAR(self->name);
-    Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-static PyObject *
-timezone_richcompare(PyDateTime_TimeZone *self,
-                     PyDateTime_TimeZone *other, int op)
-{
-    if (op != Py_EQ && op != Py_NE) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-    return delta_richcompare(self->offset, other->offset, op);
-}
-
-static long
-timezone_hash(PyDateTime_TimeZone *self)
-{
-    return delta_hash((PyDateTime_Delta *)self->offset);
-}
-
-/* Check argument type passed to tzname, utcoffset, or dst methods.
-   Returns 0 for good argument.  Returns -1 and sets exception info
-   otherwise.
- */
-static int
-_timezone_check_argument(PyObject *dt, const char *meth)
-{
-    if (dt == Py_None || PyDateTime_Check(dt))
-        return 0;
-    PyErr_Format(PyExc_TypeError, "%s(dt) argument must be a datetime instance"
-                 " or None, not %.200s", meth, Py_TYPE(dt)->tp_name);
-    return -1;
-}
-
-static PyObject *
-timezone_repr(PyDateTime_TimeZone *self)
-{
-    /* Note that although timezone is not subclassable, it is convenient
-       to use Py_TYPE(self)->tp_name here. */
-    const char *type_name = Py_TYPE(self)->tp_name;
-
-    if (((PyObject *)self) == PyDateTime_TimeZone_UTC)
-        return PyUnicode_FromFormat("%s.utc", type_name);
-
-    if (self->name == NULL)
-        return PyUnicode_FromFormat("%s(%R)", type_name, self->offset);
-
-    return PyUnicode_FromFormat("%s(%R, %R)", type_name, self->offset,
-                                self->name);
-}
-
-
-static PyObject *
-timezone_str(PyDateTime_TimeZone *self)
-{
-    char buf[10];
-    int hours, minutes, seconds;
-    PyObject *offset;
-    char sign;
-
-    if (self->name != NULL) {
-        Py_INCREF(self->name);
-        return self->name;
-    }
-    /* Offset is normalized, so it is negative if days < 0 */
-    if (GET_TD_DAYS(self->offset) < 0) {
-        sign = '-';
-        offset = delta_negative((PyDateTime_Delta *)self->offset);
-        if (offset == NULL)
-            return NULL;
-    }
-    else {
-        sign = '+';
-        offset = self->offset;
-        Py_INCREF(offset);
-    }
-    /* Offset is not negative here. */
-    seconds = GET_TD_SECONDS(offset);
-    Py_DECREF(offset);
-    minutes = divmod(seconds, 60, &seconds);
-    hours = divmod(minutes, 60, &minutes);
-    assert(seconds == 0);
-    /* XXX ignore sub-minute data, curently not allowed. */
-    PyOS_snprintf(buf, sizeof(buf), "UTC%c%02d:%02d", sign, hours, minutes);
-
-    return PyUnicode_FromString(buf);
-}
-
-static PyObject *
-timezone_tzname(PyDateTime_TimeZone *self, PyObject *dt)
-{
-    if (_timezone_check_argument(dt, "tzname") == -1)
-        return NULL;
-
-    return timezone_str(self);
-}
-
-static PyObject *
-timezone_utcoffset(PyDateTime_TimeZone *self, PyObject *dt)
-{
-    if (_timezone_check_argument(dt, "utcoffset") == -1)
-        return NULL;
-
-    Py_INCREF(self->offset);
-    return self->offset;
-}
-
-static PyObject *
-timezone_dst(PyObject *self, PyObject *dt)
-{
-    if (_timezone_check_argument(dt, "dst") == -1)
-        return NULL;
-
-    Py_RETURN_NONE;
-}
-
-static PyObject *
-timezone_fromutc(PyDateTime_TimeZone *self, PyDateTime_DateTime *dt)
-{
-    if (!PyDateTime_Check(dt)) {
-        PyErr_SetString(PyExc_TypeError,
-                        "fromutc: argument must be a datetime");
-        return NULL;
-    }
-    if (!HASTZINFO(dt) || dt->tzinfo != (PyObject *)self) {
-        PyErr_SetString(PyExc_ValueError, "fromutc: dt.tzinfo "
-                        "is not self");
-        return NULL;
-    }
-
-    return add_datetime_timedelta(dt, (PyDateTime_Delta *)self->offset, 1);
-}
-
-static PyObject *
-timezone_getinitargs(PyDateTime_TimeZone *self)
-{
-    if (self->name == NULL)
-        return Py_BuildValue("(O)", self->offset);
-    return Py_BuildValue("(OO)", self->offset, self->name);
-}
-
-static PyMethodDef timezone_methods[] = {
-    {"tzname", (PyCFunction)timezone_tzname, METH_O,
-     PyDoc_STR("If name is specified when timezone is created, returns the name."
-               "  Otherwise returns offset as 'UTC(+|-)HH:MM'.")},
-
-    {"utcoffset", (PyCFunction)timezone_utcoffset, METH_O,
-     PyDoc_STR("Return fixed offset.")},
-
-    {"dst", (PyCFunction)timezone_dst, METH_O,
-     PyDoc_STR("Return None.")},
-
-    {"fromutc", (PyCFunction)timezone_fromutc, METH_O,
-     PyDoc_STR("datetime in UTC -> datetime in local time.")},
-
-    {"__getinitargs__", (PyCFunction)timezone_getinitargs, METH_NOARGS,
-     PyDoc_STR("pickle support")},
-
-    {NULL, NULL}
-};
-
-static char timezone_doc[] =
-PyDoc_STR("Fixed offset from UTC implementation of tzinfo.");
-
-static PyTypeObject PyDateTime_TimeZoneType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "datetime.timezone",              /* tp_name */
-    sizeof(PyDateTime_TimeZone),      /* tp_basicsize */
-    0,                                /* tp_itemsize */
-    (destructor)timezone_dealloc,     /* tp_dealloc */
-    0,                                /* tp_print */
-    0,                                /* tp_getattr */
-    0,                                /* tp_setattr */
-    0,                                /* tp_reserved */
-    (reprfunc)timezone_repr,          /* tp_repr */
-    0,                                /* tp_as_number */
-    0,                                /* tp_as_sequence */
-    0,                                /* tp_as_mapping */
-    (hashfunc)timezone_hash,          /* tp_hash */
-    0,                                /* tp_call */
-    (reprfunc)timezone_str,           /* tp_str */
-    0,                                /* tp_getattro */
-    0,                                /* tp_setattro */
-    0,                                /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT,               /* tp_flags */
-    timezone_doc,                     /* tp_doc */
-    0,                                /* tp_traverse */
-    0,                                /* tp_clear */
-    (richcmpfunc)timezone_richcompare,/* tp_richcompare */
-    0,                                /* tp_weaklistoffset */
-    0,                                /* tp_iter */
-    0,                                /* tp_iternext */
-    timezone_methods,                 /* tp_methods */
-    0,                                /* tp_members */
-    0,                                /* tp_getset */
-    &PyDateTime_TZInfoType,           /* tp_base */
-    0,                                /* tp_dict */
-    0,                                /* tp_descr_get */
-    0,                                /* tp_descr_set */
-    0,                                /* tp_dictoffset */
-    0,                                /* tp_init */
-    0,                                /* tp_alloc */
-    timezone_new,                     /* tp_new */
-};
-
-/*
- * PyDateTime_Time implementation.
- */
-
-/* Accessor properties.
- */
-
-static PyObject *
-time_hour(PyDateTime_Time *self, void *unused)
-{
-    return PyLong_FromLong(TIME_GET_HOUR(self));
-}
-
-static PyObject *
-time_minute(PyDateTime_Time *self, void *unused)
-{
-    return PyLong_FromLong(TIME_GET_MINUTE(self));
-}
-
-/* The name time_second conflicted with some platform header file. */
-static PyObject *
-py_time_second(PyDateTime_Time *self, void *unused)
-{
-    return PyLong_FromLong(TIME_GET_SECOND(self));
-}
-
-static PyObject *
-time_microsecond(PyDateTime_Time *self, void *unused)
-{
-    return PyLong_FromLong(TIME_GET_MICROSECOND(self));
-}
-
-static PyObject *
-time_tzinfo(PyDateTime_Time *self, void *unused)
-{
-    PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
-    Py_INCREF(result);
-    return result;
-}
-
-static PyGetSetDef time_getset[] = {
-    {"hour",        (getter)time_hour},
-    {"minute",      (getter)time_minute},
-    {"second",      (getter)py_time_second},
-    {"microsecond", (getter)time_microsecond},
-    {"tzinfo",          (getter)time_tzinfo},
-    {NULL}
-};
-
-/*
- * Constructors.
- */
-
-static char *time_kws[] = {"hour", "minute", "second", "microsecond",
-                           "tzinfo", NULL};
-
-static PyObject *
-time_new(PyTypeObject *type, PyObject *args, PyObject *kw)
-{
-    PyObject *self = NULL;
-    PyObject *state;
-    int hour = 0;
-    int minute = 0;
-    int second = 0;
-    int usecond = 0;
-    PyObject *tzinfo = Py_None;
-
-    /* Check for invocation from pickle with __getstate__ state */
-    if (PyTuple_GET_SIZE(args) >= 1 &&
-        PyTuple_GET_SIZE(args) <= 2 &&
-        PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
-        PyBytes_GET_SIZE(state) == _PyDateTime_TIME_DATASIZE &&
-        ((unsigned char) (PyBytes_AS_STRING(state)[0])) < 24)
-    {
-        PyDateTime_Time *me;
-        char aware;
-
-        if (PyTuple_GET_SIZE(args) == 2) {
-            tzinfo = PyTuple_GET_ITEM(args, 1);
-            if (check_tzinfo_subclass(tzinfo) < 0) {
-                PyErr_SetString(PyExc_TypeError, "bad "
-                    "tzinfo state arg");
-                return NULL;
-            }
-        }
-        aware = (char)(tzinfo != Py_None);
-        me = (PyDateTime_Time *) (type->tp_alloc(type, aware));
-        if (me != NULL) {
-            char *pdata = PyBytes_AS_STRING(state);
-
-            memcpy(me->data, pdata, _PyDateTime_TIME_DATASIZE);
-            me->hashcode = -1;
-            me->hastzinfo = aware;
-            if (aware) {
-                Py_INCREF(tzinfo);
-                me->tzinfo = tzinfo;
-            }
-        }
-        return (PyObject *)me;
-    }
-
-    if (PyArg_ParseTupleAndKeywords(args, kw, "|iiiiO", time_kws,
-                                    &hour, &minute, &second, &usecond,
-                                    &tzinfo)) {
-        if (check_time_args(hour, minute, second, usecond) < 0)
-            return NULL;
-        if (check_tzinfo_subclass(tzinfo) < 0)
-            return NULL;
-        self = new_time_ex(hour, minute, second, usecond, tzinfo,
-                           type);
-    }
-    return self;
-}
-
-/*
- * Destructor.
- */
-
-static void
-time_dealloc(PyDateTime_Time *self)
-{
-    if (HASTZINFO(self)) {
-        Py_XDECREF(self->tzinfo);
-    }
-    Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-/*
- * Indirect access to tzinfo methods.
- */
-
-/* These are all METH_NOARGS, so don't need to check the arglist. */
-static PyObject *
-time_utcoffset(PyObject *self, PyObject *unused) {
-    return call_utcoffset(GET_TIME_TZINFO(self), Py_None);
-}
-
-static PyObject *
-time_dst(PyObject *self, PyObject *unused) {
-    return call_dst(GET_TIME_TZINFO(self), Py_None);
-}
-
-static PyObject *
-time_tzname(PyDateTime_Time *self, PyObject *unused) {
-    return call_tzname(GET_TIME_TZINFO(self), Py_None);
-}
-
-/*
- * Various ways to turn a time into a string.
- */
-
-static PyObject *
-time_repr(PyDateTime_Time *self)
-{
-    const char *type_name = Py_TYPE(self)->tp_name;
-    int h = TIME_GET_HOUR(self);
-    int m = TIME_GET_MINUTE(self);
-    int s = TIME_GET_SECOND(self);
-    int us = TIME_GET_MICROSECOND(self);
-    PyObject *result = NULL;
-
-    if (us)
-        result = PyUnicode_FromFormat("%s(%d, %d, %d, %d)",
-                                      type_name, h, m, s, us);
-    else if (s)
-        result = PyUnicode_FromFormat("%s(%d, %d, %d)",
-                                      type_name, h, m, s);
-    else
-        result = PyUnicode_FromFormat("%s(%d, %d)", type_name, h, m);
-    if (result != NULL && HASTZINFO(self))
-        result = append_keyword_tzinfo(result, self->tzinfo);
-    return result;
-}
-
-static PyObject *
-time_str(PyDateTime_Time *self)
-{
-    return PyObject_CallMethod((PyObject *)self, "isoformat", "()");
-}
-
-static PyObject *
-time_isoformat(PyDateTime_Time *self, PyObject *unused)
-{
-    char buf[100];
-    PyObject *result;
-    int us = TIME_GET_MICROSECOND(self);;
-
-    if (us)
-        result = PyUnicode_FromFormat("%02d:%02d:%02d.%06d",
-                                      TIME_GET_HOUR(self),
-                                      TIME_GET_MINUTE(self),
-                                      TIME_GET_SECOND(self),
-                                      us);
-    else
-        result = PyUnicode_FromFormat("%02d:%02d:%02d",
-                                      TIME_GET_HOUR(self),
-                                      TIME_GET_MINUTE(self),
-                                      TIME_GET_SECOND(self));
-
-    if (result == NULL || !HASTZINFO(self) || self->tzinfo == Py_None)
-        return result;
-
-    /* We need to append the UTC offset. */
-    if (format_utcoffset(buf, sizeof(buf), ":", self->tzinfo,
-                         Py_None) < 0) {
-        Py_DECREF(result);
-        return NULL;
-    }
-    PyUnicode_AppendAndDel(&result, PyUnicode_FromString(buf));
-    return result;
-}
-
-static PyObject *
-time_strftime(PyDateTime_Time *self, PyObject *args, PyObject *kw)
-{
-    PyObject *result;
-    PyObject *tuple;
-    PyObject *format;
-    static char *keywords[] = {"format", NULL};
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "U:strftime", keywords,
-                                      &format))
-        return NULL;
-
-    /* Python's strftime does insane things with the year part of the
-     * timetuple.  The year is forced to (the otherwise nonsensical)
-     * 1900 to worm around that.
-     */
-    tuple = Py_BuildValue("iiiiiiiii",
-                          1900, 1, 1, /* year, month, day */
-                  TIME_GET_HOUR(self),
-                  TIME_GET_MINUTE(self),
-                  TIME_GET_SECOND(self),
-                  0, 1, -1); /* weekday, daynum, dst */
-    if (tuple == NULL)
-        return NULL;
-    assert(PyTuple_Size(tuple) == 9);
-    result = wrap_strftime((PyObject *)self, format, tuple,
-                           Py_None);
-    Py_DECREF(tuple);
-    return result;
-}
-
-/*
- * Miscellaneous methods.
- */
-
-static PyObject *
-time_richcompare(PyObject *self, PyObject *other, int op)
-{
-    PyObject *result = NULL;
-    PyObject *offset1, *offset2;
-    int diff;
-
-    if (! PyTime_Check(other)) {
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-
-    if (GET_TIME_TZINFO(self) == GET_TIME_TZINFO(other)) {
-        diff = memcmp(((PyDateTime_Time *)self)->data,
-                      ((PyDateTime_Time *)other)->data,
-                      _PyDateTime_TIME_DATASIZE);
-        return diff_to_bool(diff, op);
-    }
-    offset1 = time_utcoffset(self, NULL);
-    if (offset1 == NULL)
-        return NULL;
-    offset2 = time_utcoffset(other, NULL);
-    if (offset2 == NULL)
-        goto done;
-    /* If they're both naive, or both aware and have the same offsets,
-     * we get off cheap.  Note that if they're both naive, offset1 ==
-     * offset2 == Py_None at this point.
-     */
-    if ((offset1 == offset2) ||
-        (PyDelta_Check(offset1) && PyDelta_Check(offset2) &&
-         delta_cmp(offset1, offset2) == 0)) {
-        diff = memcmp(((PyDateTime_Time *)self)->data,
-                      ((PyDateTime_Time *)other)->data,
-                      _PyDateTime_TIME_DATASIZE);
-        result = diff_to_bool(diff, op);
-    }
-    /* The hard case: both aware with different UTC offsets */
-    else if (offset1 != Py_None && offset2 != Py_None) {
-        int offsecs1, offsecs2;
-        assert(offset1 != offset2); /* else last "if" handled it */
-        offsecs1 = TIME_GET_HOUR(self) * 3600 +
-                   TIME_GET_MINUTE(self) * 60 +
-                   TIME_GET_SECOND(self) -
-                   GET_TD_DAYS(offset1) * 86400 -
-                   GET_TD_SECONDS(offset1);
-        offsecs2 = TIME_GET_HOUR(other) * 3600 +
-                   TIME_GET_MINUTE(other) * 60 +
-                   TIME_GET_SECOND(other) -
-                   GET_TD_DAYS(offset2) * 86400 -
-                   GET_TD_SECONDS(offset2);
-        diff = offsecs1 - offsecs2;
-        if (diff == 0)
-            diff = TIME_GET_MICROSECOND(self) -
-                   TIME_GET_MICROSECOND(other);
-        result = diff_to_bool(diff, op);
-    }
-    else {
-        PyErr_SetString(PyExc_TypeError,
-                        "can't compare offset-naive and "
-                        "offset-aware times");
-    }
- done:
-    Py_DECREF(offset1);
-    Py_XDECREF(offset2);
-    return result;
-}
-
-static long
-time_hash(PyDateTime_Time *self)
-{
-    if (self->hashcode == -1) {
-        PyObject *offset;
-
-        offset = time_utcoffset((PyObject *)self, NULL);
-
-        if (offset == NULL)
-            return -1;
-
-        /* Reduce this to a hash of another object. */
-        if (offset == Py_None)
-            self->hashcode = generic_hash(
-                (unsigned char *)self->data, _PyDateTime_TIME_DATASIZE);
-        else {
-            PyObject *temp1, *temp2;
-            int seconds, microseconds;
-            assert(HASTZINFO(self));
-            seconds = TIME_GET_HOUR(self) * 3600 +
-                      TIME_GET_MINUTE(self) * 60 +
-                      TIME_GET_SECOND(self);
-            microseconds = TIME_GET_MICROSECOND(self);
-            temp1 = new_delta(0, seconds, microseconds, 1);
-            if (temp1 == NULL) {
-                Py_DECREF(offset);
-                return -1;
-            }
-            temp2 = delta_subtract(temp1, offset);
-            Py_DECREF(temp1);
-            if (temp2 == NULL) {
-                Py_DECREF(offset);
-                return -1;
-            }
-            self->hashcode = PyObject_Hash(temp2);
-            Py_DECREF(temp2);
-        }
-        Py_DECREF(offset);
-    }
-    return self->hashcode;
-}
-
-static PyObject *
-time_replace(PyDateTime_Time *self, PyObject *args, PyObject *kw)
-{
-    PyObject *clone;
-    PyObject *tuple;
-    int hh = TIME_GET_HOUR(self);
-    int mm = TIME_GET_MINUTE(self);
-    int ss = TIME_GET_SECOND(self);
-    int us = TIME_GET_MICROSECOND(self);
-    PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "|iiiiO:replace",
-                                      time_kws,
-                                      &hh, &mm, &ss, &us, &tzinfo))
-        return NULL;
-    tuple = Py_BuildValue("iiiiO", hh, mm, ss, us, tzinfo);
-    if (tuple == NULL)
-        return NULL;
-    clone = time_new(Py_TYPE(self), tuple, NULL);
-    Py_DECREF(tuple);
-    return clone;
-}
-
-static int
-time_bool(PyObject *self)
-{
-    PyObject *offset, *tzinfo;
-    int offsecs = 0;
-
-    if (TIME_GET_SECOND(self) || TIME_GET_MICROSECOND(self)) {
-        /* Since utcoffset is in whole minutes, nothing can
-         * alter the conclusion that this is nonzero.
-         */
-        return 1;
-    }
-    tzinfo = GET_TIME_TZINFO(self);
-    if (tzinfo != Py_None) {
-        offset = call_utcoffset(tzinfo, Py_None);
-        if (offset == NULL)
-            return -1;
-        offsecs = GET_TD_DAYS(offset)*86400 + GET_TD_SECONDS(offset);
-        Py_DECREF(offset);
-    }
-    return (TIME_GET_MINUTE(self)*60 - offsecs + TIME_GET_HOUR(self)*3600) != 0;
-}
-
-/* Pickle support, a simple use of __reduce__. */
-
-/* Let basestate be the non-tzinfo data string.
- * If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
- * So it's a tuple in any (non-error) case.
- * __getstate__ isn't exposed.
- */
-static PyObject *
-time_getstate(PyDateTime_Time *self)
-{
-    PyObject *basestate;
-    PyObject *result = NULL;
-
-    basestate =  PyBytes_FromStringAndSize((char *)self->data,
-                                            _PyDateTime_TIME_DATASIZE);
-    if (basestate != NULL) {
-        if (! HASTZINFO(self) || self->tzinfo == Py_None)
-            result = PyTuple_Pack(1, basestate);
-        else
-            result = PyTuple_Pack(2, basestate, self->tzinfo);
-        Py_DECREF(basestate);
-    }
-    return result;
-}
-
-static PyObject *
-time_reduce(PyDateTime_Time *self, PyObject *arg)
-{
-    return Py_BuildValue("(ON)", Py_TYPE(self), time_getstate(self));
-}
-
-static PyMethodDef time_methods[] = {
-
-    {"isoformat",   (PyCFunction)time_isoformat,        METH_NOARGS,
-     PyDoc_STR("Return string in ISO 8601 format, HH:MM:SS[.mmmmmm]"
-               "[+HH:MM].")},
-
-    {"strftime",        (PyCFunction)time_strftime,     METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("format -> strftime() style string.")},
-
-    {"__format__",      (PyCFunction)date_format,       METH_VARARGS,
-     PyDoc_STR("Formats self with strftime.")},
-
-    {"utcoffset",       (PyCFunction)time_utcoffset,    METH_NOARGS,
-     PyDoc_STR("Return self.tzinfo.utcoffset(self).")},
-
-    {"tzname",          (PyCFunction)time_tzname,       METH_NOARGS,
-     PyDoc_STR("Return self.tzinfo.tzname(self).")},
-
-    {"dst",             (PyCFunction)time_dst,          METH_NOARGS,
-     PyDoc_STR("Return self.tzinfo.dst(self).")},
-
-    {"replace",     (PyCFunction)time_replace,          METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("Return time with new specified fields.")},
-
-    {"__reduce__", (PyCFunction)time_reduce,        METH_NOARGS,
-     PyDoc_STR("__reduce__() -> (cls, state)")},
-
-    {NULL,      NULL}
-};
-
-static char time_doc[] =
-PyDoc_STR("time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object\n\
-\n\
-All arguments are optional. tzinfo may be None, or an instance of\n\
-a tzinfo subclass. The remaining arguments may be ints or longs.\n");
-
-static PyNumberMethods time_as_number = {
-    0,                                          /* nb_add */
-    0,                                          /* nb_subtract */
-    0,                                          /* nb_multiply */
-    0,                                          /* nb_remainder */
-    0,                                          /* nb_divmod */
-    0,                                          /* nb_power */
-    0,                                          /* nb_negative */
-    0,                                          /* nb_positive */
-    0,                                          /* nb_absolute */
-    (inquiry)time_bool,                         /* nb_bool */
-};
-
-static PyTypeObject PyDateTime_TimeType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "datetime.time",                            /* tp_name */
-    sizeof(PyDateTime_Time),                    /* tp_basicsize */
-    0,                                          /* tp_itemsize */
-    (destructor)time_dealloc,                   /* tp_dealloc */
-    0,                                          /* tp_print */
-    0,                                          /* tp_getattr */
-    0,                                          /* tp_setattr */
-    0,                                          /* tp_reserved */
-    (reprfunc)time_repr,                        /* tp_repr */
-    &time_as_number,                            /* tp_as_number */
-    0,                                          /* tp_as_sequence */
-    0,                                          /* tp_as_mapping */
-    (hashfunc)time_hash,                        /* tp_hash */
-    0,                                          /* tp_call */
-    (reprfunc)time_str,                         /* tp_str */
-    PyObject_GenericGetAttr,                    /* tp_getattro */
-    0,                                          /* tp_setattro */
-    0,                                          /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
-    time_doc,                                   /* tp_doc */
-    0,                                          /* tp_traverse */
-    0,                                          /* tp_clear */
-    time_richcompare,                           /* tp_richcompare */
-    0,                                          /* tp_weaklistoffset */
-    0,                                          /* tp_iter */
-    0,                                          /* tp_iternext */
-    time_methods,                               /* tp_methods */
-    0,                                          /* tp_members */
-    time_getset,                                /* tp_getset */
-    0,                                          /* tp_base */
-    0,                                          /* tp_dict */
-    0,                                          /* tp_descr_get */
-    0,                                          /* tp_descr_set */
-    0,                                          /* tp_dictoffset */
-    0,                                          /* tp_init */
-    time_alloc,                                 /* tp_alloc */
-    time_new,                                   /* tp_new */
-    0,                                          /* tp_free */
-};
-
-/*
- * PyDateTime_DateTime implementation.
- */
-
-/* Accessor properties.  Properties for day, month, and year are inherited
- * from date.
- */
-
-static PyObject *
-datetime_hour(PyDateTime_DateTime *self, void *unused)
-{
-    return PyLong_FromLong(DATE_GET_HOUR(self));
-}
-
-static PyObject *
-datetime_minute(PyDateTime_DateTime *self, void *unused)
-{
-    return PyLong_FromLong(DATE_GET_MINUTE(self));
-}
-
-static PyObject *
-datetime_second(PyDateTime_DateTime *self, void *unused)
-{
-    return PyLong_FromLong(DATE_GET_SECOND(self));
-}
-
-static PyObject *
-datetime_microsecond(PyDateTime_DateTime *self, void *unused)
-{
-    return PyLong_FromLong(DATE_GET_MICROSECOND(self));
-}
-
-static PyObject *
-datetime_tzinfo(PyDateTime_DateTime *self, void *unused)
-{
-    PyObject *result = HASTZINFO(self) ? self->tzinfo : Py_None;
-    Py_INCREF(result);
-    return result;
-}
-
-static PyGetSetDef datetime_getset[] = {
-    {"hour",        (getter)datetime_hour},
-    {"minute",      (getter)datetime_minute},
-    {"second",      (getter)datetime_second},
-    {"microsecond", (getter)datetime_microsecond},
-    {"tzinfo",          (getter)datetime_tzinfo},
-    {NULL}
-};
-
-/*
- * Constructors.
- */
-
-static char *datetime_kws[] = {
-    "year", "month", "day", "hour", "minute", "second",
-    "microsecond", "tzinfo", NULL
-};
-
-static PyObject *
-datetime_new(PyTypeObject *type, PyObject *args, PyObject *kw)
-{
-    PyObject *self = NULL;
-    PyObject *state;
-    int year;
-    int month;
-    int day;
-    int hour = 0;
-    int minute = 0;
-    int second = 0;
-    int usecond = 0;
-    PyObject *tzinfo = Py_None;
-
-    /* Check for invocation from pickle with __getstate__ state */
-    if (PyTuple_GET_SIZE(args) >= 1 &&
-        PyTuple_GET_SIZE(args) <= 2 &&
-        PyBytes_Check(state = PyTuple_GET_ITEM(args, 0)) &&
-        PyBytes_GET_SIZE(state) == _PyDateTime_DATETIME_DATASIZE &&
-        MONTH_IS_SANE(PyBytes_AS_STRING(state)[2]))
-    {
-        PyDateTime_DateTime *me;
-        char aware;
-
-        if (PyTuple_GET_SIZE(args) == 2) {
-            tzinfo = PyTuple_GET_ITEM(args, 1);
-            if (check_tzinfo_subclass(tzinfo) < 0) {
-                PyErr_SetString(PyExc_TypeError, "bad "
-                    "tzinfo state arg");
-                return NULL;
-            }
-        }
-        aware = (char)(tzinfo != Py_None);
-        me = (PyDateTime_DateTime *) (type->tp_alloc(type , aware));
-        if (me != NULL) {
-            char *pdata = PyBytes_AS_STRING(state);
-
-            memcpy(me->data, pdata, _PyDateTime_DATETIME_DATASIZE);
-            me->hashcode = -1;
-            me->hastzinfo = aware;
-            if (aware) {
-                Py_INCREF(tzinfo);
-                me->tzinfo = tzinfo;
-            }
-        }
-        return (PyObject *)me;
-    }
-
-    if (PyArg_ParseTupleAndKeywords(args, kw, "iii|iiiiO", datetime_kws,
-                                    &year, &month, &day, &hour, &minute,
-                                    &second, &usecond, &tzinfo)) {
-        if (check_date_args(year, month, day) < 0)
-            return NULL;
-        if (check_time_args(hour, minute, second, usecond) < 0)
-            return NULL;
-        if (check_tzinfo_subclass(tzinfo) < 0)
-            return NULL;
-        self = new_datetime_ex(year, month, day,
-                                hour, minute, second, usecond,
-                                tzinfo, type);
-    }
-    return self;
-}
-
-/* TM_FUNC is the shared type of localtime() and gmtime(). */
-typedef struct tm *(*TM_FUNC)(const time_t *timer);
-
-/* Internal helper.
- * Build datetime from a time_t and a distinct count of microseconds.
- * Pass localtime or gmtime for f, to control the interpretation of timet.
- */
-static PyObject *
-datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us,
-                           PyObject *tzinfo)
-{
-    struct tm *tm;
-    PyObject *result = NULL;
-
-    tm = f(&timet);
-    if (tm) {
-        /* The platform localtime/gmtime may insert leap seconds,
-         * indicated by tm->tm_sec > 59.  We don't care about them,
-         * except to the extent that passing them on to the datetime
-         * constructor would raise ValueError for a reason that
-         * made no sense to the user.
-         */
-        if (tm->tm_sec > 59)
-            tm->tm_sec = 59;
-        result = PyObject_CallFunction(cls, "iiiiiiiO",
-                                       tm->tm_year + 1900,
-                                       tm->tm_mon + 1,
-                                       tm->tm_mday,
-                                       tm->tm_hour,
-                                       tm->tm_min,
-                                       tm->tm_sec,
-                                       us,
-                                       tzinfo);
-    }
-    else
-        PyErr_SetString(PyExc_ValueError,
-                        "timestamp out of range for "
-                        "platform localtime()/gmtime() function");
-    return result;
-}
-
-/* Internal helper.
- * Build datetime from a Python timestamp.  Pass localtime or gmtime for f,
- * to control the interpretation of the timestamp.  Since a double doesn't
- * have enough bits to cover a datetime's full range of precision, it's
- * better to call datetime_from_timet_and_us provided you have a way
- * to get that much precision (e.g., C time() isn't good enough).
- */
-static PyObject *
-datetime_from_timestamp(PyObject *cls, TM_FUNC f, double timestamp,
-                        PyObject *tzinfo)
-{
-    time_t timet;
-    double fraction;
-    int us;
-
-    timet = _PyTime_DoubleToTimet(timestamp);
-    if (timet == (time_t)-1 && PyErr_Occurred())
-        return NULL;
-    fraction = timestamp - (double)timet;
-    us = (int)round_to_long(fraction * 1e6);
-    if (us < 0) {
-        /* Truncation towards zero is not what we wanted
-           for negative numbers (Python's mod semantics) */
-        timet -= 1;
-        us += 1000000;
-    }
-    /* If timestamp is less than one microsecond smaller than a
-     * full second, round up. Otherwise, ValueErrors are raised
-     * for some floats. */
-    if (us == 1000000) {
-        timet += 1;
-        us = 0;
-    }
-    return datetime_from_timet_and_us(cls, f, timet, us, tzinfo);
-}
-
-/* Internal helper.
- * Build most accurate possible datetime for current time.  Pass localtime or
- * gmtime for f as appropriate.
- */
-static PyObject *
-datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
-{
-#ifdef HAVE_GETTIMEOFDAY
-    struct timeval t;
-
-#ifdef GETTIMEOFDAY_NO_TZ
-    gettimeofday(&t);
-#else
-    gettimeofday(&t, (struct timezone *)NULL);
-#endif
-    return datetime_from_timet_and_us(cls, f, t.tv_sec, (int)t.tv_usec,
-                                      tzinfo);
-
-#else   /* ! HAVE_GETTIMEOFDAY */
-    /* No flavor of gettimeofday exists on this platform.  Python's
-     * time.time() does a lot of other platform tricks to get the
-     * best time it can on the platform, and we're not going to do
-     * better than that (if we could, the better code would belong
-     * in time.time()!)  We're limited by the precision of a double,
-     * though.
-     */
-    PyObject *time;
-    double dtime;
-
-    time = time_time();
-    if (time == NULL)
-        return NULL;
-    dtime = PyFloat_AsDouble(time);
-    Py_DECREF(time);
-    if (dtime == -1.0 && PyErr_Occurred())
-        return NULL;
-    return datetime_from_timestamp(cls, f, dtime, tzinfo);
-#endif  /* ! HAVE_GETTIMEOFDAY */
-}
-
-/* Return best possible local time -- this isn't constrained by the
- * precision of a timestamp.
- */
-static PyObject *
-datetime_now(PyObject *cls, PyObject *args, PyObject *kw)
-{
-    PyObject *self;
-    PyObject *tzinfo = Py_None;
-    static char *keywords[] = {"tz", NULL};
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "|O:now", keywords,
-                                      &tzinfo))
-        return NULL;
-    if (check_tzinfo_subclass(tzinfo) < 0)
-        return NULL;
-
-    self = datetime_best_possible(cls,
-                                  tzinfo == Py_None ? localtime : gmtime,
-                                  tzinfo);
-    if (self != NULL && tzinfo != Py_None) {
-        /* Convert UTC to tzinfo's zone. */
-        PyObject *temp = self;
-        self = PyObject_CallMethod(tzinfo, "fromutc", "O", self);
-        Py_DECREF(temp);
-    }
-    return self;
-}
-
-/* Return best possible UTC time -- this isn't constrained by the
- * precision of a timestamp.
- */
-static PyObject *
-datetime_utcnow(PyObject *cls, PyObject *dummy)
-{
-    return datetime_best_possible(cls, gmtime, Py_None);
-}
-
-/* Return new local datetime from timestamp (Python timestamp -- a double). */
-static PyObject *
-datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
-{
-    PyObject *self;
-    double timestamp;
-    PyObject *tzinfo = Py_None;
-    static char *keywords[] = {"timestamp", "tz", NULL};
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "d|O:fromtimestamp",
-                                      keywords, &timestamp, &tzinfo))
-        return NULL;
-    if (check_tzinfo_subclass(tzinfo) < 0)
-        return NULL;
-
-    self = datetime_from_timestamp(cls,
-                                   tzinfo == Py_None ? localtime : gmtime,
-                                   timestamp,
-                                   tzinfo);
-    if (self != NULL && tzinfo != Py_None) {
-        /* Convert UTC to tzinfo's zone. */
-        PyObject *temp = self;
-        self = PyObject_CallMethod(tzinfo, "fromutc", "O", self);
-        Py_DECREF(temp);
-    }
-    return self;
-}
-
-/* Return new UTC datetime from timestamp (Python timestamp -- a double). */
-static PyObject *
-datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
-{
-    double timestamp;
-    PyObject *result = NULL;
-
-    if (PyArg_ParseTuple(args, "d:utcfromtimestamp", &timestamp))
-        result = datetime_from_timestamp(cls, gmtime, timestamp,
-                                         Py_None);
-    return result;
-}
-
-/* Return new datetime from _strptime.strptime_datetime(). */
-static PyObject *
-datetime_strptime(PyObject *cls, PyObject *args)
-{
-    static PyObject *module = NULL;
-    const Py_UNICODE *string, *format;
-
-    if (!PyArg_ParseTuple(args, "uu:strptime", &string, &format))
-        return NULL;
-
-    if (module == NULL) {
-        module = PyImport_ImportModuleNoBlock("_strptime");
-        if (module == NULL)
-            return NULL;
-    }
-    return PyObject_CallMethod(module, "_strptime_datetime", "Ouu",
-                               cls, string, format);
-}
-
-/* Return new datetime from date/datetime and time arguments. */
-static PyObject *
-datetime_combine(PyObject *cls, PyObject *args, PyObject *kw)
-{
-    static char *keywords[] = {"date", "time", NULL};
-    PyObject *date;
-    PyObject *time;
-    PyObject *result = NULL;
-
-    if (PyArg_ParseTupleAndKeywords(args, kw, "O!O!:combine", keywords,
-                                    &PyDateTime_DateType, &date,
-                                    &PyDateTime_TimeType, &time)) {
-        PyObject *tzinfo = Py_None;
-
-        if (HASTZINFO(time))
-            tzinfo = ((PyDateTime_Time *)time)->tzinfo;
-        result = PyObject_CallFunction(cls, "iiiiiiiO",
-                                        GET_YEAR(date),
-                                        GET_MONTH(date),
-                                        GET_DAY(date),
-                                        TIME_GET_HOUR(time),
-                                        TIME_GET_MINUTE(time),
-                                        TIME_GET_SECOND(time),
-                                        TIME_GET_MICROSECOND(time),
-                                        tzinfo);
-    }
-    return result;
-}
-
-/*
- * Destructor.
- */
-
-static void
-datetime_dealloc(PyDateTime_DateTime *self)
-{
-    if (HASTZINFO(self)) {
-        Py_XDECREF(self->tzinfo);
-    }
-    Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-/*
- * Indirect access to tzinfo methods.
- */
-
-/* These are all METH_NOARGS, so don't need to check the arglist. */
-static PyObject *
-datetime_utcoffset(PyObject *self, PyObject *unused) {
-    return call_utcoffset(GET_DT_TZINFO(self), self);
-}
-
-static PyObject *
-datetime_dst(PyObject *self, PyObject *unused) {
-    return call_dst(GET_DT_TZINFO(self), self);
-}
-
-static PyObject *
-datetime_tzname(PyObject *self, PyObject *unused) {
-    return call_tzname(GET_DT_TZINFO(self), self);
-}
-
-/*
- * datetime arithmetic.
- */
-
-/* factor must be 1 (to add) or -1 (to subtract).  The result inherits
- * the tzinfo state of date.
- */
-static PyObject *
-add_datetime_timedelta(PyDateTime_DateTime *date, PyDateTime_Delta *delta,
-                       int factor)
-{
-    /* Note that the C-level additions can't overflow, because of
-     * invariant bounds on the member values.
-     */
-    int year = GET_YEAR(date);
-    int month = GET_MONTH(date);
-    int day = GET_DAY(date) + GET_TD_DAYS(delta) * factor;
-    int hour = DATE_GET_HOUR(date);
-    int minute = DATE_GET_MINUTE(date);
-    int second = DATE_GET_SECOND(date) + GET_TD_SECONDS(delta) * factor;
-    int microsecond = DATE_GET_MICROSECOND(date) +
-                      GET_TD_MICROSECONDS(delta) * factor;
-
-    assert(factor == 1 || factor == -1);
-    if (normalize_datetime(&year, &month, &day,
-                           &hour, &minute, &second, &microsecond) < 0)
-        return NULL;
-    else
-        return new_datetime(year, month, day,
-                            hour, minute, second, microsecond,
-                            HASTZINFO(date) ? date->tzinfo : Py_None);
-}
-
-static PyObject *
-datetime_add(PyObject *left, PyObject *right)
-{
-    if (PyDateTime_Check(left)) {
-        /* datetime + ??? */
-        if (PyDelta_Check(right))
-            /* datetime + delta */
-            return add_datetime_timedelta(
-                            (PyDateTime_DateTime *)left,
-                            (PyDateTime_Delta *)right,
-                            1);
-    }
-    else if (PyDelta_Check(left)) {
-        /* delta + datetime */
-        return add_datetime_timedelta((PyDateTime_DateTime *) right,
-                                      (PyDateTime_Delta *) left,
-                                      1);
-    }
-    Py_INCREF(Py_NotImplemented);
-    return Py_NotImplemented;
-}
-
-static PyObject *
-datetime_subtract(PyObject *left, PyObject *right)
-{
-    PyObject *result = Py_NotImplemented;
-
-    if (PyDateTime_Check(left)) {
-        /* datetime - ??? */
-        if (PyDateTime_Check(right)) {
-            /* datetime - datetime */
-            PyObject *offset1, *offset2, *offdiff = NULL;
-            int delta_d, delta_s, delta_us;
-
-            if (GET_DT_TZINFO(left) == GET_DT_TZINFO(right)) {
-                offset2 = offset1 = Py_None;
-                Py_INCREF(offset1);
-                Py_INCREF(offset2);
-            }
-            else {
-                offset1 = datetime_utcoffset(left, NULL);
-                if (offset1 == NULL)
-                    return NULL;
-                offset2 = datetime_utcoffset(right, NULL);
-                if (offset2 == NULL) {
-                    Py_DECREF(offset1);
-                    return NULL;
-                }
-                if ((offset1 != Py_None) != (offset2 != Py_None)) {
-                    PyErr_SetString(PyExc_TypeError,
-                                    "can't subtract offset-naive and "
-                                    "offset-aware datetimes");
-                    Py_DECREF(offset1);
-                    Py_DECREF(offset2);
-                    return NULL;
-                }
-            }
-            if ((offset1 != offset2) &&
-                delta_cmp(offset1, offset2) != 0) {
-                offdiff = delta_subtract(offset1, offset2);
-                if (offdiff == NULL) {
-                    Py_DECREF(offset1);
-                    Py_DECREF(offset2);
-                    return NULL;
-                }
-            }
-            Py_DECREF(offset1);
-            Py_DECREF(offset2);
-            delta_d = ymd_to_ord(GET_YEAR(left),
-                                 GET_MONTH(left),
-                                 GET_DAY(left)) -
-                      ymd_to_ord(GET_YEAR(right),
-                                 GET_MONTH(right),
-                                 GET_DAY(right));
-            /* These can't overflow, since the values are
-             * normalized.  At most this gives the number of
-             * seconds in one day.
-             */
-            delta_s = (DATE_GET_HOUR(left) -
-                       DATE_GET_HOUR(right)) * 3600 +
-                      (DATE_GET_MINUTE(left) -
-                       DATE_GET_MINUTE(right)) * 60 +
-                      (DATE_GET_SECOND(left) -
-                       DATE_GET_SECOND(right));
-            delta_us = DATE_GET_MICROSECOND(left) -
-                       DATE_GET_MICROSECOND(right);
-            result = new_delta(delta_d, delta_s, delta_us, 1);
-            if (offdiff != NULL) {
-                PyObject *temp = result;
-                result = delta_subtract(result, offdiff);
-                Py_DECREF(temp);
-                Py_DECREF(offdiff);
-            }
-        }
-        else if (PyDelta_Check(right)) {
-            /* datetime - delta */
-            result = add_datetime_timedelta(
-                            (PyDateTime_DateTime *)left,
-                            (PyDateTime_Delta *)right,
-                            -1);
-        }
-    }
-
-    if (result == Py_NotImplemented)
-        Py_INCREF(result);
-    return result;
-}
-
-/* Various ways to turn a datetime into a string. */
-
-static PyObject *
-datetime_repr(PyDateTime_DateTime *self)
-{
-    const char *type_name = Py_TYPE(self)->tp_name;
-    PyObject *baserepr;
-
-    if (DATE_GET_MICROSECOND(self)) {
-        baserepr = PyUnicode_FromFormat(
-                      "%s(%d, %d, %d, %d, %d, %d, %d)",
-                      type_name,
-                      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
-                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
-                      DATE_GET_SECOND(self),
-                      DATE_GET_MICROSECOND(self));
-    }
-    else if (DATE_GET_SECOND(self)) {
-        baserepr = PyUnicode_FromFormat(
-                      "%s(%d, %d, %d, %d, %d, %d)",
-                      type_name,
-                      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
-                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
-                      DATE_GET_SECOND(self));
-    }
-    else {
-        baserepr = PyUnicode_FromFormat(
-                      "%s(%d, %d, %d, %d, %d)",
-                      type_name,
-                      GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
-                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self));
-    }
-    if (baserepr == NULL || ! HASTZINFO(self))
-        return baserepr;
-    return append_keyword_tzinfo(baserepr, self->tzinfo);
-}
-
-static PyObject *
-datetime_str(PyDateTime_DateTime *self)
-{
-    return PyObject_CallMethod((PyObject *)self, "isoformat", "(s)", " ");
-}
-
-static PyObject *
-datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
-{
-    int sep = 'T';
-    static char *keywords[] = {"sep", NULL};
-    char buffer[100];
-    PyObject *result;
-    int us = DATE_GET_MICROSECOND(self);
-
-    if (!PyArg_ParseTupleAndKeywords(args, kw, "|C:isoformat", keywords, &sep))
-        return NULL;
-    if (us)
-        result = PyUnicode_FromFormat("%04d-%02d-%02d%c%02d:%02d:%02d.%06d",
-                                      GET_YEAR(self), GET_MONTH(self),
-                                      GET_DAY(self), (int)sep,
-                                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
-                                      DATE_GET_SECOND(self), us);
-    else
-        result = PyUnicode_FromFormat("%04d-%02d-%02d%c%02d:%02d:%02d",
-                                      GET_YEAR(self), GET_MONTH(self),
-                                      GET_DAY(self), (int)sep,
-                                      DATE_GET_HOUR(self), DATE_GET_MINUTE(self),
-                                      DATE_GET_SECOND(self));
-
-    if (!result || !HASTZINFO(self))
-        return result;
-
-    /* We need to append the UTC offset. */
-    if (format_utcoffset(buffer, sizeof(buffer), ":", self->tzinfo,
-                         (PyObject *)self) < 0) {
-        Py_DECREF(result);
-        return NULL;
-    }
-    PyUnicode_AppendAndDel(&result, PyUnicode_FromString(buffer));
-    return result;
-}
-
-static PyObject *
-datetime_ctime(PyDateTime_DateTime *self)
-{
-    return format_ctime((PyDateTime_Date *)self,
-                        DATE_GET_HOUR(self),
-                        DATE_GET_MINUTE(self),
-                        DATE_GET_SECOND(self));
-}
-
-/* Miscellaneous methods. */
-
-static PyObject *
-datetime_richcompare(PyObject *self, PyObject *other, int op)
-{
-    PyObject *result = NULL;
-    PyObject *offset1, *offset2;
-    int diff;
-
-    if (! PyDateTime_Check(other)) {
-        if (PyDate_Check(other)) {
-            /* Prevent invocation of date_richcompare.  We want to
-               return NotImplemented here to give the other object
-               a chance.  But since DateTime is a subclass of
-               Date, if the other object is a Date, it would
-               compute an ordering based on the date part alone,
-               and we don't want that.  So force unequal or
-               uncomparable here in that case. */
-            if (op == Py_EQ)
-                Py_RETURN_FALSE;
-            if (op == Py_NE)
-                Py_RETURN_TRUE;
-            return cmperror(self, other);
-        }
-        Py_INCREF(Py_NotImplemented);
-        return Py_NotImplemented;
-    }
-
-    if (GET_DT_TZINFO(self) == GET_DT_TZINFO(other)) {
-        diff = memcmp(((PyDateTime_DateTime *)self)->data,
-                      ((PyDateTime_DateTime *)other)->data,
-                      _PyDateTime_DATETIME_DATASIZE);
-        return diff_to_bool(diff, op);
-    }
-    offset1 = datetime_utcoffset(self, NULL);
-    if (offset1 == NULL)
-        return NULL;
-    offset2 = datetime_utcoffset(other, NULL);
-    if (offset2 == NULL)
-        goto done;
-    /* If they're both naive, or both aware and have the same offsets,
-     * we get off cheap.  Note that if they're both naive, offset1 ==
-     * offset2 == Py_None at this point.
-     */
-    if ((offset1 == offset2) ||
-        (PyDelta_Check(offset1) && PyDelta_Check(offset2) &&
-         delta_cmp(offset1, offset2) == 0)) {
-        diff = memcmp(((PyDateTime_DateTime *)self)->data,
-                      ((PyDateTime_DateTime *)other)->data,
-                      _PyDateTime_DATETIME_DATASIZE);
-        result = diff_to_bool(diff, op);
-    }
-    else if (offset1 != Py_None && offset2 != Py_None) {
-        PyDateTime_Delta *delta;
-
-        assert(offset1 != offset2); /* else last "if" handled it */
-        delta = (PyDateTime_Delta *)datetime_subtract((PyObject *)self,
-                                                       other);
-        if (delta == NULL)
-            goto done;
-        diff = GET_TD_DAYS(delta);
-        if (diff == 0)
-            diff = GET_TD_SECONDS(delta) |
-                   GET_TD_MICROSECONDS(delta);
-        Py_DECREF(delta);
-        result = diff_to_bool(diff, op);
-    }
-    else {
-        PyErr_SetString(PyExc_TypeError,
-                        "can't compare offset-naive and "
-                        "offset-aware datetimes");
-    }
- done:
-    Py_DECREF(offset1);
-    Py_XDECREF(offset2);
-    return result;
-}
-
-static long
-datetime_hash(PyDateTime_DateTime *self)
-{
-    if (self->hashcode == -1) {
-        PyObject *offset;
-
-        offset = datetime_utcoffset((PyObject *)self, NULL);
-
-        if (offset == NULL)
-            return -1;
-
-        /* Reduce this to a hash of another object. */
-        if (offset == Py_None)
-            self->hashcode = generic_hash(
-                (unsigned char *)self->data, _PyDateTime_DATETIME_DATASIZE);
-        else {
-            PyObject *temp1, *temp2;
-            int days, seconds;
-
-            assert(HASTZINFO(self));
-            days = ymd_to_ord(GET_YEAR(self),
-                              GET_MONTH(self),
-                              GET_DAY(self));
-            seconds = DATE_GET_HOUR(self) * 3600 +
-                      DATE_GET_MINUTE(self) * 60 +
-                      DATE_GET_SECOND(self);
-            temp1 = new_delta(days, seconds,
-                              DATE_GET_MICROSECOND(self),
-                              1);
-            if (temp1 == NULL) {
-                Py_DECREF(offset);
-                return -1;
-            }
-            temp2 = delta_subtract(temp1, offset);
-            Py_DECREF(temp1);
-            if (temp2 == NULL) {
-                Py_DECREF(offset);
-                return -1;
-            }
-            self->hashcode = PyObject_Hash(temp2);
-            Py_DECREF(temp2);
-        }
-        Py_DECREF(offset);
-    }
-    return self->hashcode;
-}
-
-static PyObject *
-datetime_replace(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
-{
-    PyObject *clone;
-    PyObject *tuple;
-    int y = GET_YEAR(self);
-    int m = GET_MONTH(self);
-    int d = GET_DAY(self);
-    int hh = DATE_GET_HOUR(self);
-    int mm = DATE_GET_MINUTE(self);
-    int ss = DATE_GET_SECOND(self);
-    int us = DATE_GET_MICROSECOND(self);
-    PyObject *tzinfo = HASTZINFO(self) ? self->tzinfo : Py_None;
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "|iiiiiiiO:replace",
-                                      datetime_kws,
-                                      &y, &m, &d, &hh, &mm, &ss, &us,
-                                      &tzinfo))
-        return NULL;
-    tuple = Py_BuildValue("iiiiiiiO", y, m, d, hh, mm, ss, us, tzinfo);
-    if (tuple == NULL)
-        return NULL;
-    clone = datetime_new(Py_TYPE(self), tuple, NULL);
-    Py_DECREF(tuple);
-    return clone;
-}
-
-static PyObject *
-datetime_astimezone(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
-{
-    PyObject *result;
-    PyObject *offset;
-    PyObject *temp;
-    PyObject *tzinfo;
-    static char *keywords[] = {"tz", NULL};
-
-    if (! PyArg_ParseTupleAndKeywords(args, kw, "O!:astimezone", keywords,
-                                      &PyDateTime_TZInfoType, &tzinfo))
-        return NULL;
-
-    if (!HASTZINFO(self) || self->tzinfo == Py_None)
-        goto NeedAware;
-
-    /* Conversion to self's own time zone is a NOP. */
-    if (self->tzinfo == tzinfo) {
-        Py_INCREF(self);
-        return (PyObject *)self;
-    }
-
-    /* Convert self to UTC. */
-    offset = datetime_utcoffset((PyObject *)self, NULL);
-    if (offset == NULL)
-        return NULL;
-    if (offset == Py_None) {
-        Py_DECREF(offset);
-      NeedAware:
-        PyErr_SetString(PyExc_ValueError, "astimezone() cannot be applied to "
-                        "a naive datetime");
-        return NULL;
-    }
-
-    /* result = self - offset */
-    result = add_datetime_timedelta(self,
-                (PyDateTime_Delta *)offset, -1);
-    Py_DECREF(offset);
-    if (result == NULL)
-        return NULL;
-
-    /* Attach new tzinfo and let fromutc() do the rest. */
-    temp = ((PyDateTime_DateTime *)result)->tzinfo;
-    ((PyDateTime_DateTime *)result)->tzinfo = tzinfo;
-    Py_INCREF(tzinfo);
-    Py_DECREF(temp);
-
-    temp = result;
-    result = PyObject_CallMethod(tzinfo, "fromutc", "O", temp);
-    Py_DECREF(temp);
-
-    return result;
-}
-
-static PyObject *
-datetime_timetuple(PyDateTime_DateTime *self)
-{
-    int dstflag = -1;
-
-    if (HASTZINFO(self) && self->tzinfo != Py_None) {
-        PyObject * dst;
-
-        dst = call_dst(self->tzinfo, (PyObject *)self);
-        if (dst == NULL)
-            return NULL;
-
-        if (dst != Py_None)
-            dstflag = delta_bool((PyDateTime_Delta *)dst);
-        Py_DECREF(dst);
-    }
-    return build_struct_time(GET_YEAR(self),
-                             GET_MONTH(self),
-                             GET_DAY(self),
-                             DATE_GET_HOUR(self),
-                             DATE_GET_MINUTE(self),
-                             DATE_GET_SECOND(self),
-                             dstflag);
-}
-
-static PyObject *
-datetime_getdate(PyDateTime_DateTime *self)
-{
-    return new_date(GET_YEAR(self),
-                    GET_MONTH(self),
-                    GET_DAY(self));
-}
-
-static PyObject *
-datetime_gettime(PyDateTime_DateTime *self)
-{
-    return new_time(DATE_GET_HOUR(self),
-                    DATE_GET_MINUTE(self),
-                    DATE_GET_SECOND(self),
-                    DATE_GET_MICROSECOND(self),
-                    Py_None);
-}
-
-static PyObject *
-datetime_gettimetz(PyDateTime_DateTime *self)
-{
-    return new_time(DATE_GET_HOUR(self),
-                    DATE_GET_MINUTE(self),
-                    DATE_GET_SECOND(self),
-                    DATE_GET_MICROSECOND(self),
-                    GET_DT_TZINFO(self));
-}
-
-static PyObject *
-datetime_utctimetuple(PyDateTime_DateTime *self)
-{
-    int y, m, d, hh, mm, ss;
-    PyObject *tzinfo;
-    PyDateTime_DateTime *utcself;
-
-    tzinfo = GET_DT_TZINFO(self);
-    if (tzinfo == Py_None) {
-        utcself = self;
-        Py_INCREF(utcself);
-    }
-    else {
-        PyObject *offset;
-        offset = call_utcoffset(tzinfo, (PyObject *)self);
-        if (offset == NULL)
-            return NULL;
-        if (offset == Py_None) {
-            Py_DECREF(offset);
-            utcself = self;
-            Py_INCREF(utcself);
-        }
-        else {
-            utcself = (PyDateTime_DateTime *)add_datetime_timedelta(self,
-                                                (PyDateTime_Delta *)offset, -1);
-            Py_DECREF(offset);
-            if (utcself == NULL)
-                return NULL;
-        }
-    }
-    y = GET_YEAR(utcself);
-    m = GET_MONTH(utcself);
-    d = GET_DAY(utcself);
-    hh = DATE_GET_HOUR(utcself);
-    mm = DATE_GET_MINUTE(utcself);
-    ss = DATE_GET_SECOND(utcself);
-
-    Py_DECREF(utcself);
-    return build_struct_time(y, m, d, hh, mm, ss, 0);
-}
-
-/* Pickle support, a simple use of __reduce__. */
-
-/* Let basestate be the non-tzinfo data string.
- * If tzinfo is None, this returns (basestate,), else (basestate, tzinfo).
- * So it's a tuple in any (non-error) case.
- * __getstate__ isn't exposed.
- */
-static PyObject *
-datetime_getstate(PyDateTime_DateTime *self)
-{
-    PyObject *basestate;
-    PyObject *result = NULL;
-
-    basestate = PyBytes_FromStringAndSize((char *)self->data,
-                                           _PyDateTime_DATETIME_DATASIZE);
-    if (basestate != NULL) {
-        if (! HASTZINFO(self) || self->tzinfo == Py_None)
-            result = PyTuple_Pack(1, basestate);
-        else
-            result = PyTuple_Pack(2, basestate, self->tzinfo);
-        Py_DECREF(basestate);
-    }
-    return result;
-}
-
-static PyObject *
-datetime_reduce(PyDateTime_DateTime *self, PyObject *arg)
-{
-    return Py_BuildValue("(ON)", Py_TYPE(self), datetime_getstate(self));
-}
-
-static PyMethodDef datetime_methods[] = {
-
-    /* Class methods: */
-
-    {"now",         (PyCFunction)datetime_now,
-     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
-     PyDoc_STR("[tz] -> new datetime with tz's local day and time.")},
-
-    {"utcnow",         (PyCFunction)datetime_utcnow,
-     METH_NOARGS | METH_CLASS,
-     PyDoc_STR("Return a new datetime representing UTC day and time.")},
-
-    {"fromtimestamp", (PyCFunction)datetime_fromtimestamp,
-     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
-     PyDoc_STR("timestamp[, tz] -> tz's local time from POSIX timestamp.")},
-
-    {"utcfromtimestamp", (PyCFunction)datetime_utcfromtimestamp,
-     METH_VARARGS | METH_CLASS,
-     PyDoc_STR("timestamp -> UTC datetime from a POSIX timestamp "
-               "(like time.time()).")},
-
-    {"strptime", (PyCFunction)datetime_strptime,
-     METH_VARARGS | METH_CLASS,
-     PyDoc_STR("string, format -> new datetime parsed from a string "
-               "(like time.strptime()).")},
-
-    {"combine", (PyCFunction)datetime_combine,
-     METH_VARARGS | METH_KEYWORDS | METH_CLASS,
-     PyDoc_STR("date, time -> datetime with same date and time fields")},
-
-    /* Instance methods: */
-
-    {"date",   (PyCFunction)datetime_getdate, METH_NOARGS,
-     PyDoc_STR("Return date object with same year, month and day.")},
-
-    {"time",   (PyCFunction)datetime_gettime, METH_NOARGS,
-     PyDoc_STR("Return time object with same time but with tzinfo=None.")},
-
-    {"timetz",   (PyCFunction)datetime_gettimetz, METH_NOARGS,
-     PyDoc_STR("Return time object with same time and tzinfo.")},
-
-    {"ctime",       (PyCFunction)datetime_ctime,        METH_NOARGS,
-     PyDoc_STR("Return ctime() style string.")},
-
-    {"timetuple",   (PyCFunction)datetime_timetuple, METH_NOARGS,
-     PyDoc_STR("Return time tuple, compatible with time.localtime().")},
-
-    {"utctimetuple",   (PyCFunction)datetime_utctimetuple, METH_NOARGS,
-     PyDoc_STR("Return UTC time tuple, compatible with time.localtime().")},
-
-    {"isoformat",   (PyCFunction)datetime_isoformat, METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("[sep] -> string in ISO 8601 format, "
-               "YYYY-MM-DDTHH:MM:SS[.mmmmmm][+HH:MM].\n\n"
-               "sep is used to separate the year from the time, and "
-               "defaults to 'T'.")},
-
-    {"utcoffset",       (PyCFunction)datetime_utcoffset, METH_NOARGS,
-     PyDoc_STR("Return self.tzinfo.utcoffset(self).")},
-
-    {"tzname",          (PyCFunction)datetime_tzname,   METH_NOARGS,
-     PyDoc_STR("Return self.tzinfo.tzname(self).")},
-
-    {"dst",             (PyCFunction)datetime_dst, METH_NOARGS,
-     PyDoc_STR("Return self.tzinfo.dst(self).")},
-
-    {"replace",     (PyCFunction)datetime_replace,      METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("Return datetime with new specified fields.")},
-
-    {"astimezone",  (PyCFunction)datetime_astimezone, METH_VARARGS | METH_KEYWORDS,
-     PyDoc_STR("tz -> convert to local time in new timezone tz\n")},
-
-    {"__reduce__", (PyCFunction)datetime_reduce,     METH_NOARGS,
-     PyDoc_STR("__reduce__() -> (cls, state)")},
-
-    {NULL,      NULL}
-};
-
-static char datetime_doc[] =
-PyDoc_STR("datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])\n\
-\n\
-The year, month and day arguments are required. tzinfo may be None, or an\n\
-instance of a tzinfo subclass. The remaining arguments may be ints or longs.\n");
-
-static PyNumberMethods datetime_as_number = {
-    datetime_add,                               /* nb_add */
-    datetime_subtract,                          /* nb_subtract */
-    0,                                          /* nb_multiply */
-    0,                                          /* nb_remainder */
-    0,                                          /* nb_divmod */
-    0,                                          /* nb_power */
-    0,                                          /* nb_negative */
-    0,                                          /* nb_positive */
-    0,                                          /* nb_absolute */
-    0,                                          /* nb_bool */
-};
-
-static PyTypeObject PyDateTime_DateTimeType = {
-    PyVarObject_HEAD_INIT(NULL, 0)
-    "datetime.datetime",                        /* tp_name */
-    sizeof(PyDateTime_DateTime),                /* tp_basicsize */
-    0,                                          /* tp_itemsize */
-    (destructor)datetime_dealloc,               /* tp_dealloc */
-    0,                                          /* tp_print */
-    0,                                          /* tp_getattr */
-    0,                                          /* tp_setattr */
-    0,                                          /* tp_reserved */
-    (reprfunc)datetime_repr,                    /* tp_repr */
-    &datetime_as_number,                        /* tp_as_number */
-    0,                                          /* tp_as_sequence */
-    0,                                          /* tp_as_mapping */
-    (hashfunc)datetime_hash,                    /* tp_hash */
-    0,                                          /* tp_call */
-    (reprfunc)datetime_str,                     /* tp_str */
-    PyObject_GenericGetAttr,                    /* tp_getattro */
-    0,                                          /* tp_setattro */
-    0,                                          /* tp_as_buffer */
-    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
-    datetime_doc,                               /* tp_doc */
-    0,                                          /* tp_traverse */
-    0,                                          /* tp_clear */
-    datetime_richcompare,                       /* tp_richcompare */
-    0,                                          /* tp_weaklistoffset */
-    0,                                          /* tp_iter */
-    0,                                          /* tp_iternext */
-    datetime_methods,                           /* tp_methods */
-    0,                                          /* tp_members */
-    datetime_getset,                            /* tp_getset */
-    &PyDateTime_DateType,                       /* tp_base */
-    0,                                          /* tp_dict */
-    0,                                          /* tp_descr_get */
-    0,                                          /* tp_descr_set */
-    0,                                          /* tp_dictoffset */
-    0,                                          /* tp_init */
-    datetime_alloc,                             /* tp_alloc */
-    datetime_new,                               /* tp_new */
-    0,                                          /* tp_free */
-};
-
-/* ---------------------------------------------------------------------------
- * Module methods and initialization.
- */
-
-static PyMethodDef module_methods[] = {
-    {NULL, NULL}
-};
-
-/* C API.  Clients get at this via PyDateTime_IMPORT, defined in
- * datetime.h.
- */
-static PyDateTime_CAPI CAPI = {
-    &PyDateTime_DateType,
-    &PyDateTime_DateTimeType,
-    &PyDateTime_TimeType,
-    &PyDateTime_DeltaType,
-    &PyDateTime_TZInfoType,
-    new_date_ex,
-    new_datetime_ex,
-    new_time_ex,
-    new_delta_ex,
-    datetime_fromtimestamp,
-    date_fromtimestamp
-};
-
-
-
-static struct PyModuleDef datetimemodule = {
-    PyModuleDef_HEAD_INIT,
-    "datetime",
-    "Fast implementation of the datetime type.",
-    -1,
-    module_methods,
-    NULL,
-    NULL,
-    NULL,
-    NULL
-};
-
-PyMODINIT_FUNC
-PyInit_datetime(void)
-{
-    PyObject *m;        /* a module object */
-    PyObject *d;        /* its dict */
-    PyObject *x;
-    PyObject *delta;
-
-    m = PyModule_Create(&datetimemodule);
-    if (m == NULL)
-        return NULL;
-
-    if (PyType_Ready(&PyDateTime_DateType) < 0)
-        return NULL;
-    if (PyType_Ready(&PyDateTime_DateTimeType) < 0)
-        return NULL;
-    if (PyType_Ready(&PyDateTime_DeltaType) < 0)
-        return NULL;
-    if (PyType_Ready(&PyDateTime_TimeType) < 0)
-        return NULL;
-    if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
-        return NULL;
-    if (PyType_Ready(&PyDateTime_TimeZoneType) < 0)
-        return NULL;
-
-    /* timedelta values */
-    d = PyDateTime_DeltaType.tp_dict;
-
-    x = new_delta(0, 0, 1, 0);
-    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_delta(-MAX_DELTA_DAYS, 0, 0, 0);
-    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_delta(MAX_DELTA_DAYS, 24*3600-1, 1000000-1, 0);
-    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    /* date values */
-    d = PyDateTime_DateType.tp_dict;
-
-    x = new_date(1, 1, 1);
-    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_date(MAXYEAR, 12, 31);
-    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_delta(1, 0, 0, 0);
-    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    /* time values */
-    d = PyDateTime_TimeType.tp_dict;
-
-    x = new_time(0, 0, 0, 0, Py_None);
-    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_time(23, 59, 59, 999999, Py_None);
-    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_delta(0, 0, 1, 0);
-    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    /* datetime values */
-    d = PyDateTime_DateTimeType.tp_dict;
-
-    x = new_datetime(1, 1, 1, 0, 0, 0, 0, Py_None);
-    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_datetime(MAXYEAR, 12, 31, 23, 59, 59, 999999, Py_None);
-    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    x = new_delta(0, 0, 1, 0);
-    if (x == NULL || PyDict_SetItemString(d, "resolution", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    /* timezone values */
-    d = PyDateTime_TimeZoneType.tp_dict;
-
-    delta = new_delta(0, 0, 0, 0);
-    if (delta == NULL)
-        return NULL;
-    x = new_timezone(delta, NULL);
-    Py_DECREF(delta);
-    if (x == NULL || PyDict_SetItemString(d, "utc", x) < 0)
-        return NULL;
-    PyDateTime_TimeZone_UTC = x;
-
-    delta = new_delta(-1, 60, 0, 1); /* -23:59 */
-    if (delta == NULL)
-        return NULL;
-    x = new_timezone(delta, NULL);
-    Py_DECREF(delta);
-    if (x == NULL || PyDict_SetItemString(d, "min", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    delta = new_delta(0, (23 * 60 + 59) * 60, 0, 0); /* +23:59 */
-    if (delta == NULL)
-        return NULL;
-    x = new_timezone(delta, NULL);
-    Py_DECREF(delta);
-    if (x == NULL || PyDict_SetItemString(d, "max", x) < 0)
-        return NULL;
-    Py_DECREF(x);
-
-    /* module initialization */
-    PyModule_AddIntConstant(m, "MINYEAR", MINYEAR);
-    PyModule_AddIntConstant(m, "MAXYEAR", MAXYEAR);
-
-    Py_INCREF(&PyDateTime_DateType);
-    PyModule_AddObject(m, "date", (PyObject *) &PyDateTime_DateType);
-
-    Py_INCREF(&PyDateTime_DateTimeType);
-    PyModule_AddObject(m, "datetime",
-                       (PyObject *)&PyDateTime_DateTimeType);
-
-    Py_INCREF(&PyDateTime_TimeType);
-    PyModule_AddObject(m, "time", (PyObject *) &PyDateTime_TimeType);
-
-    Py_INCREF(&PyDateTime_DeltaType);
-    PyModule_AddObject(m, "timedelta", (PyObject *) &PyDateTime_DeltaType);
-
-    Py_INCREF(&PyDateTime_TZInfoType);
-    PyModule_AddObject(m, "tzinfo", (PyObject *) &PyDateTime_TZInfoType);
-
-    Py_INCREF(&PyDateTime_TimeZoneType);
-    PyModule_AddObject(m, "timezone", (PyObject *) &PyDateTime_TimeZoneType);
-
-    x = PyCapsule_New(&CAPI, PyDateTime_CAPSULE_NAME, NULL);
-    if (x == NULL)
-        return NULL;
-    PyModule_AddObject(m, "datetime_CAPI", x);
-
-    /* A 4-year cycle has an extra leap day over what we'd get from
-     * pasting together 4 single years.
-     */
-    assert(DI4Y == 4 * 365 + 1);
-    assert(DI4Y == days_before_year(4+1));
-
-    /* Similarly, a 400-year cycle has an extra leap day over what we'd
-     * get from pasting together 4 100-year cycles.
-     */
-    assert(DI400Y == 4 * DI100Y + 1);
-    assert(DI400Y == days_before_year(400+1));
-
-    /* OTOH, a 100-year cycle has one fewer leap day than we'd get from
-     * pasting together 25 4-year cycles.
-     */
-    assert(DI100Y == 25 * DI4Y - 1);
-    assert(DI100Y == days_before_year(100+1));
-
-    us_per_us = PyLong_FromLong(1);
-    us_per_ms = PyLong_FromLong(1000);
-    us_per_second = PyLong_FromLong(1000000);
-    us_per_minute = PyLong_FromLong(60000000);
-    seconds_per_day = PyLong_FromLong(24 * 3600);
-    if (us_per_us == NULL || us_per_ms == NULL || us_per_second == NULL ||
-        us_per_minute == NULL || seconds_per_day == NULL)
-        return NULL;
-
-    /* The rest are too big for 32-bit ints, but even
-     * us_per_week fits in 40 bits, so doubles should be exact.
-     */
-    us_per_hour = PyLong_FromDouble(3600000000.0);
-    us_per_day = PyLong_FromDouble(86400000000.0);
-    us_per_week = PyLong_FromDouble(604800000000.0);
-    if (us_per_hour == NULL || us_per_day == NULL || us_per_week == NULL)
-        return NULL;
-    return m;
-}
-
-/* ---------------------------------------------------------------------------
-Some time zone algebra.  For a datetime x, let
-    x.n = x stripped of its timezone -- its naive time.
-    x.o = x.utcoffset(), and assuming that doesn't raise an exception or
-      return None
-    x.d = x.dst(), and assuming that doesn't raise an exception or
-      return None
-    x.s = x's standard offset, x.o - x.d
-
-Now some derived rules, where k is a duration (timedelta).
-
-1. x.o = x.s + x.d
-   This follows from the definition of x.s.
-
-2. If x and y have the same tzinfo member, x.s = y.s.
-   This is actually a requirement, an assumption we need to make about
-   sane tzinfo classes.
-
-3. The naive UTC time corresponding to x is x.n - x.o.
-   This is again a requirement for a sane tzinfo class.
-
-4. (x+k).s = x.s
-   This follows from #2, and that datimetimetz+timedelta preserves tzinfo.
-
-5. (x+k).n = x.n + k
-   Again follows from how arithmetic is defined.
-
-Now we can explain tz.fromutc(x).  Let's assume it's an interesting case
-(meaning that the various tzinfo methods exist, and don't blow up or return
-None when called).
-
-The function wants to return a datetime y with timezone tz, equivalent to x.
-x is already in UTC.
-
-By #3, we want
-
-    y.n - y.o = x.n                             [1]
-
-The algorithm starts by attaching tz to x.n, and calling that y.  So
-x.n = y.n at the start.  Then it wants to add a duration k to y, so that [1]
-becomes true; in effect, we want to solve [2] for k:
-
-   (y+k).n - (y+k).o = x.n                      [2]
-
-By #1, this is the same as
-
-   (y+k).n - ((y+k).s + (y+k).d) = x.n          [3]
-
-By #5, (y+k).n = y.n + k, which equals x.n + k because x.n=y.n at the start.
-Substituting that into [3],
-
-   x.n + k - (y+k).s - (y+k).d = x.n; the x.n terms cancel, leaving
-   k - (y+k).s - (y+k).d = 0; rearranging,
-   k = (y+k).s - (y+k).d; by #4, (y+k).s == y.s, so
-   k = y.s - (y+k).d
-
-On the RHS, (y+k).d can't be computed directly, but y.s can be, and we
-approximate k by ignoring the (y+k).d term at first.  Note that k can't be
-very large, since all offset-returning methods return a duration of magnitude
-less than 24 hours.  For that reason, if y is firmly in std time, (y+k).d must
-be 0, so ignoring it has no consequence then.
-
-In any case, the new value is
-
-    z = y + y.s                                 [4]
-
-It's helpful to step back at look at [4] from a higher level:  it's simply
-mapping from UTC to tz's standard time.
-
-At this point, if
-
-    z.n - z.o = x.n                             [5]
-
-we have an equivalent time, and are almost done.  The insecurity here is
-at the start of daylight time.  Picture US Eastern for concreteness.  The wall
-time jumps from 1:59 to 3:00, and wall hours of the form 2:MM don't make good
-sense then.  The docs ask that an Eastern tzinfo class consider such a time to
-be EDT (because it's "after 2"), which is a redundant spelling of 1:MM EST
-on the day DST starts.  We want to return the 1:MM EST spelling because that's
-the only spelling that makes sense on the local wall clock.
-
-In fact, if [5] holds at this point, we do have the standard-time spelling,
-but that takes a bit of proof.  We first prove a stronger result.  What's the
-difference between the LHS and RHS of [5]?  Let
-
-    diff = x.n - (z.n - z.o)                    [6]
-
-Now
-    z.n =                       by [4]
-    (y + y.s).n =               by #5
-    y.n + y.s =                 since y.n = x.n
-    x.n + y.s =                 since z and y are have the same tzinfo member,
-                                    y.s = z.s by #2
-    x.n + z.s
-
-Plugging that back into [6] gives
-
-    diff =
-    x.n - ((x.n + z.s) - z.o) =     expanding
-    x.n - x.n - z.s + z.o =         cancelling
-    - z.s + z.o =                   by #2
-    z.d
-
-So diff = z.d.
-
-If [5] is true now, diff = 0, so z.d = 0 too, and we have the standard-time
-spelling we wanted in the endcase described above.  We're done.  Contrarily,
-if z.d = 0, then we have a UTC equivalent, and are also done.
-
-If [5] is not true now, diff = z.d != 0, and z.d is the offset we need to
-add to z (in effect, z is in tz's standard time, and we need to shift the
-local clock into tz's daylight time).
-
-Let
-
-    z' = z + z.d = z + diff                     [7]
-
-and we can again ask whether
-
-    z'.n - z'.o = x.n                           [8]
-
-If so, we're done.  If not, the tzinfo class is insane, according to the
-assumptions we've made.  This also requires a bit of proof.  As before, let's
-compute the difference between the LHS and RHS of [8] (and skipping some of
-the justifications for the kinds of substitutions we've done several times
-already):
-
-    diff' = x.n - (z'.n - z'.o) =           replacing z'.n via [7]
-        x.n  - (z.n + diff - z'.o) =    replacing diff via [6]
-        x.n - (z.n + x.n - (z.n - z.o) - z'.o) =
-        x.n - z.n - x.n + z.n - z.o + z'.o =    cancel x.n
-        - z.n + z.n - z.o + z'.o =              cancel z.n
-        - z.o + z'.o =                      #1 twice
-        -z.s - z.d + z'.s + z'.d =          z and z' have same tzinfo
-        z'.d - z.d
-
-So z' is UTC-equivalent to x iff z'.d = z.d at this point.  If they are equal,
-we've found the UTC-equivalent so are done.  In fact, we stop with [7] and
-return z', not bothering to compute z'.d.
-
-How could z.d and z'd differ?  z' = z + z.d [7], so merely moving z' by
-a dst() offset, and starting *from* a time already in DST (we know z.d != 0),
-would have to change the result dst() returns:  we start in DST, and moving
-a little further into it takes us out of DST.
-
-There isn't a sane case where this can happen.  The closest it gets is at
-the end of DST, where there's an hour in UTC with no spelling in a hybrid
-tzinfo class.  In US Eastern, that's 5:MM UTC = 0:MM EST = 1:MM EDT.  During
-that hour, on an Eastern clock 1:MM is taken as being in standard time (6:MM
-UTC) because the docs insist on that, but 0:MM is taken as being in daylight
-time (4:MM UTC).  There is no local time mapping to 5:MM UTC.  The local
-clock jumps from 1:59 back to 1:00 again, and repeats the 1:MM hour in
-standard time.  Since that's what the local clock *does*, we want to map both
-UTC hours 5:MM and 6:MM to 1:MM Eastern.  The result is ambiguous
-in local time, but so it goes -- it's the way the local clock works.
-
-When x = 5:MM UTC is the input to this algorithm, x.o=0, y.o=-5 and y.d=0,
-so z=0:MM.  z.d=60 (minutes) then, so [5] doesn't hold and we keep going.
-z' = z + z.d = 1:MM then, and z'.d=0, and z'.d - z.d = -60 != 0 so [8]
-(correctly) concludes that z' is not UTC-equivalent to x.
-
-Because we know z.d said z was in daylight time (else [5] would have held and
-we would have stopped then), and we know z.d != z'.d (else [8] would have held
-and we would have stopped then), and there are only 2 possible values dst() can
-return in Eastern, it follows that z'.d must be 0 (which it is in the example,
-but the reasoning doesn't depend on the example -- it depends on there being
-two possible dst() outcomes, one zero and the other non-zero).  Therefore
-z' must be in standard time, and is the spelling we want in this case.
-
-Note again that z' is not UTC-equivalent as far as the hybrid tzinfo class is
-concerned (because it takes z' as being in standard time rather than the
-daylight time we intend here), but returning it gives the real-life "local
-clock repeats an hour" behavior when mapping the "unspellable" UTC hour into
-tz.
-
-When the input is 6:MM, z=1:MM and z.d=0, and we stop at once, again with
-the 1:MM standard time spelling we want.
-
-So how can this break?  One of the assumptions must be violated.  Two
-possibilities:
-
-1) [2] effectively says that y.s is invariant across all y belong to a given
-   time zone.  This isn't true if, for political reasons or continental drift,
-   a region decides to change its base offset from UTC.
-
-2) There may be versions of "double daylight" time where the tail end of
-   the analysis gives up a step too early.  I haven't thought about that
-   enough to say.
-
-In any case, it's clear that the default fromutc() is strong enough to handle
-"almost all" time zones:  so long as the standard offset is invariant, it
-doesn't matter if daylight time transition points change from year to year, or
-if daylight time is skipped in some years; it doesn't matter how large or
-small dst() may get within its bounds; and it doesn't even matter if some
-perverse time zone returns a negative dst()).  So a breaking case must be
-pretty bizarre, and a tzinfo subclass can override fromutc() if it is.
---------------------------------------------------------------------------- */

Modified: python/branches/import_unicode/Modules/getpath.c
==============================================================================
--- python/branches/import_unicode/Modules/getpath.c	(original)
+++ python/branches/import_unicode/Modules/getpath.c	Fri Jul 30 01:19:37 2010
@@ -559,7 +559,7 @@
         if (!ismodule(argv0_path)) {
                 /* We are in the build directory so use the name of the
                    executable - we know that the absolute path is passed */
-                wcsncpy(argv0_path, prog, MAXPATHLEN);
+                wcsncpy(argv0_path, progpath, MAXPATHLEN);
         }
         else {
                 /* Use the location of the library as the progpath */

Modified: python/branches/import_unicode/Modules/makesetup
==============================================================================
--- python/branches/import_unicode/Modules/makesetup	(original)
+++ python/branches/import_unicode/Modules/makesetup	Fri Jul 30 01:19:37 2010
@@ -219,7 +219,7 @@
 			case $doconfig in
 			no)	cc="$cc \$(CCSHARED) \$(CFLAGS) \$(CPPFLAGS)";;
 			*)
-				cc="$cc \$(PY_CFLAGS)";;
+				cc="$cc \$(PY_CORE_CFLAGS)";;
 			esac
 			rule="$obj: $src; $cc $cpps -c $src -o $obj"
 			echo "$rule" >>$rulesf

Modified: python/branches/import_unicode/Modules/mathmodule.c
==============================================================================
--- python/branches/import_unicode/Modules/mathmodule.c	(original)
+++ python/branches/import_unicode/Modules/mathmodule.c	Fri Jul 30 01:19:37 2010
@@ -1818,6 +1818,19 @@
 Convert angle x from degrees to radians.");
 
 static PyObject *
+math_isfinite(PyObject *self, PyObject *arg)
+{
+    double x = PyFloat_AsDouble(arg);
+    if (x == -1.0 && PyErr_Occurred())
+        return NULL;
+    return PyBool_FromLong((long)Py_IS_FINITE(x));
+}
+
+PyDoc_STRVAR(math_isfinite_doc,
+"isfinite(x) -> bool\n\n\
+Return True if x is neither an infinity nor a NaN, and False otherwise.");
+
+static PyObject *
 math_isnan(PyObject *self, PyObject *arg)
 {
     double x = PyFloat_AsDouble(arg);
@@ -1828,7 +1841,7 @@
 
 PyDoc_STRVAR(math_isnan_doc,
 "isnan(x) -> bool\n\n\
-Check if float x is not a number (NaN).");
+Return True if x is a NaN (not a number), and False otherwise.");
 
 static PyObject *
 math_isinf(PyObject *self, PyObject *arg)
@@ -1841,7 +1854,7 @@
 
 PyDoc_STRVAR(math_isinf_doc,
 "isinf(x) -> bool\n\n\
-Check if float x is infinite (positive or negative).");
+Return True if x is a positive or negative infinity, and False otherwise.");
 
 static PyMethodDef math_methods[] = {
     {"acos",            math_acos,      METH_O,         math_acos_doc},
@@ -1868,6 +1881,7 @@
     {"fsum",            math_fsum,      METH_O,         math_fsum_doc},
     {"gamma",           math_gamma,     METH_O,         math_gamma_doc},
     {"hypot",           math_hypot,     METH_VARARGS,   math_hypot_doc},
+    {"isfinite",        math_isfinite,  METH_O,         math_isfinite_doc},
     {"isinf",           math_isinf,     METH_O,         math_isinf_doc},
     {"isnan",           math_isnan,     METH_O,         math_isnan_doc},
     {"ldexp",           math_ldexp,     METH_VARARGS,   math_ldexp_doc},

Modified: python/branches/import_unicode/Modules/posixmodule.c
==============================================================================
--- python/branches/import_unicode/Modules/posixmodule.c	(original)
+++ python/branches/import_unicode/Modules/posixmodule.c	Fri Jul 30 01:19:37 2010
@@ -1117,7 +1117,8 @@
                                                 "GetFinalPathNameByHandleA");
         *(FARPROC*)&Py_GetFinalPathNameByHandleW = GetProcAddress(hKernel32,
                                                 "GetFinalPathNameByHandleW");
-        has_GetFinalPathNameByHandle = Py_GetFinalPathNameByHandleA && Py_GetFinalPathNameByHandleW;
+        has_GetFinalPathNameByHandle = Py_GetFinalPathNameByHandleA &&
+                                       Py_GetFinalPathNameByHandleW;
     }
     return has_GetFinalPathNameByHandle;
 }
@@ -1310,9 +1311,12 @@
     /* similar to stat() */
     result->st_mode = attributes_to_mode(info.dwFileAttributes);
     result->st_size = (((__int64)info.nFileSizeHigh)<<32) + info.nFileSizeLow;
-    FILE_TIME_to_time_t_nsec(&info.ftCreationTime, &result->st_ctime, &result->st_ctime_nsec);
-    FILE_TIME_to_time_t_nsec(&info.ftLastWriteTime, &result->st_mtime, &result->st_mtime_nsec);
-    FILE_TIME_to_time_t_nsec(&info.ftLastAccessTime, &result->st_atime, &result->st_atime_nsec);
+    FILE_TIME_to_time_t_nsec(&info.ftCreationTime, &result->st_ctime,
+                             &result->st_ctime_nsec);
+    FILE_TIME_to_time_t_nsec(&info.ftLastWriteTime, &result->st_mtime,
+                             &result->st_mtime_nsec);
+    FILE_TIME_to_time_t_nsec(&info.ftLastAccessTime, &result->st_atime,
+                             &result->st_atime_nsec);
     /* specific to fstat() */
     result->st_nlink = info.nNumberOfLinks;
     result->st_ino = (((__int64)info.nFileIndexHigh)<<32) + info.nFileIndexLow;
@@ -2287,10 +2291,10 @@
 
 
 PyDoc_STRVAR(posix_listdir__doc__,
-"listdir(path) -> list_of_strings\n\n\
+"listdir([path]) -> list_of_strings\n\n\
 Return a list containing the names of the entries in the directory.\n\
 \n\
-    path: path of directory to list\n\
+    path: path of directory to list (default: '.')\n\
 \n\
 The list is in arbitrary order.  It does not include the special\n\
 entries '.' and '..' even if they are present in the directory.");
@@ -2311,18 +2315,25 @@
     char *bufptr = namebuf;
     Py_ssize_t len = sizeof(namebuf)-5; /* only claim to have space for MAX_PATH */
 
-    PyObject *po;
-    if (PyArg_ParseTuple(args, "U:listdir", &po)) {
+    PyObject *po = NULL;
+    if (PyArg_ParseTuple(args, "|U:listdir", &po)) {
         WIN32_FIND_DATAW wFileData;
-        Py_UNICODE *wnamebuf;
+        Py_UNICODE *wnamebuf, *po_wchars;
+        
+        if (po == NULL) { // Default arg: "."
+            po_wchars = L".";
+            len = 1;
+        } else {
+            po_wchars = PyUnicode_AS_UNICODE(po);
+            len = PyUnicode_GET_SIZE(po);
+        }
         /* Overallocate for \\*.*\0 */
-        len = PyUnicode_GET_SIZE(po);
         wnamebuf = malloc((len + 5) * sizeof(wchar_t));
         if (!wnamebuf) {
             PyErr_NoMemory();
             return NULL;
         }
-        wcscpy(wnamebuf, PyUnicode_AS_UNICODE(po));
+        wcscpy(wnamebuf, po_wchars);
         if (len > 0) {
             Py_UNICODE wch = wnamebuf[len-1];
             if (wch != L'/' && wch != L'\\' && wch != L':')
@@ -2544,12 +2555,17 @@
     int arg_is_unicode = 1;
 
     errno = 0;
-    if (!PyArg_ParseTuple(args, "U:listdir", &v)) {
+    /* v is never read, so it does not need to be initialized yet. */
+    if (!PyArg_ParseTuple(args, "|U:listdir", &v)) {
         arg_is_unicode = 0;
         PyErr_Clear();
     }
-    if (!PyArg_ParseTuple(args, "O&:listdir", PyUnicode_FSConverter, &oname))
+    oname = NULL;
+    if (!PyArg_ParseTuple(args, "|O&:listdir", PyUnicode_FSConverter, &oname))
         return NULL;
+    if (oname == NULL) { // Default arg: "."
+      oname = PyBytes_FromString(".");
+    }
     name = PyBytes_AsString(oname);
     if ((dirp = opendir(name)) == NULL) {
         return posix_error_with_allocated_filename(oname);
@@ -2691,7 +2707,8 @@
     
     if(hFile == INVALID_HANDLE_VALUE) {
         return win32_error_unicode("GetFinalPathNamyByHandle", path);
-        return PyErr_Format(PyExc_RuntimeError, "Could not get a handle to file.");
+        return PyErr_Format(PyExc_RuntimeError,
+                            "Could not get a handle to file.");
     }
 
     /* We have a good handle to the target, use it to determine the
@@ -3005,7 +3022,8 @@
 posix_unlink(PyObject *self, PyObject *args)
 {
 #ifdef MS_WINDOWS
-    return win32_1str(args, "remove", "y:remove", DeleteFileA, "U:remove", Py_DeleteFileW);
+    return win32_1str(args, "remove", "y:remove", DeleteFileA,
+                      "U:remove", Py_DeleteFileW);
 #else
     return posix_1str(args, "O&:remove", unlink);
 #endif
@@ -4148,17 +4166,49 @@
 #define MAX_GROUPS 64
 #endif
     gid_t grouplist[MAX_GROUPS];
+
+    /* On MacOSX getgroups(2) can return more than MAX_GROUPS results 
+     * This is a helper variable to store the intermediate result when
+     * that happens.
+     *
+     * To keep the code readable the OSX behaviour is unconditional,
+     * according to the POSIX spec this should be safe on all unix-y
+     * systems.
+     */
+    gid_t* alt_grouplist = grouplist;
     int n;
 
     n = getgroups(MAX_GROUPS, grouplist);
-    if (n < 0)
-        posix_error();
-    else {
-        result = PyList_New(n);
-        if (result != NULL) {
+    if (n < 0) {
+        if (errno == EINVAL) {
+            n = getgroups(0, NULL);
+            if (n == -1) {
+                return posix_error();
+            }
+            if (n == 0) {
+                /* Avoid malloc(0) */
+                alt_grouplist = grouplist;
+            } else {
+                alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));
+                if (alt_grouplist == NULL) {
+                    errno = EINVAL;
+                    return posix_error();
+                }
+                n = getgroups(n, alt_grouplist);
+                if (n == -1) {
+                    PyMem_Free(alt_grouplist);
+                    return posix_error();
+                }
+            }
+        } else {
+            return posix_error();
+        }
+    }
+    result = PyList_New(n);
+    if (result != NULL) {
         int i;
         for (i = 0; i < n; ++i) {
-            PyObject *o = PyLong_FromLong((long)grouplist[i]);
+            PyObject *o = PyLong_FromLong((long)alt_grouplist[i]);
             if (o == NULL) {
             Py_DECREF(result);
             result = NULL;
@@ -4166,7 +4216,10 @@
             }
             PyList_SET_ITEM(result, i, o);
         }
-        }
+    }
+
+    if (alt_grouplist != grouplist) {
+        PyMem_Free(alt_grouplist);
     }
 
     return result;
@@ -4959,7 +5012,8 @@
     };
 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
 
-#define REPARSE_DATA_BUFFER_HEADER_SIZE  FIELD_OFFSET(REPARSE_DATA_BUFFER, GenericReparseBuffer)
+#define REPARSE_DATA_BUFFER_HEADER_SIZE  FIELD_OFFSET(REPARSE_DATA_BUFFER,\
+                                                      GenericReparseBuffer)
 
 #define MAXIMUM_REPARSE_DATA_BUFFER_SIZE  ( 16 * 1024 )
 
@@ -5023,8 +5077,11 @@
                 "not a symbolic link");
         return NULL;
     }
-    print_name = rdb->SymbolicLinkReparseBuffer.PathBuffer + rdb->SymbolicLinkReparseBuffer.PrintNameOffset;
-    result = PyUnicode_FromWideChar(print_name, rdb->SymbolicLinkReparseBuffer.PrintNameLength/2);
+    print_name = rdb->SymbolicLinkReparseBuffer.PathBuffer +
+                 rdb->SymbolicLinkReparseBuffer.PrintNameOffset;
+
+    result = PyUnicode_FromWideChar(print_name,
+                    rdb->SymbolicLinkReparseBuffer.PrintNameLength/2);
     return result;
 }
 
@@ -5043,7 +5100,8 @@
     if (has_CreateSymbolicLinkW)
         return has_CreateSymbolicLinkW;
     hKernel32 = GetModuleHandle("KERNEL32");
-    *(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32, "CreateSymbolicLinkW");
+    *(FARPROC*)&Py_CreateSymbolicLinkW = GetProcAddress(hKernel32,
+                                                        "CreateSymbolicLinkW");
     if (Py_CreateSymbolicLinkW)
         has_CreateSymbolicLinkW = 1;
     return has_CreateSymbolicLinkW;
@@ -7586,7 +7644,8 @@
     {"symlink",         posix_symlink, METH_VARARGS, posix_symlink__doc__},
 #endif /* HAVE_SYMLINK */
 #if !defined(HAVE_SYMLINK) && defined(MS_WINDOWS)
-    {"symlink", (PyCFunction)win_symlink, METH_VARARGS | METH_KEYWORDS, win_symlink__doc__},
+    {"symlink", (PyCFunction)win_symlink, METH_VARARGS | METH_KEYWORDS,
+                win_symlink__doc__},
 #endif /* !defined(HAVE_SYMLINK) && defined(MS_WINDOWS) */
 #ifdef HAVE_SYSTEM
     {"system",          posix_system, METH_VARARGS, posix_system__doc__},

Modified: python/branches/import_unicode/Modules/sha1module.c
==============================================================================
--- python/branches/import_unicode/Modules/sha1module.c	(original)
+++ python/branches/import_unicode/Modules/sha1module.c	Fri Jul 30 01:19:37 2010
@@ -127,50 +127,50 @@
 
     /* compress */
     /* round one */
-    #define FF0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
-    #define FF1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
-    #define FF2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
-    #define FF3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
+    #define FF_0(a,b,c,d,e,i) e = (ROLc(a, 5) + F0(b,c,d) + e + W[i] + 0x5a827999UL); b = ROLc(b, 30);
+    #define FF_1(a,b,c,d,e,i) e = (ROLc(a, 5) + F1(b,c,d) + e + W[i] + 0x6ed9eba1UL); b = ROLc(b, 30);
+    #define FF_2(a,b,c,d,e,i) e = (ROLc(a, 5) + F2(b,c,d) + e + W[i] + 0x8f1bbcdcUL); b = ROLc(b, 30);
+    #define FF_3(a,b,c,d,e,i) e = (ROLc(a, 5) + F3(b,c,d) + e + W[i] + 0xca62c1d6UL); b = ROLc(b, 30);
 
     for (i = 0; i < 20; ) {
-       FF0(a,b,c,d,e,i++);
-       FF0(e,a,b,c,d,i++);
-       FF0(d,e,a,b,c,i++);
-       FF0(c,d,e,a,b,i++);
-       FF0(b,c,d,e,a,i++);
+       FF_0(a,b,c,d,e,i++);
+       FF_0(e,a,b,c,d,i++);
+       FF_0(d,e,a,b,c,i++);
+       FF_0(c,d,e,a,b,i++);
+       FF_0(b,c,d,e,a,i++);
     }
 
     /* round two */
     for (; i < 40; )  {
-       FF1(a,b,c,d,e,i++);
-       FF1(e,a,b,c,d,i++);
-       FF1(d,e,a,b,c,i++);
-       FF1(c,d,e,a,b,i++);
-       FF1(b,c,d,e,a,i++);
+       FF_1(a,b,c,d,e,i++);
+       FF_1(e,a,b,c,d,i++);
+       FF_1(d,e,a,b,c,i++);
+       FF_1(c,d,e,a,b,i++);
+       FF_1(b,c,d,e,a,i++);
     }
 
     /* round three */
     for (; i < 60; )  {
-       FF2(a,b,c,d,e,i++);
-       FF2(e,a,b,c,d,i++);
-       FF2(d,e,a,b,c,i++);
-       FF2(c,d,e,a,b,i++);
-       FF2(b,c,d,e,a,i++);
+       FF_2(a,b,c,d,e,i++);
+       FF_2(e,a,b,c,d,i++);
+       FF_2(d,e,a,b,c,i++);
+       FF_2(c,d,e,a,b,i++);
+       FF_2(b,c,d,e,a,i++);
     }
 
     /* round four */
     for (; i < 80; )  {
-       FF3(a,b,c,d,e,i++);
-       FF3(e,a,b,c,d,i++);
-       FF3(d,e,a,b,c,i++);
-       FF3(c,d,e,a,b,i++);
-       FF3(b,c,d,e,a,i++);
+       FF_3(a,b,c,d,e,i++);
+       FF_3(e,a,b,c,d,i++);
+       FF_3(d,e,a,b,c,i++);
+       FF_3(c,d,e,a,b,i++);
+       FF_3(b,c,d,e,a,i++);
     }
 
-    #undef FF0
-    #undef FF1
-    #undef FF2
-    #undef FF3
+    #undef FF_0
+    #undef FF_1
+    #undef FF_2
+    #undef FF_3
 
     /* store */
     sha1->state[0] = sha1->state[0] + a;

Modified: python/branches/import_unicode/Modules/zipimport.c
==============================================================================
--- python/branches/import_unicode/Modules/zipimport.c	(original)
+++ python/branches/import_unicode/Modules/zipimport.c	Fri Jul 30 01:19:37 2010
@@ -553,19 +553,19 @@
 "is_package(fullname) -> bool.\n\
 \n\
 Return True if the module specified by fullname is a package.\n\
-Raise ZipImportError is the module couldn't be found.");
+Raise ZipImportError if the module couldn't be found.");
 
 PyDoc_STRVAR(doc_get_code,
 "get_code(fullname) -> code object.\n\
 \n\
 Return the code object for the specified module. Raise ZipImportError\n\
-is the module couldn't be found.");
+if the module couldn't be found.");
 
 PyDoc_STRVAR(doc_get_source,
 "get_source(fullname) -> source string.\n\
 \n\
 Return the source code for the specified module. Raise ZipImportError\n\
-is the module couldn't be found, return None if the archive does\n\
+if the module couldn't be found, return None if the archive does\n\
 contain the module, but has no source for it.");
 
 

Modified: python/branches/import_unicode/Objects/bytearrayobject.c
==============================================================================
--- python/branches/import_unicode/Objects/bytearrayobject.c	(original)
+++ python/branches/import_unicode/Objects/bytearrayobject.c	Fri Jul 30 01:19:37 2010
@@ -33,6 +33,7 @@
         PyObject *index = PyNumber_Index(arg);
         if (index == NULL) {
             PyErr_Format(PyExc_TypeError, "an integer is required");
+            *value = -1;
             return 0;
         }
         face_value = PyLong_AsLong(index);
@@ -42,6 +43,7 @@
     if (face_value < 0 || face_value >= 256) {
         /* this includes the OverflowError in case the long is too large */
         PyErr_SetString(PyExc_ValueError, "byte must be in range(0, 256)");
+        *value = -1;
         return 0;
     }
 

Modified: python/branches/import_unicode/Objects/memoryobject.c
==============================================================================
--- python/branches/import_unicode/Objects/memoryobject.c	(original)
+++ python/branches/import_unicode/Objects/memoryobject.c	Fri Jul 30 01:19:37 2010
@@ -624,7 +624,7 @@
 static int
 memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value)
 {
-    Py_ssize_t start, len, bytelen, i;
+    Py_ssize_t start, len, bytelen;
     Py_buffer srcview;
     Py_buffer *view = &(self->view);
     char *srcbuf, *destbuf;
@@ -694,16 +694,8 @@
     if (destbuf + bytelen < srcbuf || srcbuf + bytelen < destbuf)
         /* No overlapping */
         memcpy(destbuf, srcbuf, bytelen);
-    else if (destbuf < srcbuf) {
-        /* Copy in ascending order */
-        for (i = 0; i < bytelen; i++)
-            destbuf[i] = srcbuf[i];
-    }
-    else {
-        /* Copy in descencing order */
-        for (i = bytelen - 1; i >= 0; i--)
-            destbuf[i] = srcbuf[i];
-    }
+    else
+        memmove(destbuf, srcbuf, bytelen);
 
     PyBuffer_Release(&srcview);
     return 0;

Modified: python/branches/import_unicode/Objects/object.c
==============================================================================
--- python/branches/import_unicode/Objects/object.c	(original)
+++ python/branches/import_unicode/Objects/object.c	Fri Jul 30 01:19:37 2010
@@ -260,15 +260,10 @@
     return PyObject_INIT_VAR(op, tp, nitems);
 }
 
-/* Implementation of PyObject_Print with recursion checking */
-static int
-internal_print(PyObject *op, FILE *fp, int flags, int nesting)
+int
+PyObject_Print(PyObject *op, FILE *fp, int flags)
 {
     int ret = 0;
-    if (nesting > 10) {
-        PyErr_SetString(PyExc_RuntimeError, "print recursion");
-        return -1;
-    }
     if (PyErr_CheckSignals())
         return -1;
 #ifdef USE_STACKCHECK
@@ -335,12 +330,6 @@
     return ret;
 }
 
-int
-PyObject_Print(PyObject *op, FILE *fp, int flags)
-{
-    return internal_print(op, fp, flags, 0);
-}
-
 /* For debugging convenience.  Set a breakpoint here and call it from your DLL */
 void
 _Py_BreakPoint(void)

Modified: python/branches/import_unicode/Objects/stringlib/formatter.h
==============================================================================
--- python/branches/import_unicode/Objects/stringlib/formatter.h	(original)
+++ python/branches/import_unicode/Objects/stringlib/formatter.h	Fri Jul 30 01:19:37 2010
@@ -776,14 +776,6 @@
             goto done;
         }
 
-        /* Error to specify a comma. */
-        if (format->thousands_separators) {
-            PyErr_SetString(PyExc_ValueError,
-                            "Thousands separators not allowed with integer"
-                            " format specifier 'c'");
-            goto done;
-        }
-
         /* taken from unicodeobject.c formatchar() */
         /* Integer input truncated to a character */
 /* XXX: won't work for int */

Modified: python/branches/import_unicode/Objects/unicodeobject.c
==============================================================================
--- python/branches/import_unicode/Objects/unicodeobject.c	(original)
+++ python/branches/import_unicode/Objects/unicodeobject.c	Fri Jul 30 01:19:37 2010
@@ -307,8 +307,7 @@
   reset:
     /* Reset the object caches */
     if (unicode->defenc) {
-        Py_DECREF(unicode->defenc);
-        unicode->defenc = NULL;
+        Py_CLEAR(unicode->defenc);
     }
     unicode->hash = -1;
 
@@ -427,8 +426,7 @@
             unicode->length = 0;
         }
         if (unicode->defenc) {
-            Py_DECREF(unicode->defenc);
-            unicode->defenc = NULL;
+            Py_CLEAR(unicode->defenc);
         }
         /* Add to free list */
         *(PyUnicodeObject **)unicode = free_list;
@@ -9243,7 +9241,7 @@
                 else if (c >= '0' && c <= '9') {
                     prec = c - '0';
                     while (--fmtcnt >= 0) {
-                        c = Py_CHARMASK(*fmt++);
+                        c = *fmt++;
                         if (c < '0' || c > '9')
                             break;
                         if ((prec*10) / 10 != prec) {

Modified: python/branches/import_unicode/PC/config.c
==============================================================================
--- python/branches/import_unicode/PC/config.c	(original)
+++ python/branches/import_unicode/PC/config.c	Fri Jul 30 01:19:37 2010
@@ -43,7 +43,7 @@
 extern PyObject* PyInit_parser(void);
 extern PyObject* PyInit_winreg(void);
 extern PyObject* PyInit__struct(void);
-extern PyObject* PyInit_datetime(void);
+extern PyObject* PyInit__datetime(void);
 extern PyObject* PyInit__functools(void);
 extern PyObject* PyInit__json(void);
 extern PyObject* PyInit_zlib(void);
@@ -116,7 +116,7 @@
     {"parser", PyInit_parser},
     {"winreg", PyInit_winreg},
     {"_struct", PyInit__struct},
-    {"datetime", PyInit_datetime},
+    {"_datetime", PyInit__datetime},
     {"_functools", PyInit__functools},
     {"_json", PyInit__json},
 

Modified: python/branches/import_unicode/PCbuild/pythoncore.vcproj
==============================================================================
--- python/branches/import_unicode/PCbuild/pythoncore.vcproj	(original)
+++ python/branches/import_unicode/PCbuild/pythoncore.vcproj	Fri Jul 30 01:19:37 2010
@@ -1068,7 +1068,7 @@
 				>
 			</File>
 			<File
-				RelativePath="..\Modules\datetimemodule.c"
+				RelativePath="..\Modules\_datetimemodule.c"
 				>
 			</File>
 			<File

Modified: python/branches/import_unicode/Python/ceval.c
==============================================================================
--- python/branches/import_unicode/Python/ceval.c	(original)
+++ python/branches/import_unicode/Python/ceval.c	Fri Jul 30 01:19:37 2010
@@ -3457,7 +3457,8 @@
             return 1;
         }
         Py_DECREF(w);
-        PyErr_SetString(PyExc_ValueError, "too many values to unpack");
+        PyErr_Format(PyExc_ValueError, "too many values to unpack "
+                     "(expected %d)", argcnt);
         goto Error;
     }
 

Modified: python/branches/import_unicode/Python/getargs.c
==============================================================================
--- python/branches/import_unicode/Python/getargs.c	(original)
+++ python/branches/import_unicode/Python/getargs.c	Fri Jul 30 01:19:37 2010
@@ -1246,13 +1246,15 @@
             PyErr_Clear();
             return converterr("read-write buffer", arg, msgbuf, bufsize);
         }
+        if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C')) {
+            PyBuffer_Release((Py_buffer*)p);
+            return converterr("contiguous buffer", arg, msgbuf, bufsize);
+        }
         if (addcleanup(p, freelist, cleanup_buffer)) {
             return converterr(
                 "(cleanup problem)",
                 arg, msgbuf, bufsize);
         }
-        if (!PyBuffer_IsContiguous((Py_buffer*)p, 'C'))
-            return converterr("contiguous buffer", arg, msgbuf, bufsize);
         break;
     }
 
@@ -1274,41 +1276,26 @@
 
     *errmsg = NULL;
     *p = NULL;
-    if (pb == NULL ||
-        pb->bf_getbuffer == NULL ||
-        pb->bf_releasebuffer != NULL) {
-        *errmsg = "bytes or read-only buffer";
+    if (pb != NULL && pb->bf_releasebuffer != NULL) {
+        *errmsg = "read-only pinned buffer";
         return -1;
     }
 
-    if (PyObject_GetBuffer(arg, &view, PyBUF_SIMPLE) != 0) {
-        *errmsg = "bytes or single-segment read-only buffer";
+    if (getbuffer(arg, &view, errmsg) < 0)
         return -1;
-    }
     count = view.len;
     *p = view.buf;
     PyBuffer_Release(&view);
     return count;
 }
 
-/* XXX for 3.x, getbuffer and convertbuffer can probably
-   be merged again. */
 static int
 getbuffer(PyObject *arg, Py_buffer *view, char **errmsg)
 {
-    PyBufferProcs *pb = Py_TYPE(arg)->tp_as_buffer;
-    if (pb == NULL) {
+    if (PyObject_GetBuffer(arg, view, PyBUF_SIMPLE) != 0) {
         *errmsg = "bytes or buffer";
         return -1;
     }
-    if (pb->bf_getbuffer == NULL) {
-        *errmsg = "convertible to a buffer";
-        return -1;
-    }
-    if (PyObject_GetBuffer(arg, view, 0) < 0) {
-        *errmsg = "convertible to a buffer";
-        return -1;
-    }
     if (!PyBuffer_IsContiguous(view, 'C')) {
         PyBuffer_Release(view);
         *errmsg = "contiguous buffer";

Modified: python/branches/import_unicode/Python/graminit.c
==============================================================================
--- python/branches/import_unicode/Python/graminit.c	(original)
+++ python/branches/import_unicode/Python/graminit.c	Fri Jul 30 01:19:37 2010
@@ -180,8 +180,8 @@
     {24, 9},
 };
 static arc arcs_8_5[4] = {
-    {28, 1},
-    {31, 2},
+    {28, 10},
+    {31, 11},
     {32, 3},
     {0, 5},
 };
@@ -190,7 +190,7 @@
     {0, 6},
 };
 static arc arcs_8_7[2] = {
-    {28, 10},
+    {28, 12},
     {32, 3},
 };
 static arc arcs_8_8[1] = {
@@ -201,14 +201,40 @@
     {0, 9},
 };
 static arc arcs_8_10[3] = {
-    {30, 7},
-    {29, 11},
+    {30, 5},
+    {29, 4},
     {0, 10},
 };
-static arc arcs_8_11[1] = {
+static arc arcs_8_11[3] = {
+    {28, 13},
+    {30, 14},
+    {0, 11},
+};
+static arc arcs_8_12[3] = {
+    {30, 7},
+    {29, 15},
+    {0, 12},
+};
+static arc arcs_8_13[2] = {
+    {30, 14},
+    {0, 13},
+};
+static arc arcs_8_14[2] = {
+    {28, 16},
+    {32, 3},
+};
+static arc arcs_8_15[1] = {
     {24, 6},
 };
-static state states_8[12] = {
+static arc arcs_8_16[3] = {
+    {30, 14},
+    {29, 17},
+    {0, 16},
+};
+static arc arcs_8_17[1] = {
+    {24, 13},
+};
+static state states_8[18] = {
     {3, arcs_8_0},
     {3, arcs_8_1},
     {3, arcs_8_2},
@@ -220,7 +246,13 @@
     {1, arcs_8_8},
     {2, arcs_8_9},
     {3, arcs_8_10},
-    {1, arcs_8_11},
+    {3, arcs_8_11},
+    {3, arcs_8_12},
+    {2, arcs_8_13},
+    {2, arcs_8_14},
+    {1, arcs_8_15},
+    {3, arcs_8_16},
+    {1, arcs_8_17},
 };
 static arc arcs_9_0[1] = {
     {21, 1},
@@ -263,8 +295,8 @@
     {24, 9},
 };
 static arc arcs_10_5[4] = {
-    {34, 1},
-    {31, 2},
+    {34, 10},
+    {31, 11},
     {32, 3},
     {0, 5},
 };
@@ -273,7 +305,7 @@
     {0, 6},
 };
 static arc arcs_10_7[2] = {
-    {34, 10},
+    {34, 12},
     {32, 3},
 };
 static arc arcs_10_8[1] = {
@@ -284,14 +316,40 @@
     {0, 9},
 };
 static arc arcs_10_10[3] = {
-    {30, 7},
-    {29, 11},
+    {30, 5},
+    {29, 4},
     {0, 10},
 };
-static arc arcs_10_11[1] = {
+static arc arcs_10_11[3] = {
+    {34, 13},
+    {30, 14},
+    {0, 11},
+};
+static arc arcs_10_12[3] = {
+    {30, 7},
+    {29, 15},
+    {0, 12},
+};
+static arc arcs_10_13[2] = {
+    {30, 14},
+    {0, 13},
+};
+static arc arcs_10_14[2] = {
+    {34, 16},
+    {32, 3},
+};
+static arc arcs_10_15[1] = {
     {24, 6},
 };
-static state states_10[12] = {
+static arc arcs_10_16[3] = {
+    {30, 14},
+    {29, 17},
+    {0, 16},
+};
+static arc arcs_10_17[1] = {
+    {24, 13},
+};
+static state states_10[18] = {
     {3, arcs_10_0},
     {3, arcs_10_1},
     {3, arcs_10_2},
@@ -303,7 +361,13 @@
     {1, arcs_10_8},
     {2, arcs_10_9},
     {3, arcs_10_10},
-    {1, arcs_10_11},
+    {3, arcs_10_11},
+    {3, arcs_10_12},
+    {2, arcs_10_13},
+    {2, arcs_10_14},
+    {1, arcs_10_15},
+    {3, arcs_10_16},
+    {1, arcs_10_17},
 };
 static arc arcs_11_0[1] = {
     {21, 1},
@@ -1755,11 +1819,11 @@
      "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
     {263, "parameters", 0, 4, states_7,
      "\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {264, "typedargslist", 0, 12, states_8,
+    {264, "typedargslist", 0, 18, states_8,
      "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
     {265, "tfpdef", 0, 4, states_9,
      "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {266, "varargslist", 0, 12, states_10,
+    {266, "varargslist", 0, 18, states_10,
      "\000\000\040\200\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
     {267, "vfpdef", 0, 2, states_11,
      "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},

Modified: python/branches/import_unicode/Tools/gdb/libpython.py
==============================================================================
--- python/branches/import_unicode/Tools/gdb/libpython.py	(original)
+++ python/branches/import_unicode/Tools/gdb/libpython.py	Fri Jul 30 01:19:37 2010
@@ -43,6 +43,7 @@
 from __future__ import with_statement
 import gdb
 import locale
+import sys
 
 # Look up the gdb.Type for some standard types:
 _type_char_ptr = gdb.lookup_type('char').pointer() # char*
@@ -55,7 +56,6 @@
 
 Py_TPFLAGS_HEAPTYPE = (1L << 9)
 
-Py_TPFLAGS_INT_SUBCLASS      = (1L << 23)
 Py_TPFLAGS_LONG_SUBCLASS     = (1L << 24)
 Py_TPFLAGS_LIST_SUBCLASS     = (1L << 25)
 Py_TPFLAGS_TUPLE_SUBCLASS    = (1L << 26)
@@ -312,8 +312,6 @@
         if tp_flags & Py_TPFLAGS_HEAPTYPE:
             return HeapTypeObjectPtr
 
-        if tp_flags & Py_TPFLAGS_INT_SUBCLASS:
-            return PyIntObjectPtr
         if tp_flags & Py_TPFLAGS_LONG_SUBCLASS:
             return PyLongObjectPtr
         if tp_flags & Py_TPFLAGS_LIST_SUBCLASS:

Modified: python/branches/import_unicode/Tools/i18n/msgfmt.py
==============================================================================
--- python/branches/import_unicode/Tools/i18n/msgfmt.py	(original)
+++ python/branches/import_unicode/Tools/i18n/msgfmt.py	Fri Jul 30 01:19:37 2010
@@ -165,7 +165,7 @@
             section = STR
             if l.startswith('msgstr['):
                 if not is_plural:
-                    print(sys.stderr, 'plural without msgid_plural on %s:%d' % (infile, lno),
+                    print('plural without msgid_plural on %s:%d' % (infile, lno),
                           file=sys.stderr)
                     sys.exit(1)
                 l = l.split(']', 1)[1]
@@ -173,7 +173,7 @@
                     msgstr += b'\0' # Separator of the various plural forms
             else:
                 if is_plural:
-                    print(sys.stderr, 'indexed msgstr required for plural on  %s:%d' % (infile, lno),
+                    print('indexed msgstr required for plural on  %s:%d' % (infile, lno),
                           file=sys.stderr)
                     sys.exit(1)
                 l = l[6:]

Modified: python/branches/import_unicode/configure
==============================================================================
--- python/branches/import_unicode/configure	(original)
+++ python/branches/import_unicode/configure	Fri Jul 30 01:19:37 2010
@@ -1929,11 +1929,11 @@
        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 $ac_includes_default
+	     enum { N = $2 / 2 - 1 };
 int
 main ()
 {
-static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 };
-	     0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
+static int test_array [1 - 2 * !(0 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1))];
 test_array [0] = 0
 
   ;
@@ -1944,11 +1944,11 @@
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
 $ac_includes_default
+	        enum { N = $2 / 2 - 1 };
 int
 main ()
 {
-static int test_array [1 - 2 * !(enum { N = $2 / 2 - 1 };
-		($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
+static int test_array [1 - 2 * !(($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 1)
 		 < ($ac_type) ((((($ac_type) 1 << N) << N) - 1) * 2 + 2))];
 test_array [0] = 0
 
@@ -3158,9 +3158,12 @@
 (it is also a good idea to do 'make clean' before compiling)" "$LINENO" 5
 fi
 
-# If the user set CFLAGS, use this instead of the automatically
-# determined setting
-preset_cflags="$CFLAGS"
+# Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
+# when the compiler supports them, but we don't always want -O2, and
+# we set -g later.
+if test -z "$CFLAGS"; then
+        CFLAGS=
+fi
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3952,10 +3955,6 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
-if test ! -z "$preset_cflags"
-then
-	CFLAGS=$preset_cflags
-fi
 
 
 

Modified: python/branches/import_unicode/configure.in
==============================================================================
--- python/branches/import_unicode/configure.in	(original)
+++ python/branches/import_unicode/configure.in	Fri Jul 30 01:19:37 2010
@@ -461,14 +461,13 @@
 (it is also a good idea to do 'make clean' before compiling)])
 fi
 
-# If the user set CFLAGS, use this instead of the automatically
-# determined setting
-preset_cflags="$CFLAGS"
-AC_PROG_CC
-if test ! -z "$preset_cflags"
-then
-	CFLAGS=$preset_cflags
+# Don't let AC_PROG_CC set the default CFLAGS. It normally sets -g -O2
+# when the compiler supports them, but we don't always want -O2, and
+# we set -g later.
+if test -z "$CFLAGS"; then
+        CFLAGS=
 fi
+AC_PROG_CC
 
 AC_SUBST(CXX)
 AC_SUBST(MAINCC)

Modified: python/branches/import_unicode/setup.py
==============================================================================
--- python/branches/import_unicode/setup.py	(original)
+++ python/branches/import_unicode/setup.py	Fri Jul 30 01:19:37 2010
@@ -222,7 +222,7 @@
         if compiler is not None:
             (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS')
             args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags
-        self.compiler_obj.set_executables(**args)
+        self.compiler.set_executables(**args)
 
         build_ext.build_extensions(self)
 
@@ -343,8 +343,8 @@
 
     def detect_modules(self):
         # Ensure that /usr/local is always used
-        add_dir_to_list(self.compiler_obj.library_dirs, '/usr/local/lib')
-        add_dir_to_list(self.compiler_obj.include_dirs, '/usr/local/include')
+        add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
+        add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
 
         # Add paths specified in the environment variables LDFLAGS and
         # CPPFLAGS for header and library files.
@@ -353,9 +353,9 @@
         # the environment variable is not set even though the value were passed
         # into configure and stored in the Makefile (issue found on OS X 10.3).
         for env_var, arg_name, dir_list in (
-                ('LDFLAGS', '-R', self.compiler_obj.runtime_library_dirs),
-                ('LDFLAGS', '-L', self.compiler_obj.library_dirs),
-                ('CPPFLAGS', '-I', self.compiler_obj.include_dirs)):
+                ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
+                ('LDFLAGS', '-L', self.compiler.library_dirs),
+                ('CPPFLAGS', '-I', self.compiler.include_dirs)):
             env_val = sysconfig.get_config_var(env_var)
             if env_val:
                 # To prevent optparse from raising an exception about any
@@ -381,19 +381,19 @@
                         add_dir_to_list(dir_list, directory)
 
         if os.path.normpath(sys.prefix) != '/usr':
-            add_dir_to_list(self.compiler_obj.library_dirs,
+            add_dir_to_list(self.compiler.library_dirs,
                             sysconfig.get_config_var("LIBDIR"))
-            add_dir_to_list(self.compiler_obj.include_dirs,
+            add_dir_to_list(self.compiler.include_dirs,
                             sysconfig.get_config_var("INCLUDEDIR"))
 
         # lib_dirs and inc_dirs are used to search for files;
         # if a file is found in one of those directories, it can
         # be assumed that no additional -I,-L directives are needed.
-        lib_dirs = self.compiler_obj.library_dirs + [
+        lib_dirs = self.compiler.library_dirs + [
             '/lib64', '/usr/lib64',
             '/lib', '/usr/lib',
             ]
-        inc_dirs = self.compiler_obj.include_dirs + ['/usr/include']
+        inc_dirs = self.compiler.include_dirs + ['/usr/include']
         exts = []
         missing = []
 
@@ -452,7 +452,7 @@
         # time operations and variables
         exts.append( Extension('time', ['timemodule.c', '_time.c'],
                                libraries=math_libs) )
-        exts.append( Extension('datetime', ['datetimemodule.c', '_time.c'],
+        exts.append( Extension('_datetime', ['_datetimemodule.c', '_time.c'],
                                libraries=math_libs) )
         # fast iterator tools implemented in C
         exts.append( Extension("itertools", ["itertoolsmodule.c"]) )
@@ -525,7 +525,7 @@
         exts.append( Extension('audioop', ['audioop.c']) )
 
         # readline
-        do_readline = self.compiler_obj.find_library_file(lib_dirs, 'readline')
+        do_readline = self.compiler.find_library_file(lib_dirs, 'readline')
         readline_termcap_library = ""
         curses_library = ""
         # Determine if readline is already linked against curses or tinfo.
@@ -534,28 +534,29 @@
             tmpfile = os.path.join(self.build_temp, 'readline_termcap_lib')
             if not os.path.exists(self.build_temp):
                 os.makedirs(self.build_temp)
-            os.system("ldd %s > %s" % (do_readline, tmpfile))
-            fp = open(tmpfile)
-            for ln in fp:
-                if 'curses' in ln:
-                    readline_termcap_library = re.sub(
-                        r'.*lib(n?cursesw?)\.so.*', r'\1', ln
-                    ).rstrip()
-                    break
-                if 'tinfo' in ln: # termcap interface split out from ncurses
-                    readline_termcap_library = 'tinfo'
-                    break
-            fp.close()
+            ret = os.system("ldd %s > %s" % (do_readline, tmpfile))
+            if ret >> 8 == 0:
+                fp = open(tmpfile)
+                for ln in fp:
+                    if 'curses' in ln:
+                        readline_termcap_library = re.sub(
+                            r'.*lib(n?cursesw?)\.so.*', r'\1', ln
+                        ).rstrip()
+                        break
+                    if 'tinfo' in ln: # termcap interface split out from ncurses
+                        readline_termcap_library = 'tinfo'
+                        break
+                fp.close()
             os.unlink(tmpfile)
         # Issue 7384: If readline is already linked against curses,
         # use the same library for the readline and curses modules.
         if 'curses' in readline_termcap_library:
             curses_library = readline_termcap_library
-        elif self.compiler_obj.find_library_file(lib_dirs, 'ncursesw'):
+        elif self.compiler.find_library_file(lib_dirs, 'ncursesw'):
             curses_library = 'ncursesw'
-        elif self.compiler_obj.find_library_file(lib_dirs, 'ncurses'):
+        elif self.compiler.find_library_file(lib_dirs, 'ncurses'):
             curses_library = 'ncurses'
-        elif self.compiler_obj.find_library_file(lib_dirs, 'curses'):
+        elif self.compiler.find_library_file(lib_dirs, 'curses'):
             curses_library = 'curses'
 
         if platform == 'darwin':
@@ -585,7 +586,7 @@
                 pass # Issue 7384: Already linked against curses or tinfo.
             elif curses_library:
                 readline_libs.append(curses_library)
-            elif self.compiler_obj.find_library_file(lib_dirs +
+            elif self.compiler.find_library_file(lib_dirs +
                                                      ['/usr/lib/termcap'],
                                                      'termcap'):
                 readline_libs.append('termcap')
@@ -598,7 +599,7 @@
 
         # crypt module.
 
-        if self.compiler_obj.find_library_file(lib_dirs, 'crypt'):
+        if self.compiler.find_library_file(lib_dirs, 'crypt'):
             libs = ['crypt']
         else:
             libs = []
@@ -626,7 +627,7 @@
                                ['/usr/kerberos/include'])
             if krb5_h:
                 ssl_incs += krb5_h
-        ssl_libs = find_library_file(self.compiler_obj, 'ssl',lib_dirs,
+        ssl_libs = find_library_file(self.compiler, 'ssl',lib_dirs,
                                      ['/usr/local/ssl/lib',
                                       '/usr/contrib/ssl/lib/'
                                      ] )
@@ -951,7 +952,7 @@
                 os.path.join(sqlite_incdir, '..', '..', 'lib64'),
                 os.path.join(sqlite_incdir, '..', '..', 'lib'),
             ]
-            sqlite_libfile = self.compiler_obj.find_library_file(
+            sqlite_libfile = self.compiler.find_library_file(
                                 sqlite_dirs_to_check + lib_dirs, 'sqlite3')
             if sqlite_libfile:
                 sqlite_libdir = [os.path.abspath(os.path.dirname(sqlite_libfile))]
@@ -1013,7 +1014,7 @@
                 if cand == "ndbm":
                     if find_file("ndbm.h", inc_dirs, []) is not None:
                         # Some systems have -lndbm, others don't
-                        if self.compiler_obj.find_library_file(lib_dirs,
+                        if self.compiler.find_library_file(lib_dirs,
                                                                'ndbm'):
                             ndbm_libs = ['ndbm']
                         else:
@@ -1027,9 +1028,9 @@
                         break
 
                 elif cand == "gdbm":
-                    if self.compiler_obj.find_library_file(lib_dirs, 'gdbm'):
+                    if self.compiler.find_library_file(lib_dirs, 'gdbm'):
                         gdbm_libs = ['gdbm']
-                        if self.compiler_obj.find_library_file(lib_dirs,
+                        if self.compiler.find_library_file(lib_dirs,
                                                                'gdbm_compat'):
                             gdbm_libs.append('gdbm_compat')
                         if find_file("gdbm/ndbm.h", inc_dirs, []) is not None:
@@ -1070,7 +1071,7 @@
 
         # Anthony Baxter's gdbm module.  GNU dbm(3) will require -lgdbm:
         if ('gdbm' in dbm_order and
-            self.compiler_obj.find_library_file(lib_dirs, 'gdbm')):
+            self.compiler.find_library_file(lib_dirs, 'gdbm')):
             exts.append( Extension('_gdbm', ['_gdbmmodule.c'],
                                    libraries = ['gdbm'] ) )
         else:
@@ -1086,7 +1087,7 @@
             # Sun yellow pages. Some systems have the functions in libc.
             if (platform not in ['cygwin', 'qnx6'] and
                 find_file('rpcsvc/yp_prot.h', inc_dirs, []) is not None):
-                if (self.compiler_obj.find_library_file(lib_dirs, 'nsl')):
+                if (self.compiler.find_library_file(lib_dirs, 'nsl')):
                     libs = ['nsl']
                 else:
                     libs = []
@@ -1111,9 +1112,9 @@
         elif curses_library == 'curses' and platform != 'darwin':
                 # OSX has an old Berkeley curses, not good enough for
                 # the _curses module.
-            if (self.compiler_obj.find_library_file(lib_dirs, 'terminfo')):
+            if (self.compiler.find_library_file(lib_dirs, 'terminfo')):
                 curses_libs = ['curses', 'terminfo']
-            elif (self.compiler_obj.find_library_file(lib_dirs, 'termcap')):
+            elif (self.compiler.find_library_file(lib_dirs, 'termcap')):
                 curses_libs = ['curses', 'termcap']
             else:
                 curses_libs = ['curses']
@@ -1125,7 +1126,7 @@
 
         # If the curses module is enabled, check for the panel module
         if (module_enabled(exts, '_curses') and
-            self.compiler_obj.find_library_file(lib_dirs, panel_library)):
+            self.compiler.find_library_file(lib_dirs, panel_library)):
             exts.append( Extension('_curses_panel', ['_curses_panel.c'],
                                    libraries = [panel_library] + curses_libs) )
         else:
@@ -1158,7 +1159,7 @@
                     version = line.split()[2]
                     break
             if version >= version_req:
-                if (self.compiler_obj.find_library_file(lib_dirs, 'z')):
+                if (self.compiler.find_library_file(lib_dirs, 'z')):
                     if sys.platform == "darwin":
                         zlib_extra_link_args = ('-Wl,-search_paths_first',)
                     else:
@@ -1190,7 +1191,7 @@
                                extra_link_args = extra_link_args) )
 
         # Gustavo Niemeyer's bz2 module.
-        if (self.compiler_obj.find_library_file(lib_dirs, 'bz2')):
+        if (self.compiler.find_library_file(lib_dirs, 'bz2')):
             if sys.platform == "darwin":
                 bz2_extra_link_args = ('-Wl,-search_paths_first',)
             else:
@@ -1451,9 +1452,9 @@
         tcllib = tklib = tcl_includes = tk_includes = None
         for version in ['8.6', '86', '8.5', '85', '8.4', '84', '8.3', '83',
                         '8.2', '82', '8.1', '81', '8.0', '80']:
-            tklib = self.compiler_obj.find_library_file(lib_dirs,
+            tklib = self.compiler.find_library_file(lib_dirs,
                                                         'tk' + version)
-            tcllib = self.compiler_obj.find_library_file(lib_dirs,
+            tcllib = self.compiler.find_library_file(lib_dirs,
                                                          'tcl' + version)
             if tklib and tcllib:
                 # Exit the loop when we've found the Tcl/Tk libraries
@@ -1512,11 +1513,11 @@
                 return
 
         # Check for BLT extension
-        if self.compiler_obj.find_library_file(lib_dirs + added_lib_dirs,
+        if self.compiler.find_library_file(lib_dirs + added_lib_dirs,
                                                'BLT8.0'):
             defs.append( ('WITH_BLT', 1) )
             libs.append('BLT8.0')
-        elif self.compiler_obj.find_library_file(lib_dirs + added_lib_dirs,
+        elif self.compiler.find_library_file(lib_dirs + added_lib_dirs,
                                                 'BLT'):
             defs.append( ('WITH_BLT', 1) )
             libs.append('BLT')
@@ -1571,7 +1572,7 @@
                              ]]
 
         # Add .S (preprocessed assembly) to C compiler source extensions.
-        self.compiler_obj.src_extensions.append('.S')
+        self.compiler.src_extensions.append('.S')
 
         include_dirs = [os.path.join(ffi_srcdir, 'include'),
                         os.path.join(ffi_srcdir, 'powerpc')]
@@ -1616,7 +1617,7 @@
                 exec(f.read(), globals(), fficonfig)
 
             # Add .S (preprocessed assembly) to C compiler source extensions.
-            self.compiler_obj.src_extensions.append('.S')
+            self.compiler.src_extensions.append('.S')
 
             include_dirs = [os.path.join(ffi_builddir, 'include'),
                             ffi_builddir,
@@ -1698,7 +1699,7 @@
         ffi_lib = None
         if ffi_inc is not None:
             for lib_name in ('ffi_convenience', 'ffi_pic', 'ffi'):
-                if (self.compiler_obj.find_library_file(lib_dirs, lib_name)):
+                if (self.compiler.find_library_file(lib_dirs, lib_name)):
                     ffi_lib = lib_name
                     break
 


More information about the Python-checkins mailing list